A Pen by weedkiller on CodePen.
Created
July 21, 2018 05:51
-
-
Save weedkiller/d97000baec67c54dc89fb27ce50bf30e to your computer and use it in GitHub Desktop.
I Want My Data Points on the Map - Esri Leaflet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta charset=utf-8 /> | |
<title>I Want My Data Points on the Map - Esri Leaflet</title> | |
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' /> | |
<!-- Load Leaflet CSS from CDN. More info at: http://leafletjs.com/examples/quick-start.html--> | |
<link rel="stylesheet" href="//cdn.jsdelivr.net/leaflet/0.7.3/leaflet.css" /> | |
<!-- Load the Leaflet from CDN. More info at: http://leafletjs.com/examples/quick-start.html--> | |
<script src="//cdn.jsdelivr.net/leaflet/0.7.3/leaflet.js"></script> | |
<!-- Load the Esri Leaflet plugin from CDN. For more info: https://esri.github.io/esri-leaflet/examples/ --> | |
<script src="//cdn.jsdelivr.net/leaflet.esri/1.0.0/esri-leaflet.js"></script> | |
</head> | |
<body> | |
<!-- The following is the div that is acting as a container to hold the map--> | |
<div id="map"></div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Check out more Sample code and API reference at https://esri.github.io/esri-leaflet/examples/ | |
//Adds the map control and sets the center point to Durham and zoom scale to 10. For more info on the Leaflet map control check out: http://leafletjs.com/reference.html#map-class | |
var map = L.map('map').setView([35.9886, -78.9072], 10); //35.9886° N, 78.9072° W | |
//Adds a basemap to the map. To see all the available basemaps: https://esri.github.io/esri-leaflet/api-reference/layers/basemap-layer.html | |
L.esri.basemapLayer('Topographic').addTo(map); | |
//The following line of code adds a number of data points coming from a Esri rest endpoint. The data is farmers markets in Wake County and from: https://data.ral.opendata.arcgis.com/datasets/953ff61e36bd468d8ae267437377fa9c_0.\ . The points are added as a feature layer which means you can see the points on the map and create a popup showing the information about the points. To learn more about feature layers: https://esri.github.io/esri-leaflet/api-reference/layers/feature-layer.html | |
var bikeIcon = L.icon({ | |
//Replace URL on the next line to point to your icon | |
iconUrl: 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/131702/icon_farmersMarket.png', | |
iconSize: [40,30] | |
}); | |
var farmersMarkets = L.esri.featureLayer({ | |
//To add your own data point, replace the url on the next line.. | |
url: 'https://maps.wakegov.com/arcgis/rest/services/Property/CountyFacilities/MapServer/0', | |
pointToLayer: function (geojson, latlng) { | |
return L.marker(latlng, { | |
icon: bikeIcon | |
}); | |
}, | |
}).addTo(map); | |
//The following code turns on popups, which display information about each data point. Simple html is used to connect to the fields in the data. Check out all the fields for the Farmers Market dataset at: http://maps.wakegov.com/arcgis/rest/services/Health/FarmersMkts/MapServer For more info on popups: http://leafletjs.com/reference.html#popup-options | |
farmersMarkets.bindPopup(function(feature) { | |
//To show the fields in your data, replace the field names in the {} to match your data | |
return L.Util.template('<p>{BLDGDESC}<br>{FAC_ADDRESS}<br>{TYPE}</p>', feature.properties); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* CSS to style the whole html page*/ | |
body { | |
margin: 0; | |
padding: 0; | |
} | |
/* CSS to style the map*/ | |
#map { | |
position: absolute; | |
top: 0; | |
bottom: 0; | |
right: 0; | |
left: 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment