-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.html
214 lines (193 loc) · 7.58 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
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Cluster</title>
<link rel="stylesheet" href="http://js.arcgis.com/3.11/dijit/themes/tundra/tundra.css">
<link rel="stylesheet" href="http://js.arcgis.com/3.11/esri/css/esri.css">
<style>
html, body { height: 100%; width: 100%; margin: 0; padding: 0; }
#map{ margin: 0; padding: 0; }
/* center the image in the popup */
.esriViewPopup .gallery { margin: 0 auto !important; }
/* CSS for Cluster Layer */
#clusters_layer > circle { cursor: pointer; }
#clusters_layer > text { cursor: pointer; }
</style>
<script>
// helpful for understanding dojoConfig.packages vs. dojoConfig.paths:
// http://www.sitepen.com/blog/2013/06/20/dojo-faq-what-is-the-difference-packages-vs-paths-vs-aliases/
var dojoConfig = {
paths: {
extras: location.pathname.replace(/\/[^/]+$/, '')
}
};
</script>
<script src="http://js.arcgis.com/3.11/"></script>
<script>
var map;
require([
'dojo/parser',
'dojo/ready',
'dojo/_base/array',
'dojo/_base/Color',
'dojo/dom-style',
'dojo/query',
'esri/map',
'esri/request',
'esri/graphic',
'esri/geometry/Extent',
'esri/symbols/SimpleMarkerSymbol',
'esri/symbols/SimpleLineSymbol',
'esri/symbols/SimpleFillSymbol',
'esri/symbols/PictureMarkerSymbol',
'esri/renderers/ClassBreaksRenderer',
'esri/layers/GraphicsLayer',
'esri/SpatialReference',
'esri/dijit/PopupTemplate',
'esri/geometry/Point',
'esri/geometry/webMercatorUtils',
'extras/ClusterFeatureLayer',
'dijit/layout/BorderContainer',
'dijit/layout/ContentPane',
'dojo/domReady!'
], function(
parser, ready, arrayUtils, Color, domStyle, query,
Map, esriRequest, Graphic, Extent,
SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol, PictureMarkerSymbol, ClassBreaksRenderer,
GraphicsLayer, SpatialReference, PopupTemplate, Point, webMercatorUtils,
ClusterFeatureLayer
) {
ready(function() {
parser.parse();
var clusterLayer;
var popupOptions = {
'markerSymbol': new SimpleMarkerSymbol('circle', 20, null, new Color([0, 0, 0, 0.25])),
'marginLeft': '20',
'marginTop': '20'
};
map = new Map('map', {
basemap: 'gray',
center: [-118.182, 33.913],
zoom: 10
});
map.on('load', function() {
// hide the popup's ZoomTo link as it doesn't make sense for cluster features
domStyle.set(query('a.action.zoomTo')[0], 'display', 'none');
addClusters();
});
function addClusters(resp) {
// popupTemplate to work with attributes specific to this dataset
var popupTemplate = PopupTemplate({
'title': '',
'fieldInfos': [{
'fieldName': 'TRACTCE10',
'label': 'Tract: ',
visible: true
}, {
'fieldName': 'NAME10',
'label': 'Name: ',
visible: true
}]
});
/*
var popupTemplate = PopupTemplate({
'title': '',
'fieldInfos': [{
'fieldName': 'CaseNum',
'label': 'Case Number: ',
visible: true
}, {
'fieldName': 'Block',
'label': 'Block: ',
visible: true
}, {
'fieldName': 'Descrip',
'label': 'Description: ',
visible: true
}]
});
*/
// cluster layer that uses OpenLayers style clustering
// class break renderer service
// http://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/CTAStationStats/FeatureServer/0
// simple renderer service
// http://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/ChicagoCrime/FeatureServer/0
clusterLayer = new ClusterFeatureLayer({
'url': 'http://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/CT2010_pts/FeatureServer/0',
'distance': 100,
'id': 'clusters',
'labelColor': '#fff',
'resolution': map.extent.getWidth() / map.width,
'singleColor': '#888',
'singleTemplate': popupTemplate,
'useDefaultSymbol': true,
'objectIdField': 'FID' // define the objectid field
});
var picBaseUrl = 'http://static.arcgis.com/images/Symbols/Shapes/';
var defaultSym = new PictureMarkerSymbol(picBaseUrl + 'BluePin1LargeB.png', 32, 32).setOffset(0, 15);
var renderer = new ClassBreaksRenderer(defaultSym, 'clusterCount');
var sls = SimpleLineSymbol;
var sms = SimpleMarkerSymbol;
var small = new sms('circle', 20,
new sls(sls.STYLE_SOLID, new Color([255,191,0,0.25]), 15),
new Color([255,191,0,0.5]));
var medium = new sms('circle', 30,
new sls(sls.STYLE_SOLID, new Color([148,0,211,0.25]), 15),
new Color([148,0,211,0.5]));
var large = new sms('circle', 50,
new sls(sls.STYLE_SOLID, new Color([255,0,0,0.25]), 15),
new Color([255,0,0,0.5]));
renderer.addBreak(2, 10, small);
renderer.addBreak(10, 25, medium);
renderer.addBreak(25, 5000, large);
// Providing a ClassBreakRenderer is also optional
//clusterLayer.setRenderer(renderer);
map.addLayer(clusterLayer);
// close the info window when the map is clicked
map.on('click', cleanUp);
// close the info window when esc is pressed
map.on('key-down', function(e) {
if (e.keyCode === 27) {
cleanUp();
}
});
}
function cleanUp() {
map.infoWindow.hide();
//clusterLayer.clearSingles();
}
function error(err) {
console.log('something failed: ', err);
}
// show cluster extents...
// never called directly but useful from the console
window.showExtents = function() {
var extents = map.getLayer('clusterExtents');
if ( extents ) {
map.removeLayer(extents);
}
extents = new GraphicsLayer({ id: 'clusterExtents' });
var sym = new SimpleFillSymbol().setColor(new Color([205, 193, 197, 0.5]));
arrayUtils.forEach(clusterLayer._clusters, function(c, idx) {
var e = c.attributes.extent;
extents.add(new Graphic(new Extent(e[0], e[1], e[2], e[3], map.spatialReference), sym));
}, this);
map.addLayer(extents, 0);
}
});
});
</script>
</head>
<body>
<div data-dojo-type="dijit/layout/BorderContainer"
data-dojo-props="design:'headline',gutters:false"
style="width: 100%; height: 100%; margin: 0;">
<div id="map"
data-dojo-type="dijit/layout/ContentPane"
data-dojo-props="region:'center'">
</div>
</div>
</body>
</html>