-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathindex.html
More file actions
364 lines (343 loc) · 13.1 KB
/
index.html
File metadata and controls
364 lines (343 loc) · 13.1 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" />
<!--The viewport meta tag is used to improve the presentation and behavior
of the samples on iOS devices-->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>heatmap.js ArcGIS JavaScript API Heatmap Layer</title>
<link rel="shortcut icon"
type="image/png" href="http://www.patrick-wied.at/img/favicon.png" />
<link rel="stylesheet" type="text/css" href="http://js.arcgis.com/3.10/js/dojo/dijit/themes/claro/claro.css">
<link rel="stylesheet" type="text/css" href="http://js.arcgis.com/3.10/js/esri/css/esri.css" />
<style>
body, html {
margin:0;
padding:0;
font-family:Arial;
}
h1 {
margin-bottom:10px;
}
h2 {
margin-top:0;
}
#main {
position:relative;
width:1020px;
padding:20px;
margin:auto;
}
#heatmapArea {
position:relative;
float:left;
width:800px;
height:600px;
border:1px dashed black;
}
#configArea {
position:relative;
float:left;
width:200px;
padding:15px;
padding-top:0;
padding-right:0;
}
.btn {
margin-top:25px;
padding:10px 20px 10px 20px;
-moz-border-radius:15px;
-o-border-radius:15px;
-webkit-border-radius:15px;
border-radius:15px;
border:2px solid black;
cursor:pointer;
color:white;
background-color:black;
}
#map {
width:800px;
height:600px;
}
#title {
font-family:arial;
display:inline-block;
position:absolute;
font-weight:bold;
font-size:21px;
line-height:28px;
top:20px;
right:20px;
z-index:99;
background:rgba(255, 255, 255, 0.65);
padding:10px 20px;
-webkit-border-radius: 3px;
border-radius: 3px;
text-shadow:1px 1px 1px #FFFFFF -webkit-box-shadow: 2px 2px 2px 0 rgba(0, 0, 0, 0.1);
box-shadow: 2px 2px 2px 0 rgba(0, 0, 0, 0.1);
}
</style>
<link rel="stylesheet" type="text/css" href="http://js.arcgis.com/3.10/js/esri/dijit/css/Popup.css"/>
</head>
<body class="claro">
<div id="main">
<h1>ArcGIS JavaScript API Heatmap Overlay</h1>
<a href="http://www.arcgis.com/home/item.html?id=3a6d8158252e4b96a8ecfb8b912df78d">Download code</a>.
<br
/>
<br />
<div id="heatmapArea">
<div id="heatLayer"></div>
<div id="title">San Francisco 311 incidents</div>
<div id="map"></div>
</div>
<div id="configArea">
<h2>Sidenotes</h2>
This is a demonstration of a canvas heatmap overlay with the <a href="http://help.arcgis.com/en/webapi/javascript/arcgis/"
target="_blank">ArcGIS API for JavaScript</a>.
<br />
<br />View the <a href="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/MapServer/0"
target="_blank">Feature layer</a>.
<div id="tog" class="btn">Toggle HeatmapOverlay</div>
<div id="tog2" class="btn">Toggle Points</div>
<div id="tog3" class="btn">Local Max Off</div>
</div>
<div style="text-align:center;"><a href="http://www.patrick-wied.at/static/heatmapjs/">heatmap.js</a> by
<a
href="http://www.patrick-wied.at" target="_blank">Patrick Wied</a>
</div>
</div>
<div style="clear:both;"></div>
<div style="width:1020px; padding:20px; margin:auto;">
<h2>Description</h2>
<p>This is a custom DynamicMapServiceLayer for Heatmap.js to work with the
ArcGIS Javascript API.</p>
<h2>Instructions</h2>
<ol>
<li>Include the heatmap.js in your HTML document and require "application/HeatmapLayer" <pre>
<script type="text/javascript" src="src/heatmap.js"></script>
</pre>
</li>
<li>Add a div with an ID to hold he canvas element <pre><div id="heatLayer"></div></pre>
</li>
<li>Create the heatmap with it's settings and assign it to a global variable. <pre>
// create heat layer
heatLayer = new HeatmapLayer({
config: {
"useLocalMaximum": false,
"radius": 40,
"gradient": {
0.45: "rgb(000,000,255)",
0.55: "rgb(000,255,255)",
0.65: "rgb(000,255,000)",
0.95: "rgb(255,255,000)",
1.00: "rgb(255,000,000)"
}
},
"map": map,
"opacity": 0.85
}, "heatLayer");
</pre>
</li>
<li>Add the heatLayer to the map. <pre>
map.addLayer(heatLayer);
</pre>
</li>
<li>Now you just need to add data points to the heatmap. In the example above,
I am adding features from a feature layer of 311 incidents. Here's an example with
two features. <pre>
var data = [
{
attributes: {},
geometry: {
spatialReference: {wkid: 102100}
type: "point"
x: -13625078.0408
y: 4548494.332400002
}
},
{
attributes: {},
geometry: {
spatialReference: {wkid: 102100}
type: "point"
x: -13625078.0408
y: 4548494.332400002
}
}
];
</pre>
<pre>
heatLayer.setData(data);
</pre>
</li>
<li>I created a function that executes on map pan that gets all the features
from a featureLayer within the map's extent.
<pre>
function getFeatures() {
// set up query
var q = new Query();
// only within extent
q.geometry = map.extent;
// give me all of them!
q.where = "1=1";
// make sure I get them back in my spatial reference
q.outSpatialReference = map.spatialReference;
// get em!
featureLayer.queryFeatures(q, function (featureSet) {
var data = [];
// if we get results back
if (featureSet && featureSet.features && featureSet.features.length > 0) {
// set data to features
data = featureSet.features;
}
// set heatmap data
heatLayer.setData(data);
});
}
</pre>
</li>
</ol>
<h2>Dependencies</h2>
<ul>
<li>HTML5 Canvas
<iframe src="http://caniuse.com/canvas/embed/" width="1020"
scrolling="no" frameborder="0" height="400"></iframe>
</li>
<li> <a href="http://www.patrick-wied.at/static/heatmapjs/">Heatmap.js</a>
</li>
</ul>
</div>
</body>
<script type="text/javascript">
// get current path
var pathRegex = new RegExp(/\/[^\/]+$/);
var locationPath = location.pathname.replace(pathRegex, '');
// Dojo Config
var dojoConfig = {
packages: [
{
name: "application",
location: locationPath + 'src/'
}
]
};
</script>
<script type="text/javascript" src="http://js.arcgis.com/3.10/"></script>
<script type="text/javascript" src="src/heatmap.js"></script>
<script type="text/javascript">
require([
"esri/map",
"dojo/on",
"dojo/dom",
"esri/layers/FeatureLayer",
"application/HeatmapLayer",
"esri/tasks/query",
"esri/geometry/Extent",
"dojo/domReady!"
], function(
Map,
on,
dom,
FeatureLayer,
HeatmapLayer,
Query,
Extent
){
// Variables
var map;
var heatLayer;
var featureLayer;
// get the features within the current extent from the feature layer
function getFeatures() {
// set up query
var q = new Query();
// only within extent
q.geometry = map.extent;
// give me all of them!
q.where = "1=1";
// make sure I get them back in my spatial reference
q.outSpatialReference = map.spatialReference;
// get em!
featureLayer.queryFeatures(q, function (featureSet) {
var data = [];
// if we get results back
if (featureSet && featureSet.features && featureSet.features.length) {
// set data to features
data = featureSet.features;
}
// set heatmap data
heatLayer.setData(data);
});
}
// initial extent of map
var initExtent = new Extent({
xmax: -13624229.32056175,
xmin: -13625120.886837104,
ymax: 4548374.604660432,
ymin: 4547966.144290476,
"spatialReference": {
"wkid": 102100
}
});
// create map
map = new Map("map", {
extent: initExtent,
sliderStyle: "small",
basemap: "streets"
});
// create heat layer
heatLayer = new HeatmapLayer({
"useLocalMaximum": false,
config: {
"radius": 40,
"gradient": {
0.45: "rgb(000,000,255)",
0.55: "rgb(000,255,255)",
0.65: "rgb(000,255,000)",
0.95: "rgb(255,255,000)",
1.00: "rgb(255,000,000)"
}
},
"map": map,
"opacity": 0.85
}, "heatLayer");
// add heat layer to map
map.addLayer(heatLayer);
// resize map
map.resize();
// create feature layer to get the points from
featureLayer = new FeatureLayer("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/MapServer/0", {
mode: FeatureLayer.MODE_ONDEMAND,
visible: false
});
map.addLayer(featureLayer);
// on map extent change
on(map, "extent-change", getFeatures);
on(dom.byId('tog'), "click", function () {
if (heatLayer.visible) {
heatLayer.hide();
} else {
heatLayer.show();
}
});
on(dom.byId('tog2'), "click", function () {
if (featureLayer.visible) {
featureLayer.hide();
} else {
featureLayer.show();
}
});
on(dom.byId('tog3'), "click", function () {
if (heatLayer.config.useLocalMaximum) {
this.innerHTML = 'Local Max Off';
heatLayer.config.useLocalMaximum = false;
} else {
this.innerHTML = 'Local Max On';
heatLayer.config.useLocalMaximum = true;
}
});
});
</script>
</html>