forked from ssylvia/cluster-layer-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.html
executable file
·210 lines (185 loc) · 6.26 KB
/
default.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7,IE=9">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Default Cluster Layer</title>
<link rel="shortcut icon" href="//esri.github.io/quickstart-map-js/images/favicon.ico">
<!-- ArcGIS API for JavaScript CSS-->
<link rel="stylesheet" href="https://js.arcgis.com/3.15/esri/css/esri.css">
<style>
html, body, #mapDiv {
height: 100%;
width: 100%;
margin: 0;
background-color: rgb(34, 35, 39);
}
#search {
display: block;
position: absolute;
z-index: 2;
top: 19px;
left: 62px;
}
#homeButton {
position: absolute;
top: 95px;
left: 16px;
z-index: 50;
}
.HomeButton .home {
width: 27px;
height: 27px;
}
/* Geocoder */
.simpleGeocoder .esriGeocoderContainer {
width: 225px;
}
/* Zoom buttons */
.esriSimpleSliderTL {
left: 16px;
}
/* Popup */
.esriPopup.light .contentPane {
padding-top: 0;
}
.esriPopup.light .contentPane > p {
margin: 5px 0;
}
</style>
<script type="text/javascript">
window.dojoConfig = {
async: true,
packages: [
{
name: 'app',
location: window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/')) + '/src'
}
]};
</script>
<!-- ArcGIS API for JavaScript library references -->
<script src="https://js.arcgis.com/3.15compact"></script>
<script>
require(["esri/map",
"esri/dijit/Geocoder",
"esri/dijit/HomeButton",
"esri/InfoTemplate",
"esri/graphic",
"app/clusterfeaturelayer",
"dojo/domReady!"],
function (Map, Geocoder, HomeButton, InfoTemplate, Graphic, ClusterFeatureLayer) {
// Locals
var map,
popup,
clusterLayer,
geocoder,
infoTemplate,
selectedSym;
// Create map
map = new Map("mapDiv", {
basemap: "dark-gray",
center: [-43, 40],
zoom: 3
});
// Add clusters
map.on("load", function () {
// Add layer
addClusterLayer();
addClusterLayerEvents();
});
// Save the last selected graphic
map.infoWindow.on("selection-change", function () {
addSelectedFeature();
});
// Create widget
geocoder = new Geocoder({
value: "Washington, D. C., District of Columbia, United States",
autoNavigate: true,
maxLocations: 25,
autoComplete: true,
arcgisGeocoder: {
outFields: "Place_addr, PlaceName, Score"
},
map: map
}, "search");
geocoder.startup();
var home = new HomeButton({
map: map
}, "homeButton");
home.startup();
// Set popup
popup = map.infoWindow;
popup.highlight = false;
popup.titleInBody = false;
popup.domNode.className += " light";
// Popup content
infoTemplate = new InfoTemplate("<b>City Data</b>", "<p>NAME: ${CITY_NAME}</p><p>COUNTRY: ${CNTRY_NAME}</p><p>CAPITAL: ${ADMIN_NAME}</p><p>POPULATION: ${POP}</p>");
// Create a feature layer to get feature service
function addClusterLayer() {
clusterLayer = new ClusterFeatureLayer({
"url": "http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/World_Cities/FeatureServer/0",
"distance": 75,
"id": "clusters",
"labelColor": "#fff",
"resolution": map.extent.getWidth() / map.width,
"singleTemplate": infoTemplate,
"useDefaultSymbol": false,
"zoomOnClick": true,
"showSingles": true,
"objectIdField": "FID",
outFields: ["CITY_NAME", "CNTRY_NAME", "POP", "ADMIN_NAME"]
});
map.addLayer(clusterLayer);
}
// Hide popup if selected feature is clustered
function onClustersShown(clusters) {
var i = 0,
extent;
if (map.infoWindow.isShowing && map.infoWindow._lastSelected) {
for (i; i < clusters.length; i++) {
if (clusters[i].attributes.clusterCount > 1) {
extent = clusterLayer._getClusterExtent(clusters[i]);
if (extent.contains(map.infoWindow._lastSelected.geometry)) {
map.infoWindow.hide();
break;
}
}
}
}
}
// Wire cluster layer events
function addClusterLayerEvents() {
// Clusters drawn
clusterLayer.on("clusters-shown", onClustersShown);
}
// Set selected
function addSelectedFeature() {
var selIndex = map.infoWindow.selectedIndex,
selFeature;
if (selIndex !== -1) {
selFeature = map.infoWindow.features[selIndex];
// Remove old feature first
removeSelectedFeature();
// Add new graphic
map.infoWindow._lastSelected = new Graphic(selFeature.toJson());
map.infoWindow._lastSelected.setSymbol(selectedSym);
map.graphics.add(map.infoWindow._lastSelected);
}
}
// Remove selected
function removeSelectedFeature() {
if (map.infoWindow._lastSelected) {
map.graphics.remove(map.infoWindow._lastSelected);
map.infoWindow._lastSelected = null;
}
}
});
</script>
</head>
<body>
<div id="mapDiv"></div>
<div id="search"></div>
<div id="homeButton"></div>
</body>
</html>