-
Notifications
You must be signed in to change notification settings - Fork 79
/
index.html
75 lines (62 loc) · 2.01 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Esri Leaflet and Turf</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/[email protected]/dist/leaflet.css" />
<script src="https://unpkg.com/[email protected]/dist/leaflet-src.js"></script>
<!-- Load Esri Leaflet from CDN -->
<script src="https://unpkg.com/[email protected]"></script>
<!-- Load turf -->
<script src="https://api.tiles.mapbox.com/mapbox.js/plugins/turf/v2.0.0/turf.min.js"></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');
map.setView([34, -118], 10);
// create a variable to represent the location of the end user
var userLocation;
L.esri.basemapLayer('DarkGray').addTo(map);
// ask leaflet to use HTML5 to query the user location
map.locate({
setView: true
});
// listen for the result of that asynchronous method
map.on('locationfound', function(evt) {
// construct the GeoJSON once we know where they are
userLocation = turf.point([evt.latlng.lng, evt.latlng.lat]);
// now lets see what census block the user is inside of
var censusBlocks = L.esri.featureLayer({
url: 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/1',
style: wereStylin
}).addTo(map);
});
function wereStylin (feature) {
// only show the census block the user is inside of
if (userLocation && turf.inside(userLocation, feature) ) {
return {
fillOpacity: 0.2,
opacity: 0.5
}
}
else {
return {
fillOpacity: 0,
opacity: 0
}
}
}
</script>
</body>
</html>