Guest User

Untitled

a guest
Apr 26th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. /*
  2. * This example shows how to add a layer list to a map where users can check and
  3. * and uncheck a box to show and hide a GeoJSON layer. This snippet assumes
  4. * the map (map), basemap (streets), and GeoJSON (myLayerData) have already been
  5. * declared.
  6. */
  7.  
  8. // create an operational layer that is empty for now
  9. let myLayer = L.layerGroup().addTo(map)
  10.  
  11. // add all of the GeoJSON data to the empty layer we created
  12. function addMyData (feature, layer) {
  13. myLayer.addLayer(layer)
  14. // some other code can go here, like adding a popup with layer.bindPopup("Hello")
  15. }
  16.  
  17. // create an options object that specifies which function to call on each feature
  18. let myLayerOptions = {
  19. onEachFeature: addMyData
  20. }
  21.  
  22. // create the GeoJSON layer from myLayerData
  23. L.geoJSON(myLayerData, myLayerOptions).addTo(map)
  24.  
  25. // an object containing a list of basemaps (makes more sense to use with multiple basemaps)
  26. let basemaps = {
  27. 'My Basemap': streets // replace streets with your basemap object, not shown in this snippet
  28. }
  29.  
  30. // an object containing a list of operation layers
  31. let layers = {
  32. 'My Layer': myLayer
  33. }
  34.  
  35. L.control.layers(basemaps, layers).addTo(map)
Add Comment
Please, Sign In to add comment