css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <!-- container for map -->
<div id="map"></div>
            
          
!
            
              html,
body,
#map {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
}
            
          
!
            
              "use strict";

// Create Map object
var map = L.map("map", {
  center: [40.15, -77.25], // set center coordinates for map
  zoom: 10 // set initial zoom level for map
});

// Add Open Street Map as the basemap
var osm = L.tileLayer("//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
  attribution:
    '&#169; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, CC BY-SA license'
}).addTo(map);

/*** Logic related to Esri Leaflet Geocoder Plugin ***/
// the search widget that will be hooked into the leaflet map
var searchControl;

// a layer group containing the results of a query against a geocoding service and/or feature layer (map/feature service)
var searchResults = L.layerGroup().addTo(map);

// the coordinate bounding box in which we will search for addresses/features
// this prevents from searching addresses in Europe if you're only interested in the United States, for example
var searchBounds = L.latLngBounds(
  [39.803052, -77.820029],
  [40.45317, -76.799358]
);

// Providers - the geocoding services and map/feature services that users can search against
// ArcGIS Online default geocoding service
var agolProvider = L.esri.Geocoding.arcgisOnlineProvider({
  // results from this provider will be listed under the label property
  label: "ArcGIS Online World Geocoding Service",
  // limit the number of results from this provider
  maxResults: 6
});

// Cumberland County Road Centerlines
// suggestions must be enabled on a custom gecoding service for matching results to show up in search control
// suggestions are not enabled for this service
var ccpaProvider = L.esri.Geocoding.geocodeServiceProvider({
  label: "Cumberland County Composite Locator",
  maxResults: 6,
  // this will add an attribution to the map
  attribution: "Cumberland County",
  // url for the geocoding service
  url:
    "//gis.ccpa.net/arcgiswebadaptor/rest/services/Composite_Address_Locator/GeocodeServer"
});

// Schools map service
var schoolsLayer = L.esri.Geocoding.featureLayerProvider({
  // url for the map/feature service
  url: "//gis.ccpa.net/arcgiswebadaptor/rest/services/911/MapServer/7",
  // limit which fields can be queried against
  searchFields: ["Name", "Address1", "City"],
  // define a function for how the matching features will be displayed in the results list
  formatSuggestion: function(feature) {
    return (
      feature.properties.Name +
      ", " +
      feature.properties.Address1 +
      ", " +
      feature.properties.City
    );
  },
  label: "Schools" // results will be appear in "Schools" group
});

// instantiate the search control and add to the map
searchControl = L.esri.Geocoding
  .geosearch({
    useMapBounds: false, // do not use extent of map to limit search results
    providers: [agolProvider, ccpaProvider, schoolsLayer], // providers are geocoding services or map/feature services that we can search against
    placeholder: "Search for an address",
    title: "Address Search",
    searchBounds: searchBounds, // limit search results within these coordinates
    zoomToResult: true,
    expanded: true,
    collapseAfterResult: false
  })
  .addTo(map);

// Results event - what happens when a user searches against a provider
searchControl.on("results", function(data) {
  // remove existing results from map
  searchResults.clearLayers();

  // test whether there are any results
  if (data.results.length > 0) {
    // set map view to coordinates of the first item in the results and the zoom level to 18
    map.setView(data.results[0].latlng, 18);

     // create a popup at the coordinates of the result and add the result text to the popup and open it on the map
    var popup = L.popup({ closeOnClick: true })
      .setLatLng(data.results[0].latlng)
      .setContent(data.results[0].text)
      .openOn(map);
  }
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console