-
Notifications
You must be signed in to change notification settings - Fork 79
/
index.html
55 lines (45 loc) · 1.63 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<html>
<head>
<meta charset=utf-8 />
<title>Use html5 geolocation to query</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<!-- Load Leaflet from CDN-->
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.1/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.0.1/dist/leaflet-src.js"></script>
<!-- Load Esri Leaflet from CDN -->
<script src="https://unpkg.com/esri-leaflet@2.0.4"></script>
<style>
body { margin:0; padding:0; }
#mapDiv { position: absolute; top:0; bottom:0; right:0; left:0; }
</style>
</head>
<body>
<div id="mapDiv"></div>
<script>
// html5 geolocation requires a secure connection
if (window.location.hostname != 'localhost' && window.location.protocol != "https:") {
window.location.protocol = "https";
}
var map = L.map('mapDiv').setView([34, -118], 10);
L.esri.basemapLayer('DarkGray').addTo(map);
// ask leaflet to use HTML5 to query the user location
map.locate();
// listen for the result of that asynchronous method
map.on('locationfound', function(evt) {
// construct a query object
var censusBlocks = L.esri.query({
url: 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/1'
});
// pass it the user's current location
censusBlocks.intersects(evt.latlng);
// execute the spatial query
censusBlocks.run(function(error, intersectingBlocks){
// add the GeoJson to the map
var blockLayer = L.geoJSON(intersectingBlocks).addTo(map);
// and update the map extent
map.fitBounds(blockLayer.getBounds())
});
});
</script>
</body>
</html>