forked from hakimel/reveal.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hexbindemo.html
76 lines (67 loc) · 2.06 KB
/
hexbindemo.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
76
<html>
<head>
<meta charset=utf-8 />
<title>Esri Leaflet Quickstart</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<!-- Load Leaflet from CDN-->
<link rel="stylesheet" href="//cdn.jsdelivr.net/leaflet/0.7.3/leaflet.css" />
<script src="//cdn.jsdelivr.net/leaflet/0.7.3/leaflet.js"></script>
<!-- Load Esri Leaflet from CDN -->
<script src="//cdn-geoweb.s3.amazonaws.com/esri-leaflet/1.0.0-rc.6/esri-leaflet.js"></script>
<!-- Load Turf from CDN -->
<script src="//api.tiles.mapbox.com/mapbox.js/plugins/turf/v2.0.0/turf.min.js"></script>
<style>
body {margin:0;padding:0;}
#map {position: absolute;top:0;bottom:0;right:0;left:0;}
</style>
</head>
<body>
<div id="map"></div>
<script>
var map = L.map('map').setView([45.53, -122.64], 13);
var url = "http://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/services/Heritage_Trees_Portland/FeatureServer/0";
var tiles = new L.esri.BasemapLayer('Topographic').addTo(map);
L.esri.Tasks.query({
url: url
}).run(function (error, trees, response) {
var extent = turf.extent(trees);
var grid = turf.hexGrid(extent, .25, "miles");
var count = turf.count(grid, trees, 'count');
L.geoJson(count, {
filter: function(feature){
return feature.properties.count;
},
style: function(feature, layer){
var color = '#f2f0f7';
var count = feature.properties.count;
if(count === 0){
return {
opacity: 0,
fillOpacity: 0
}
}
if(count > 1 && count < 4){
color = "#cbc9e2";
}
if(count >= 4 && count < 6){
color = "#9e9ac8";
}
if(count >= 6){
var color = "#6a51a3";
}
return {
weight: 1,
opacity: .25,
color: "#333",
fillColor: color,
fillOpacity: 0.75
}
},
onEachFeature: function(feature, layer){
layer.bindPopup(feature.properties.count + "");
}
}).addTo(map);
});
</script>
</body>
</html>