-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
508 lines (437 loc) · 17.1 KB
/
main.js
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
dojo.require("esri.map");
dojo.require("esri.layers.FeatureLayer");
dojo.require("dojox.widget.TitleGroup");
dojo.require("dijit.TitlePane");
dojo.require("dijit.form.Button");
dojo.require("dijit.layout.AccordionContainer");
dojo.require("dojo.parser");
dojo.require("dijit.form.Textarea");
dojo.require("dijit.form.DropDownButton");
dojo.require("dijit.TooltipDialog");
dojo.require("dijit.form.TextBox");
dojo.require("esri.layers.osm");
dojo.require("dijit.form.DropDownButton");
dojo.require("esri.dijit.Scalebar");
dojo.require("esri.dijit.Legend");
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.ContentPane");
dojo.require("esri.tasks.query");
dojo.require("dojox.charting.themes.Julie");
dojo.require("esri.tasks.geometry");
dojo.require("esri.dijit.Popup");
dojo.require("dijit.dijit");
dojo.require("esri.virtualearth.VETiledLayer");
dojo.require("esri.dijit.BasemapGallery");
dojo.require("esri.arcgis.utils");
dojo.require("dijit.Tooltip");
dojo.require("dijit.form.Slider");
dojo.require("dojo.fx");
var breakCount = 0; // keep track of how many individual breaks have been created, used to fetch the correct field values
var featureLayer; // the active data overlay
var diagramLayer; // the active clickable diagram layer
var map, queryTask, query, template, disconHandler;
var attributeFields = ["Kreisname", "'2010$'.Lebendgeborene", "'2010$'.Gestorbene", "Tabelle1$.Fortgezogene", "Katholisch", "'2005$'.Leistungsempfänger Pflegeversicherung I"]; // used fields from the raw data
var diagramFields = new Array(attributeFields.length);
var activeLayer = 1; // which layer is active at the beginning
var legend;
/**
* at this point the min and max values have to be entered manually for each layer.
* this is not a good approach, they should be obtained directly from the data on the server
* please change this!
*/
var maxValues = [0, 5107, 7552, 23852];
var minValues = [0, 1031, 1382, 3432];
/**
* due to a bug in ArcGIS where invoking any method that re-centers the map a onPan() event is fired,
* this counter is used to prevent an infinite loop of re-centering between the two maps in split-mode.
*/
var counter = 0;
function init() {
addTooltips(); //the mouse-over tooltips are created programmatically
initDiagramFields(); //initialize which fields should be used for which diagram layer
var popup = new esri.dijit.Popup(null, dojo.create("div")); //init popups for diagrams
esri.config.defaults.io.proxyUrl = "/arcgisserver/apis/javascript/proxy/proxy.ashx";
var extent = new esri.geometry.Extent(413447, 6487669, 1269542, 7099165, new esri.SpatialReference({
wkid: 102100
})); //initial map extent
for (var i = 0; i < parent.frames.length; i++) {
if (parent.frames[i].name != self.name) {
extent = parent.frames[i].map.extent; //in split-mode get extent from other map
}
}
map = new esri.Map("map", {
extent: extent,
infoWindow: popup,
slider: true
});
createBasemapGallery();
//add Layer overlay
dojo.connect(map, "onLoad", initOperationalLayer);
//various map events
dojo.connect(map, "onPanEnd", reLocate);
dojo.connect(map, "onZoomEnd", reLocate);
dojo.connect(map, "onMouseDown", function () {
for (var i = 0; i < parent.frames.length; i++) {
parent.frames[i].counter = 0; //the counter is used if any pan related events occured onMouseDown
}
});
dojo.connect(map, "onMouseWheel", function () {
for (var i = 0; i < parent.frames.length; i++) {
parent.frames[i].counter = 0;
}
});
dojo.connect(map, 'onLayersAddResult', function (results) {
var layerInfo = dojo.map(results, function (layer, index) {
return {
layer: layer.layer,
title: layer.layer.name
};
});
//add the legend
legend = new esri.dijit.Legend({
map: map,
layerInfos: layerInfo
}, "legend");
legend.startup();
});
//resize the map when the browser resizes (CAUSES BUGS, this causes the map to randomly zoom on split mode creation)
var resizeTimer;
dojo.connect(dijit.byId('map'), 'resize', function() { //resize the map if the div is resized
clearTimeout(resizeTimer);
resizeTimer = setTimeout( function() {
//map.resize();
map.reposition();
}, 500);
});
//Scalebar
dojo.connect(map, 'onLoad', function (theMap) {
var scalebar = new esri.dijit.Scalebar({
map: map,
scalebarUnit: 'metric',
attachTo: "bottom-left"
});
//dojo.connect(dijit.byId('map'), 'resize', map, map.resize);
});
//Baselayer
tiledMapServiceLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");
osmLayer = new esri.layers.OpenStreetMapLayer();
map.addLayer(osmLayer);
onLoadCheck();
initialColorization();
reLocate();
}
function createBasemapGallery() {
//add the basemap gallery, in this case we'll display maps from ArcGIS.com including bing maps
var basemapGallery = new esri.dijit.BasemapGallery({
showArcGISBasemaps: true,
bingMapsKey: 'Enter Bing Maps Key',
map: map
}, "basemapGallery");
basemapGallery.startup();
dojo.connect(basemapGallery, "onError", function (msg) {
console.log(msg)
});
}
/**
* opacity für FeatureLayer
*/
function setFeatureLayerOpacity(opacity) {
featureLayer.setOpacity(opacity);
}
function initDiagramFields() {
diagramFields[4] = new Array(4);
diagramFields[4][1] = "Katholisch";
diagramFields[4][2] = "Evangelisc";
diagramFields[4][3] = "Andere";
diagramFields[4][4] = "Keine";
diagramFields[5] = new Array(3);
diagramFields[5][1] = "'2005$'.Leistungsempfänger Pflegeversicherung I";
diagramFields[5][2] = "'2005$'.Leistungsempfänger Pflegeversicherung II";
diagramFields[5][3] = "'2005$'.Leistungsempfänger Pflegeversicherung III";
}
/**
* FeatureLayer Overlay
*/
function initOperationalLayer() {
featureLayer = new esri.layers.FeatureLayer("http://giv-learn.uni-muenster.de/ArcGIS/rest/services/LWL/lwl_collection/MapServer/" + activeLayer, {
mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
outFields: ["*"], //use all available fields in the data
opacity: .50
});
featureLayer.setSelectionSymbol(new esri.symbol.SimpleFillSymbol());
map.addLayers([featureLayer]);
}
/**
* see http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp_start.htm#jshelp/best_practices_feature_layers.htm
* since changed API version to 2.7 this is method not used anymore
*/
function calcOffset() {
return (map.extent.getWidth() / map.width);
}
/**
* additionally to the standard overlay, this can add an invisible,
* but clickable diagram layer
*/
function initDiagramLayer() {
diagramLayer = new esri.layers.FeatureLayer("http://giv-learn.uni-muenster.de/ArcGIS/rest/services/LWL/lwl_collection/MapServer/" + activeLayer, {
mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
outFields: ["*"],
opacity: .0
});
diagramLayer.setSelectionSymbol(new esri.symbol.SimpleFillSymbol());
map.addLayers([diagramLayer]);
}
/**
* Creates a QueryTask to show diagrams on certain layers onClick
*/
function connectDiagramFunc(layerNr) {
disconHandler = dojo.connect(map, "onClick", executeQueryTask);
queryTask = new esri.tasks.QueryTask("http://giv-learn.uni-muenster.de/ArcGIS/rest/services/LWL/lwl_collection/MapServer/" + layerNr);
query = new esri.tasks.Query();
query.returnGeometry = true;
query.outFields = ["*"];
query.outSpatialReference = map.spatialReference;
query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;
var diagramF = new Array(diagramFields[layerNr].length - 1);
for (i = 0; i < diagramFields[layerNr].length - 1; i++) {
diagramF[i] = diagramFields[layerNr][i + 1];
}
//Reference the chart theme here too
template = new esri.dijit.PopupTemplate({
title: "Verteilung in {Kreisname}",
mediaInfos: [{
type: "piechart",
value: {
fields: diagramF,
theme: "Julie"
}
}]
});
}
/**
* This method can assign a new color scheme to a layer
* as used for individual breaks
*/
function colorChange(count) {
symbol = new esri.symbol.SimpleFillSymbol();
symbol.setColor(new dojo.Color([150, 150, 150, 0.75]));
var renderer = new esri.renderer.ClassBreaksRenderer(symbol, attributeFields[activeLayer]);
for (var i = 1; i <= breakCount; i++) {
var element = document.getElementById("breakFrom" + i);
if (element) {
renderer.addBreak(document.getElementById("breakFrom" + i).value,
document.getElementById("breakTo" + i).value,
new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color("#" + document.getElementById("cp" + i).value)));
}
}
featureLayer.setRenderer(renderer);
featureLayer.refresh();
legend.refresh();
}
/**
* This method is used to initially set classes - only used at startup!
*/
function initialColorization(){
addEqualBreaks(3, "FF0000", "00FF00");
}
/**
* Method for changing the active overlay layer
*/
function layerChange(layerNr) {
//disconnect and connect click handlers for diagrams based on checkboxes
if (layerNr == 4 && !(document.getElementById("religionChk").checked)) {
dojo.disconnect(disconHandler);
map.removeLayer(diagramLayer);
diagramLayer = null;
} else if (layerNr == 4 && document.getElementById("religionChk").checked) {
dojo.disconnect(disconHandler);
connectDiagramFunc(layerNr);
document.getElementById("pflegehilfeChk").checked = false;
if (diagramLayer != null) {
map.removeLayer(diagramLayer);
diagramLayer = null;
}
initDiagramLayer();
} else if (layerNr == 5 && !(document.getElementById("pflegehilfeChk").checked)) {
dojo.disconnect(disconHandler);
map.removeLayer(diagramLayer);
diagramLayer = null;
} else if (layerNr == 5 && document.getElementById("pflegehilfeChk").checked) {
dojo.disconnect(disconHandler);
connectDiagramFunc(layerNr);
document.getElementById("religionChk").checked = false;
if (diagramLayer != null) {
map.removeLayer(diagramLayer);
diagramLayer = null;
}
initDiagramLayer();
} else {
//following applies if only a 'normal' layer change happens
activeLayer = layerNr; //setting the new layer
var d = document.getElementById("breaksPane_pane");
var olddiv = document.getElementById("Breaks");
d.removeChild(olddiv); //remove previously made class breaks
var addBreaksTable = document.createElement("table");
addBreaksTable.setAttribute("id", "Breaks");
d.appendChild(addBreaksTable);
breakCount = 0;
legend.destroy();
var legendDiv = document.getElementById("legendDiv");
var leg = document.createElement("div");
leg.setAttribute("id", "legend");
legendDiv.appendChild(leg);
map.removeLayer(featureLayer);
featureLayer = null;
initOperationalLayer();
}
}
/**
* method for automatic (equal) breaks
*/
function addEqualBreaks(number, colorStart, colorEnd) {
var breakStep = (maxValues[activeLayer] - minValues[activeLayer]) / (number);
var colorArray = generateColor(colorStart, colorEnd, number-1);
colorArray.reverse();
symbol = new esri.symbol.SimpleFillSymbol();
symbol.setColor(new dojo.Color([150, 150, 150, 0.75]));
var renderer = new esri.renderer.ClassBreaksRenderer(symbol, attributeFields[activeLayer]);
for (var i = 0; i < number; i++) {
renderer.addBreak(Math.round((minValues[activeLayer] + i * breakStep) / 10) * 10,
Math.round((minValues[activeLayer] + (i + 1) * breakStep) / 10) * 10,
new esri.symbol.SimpleFillSymbol().setColor(dojo.colorFromHex('#' + colorArray[i])));
}
var breaksList = document.getElementById("Breaks");
breaksList.innerHTML = '';
breakCount = 0;
featureLayer.setRenderer(renderer);
featureLayer.refresh();
legend.refresh();
}
/**
* executed onClick on a diagram layer
*/
function executeQueryTask(evt) {
query.geometry = evt.mapPoint;
var deferred = queryTask.execute(query);
deferred.addCallback(function (response) {
// response is a FeatureSet
// Let's return an array of features.
return dojo.map(response.features, function (feature) {
feature.setInfoTemplate(template);
return feature;
});
});
// InfoWindow expects an array of features from each deferred
// object that you pass. If the response from the task execution
// above is not an array of features, then you need to add a callback
// like the one above to post-process the response and return an
// array of features.
map.infoWindow.setFeatures([deferred]);
map.infoWindow.show(evt.mapPoint);
}
/**
* called if in split mode one map is panned
*/
function reLocate() {
for (var i = 0; i < parent.frames.length; i++) { //go through all frames and re-center
if (parent.frames[i].name != self.name) {
parent.frames[i].reCenterAndZoom(map.extent.getCenter(), map.getLevel()); //due to the frame problematic this does not work sometimes and causes errors
}
}
}
/**
* in split mode, synchronize zoom levels between both frames
* (not used anymore)
*/
function syncZoom(extent, zoomFactor, anchor, level) {
console.log("zoom from frame" + self.name);
for (var i = 0; i < parent.frames.length; i++) {
if (parent.frames[i].name != self.name) {
try {
console.log("Zoom from syncZoom in frame: " + parent.frames[i].name);
parent.frames[i].counter = 0;
parent.frames[i].map.setLevel(level);
} catch (err) {
console.log("zoom failed");
}
}
}
}
/**
* sync both maps in split mode
* check counter (check if the pan happened through actual mouse input) and
* if the centers of both maps aren't identical
*/
function reCenterAndZoom(center, zoom) {
if (counter < 1 && map.extent.getCenter().x != center.x && map.extent.getCenter().y != center.y) {
if(zoom == map.getLevel()){
map.centerAt(center);
}else{
map.centerAndZoom(center, zoom);
}
}
counter++; //is only reset to zero on onMouseDown()
}
/**
* this method check on page creation if this is in split mode
* if it is then the split-button is removed on the newly created frame
*/
function onLoadCheck() {
if (self.name == "frame2") {
document.getElementById("splitDiv").removeChild(document.getElementById("slideAwayButton_split"));
if(map != null){
//reLocate();
//parent.frames[0].map.setLevel(map.getLevel());
//map.centerAndZoom(parent.frames[0].map.extent.getCenter(), parent.frames[0].map.getLevel());
//map.setLevel(parent.frames[0].map.getLevel());
}
}
}
/**
* programmatically add onMouseOver-tooltips
*/
function addTooltips() {
//GeburtenRate Layer
new dijit.Tooltip({
connectId: ["geburtenrateInfo"],
label: "Diese Ebene zeit an wieviele <br>Geburten es im Jahr 2010 gab.<br><b>Einheit: </b>Anzahl der geborenen Babys",
showDelay: 0
});
//Demographie Layer
new dijit.Tooltip({
connectId: ["demographieInfo"],
label: "Diese Ebene zeigt an wieviele <br>Menschen aus den Bezirken im Jahr <br>2010 weggezogen sind.<br><b>Einheit: </b>Anzahl der Forgezogenen",
showDelay: 0
});
//Sterberate Layer
new dijit.Tooltip({
connectId: ["sterberateInfo"],
label: "Diese Ebene zeigt an wieviele <br>Verstorbene es im Jahr 2010 gab.<br><b>Einheit: </b>Anzahl der Verstorbenen",
showDelay: 0
});
//Religion Layer
new dijit.Tooltip({
connectId: ["religionInfo"],
label: "Diese Ebene zeigt die Religionszugehörigkeit an.<br><br><b>Diese Ebene kann nicht eingefärbt <br>(klassifiziert) werden, durch Klicken auf die <br>Bezirke können Diagramme angezeigt werden.</b>",
showDelay: 0
});
//Pflegehilfe Layer
new dijit.Tooltip({
connectId: ["pflegehilfeInfo"],
label: "Diese Ebene zeigt an wieviele Leistungsempfänger <br>es in den Pflegestufen 1, 2 oder 3 gibt.<br><br><b>Diese Ebene kann nicht eingefärbt <br>(klassifiziert) werden, durch Klicken auf die <br>Bezirke können Diagramme angezeigt werden.</b>",
showDelay: 0
});
//Themenauswahl Menü
new dijit.Tooltip({
connectId: ["themenauswahlInfo"],
label: "In diesem Untermenü kannst du aussuchen,<br>welche Daten als Ebene über die Karte <br>gelegt werden können.",
showDelay: 0
});
//Klasseneinteilung Menü
new dijit.Tooltip({
connectId: ["klasseneinteilungInfo"],
label: "In diesem Untermenü kannst du <br>die Farbgebung der Karte anpassen.",
showDelay: 0
});
}
dojo.addOnLoad(init);