Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
    <title>Old master v1</title>

    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
      #info {
        background-color: black;  
        opacity: 0.75;
        color: orange;
        font-size: 15pt;
        padding: 8px;
        visibility: hidden;
      }
      #controls {
        width: 240px;
        padding: 0px 5px 0px 5px;
          }
       .esri-button {
        margin: 5px 0px 5px 0px;
          }
      
    </style>

    <link rel="stylesheet" href="https://js.arcgis.com/4.22/esri/themes/light/main.css" />
    <script src="https://js.arcgis.com/4.22/"></script>

    <script> //Modules - the entries in 'require' and 'function' must be in the same order
      require([
        "esri/config",
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/FeatureLayer",
        "esri/widgets/Search",
        "esri/widgets/Locate",
        "esri/Graphic",
        "esri/PopupTemplate"
      ],
      function (
        esriConfig,
        Map,
        MapView,
        FeatureLayer,
        Search,
        Locate,
        Graphic,
        PopupTemplate
      
      ) {
        
        esriConfig.apiKey = "AAPKb0d58e35211c4d68a94b36b16d469ec7TVe5HESpcrOBiKcHTTZkbOrcyOMR4YlWsOOkJczMMB63FBVGN4XUDWjzldbHRpha"; //Our API Key
        
          const map = new Map({
          basemap: "osm-standard" // Basemap layer service
          });
        
        const view = new MapView({
          container: "viewDiv",
          map: map,
          center: [-0.435093,53.841965], // Map centre, Longitude, latitude
          zoom: 10,
          highlightOptions: {
            color: "orange"  //Colour of feature highlight
          }
        });
        
        
      // Define a pop-up for Streets layer
      const popupStreets = {
        "title": "Streets",
        "content": "<b>USRN:</b> {SITE_CODE}<br><b>Street Name:</b> {SITE_NAME}<br><b>Town Name:</b> {TOWN_NAME}"
      }
            
       // Streets feature layer
      const streetLayer = new FeatureLayer({
          url: "https://services6.arcgis.com/Qptn479QktK11k72/arcgis/rest/services/New_Achieve_Streets_layer/FeatureServer/0",
          outFields: ["*"],
          popupTemplate: popupStreets
          });

        map.add(streetLayer, 0); //Adds Streets layer to map
        
       
      view.popup.autoOpenEnabled = true;
      view.on("click", (event) => {
      // Get the coordinates of the click on the view
      // around the decimals to 3 decimals
      const x = Math.round(event.mapPoint.x * 1) / 1;
      const y = Math.round(event.mapPoint.y * 1) / 1;
        
  view.popup.open({
    // Set the popup's title to the coordinates of the clicked location
    title: "X, Y Coordinates: [" + x + ", " + y + "]",
    location: event.mapPoint // Set the location of the popup to the clicked location
    
  }); 
       view.popup.content = "TEST", view.popupTemplate
     
});
                    
                
      const search = new Search({  //Search widget
      view: view
    });

        view.ui.add(search, "top-right"); //Adds Search widget to the map
       
        const locate = new Locate({ //Locate widget
          view: view,
          useHeadingEnabled: false,
          goToOverride: function(view, options) {
            options.target.scale = 1500;
            return view.goTo(options.target);
          }
        });
        
        view.ui.add(locate, "top-left"); //Adds Locate widget to the map
          
        view.ui.add("info", "bottom-right");  //Adds Info box to map - box reference in Style
              
        view
          .when()
          .then(() => {
            return streetLayer.when();
          })
          .then((layer) => {
            const renderer = layer.renderer.clone();
            renderer.symbol.width = 20;
            renderer.symbol.color = [128, 128, 128, 0.1];
            layer.renderer = renderer;

          // Set up an event handler pointer-move events (mouse)
            // and retrieve the screen x, y coordinates

            return view.whenLayerView(layer);
        })
            .then((layerView) => {
            view.on("pointer-move", eventHandler);
           
            function eventHandler(event) {
              // only include graphics from streetLayer in the hitTest
              const opts = {
                include: streetLayer
              }
              // the hitTest() checks to see if any graphics from the streetLayer
              // intersect the x, y coordinates of the pointer
              view.hitTest(event, opts).then(getGraphics);
            }

            var highlight, currentName;

            function getGraphics(response) {
              // the topmost graphic from the streetsLayer
              // and display select attribute values from the
              // graphic to the user
              
              if (response.results.length) {
                const graphic = response.results[0].graphic;

                const attributes = graphic.attributes;
                const town = attributes.TOWN_NAME;
                const usrn = attributes.SITE_CODE;
                const name = attributes.SITE_NAME;
                const id = attributes.OBJECTID;
                

                if ( highlight && currentName !== usrn) {
                  highlight.remove();
                  highlight = null;
                  return;
                }

                if (highlight) {
                  return;
                }

                document.getElementById("info").style.visibility = "visible";
                document.getElementById("name").innerHTML = "Street: " + name;
                document.getElementById("town").innerHTML = "Town: " + town;
                document.getElementById("usrn").innerHTML = "USRN: " + usrn;

                // highlight all features belonging to the same street as the feature
                // returned from the hitTest
                const query = layerView.createQuery();
                query.where = "SITE_CODE = '" + usrn + "'";
                layerView.queryObjectIds(query).then((ids) => {
                  if (highlight) {
                    highlight.remove()
                  }
                  highlight = layerView.highlight(ids);
                  currentName = usrn;
                });
              } else {
                // remove the highlight if no features are
                // returned from the hitTest
                if (highlight){
                  highlight.remove();
                  highlight = null;
                }
                document.getElementById("info").style.visibility = "hidden";
              }
           }
          });
        
        view.on("click", function (evt) {
          // Create a graphic and add the geometry and symbol to it
          var graphic = new Graphic({
            geometry: {
              type: "point",
              latitude: evt.mapPoint.latitude,
              longitude: evt.mapPoint.longitude,
              spatialReference: view.spatialReference,
            },
            symbol: {
              type: "simple-marker", // autocasts as new SimpleFillSymbol
              color: [255, 10, 10],
              outline: {
                // autocasts as new SimpleLineSymbol()
                color: [255, 255, 255],
                width: 2,
              },
            },
          });
          view.graphics.removeAll();
          view.graphics.add(graphic);
          });
          
        
        view.ui.add(document.getElementById("controls"), "top-right");   //Adds Reset graphics control to the map
        
        document.getElementById("reset").addEventListener("click", resetGraphics);
        
        function resetGraphics() {
              view.graphics.removeAll();
              
            }
                        
      });
    </script>
  </head>

  <body>
    <div id="viewDiv"></div>
    <div id="info">
      <span id="name"></span> <br />
      <span id="town"></span> <br />
      <span id="usrn"></span>
      
      <div id="controls" class="esri-widget">
       <button id="reset" class="esri-button esri-button--secondary">Remove drop pin</button>
      </div>
  </body>
</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console