|
0
|
1 /*
|
|
|
2 * MapWidget.js
|
|
|
3 *
|
|
|
4 * Copyright (c) 2012, Stefan Jänicke. All rights reserved.
|
|
|
5 *
|
|
|
6 * This library is free software; you can redistribute it and/or
|
|
|
7 * modify it under the terms of the GNU Lesser General Public
|
|
|
8 * License as published by the Free Software Foundation; either
|
|
|
9 * version 3 of the License, or (at your option) any later version.
|
|
|
10 *
|
|
|
11 * This library is distributed in the hope that it will be useful,
|
|
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
14 * Lesser General Public License for more details.
|
|
|
15 *
|
|
|
16 * You should have received a copy of the GNU Lesser General Public
|
|
|
17 * License along with this library; if not, write to the Free Software
|
|
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
19 * MA 02110-1301 USA
|
|
|
20 */
|
|
|
21
|
|
|
22 /**
|
|
|
23 * @class MapWidget
|
|
|
24 * MapWidget Implementation
|
|
|
25 * @author Stefan Jänicke (stjaenicke@informatik.uni-leipzig.de)
|
|
|
26 * @release 1.0
|
|
|
27 * @release date: 2012-07-27
|
|
|
28 * @version date: 2012-07-27
|
|
|
29 *
|
|
|
30 * @param {MapWrapper} core wrapper for interaction to other widgets
|
|
|
31 * @param {HTML object} div parent div to append the map widget div
|
|
|
32 * @param {JSON} options user specified configuration that overwrites options in MapConfig.js
|
|
|
33 */
|
|
|
34 MapWidget = function(core, div, options) {
|
|
|
35
|
|
|
36 this.core = core;
|
|
|
37 this.core.setWidget(this);
|
|
|
38 this.openlayersMap
|
|
|
39 this.baseLayers
|
|
|
40 this.objectLayer
|
|
|
41
|
|
|
42 this.drawPolygon
|
|
|
43 this.drawCircle
|
|
|
44 this.selectCountry
|
|
|
45 this.dragArea
|
|
|
46 this.selectFeature
|
|
|
47 this.navigation
|
|
|
48
|
|
|
49 this.div = div;
|
|
|
50
|
|
|
51 this.iid = GeoTemConfig.getIndependentId('map');
|
|
|
52 this.config = new MapConfig(options);
|
|
|
53 this.options = this.config.options;
|
|
|
54 this.formerCP = this.options.circlePackings;
|
|
|
55 this.gui = new MapGui(this, this.div, this.options, this.iid);
|
|
|
56
|
|
|
57 this.initialize();
|
|
|
58
|
|
|
59 }
|
|
|
60
|
|
|
61 MapWidget.prototype = {
|
|
|
62
|
|
|
63 /**
|
|
|
64 * initializes the map for the Spatio Temporal Interface.
|
|
|
65 * it includes setting up all layers of the map and defines all map specific interaction possibilities
|
|
|
66 */
|
|
|
67 initialize : function() {
|
|
|
68
|
|
|
69 var map = this;
|
|
|
70
|
|
|
71 //OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";
|
|
|
72 if (map.options.proxyHost) {
|
|
|
73 OpenLayers.ProxyHost = map.options.proxyHost;
|
|
|
74 }
|
|
|
75
|
|
|
76 this.polygons = [];
|
|
|
77 this.connections = [];
|
|
|
78 this.selection = new Selection();
|
|
|
79 this.wmsOverlays = [];
|
|
|
80
|
|
|
81 this.layerZIndex = 1;
|
|
|
82 this.zIndices = [];
|
|
|
83
|
|
|
84 var activateDrag = function() {
|
|
|
85 map.dragArea.activate();
|
|
|
86 }
|
|
|
87 var deactivateDrag = function() {
|
|
|
88 map.dragArea.deactivate();
|
|
|
89 }
|
|
|
90 this.dragControl = new MapControl(this, null, 'drag', activateDrag, deactivateDrag);
|
|
|
91
|
|
|
92 /*
|
|
|
93 this.editPolygon = document.createElement("div");
|
|
|
94 this.editPolygon.title = GeoTemConfig.getString('editPolygon');
|
|
|
95 this.editPolygon.setAttribute('class','editMapPolygon');
|
|
|
96 this.toolbar.appendChild(this.editPolygon);
|
|
|
97 this.drag.onclick = function(evt){
|
|
|
98 if( map.activeControl == "drag" ){
|
|
|
99 map.deactivate("drag");
|
|
|
100 if( GeoTemConfig.navigate ){
|
|
|
101 map.activate("navigate");
|
|
|
102 }
|
|
|
103 }
|
|
|
104 else {
|
|
|
105 map.deactivate(map.activControl);
|
|
|
106 map.activate("drag");
|
|
|
107 }
|
|
|
108 }
|
|
|
109 map.addEditingMode(new OpenLayers.Control.EditingMode.PointArraySnapping());
|
|
|
110 */
|
|
|
111
|
|
|
112 this.filterBar = new FilterBar(this, this.gui.filterOptions);
|
|
|
113
|
|
|
114 this.objectLayer = new OpenLayers.Layer.Vector("Data Objects", {
|
|
|
115 projection : "EPSG:4326",
|
|
|
116 'displayInLayerSwitcher' : false,
|
|
|
117 rendererOptions : {
|
|
|
118 zIndexing : true
|
|
|
119 }
|
|
|
120 });
|
|
|
121
|
|
|
122 this.markerLayer = new OpenLayers.Layer.Markers("Markers");
|
|
|
123
|
|
|
124 this.navigation = new OpenLayers.Control.Navigation({
|
|
|
125 zoomWheelEnabled : GeoTemConfig.mouseWheelZoom
|
|
|
126 });
|
|
|
127 this.navigation.defaultDblClick = function(evt) {
|
|
|
128 var newCenter = this.map.getLonLatFromViewPortPx(evt.xy);
|
|
|
129 this.map.setCenter(newCenter, this.map.zoom + 1);
|
|
|
130 map.drawObjectLayer(false);
|
|
|
131 if (map.zoomSlider) {
|
|
|
132 map.zoomSlider.setValue(map.getZoom());
|
|
|
133 }
|
|
|
134 }
|
|
|
135 this.navigation.wheelUp = function(evt) {
|
|
|
136 this.wheelChange(evt, 1);
|
|
|
137 }
|
|
|
138 this.navigation.wheelDown = function(evt) {
|
|
|
139 this.wheelChange(evt, -1);
|
|
|
140 }
|
|
|
141
|
|
|
142 this.resolutions = [78271.516953125, 39135.7584765625, 19567.87923828125, 9783.939619140625, 4891.9698095703125, 2445.9849047851562, 1222.9924523925781, 611.4962261962891, 305.74811309814453, 152.87405654907226, 76.43702827453613, 38.218514137268066, 19.109257068634033, 9.554628534317017, 4.777314267158508, 2.388657133579254, 1.194328566789627, 0.5971642833948135, 0.29858214169740677];
|
|
|
143
|
|
|
144 var options = {
|
|
|
145 controls : [this.navigation],
|
|
|
146 projection : new OpenLayers.Projection("EPSG:900913"),
|
|
|
147 displayProjection : new OpenLayers.Projection("EPSG:4326"),
|
|
|
148 resolutions : this.resolutions,
|
|
|
149 units : 'meters',
|
|
|
150 maxExtent : new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34)
|
|
|
151 };
|
|
|
152 this.openlayersMap = new OpenLayers.Map("mapContainer"+this.iid, options);
|
|
|
153 if (map.options.navigate) {
|
|
|
154 this.activeControl = "navigate";
|
|
|
155 }
|
|
|
156 //add attribution control
|
|
|
157 this.openlayersMap.addControl(new OpenLayers.Control.Attribution());
|
|
|
158 this.mds = new MapDataSource(this, this.options);
|
|
|
159
|
|
|
160 //on zoomend, redraw objects and set slider (if it exists) accordingly (zoom by mouse wheel)
|
|
|
161 this.openlayersMap.events.register("zoomend", map, function(){
|
|
|
162 map.drawObjectLayer(false);
|
|
|
163 if (map.zoomSlider) {
|
|
|
164 map.zoomSlider.setValue(map.getZoom());
|
|
|
165 }
|
|
|
166 map.core.triggerHighlight([]);
|
|
|
167 });
|
|
|
168
|
|
|
169 if (map.options.olNavigation) {
|
|
|
170 var zoomPanel = new OpenLayers.Control.PanZoom();
|
|
|
171 zoomPanel.onButtonClick = function(evt) {
|
|
|
172 var btn = evt.buttonElement;
|
|
|
173 switch (btn.action) {
|
|
|
174 case "panup":
|
|
|
175 this.map.pan(0, -this.getSlideFactor("h"));
|
|
|
176 break;
|
|
|
177 case "pandown":
|
|
|
178 this.map.pan(0, this.getSlideFactor("h"));
|
|
|
179 break;
|
|
|
180 case "panleft":
|
|
|
181 this.map.pan(-this.getSlideFactor("w"), 0);
|
|
|
182 break;
|
|
|
183 case "panright":
|
|
|
184 this.map.pan(this.getSlideFactor("w"), 0);
|
|
|
185 break;
|
|
|
186 case "zoomin":
|
|
|
187 map.zoom(1);
|
|
|
188 break;
|
|
|
189 case "zoomout":
|
|
|
190 map.zoom(-1);
|
|
|
191 break;
|
|
|
192 case "zoomworld":
|
|
|
193 if (this.map) {
|
|
|
194 map.zoom(this.map.zoom * -1);
|
|
|
195 }
|
|
|
196 break;
|
|
|
197 }
|
|
|
198 };
|
|
|
199 this.openlayersMap.addControl(zoomPanel);
|
|
|
200 }
|
|
|
201
|
|
|
202 if (map.options.popups) {
|
|
|
203 var panMap = function() {
|
|
|
204 if (map.selectedGlyph) {
|
|
|
205 var lonlat = new OpenLayers.LonLat(map.selectedGlyph.lon, map.selectedGlyph.lat);
|
|
|
206 var pixel = map.openlayersMap.getPixelFromLonLat(lonlat);
|
|
|
207 if (map.popup) {
|
|
|
208 map.popup.shift(pixel.x, pixel.y);
|
|
|
209 }
|
|
|
210 }
|
|
|
211 }
|
|
|
212 this.openlayersMap.events.register("move", this.openlayersMap, panMap);
|
|
|
213 }
|
|
|
214
|
|
|
215 if (map.options.olMapOverview) {
|
|
|
216 this.openlayersMap.addControl(new OpenLayers.Control.OverviewMap());
|
|
|
217 }
|
|
|
218 if (map.options.olKeyboardDefaults) {
|
|
|
219 var keyboardControl = new OpenLayers.Control.KeyboardDefaults();
|
|
|
220 keyboardControl.defaultKeyPress = function(evt) {
|
|
|
221 switch(evt.keyCode) {
|
|
|
222 case OpenLayers.Event.KEY_LEFT:
|
|
|
223 this.map.pan(-this.slideFactor, 0);
|
|
|
224 break;
|
|
|
225 case OpenLayers.Event.KEY_RIGHT:
|
|
|
226 this.map.pan(this.slideFactor, 0);
|
|
|
227 break;
|
|
|
228 case OpenLayers.Event.KEY_UP:
|
|
|
229 this.map.pan(0, -this.slideFactor);
|
|
|
230 break;
|
|
|
231 case OpenLayers.Event.KEY_DOWN:
|
|
|
232 this.map.pan(0, this.slideFactor);
|
|
|
233 break;
|
|
|
234
|
|
|
235 case 33:
|
|
|
236 // Page Up. Same in all browsers.
|
|
|
237 var size = this.map.getSize();
|
|
|
238 this.map.pan(0, -0.75 * size.h);
|
|
|
239 break;
|
|
|
240 case 34:
|
|
|
241 // Page Down. Same in all browsers.
|
|
|
242 var size = this.map.getSize();
|
|
|
243 this.map.pan(0, 0.75 * size.h);
|
|
|
244 break;
|
|
|
245 case 35:
|
|
|
246 // End. Same in all browsers.
|
|
|
247 var size = this.map.getSize();
|
|
|
248 this.map.pan(0.75 * size.w, 0);
|
|
|
249 break;
|
|
|
250 case 36:
|
|
|
251 // Home. Same in all browsers.
|
|
|
252 var size = this.map.getSize();
|
|
|
253 this.map.pan(-0.75 * size.w, 0);
|
|
|
254 break;
|
|
|
255
|
|
|
256 case 43:
|
|
|
257 // +/= (ASCII), keypad + (ASCII, Opera)
|
|
|
258 case 61:
|
|
|
259 // +/= (Mozilla, Opera, some ASCII)
|
|
|
260 case 187:
|
|
|
261 // +/= (IE)
|
|
|
262 case 107:
|
|
|
263 // keypad + (IE, Mozilla)
|
|
|
264 map.zoom(1);
|
|
|
265 break;
|
|
|
266 case 45:
|
|
|
267 // -/_ (ASCII, Opera), keypad - (ASCII, Opera)
|
|
|
268 case 109:
|
|
|
269 // -/_ (Mozilla), keypad - (Mozilla, IE)
|
|
|
270 case 189:
|
|
|
271 // -/_ (IE)
|
|
|
272 case 95:
|
|
|
273 // -/_ (some ASCII)
|
|
|
274 map.zoom(-1);
|
|
|
275 break;
|
|
|
276 }
|
|
|
277 };
|
|
|
278 this.openlayersMap.addControl(keyboardControl);
|
|
|
279 }
|
|
|
280 if (map.options.olLayerSwitcher) {
|
|
|
281 this.openlayersMap.addControl(new OpenLayers.Control.LayerSwitcher());
|
|
|
282 }
|
|
|
283 if (map.options.olScaleLine) {
|
|
|
284 this.openlayersMap.addControl(new OpenLayers.Control.ScaleLine());
|
|
|
285 }
|
|
|
286 this.gui.resize();
|
|
|
287 this.setBaseLayers();
|
|
|
288 this.gui.setMapsDropdown();
|
|
|
289 this.gui.setMap();
|
|
|
290 this.openlayersMap.addLayers([this.objectLayer, this.markerLayer]);
|
|
|
291
|
|
|
292 if (map.options.boundaries) {
|
|
|
293 var boundaries = map.options.boundaries;
|
|
|
294 var bounds = new OpenLayers.Bounds(boundaries.minLon, boundaries.minLat, boundaries.maxLon, boundaries.maxLat);
|
|
|
295 var projectionBounds = bounds.transform(this.openlayersMap.displayProjection, this.openlayersMap.projection);
|
|
|
296 this.openlayersMap.zoomToExtent(projectionBounds);
|
|
|
297 } else {
|
|
|
298 this.openlayersMap.zoomToMaxExtent();
|
|
|
299 }
|
|
|
300
|
|
|
301 // manages selection of elements if a polygon was drawn
|
|
|
302 this.drawnPolygonHandler = function(polygon) {
|
|
|
303 if (map.mds.getAllObjects() == null) {
|
|
|
304 return;
|
|
|
305 }
|
|
|
306 var polygonFeature;
|
|
|
307 if ( polygon instanceof OpenLayers.Geometry.Polygon) {
|
|
|
308 polygonFeature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.MultiPolygon([polygon]));
|
|
|
309 } else if ( polygon instanceof OpenLayers.Geometry.MultiPolygon) {
|
|
|
310 polygonFeature = new OpenLayers.Feature.Vector(polygon);
|
|
|
311 }
|
|
|
312 map.polygons.push(polygonFeature);
|
|
|
313 var style = $.extend(true, {}, OpenLayers.Feature.Vector.style['default']);
|
|
|
314 style.graphicZIndex = 0;
|
|
|
315 polygonFeature.style = style;
|
|
|
316 map.objectLayer.addFeatures([polygonFeature]);
|
|
|
317 try {
|
|
|
318 map.activeControl.deactivate();
|
|
|
319 } catch(e) {
|
|
|
320 }
|
|
|
321 var circles = map.mds.getObjectsByZoom();
|
|
|
322 for (var i = 0; i < circles.length; i++) {
|
|
|
323 for (var j = 0; j < circles[i].length; j++) {
|
|
|
324 var c = circles[i][j];
|
|
|
325 if (map.inPolygon(c)) {
|
|
|
326 if ( typeof c.fatherBin != 'undefined') {
|
|
|
327 for (var k = 0; k < c.fatherBin.circles.length; k++) {
|
|
|
328 if (c.fatherBin.circles[k]) {
|
|
|
329 c.fatherBin.circles[k].setSelection(true);
|
|
|
330 }
|
|
|
331 }
|
|
|
332 } else {
|
|
|
333 c.setSelection(true);
|
|
|
334 }
|
|
|
335 }
|
|
|
336 }
|
|
|
337 }
|
|
|
338 map.mapSelection();
|
|
|
339 }
|
|
|
340
|
|
|
341 this.polygonDeselection = function() {
|
|
|
342 var circles = map.mds.getObjectsByZoom();
|
|
|
343 for (var i = 0; i < circles.length; i++) {
|
|
|
344 for (var j = 0; j < circles[i].length; j++) {
|
|
|
345 var c = circles[i][j];
|
|
|
346 if (map.inPolygon(c)) {
|
|
|
347 c.setSelection(false);
|
|
|
348 }
|
|
|
349 }
|
|
|
350 }
|
|
|
351 }
|
|
|
352 this.snapper = function() {
|
|
|
353 if (map.polygons.length == 0 || !map.options.multiSelection) {
|
|
|
354 map.deselection();
|
|
|
355 }
|
|
|
356 }
|
|
|
357 if (map.options.polygonSelect) {
|
|
|
358 this.drawPolygon = new OpenLayers.Control.DrawFeature(map.objectLayer, OpenLayers.Handler.Polygon, {
|
|
|
359 displayClass : "olControlDrawFeaturePolygon",
|
|
|
360 callbacks : {
|
|
|
361 "done" : map.drawnPolygonHandler,
|
|
|
362 "create" : map.snapper
|
|
|
363 }
|
|
|
364 });
|
|
|
365 this.openlayersMap.addControl(this.drawPolygon);
|
|
|
366 }
|
|
|
367
|
|
|
368 if (map.options.circleSelect) {
|
|
|
369 this.drawCircle = new OpenLayers.Control.DrawFeature(map.objectLayer, OpenLayers.Handler.RegularPolygon, {
|
|
|
370 displayClass : "olControlDrawFeaturePolygon",
|
|
|
371 handlerOptions : {
|
|
|
372 sides : 40
|
|
|
373 },
|
|
|
374 callbacks : {
|
|
|
375 "done" : map.drawnPolygonHandler,
|
|
|
376 "create" : map.snapper
|
|
|
377 }
|
|
|
378 });
|
|
|
379 this.openlayersMap.addControl(this.drawCircle);
|
|
|
380 }
|
|
|
381
|
|
|
382 if (map.options.squareSelect) {
|
|
|
383 this.drawSquare = new OpenLayers.Control.DrawFeature(map.objectLayer, OpenLayers.Handler.RegularPolygon, {
|
|
|
384 displayClass : "olControlDrawFeaturePolygon",
|
|
|
385 handlerOptions : {
|
|
|
386 sides : 4,
|
|
|
387 irregular: true
|
|
|
388 },
|
|
|
389 callbacks : {
|
|
|
390 "done" : map.drawnPolygonHandler,
|
|
|
391 "create" : map.snapper
|
|
|
392 }
|
|
|
393 });
|
|
|
394 this.openlayersMap.addControl(this.drawSquare);
|
|
|
395 }
|
|
|
396
|
|
|
397 if (map.options.polygonSelect || map.options.circleSelect || map.options.squareSelect) {
|
|
|
398 this.dragArea = new OpenLayers.Control.DragFeature(map.objectLayer, {
|
|
|
399 onStart : function(feature) {
|
|
|
400 feature.style.graphicZIndex = 10000;
|
|
|
401 map.polygonDeselection();
|
|
|
402 },
|
|
|
403 onComplete : function(feature) {
|
|
|
404 feature.style.graphicZIndex = 0;
|
|
|
405 map.drawnPolygonHandler(feature.geometry);
|
|
|
406 }
|
|
|
407 });
|
|
|
408 this.openlayersMap.addControl(this.dragArea);
|
|
|
409
|
|
|
410 this.modifyArea = new OpenLayers.Control.ModifyFeature(map.objectLayer, {
|
|
|
411 onStart : function(feature) {
|
|
|
412 feature.style.graphicZIndex = 10000;
|
|
|
413 map.polygonDeselection();
|
|
|
414 },
|
|
|
415 onComplete : function(feature) {
|
|
|
416 feature.style.graphicZIndex = 0;
|
|
|
417 map.drawnPolygonHandler(feature.geometry);
|
|
|
418 }
|
|
|
419 });
|
|
|
420 this.openlayersMap.addControl(this.modifyArea);
|
|
|
421 this.modifyArea.mode = OpenLayers.Control.ModifyFeature.RESHAPE;
|
|
|
422
|
|
|
423 }
|
|
|
424
|
|
|
425 // calculates the tag cloud
|
|
|
426 // manages hover selection of point objects
|
|
|
427 var hoverSelect = function(event) {
|
|
|
428 var object = event.feature;
|
|
|
429 if (object.geometry instanceof OpenLayers.Geometry.Point) {
|
|
|
430 if ( typeof map.placenameTags != 'undefined') {
|
|
|
431 map.placenameTags.remove();
|
|
|
432 }
|
|
|
433 var circle = event.feature.parent;
|
|
|
434 if ( circle instanceof CircleObject) {
|
|
|
435 circle.placenameTags = new PlacenameTags(circle, map);
|
|
|
436 map.placenameTags = circle.placenameTags;
|
|
|
437 } else {
|
|
|
438 return;
|
|
|
439 /*
|
|
|
440 event.feature.style.fillOpacity = 0.2;
|
|
|
441 event.feature.style.strokeOpacity = 1;
|
|
|
442 map.objectLayer.drawFeature(event.feature);
|
|
|
443 circle.placenameTags = new PackPlacenameTags(circle,map);
|
|
|
444 */
|
|
|
445 }
|
|
|
446 circle.placenameTags.calculate();
|
|
|
447 map.mapCircleHighlight(object.parent, false);
|
|
|
448 if ( typeof map.featureInfo != 'undefined') {
|
|
|
449 map.featureInfo.deactivate();
|
|
|
450 }
|
|
|
451 } else {
|
|
|
452 map.dragControl.checkStatus();
|
|
|
453 }
|
|
|
454 };
|
|
|
455 var hoverUnselect = function(event) {
|
|
|
456 var object = event.feature;
|
|
|
457 if (object.geometry instanceof OpenLayers.Geometry.Point) {
|
|
|
458 var circle = event.feature.parent;
|
|
|
459 if (!( circle instanceof CircleObject )) {
|
|
|
460 return;
|
|
|
461 /*
|
|
|
462 event.feature.style.fillOpacity = 0;
|
|
|
463 event.feature.style.strokeOpacity = 0;
|
|
|
464 map.objectLayer.drawFeature(event.feature);
|
|
|
465 */
|
|
|
466 }
|
|
|
467 circle.placenameTags.remove();
|
|
|
468 map.mapCircleHighlight(object.parent, true);
|
|
|
469 if ( typeof map.featureInfo != 'undefined') {
|
|
|
470 map.featureInfo.activate();
|
|
|
471 }
|
|
|
472 } else {
|
|
|
473 map.dragControl.deactivate();
|
|
|
474 }
|
|
|
475 };
|
|
|
476 var highlightCtrl = new OpenLayers.Control.SelectFeature(this.objectLayer, {
|
|
|
477 hover : true,
|
|
|
478 highlightOnly : true,
|
|
|
479 renderIntent : "temporary",
|
|
|
480 eventListeners : {
|
|
|
481 featurehighlighted : hoverSelect,
|
|
|
482 featureunhighlighted : hoverUnselect
|
|
|
483 }
|
|
|
484 });
|
|
|
485 this.openlayersMap.addControl(highlightCtrl);
|
|
|
486 highlightCtrl.activate();
|
|
|
487
|
|
|
488 this.selectFeature = new OpenLayers.Control.SelectFeature(this.objectLayer);
|
|
|
489
|
|
|
490 document.onkeydown = function(e) {
|
|
|
491 if (e.ctrlKey) {
|
|
|
492 map.ctrlKey = true;
|
|
|
493 }
|
|
|
494 }
|
|
|
495 document.onkeyup = function(e) {
|
|
|
496 map.ctrlKey = false;
|
|
|
497 }
|
|
|
498 // manages click selection of point objects
|
|
|
499 var onFeatureSelect = function(event, evt) {
|
|
|
500 if (!(event.feature.geometry instanceof OpenLayers.Geometry.Point)) {
|
|
|
501 return;
|
|
|
502 }
|
|
|
503 var circle = event.feature.parent;
|
|
|
504 if (map.options.multiSelection && map.ctrlKey) {
|
|
|
505 if (map.popup) {
|
|
|
506 map.popup.reset();
|
|
|
507 map.selectedGlyph = false;
|
|
|
508 }
|
|
|
509 circle.toggleSelection();
|
|
|
510 map.mapSelection();
|
|
|
511 return;
|
|
|
512 }
|
|
|
513 map.reset();
|
|
|
514 circle.setSelection(true);
|
|
|
515 map.objectLayer.drawFeature(circle.feature);
|
|
|
516 if (map.options.popups) {
|
|
|
517 if (map.popup) {
|
|
|
518 map.popup.reset();
|
|
|
519 }
|
|
|
520 var lonlat = event.feature.geometry.getBounds().getCenterLonLat();
|
|
|
521 var pixel = map.openlayersMap.getPixelFromLonLat(lonlat);
|
|
|
522 map.selectedGlyph = {
|
|
|
523 lon : lonlat.lon,
|
|
|
524 lat : lonlat.lat
|
|
|
525 };
|
|
|
526 map.popup = new PlacenamePopup(map);
|
|
|
527 map.popup.createPopup(pixel.x, pixel.y, circle.placenameTags.placeLabels);
|
|
|
528 if (map.options.selectDefault) {
|
|
|
529 circle.placenameTags.selectLabel();
|
|
|
530 }
|
|
|
531 }
|
|
|
532 }
|
|
|
533 this.objectLayer.events.on({
|
|
|
534 "featureselected" : onFeatureSelect
|
|
|
535 });
|
|
|
536
|
|
|
537 this.openlayersMap.addControl(this.selectFeature);
|
|
|
538 this.selectFeature.activate();
|
|
|
539
|
|
|
540 if (this.zoomSlider) {
|
|
|
541 this.zoomSlider.setMaxAndLevels(1000, this.openlayersMap.getNumZoomLevels());
|
|
|
542 this.zoomSlider.setValue(this.getZoom());
|
|
|
543 }
|
|
|
544
|
|
|
545 Publisher.Subscribe('mapChanged', this, function(mapName) {
|
|
|
546 this.client.setBaseLayerByName(mapName);
|
|
|
547 this.client.gui.setMap();
|
|
|
548 });
|
|
|
549
|
|
|
550 },
|
|
|
551
|
|
|
552 shift : function(shiftX, shiftY) {
|
|
|
553 this.openlayersMap.pan(shiftX, shiftY);
|
|
|
554 },
|
|
|
555
|
|
|
556 addBaseLayers : function(layers) {
|
|
|
557 if ( layers instanceof Array) {
|
|
|
558 for (var i in layers ) {
|
|
|
559 var layer;
|
|
|
560 if (layers[i].type === "XYZ"){
|
|
|
561 layer = new OpenLayers.Layer.XYZ(
|
|
|
562 layers[i].name,
|
|
|
563 [
|
|
|
564 layers[i].url
|
|
|
565 ],
|
|
|
566 {
|
|
|
567 sphericalMercator: true,
|
|
|
568 transitionEffect: "resize",
|
|
|
569 buffer: 1,
|
|
|
570 numZoomLevels: 12,
|
|
|
571 transparent : true,
|
|
|
572 attribution: layers[i].attribution
|
|
|
573 },
|
|
|
574 {
|
|
|
575 isBaseLayer : true
|
|
|
576 }
|
|
|
577 );
|
|
|
578 } else {
|
|
|
579 layer = new OpenLayers.Layer.WMS(
|
|
|
580 layers[i].name, layers[i].url,
|
|
|
581 {
|
|
|
582 projection : "EPSG:4326",
|
|
|
583 layers : layers[i].layer,
|
|
|
584 transparent : "true",
|
|
|
585 format : "image/png"
|
|
|
586 },
|
|
|
587 {
|
|
|
588 attribution: layers[i].attribution,
|
|
|
589 isBaseLayer : true
|
|
|
590 }
|
|
|
591 );
|
|
|
592 }
|
|
|
593 this.baseLayers.push(layer);
|
|
|
594 this.openlayersMap.addLayers([layer]);
|
|
|
595 }
|
|
|
596 }
|
|
|
597 this.gui.setMapsDropdown();
|
|
|
598 },
|
|
|
599
|
|
|
600 /**
|
|
|
601 * set online available maps for Google, Bing and OSM
|
|
|
602 */
|
|
|
603 setBaseLayers : function() {
|
|
|
604 this.baseLayers = [];
|
|
|
605 if (this.options.googleMaps) {
|
|
|
606 // see http://openlayers.org/blog/2010/07/10/google-maps-v3-for-openlayers/ for information
|
|
|
607 var gphy = new OpenLayers.Layer.Google("Google Physical", {
|
|
|
608 type : google.maps.MapTypeId.TERRAIN,
|
|
|
609 minZoomLevel : 1,
|
|
|
610 maxZoomLevel : 19
|
|
|
611 });
|
|
|
612 var gmap = new OpenLayers.Layer.Google("Google Streets", {
|
|
|
613 minZoomLevel : 1,
|
|
|
614 maxZoomLevel : 19
|
|
|
615 });
|
|
|
616 var ghyb = new OpenLayers.Layer.Google("Google Hybrid", {
|
|
|
617 type : google.maps.MapTypeId.HYBRID,
|
|
|
618 minZoomLevel : 1,
|
|
|
619 maxZoomLevel : 19
|
|
|
620 });
|
|
|
621 var gsat = new OpenLayers.Layer.Google("Google Satellite", {
|
|
|
622 type : google.maps.MapTypeId.SATELLITE,
|
|
|
623 minZoomLevel : 1,
|
|
|
624 maxZoomLevel : 19
|
|
|
625 });
|
|
|
626 this.baseLayers.push(gphy);
|
|
|
627 this.baseLayers.push(gmap);
|
|
|
628 this.baseLayers.push(ghyb);
|
|
|
629 this.baseLayers.push(gsat);
|
|
|
630 }
|
|
|
631 if (this.options.bingMaps) {
|
|
|
632 // see http://openlayers.org/blog/2010/12/18/bing-tiles-for-openlayers/ for information
|
|
|
633 var apiKey = this.options.bingApiKey;
|
|
|
634 var road = new OpenLayers.Layer.Bing({
|
|
|
635 name : "Road",
|
|
|
636 key : apiKey,
|
|
|
637 type : "Road"
|
|
|
638 });
|
|
|
639 var hybrid = new OpenLayers.Layer.Bing({
|
|
|
640 name : "Hybrid",
|
|
|
641 key : apiKey,
|
|
|
642 type : "AerialWithLabels"
|
|
|
643 });
|
|
|
644 var aerial = new OpenLayers.Layer.Bing({
|
|
|
645 name : "Aerial",
|
|
|
646 key : apiKey,
|
|
|
647 type : "Aerial"
|
|
|
648 });
|
|
|
649 this.baseLayers.push(road);
|
|
|
650 this.baseLayers.push(hybrid);
|
|
|
651 this.baseLayers.push(aerial);
|
|
|
652 }
|
|
|
653 if (this.options.osmMaps) {
|
|
|
654 this.baseLayers.push(new OpenLayers.Layer.OSM('Open Street Map', '', {
|
|
|
655 sphericalMercator : true,
|
|
|
656 zoomOffset : 1,
|
|
|
657 resolutions : this.resolutions
|
|
|
658 }));
|
|
|
659 }
|
|
|
660 if (this.options.osmMapsMapQuest) {
|
|
|
661 this.baseLayers.push(new OpenLayers.Layer.OSM('Open Street Map (MapQuest)',
|
|
|
662 ["http://otile1.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.png",
|
|
|
663 "http://otile2.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.png",
|
|
|
664 "http://otile3.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.png",
|
|
|
665 "http://otile4.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.png"],
|
|
|
666 {
|
|
|
667 sphericalMercator : true,
|
|
|
668 zoomOffset : 1,
|
|
|
669 resolutions : this.resolutions
|
|
|
670 }
|
|
|
671 ));
|
|
|
672 }
|
|
|
673 for (var i = 0; i < this.baseLayers.length; i++) {
|
|
|
674 this.openlayersMap.addLayers([this.baseLayers[i]]);
|
|
|
675 }
|
|
|
676 if (this.options.alternativeMap) {
|
|
|
677 if (!(this.options.alternativeMap instanceof Array))
|
|
|
678 this.options.alternativeMap = [this.options.alternativeMap];
|
|
|
679 this.addBaseLayers(this.options.alternativeMap);
|
|
|
680 }
|
|
|
681 this.setBaseLayerByName(this.options.baseLayer);
|
|
|
682 },
|
|
|
683
|
|
|
684 setBaseLayerByName : function(name){
|
|
|
685 for (var i = 0; i < this.baseLayers.length; i++) {
|
|
|
686 if (this.baseLayers[i].name == name) {
|
|
|
687 this.setMap(i);
|
|
|
688 }
|
|
|
689 }
|
|
|
690 },
|
|
|
691
|
|
|
692 getBaseLayerName : function() {
|
|
|
693 return this.openlayersMap.baseLayer.name;
|
|
|
694 },
|
|
|
695
|
|
|
696 setOverlays : function(layers) {
|
|
|
697 var map = this;
|
|
|
698 for (var i in this.wmsOverlays ) {
|
|
|
699 this.openlayersMap.removeLayer(this.wmsOverlays[i]);
|
|
|
700 }
|
|
|
701 this.wmsOverlays = [];
|
|
|
702 var featureInfoLayers = [];
|
|
|
703 if ( layers instanceof Array) {
|
|
|
704 for (var i in layers ) {
|
|
|
705 var layer = new OpenLayers.Layer.WMS(layers[i].name, layers[i].url, {
|
|
|
706 projection : "EPSG:4326",
|
|
|
707 layers : layers[i].layer,
|
|
|
708 transparent : "true",
|
|
|
709 format : "image/png"
|
|
|
710 }, {
|
|
|
711 isBaseLayer : false,
|
|
|
712 visibility : map.options.overlayVisibility
|
|
|
713 });
|
|
|
714 this.wmsOverlays.push(layer);
|
|
|
715 if (layers[i].featureInfo) {
|
|
|
716 featureInfoLayers.push(layer);
|
|
|
717 }
|
|
|
718 }
|
|
|
719 this.openlayersMap.addLayers(this.wmsOverlays);
|
|
|
720 }
|
|
|
721 if (this.wmsOverlays.length > 0 && map.options.overlayVisibility) {
|
|
|
722 var map = this;
|
|
|
723 if ( typeof this.featureInfo != 'undefined') {
|
|
|
724 this.featureInfo.deactivate();
|
|
|
725 this.openlayersMap.removeControl(this.featureInfo);
|
|
|
726 }
|
|
|
727 this.featureInfo = new OpenLayers.Control.WMSGetFeatureInfo({
|
|
|
728 url : '/geoserver/wms',
|
|
|
729 layers : featureInfoLayers,
|
|
|
730 eventListeners : {
|
|
|
731 getfeatureinfo : function(event) {
|
|
|
732 if (event.text == '') {
|
|
|
733 return;
|
|
|
734 }
|
|
|
735 var lonlat = map.openlayersMap.getLonLatFromPixel(new OpenLayers.Pixel(event.xy.x, event.xy.y));
|
|
|
736 map.selectedGlyph = {
|
|
|
737 lon : lonlat.lon,
|
|
|
738 lat : lonlat.lat
|
|
|
739 };
|
|
|
740 if ( typeof map.popup != 'undefined') {
|
|
|
741 map.popup.reset();
|
|
|
742 }
|
|
|
743 map.popup = new MapPopup(map);
|
|
|
744 map.popup.initialize(event.xy.x, event.xy.y);
|
|
|
745 map.popup.setContent(event.text);
|
|
|
746 }
|
|
|
747 }
|
|
|
748 });
|
|
|
749 this.openlayersMap.addControl(this.featureInfo);
|
|
|
750 this.featureInfo.activate();
|
|
|
751 this.activateCountrySelector(this.wmsOverlays[this.wmsOverlays.length - 1]);
|
|
|
752 } else {
|
|
|
753 this.deactivateCountrySelector();
|
|
|
754 if (this.openlayersMap.baseLayer instanceof OpenLayers.Layer.WMS) {
|
|
|
755 this.activateCountrySelector(this.openlayersMap.baseLayer);
|
|
|
756 }
|
|
|
757 }
|
|
|
758 },
|
|
|
759
|
|
|
760 addBaseLayer : function(layer) {
|
|
|
761 this.baseLayers.push(layer);
|
|
|
762 this.openlayersMap.addLayers([layer]);
|
|
|
763 for (var i in this.baseLayers ) {
|
|
|
764 if (this.baseLayers[i].name == this.options.baseLayer) {
|
|
|
765 this.setMap(i);
|
|
|
766 }
|
|
|
767 }
|
|
|
768 },
|
|
|
769
|
|
|
770 /**
|
|
|
771 * draws the object layer.
|
|
|
772 * @param {boolean} zoom if there was a zoom; if not, the new boundary of the map is calculated
|
|
|
773 */
|
|
|
774 drawObjectLayer : function(zoom) {
|
|
|
775 if ( typeof this.placenameTags != 'undefined') {
|
|
|
776 this.placenameTags.remove();
|
|
|
777 }
|
|
|
778 var points = this.mds.getAllObjects();
|
|
|
779 if (points == null) {
|
|
|
780 return;
|
|
|
781 }
|
|
|
782 this.objectLayer.removeAllFeatures();
|
|
|
783
|
|
|
784 if (zoom) {
|
|
|
785 var minLat, maxLat, minLon, maxLon;
|
|
|
786 var pointsHighestZoom = points[points.length - 1];
|
|
|
787 for (var i = 0; i < pointsHighestZoom.length; i++) {
|
|
|
788 for (var j = 0; j < pointsHighestZoom[i].length; j++) {
|
|
|
789 var point = pointsHighestZoom[i][j];
|
|
|
790 if (minLon == null || point.originX < minLon) {
|
|
|
791 minLon = point.originX;
|
|
|
792 }
|
|
|
793 if (maxLon == null || point.originX > maxLon) {
|
|
|
794 maxLon = point.originX;
|
|
|
795 }
|
|
|
796 if (minLat == null || point.originY < minLat) {
|
|
|
797 minLat = point.originY;
|
|
|
798 }
|
|
|
799 if (maxLat == null || point.originY > maxLat) {
|
|
|
800 maxLat = point.originY;
|
|
|
801 }
|
|
|
802 }
|
|
|
803 }
|
|
|
804 if (minLon == maxLon && minLat == maxLat) {
|
|
|
805 this.openlayersMap.setCenter(new OpenLayers.LonLat(minLon, minLat));
|
|
|
806 } else {
|
|
|
807 var gapX = 0.1 * (maxLon - minLon );
|
|
|
808 var gapY1 = 0.1 * (maxLat - minLat );
|
|
|
809 var gapY2 = (this.gui.headerHeight / this.gui.mapWindow.offsetHeight + 0.1 ) * (maxLat - minLat );
|
|
|
810 this.openlayersMap.zoomToExtent(new OpenLayers.Bounds(minLon - gapX, minLat - gapY1, maxLon + gapX, maxLat + gapY2));
|
|
|
811 this.openlayersMap.zoomTo(Math.floor(this.getZoom()));
|
|
|
812 }
|
|
|
813 if (this.zoomSlider) {
|
|
|
814 this.zoomSlider.setValue(this.getZoom());
|
|
|
815 }
|
|
|
816 }
|
|
|
817 var displayPoints = this.mds.getObjectsByZoom();
|
|
|
818 var resolution = this.openlayersMap.getResolution();
|
|
|
819 for (var i = 0; i < displayPoints.length; i++) {
|
|
|
820 for (var j = 0; j < displayPoints[i].length; j++) {
|
|
|
821 var p = displayPoints[i][j];
|
|
|
822 var x = p.originX + resolution * p.shiftX;
|
|
|
823 var y = p.originY + resolution * p.shiftY;
|
|
|
824 p.feature.geometry.x = x;
|
|
|
825 p.feature.geometry.y = y;
|
|
|
826 p.olFeature.geometry.x = x;
|
|
|
827 p.olFeature.geometry.y = y;
|
|
|
828 p.feature.style.graphicZIndex = this.zIndices[i];
|
|
|
829 p.olFeature.style.graphicZIndex = this.zIndices[i] + 1;
|
|
|
830 this.objectLayer.addFeatures([p.feature]);
|
|
|
831 this.objectLayer.addFeatures([p.olFeature]);
|
|
|
832 }
|
|
|
833 }
|
|
|
834 var zoomLevel = this.getZoom();
|
|
|
835 /*
|
|
|
836 for (var i = 0; i < this.bins[zoomLevel].length; i++) {
|
|
|
837 var p = this.bins[zoomLevel][i];
|
|
|
838 p.feature.style.graphicZIndex = 0;
|
|
|
839 this.objectLayer.addFeatures([p.feature]);
|
|
|
840 }
|
|
|
841 */
|
|
|
842
|
|
|
843 var dist = function(p1, p2) {
|
|
|
844 return Math.sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
|
|
|
845 }
|
|
|
846
|
|
|
847 this.highlightChanged(this.selection.getObjects(this.core));
|
|
|
848
|
|
|
849 },
|
|
|
850
|
|
|
851 riseLayer : function(id) {
|
|
|
852 this.lastId = id;
|
|
|
853 if ( typeof id == 'undefined') {
|
|
|
854 id = this.lastId || 0;
|
|
|
855 }
|
|
|
856 this.zIndices[id] = this.layerZIndex;
|
|
|
857 this.layerZIndex += 2;
|
|
|
858 this.drawObjectLayer(false);
|
|
|
859 for( var i=0; i<this.polygons.length; i++ ){
|
|
|
860 this.objectLayer.addFeatures([this.polygons[i]]);
|
|
|
861 }
|
|
|
862 },
|
|
|
863
|
|
|
864 /**
|
|
|
865 * initializes the object layer.
|
|
|
866 * all point representations for all zoom levels are calculated and initialized
|
|
|
867 * @param {MapObject[][]} mapObjects an array of map objects from different (1-4) sets
|
|
|
868 */
|
|
|
869 initWidget : function(datasets, zoom) {
|
|
|
870
|
|
|
871 this.clearMap();
|
|
|
872
|
|
|
873 this.datasets = datasets;
|
|
|
874 var mapObjects = [];
|
|
|
875 for (var i = 0; i < datasets.length; i++) {
|
|
|
876 mapObjects.push(datasets[i].objects);
|
|
|
877 }
|
|
|
878 if (mapObjects.length > 4) {
|
|
|
879 this.options.circlePackings = false;
|
|
|
880 } else {
|
|
|
881 this.options.circlePackings = this.formerCP;
|
|
|
882 }
|
|
|
883
|
|
|
884 if ( typeof mapObjects == 'undefined') {
|
|
|
885 return;
|
|
|
886 }
|
|
|
887
|
|
|
888 this.count = 0;
|
|
|
889 this.objectCount = 0;
|
|
|
890 for (var i = 0; i < mapObjects.length; i++) {
|
|
|
891 var c = 0;
|
|
|
892 for (var j = 0; j < mapObjects[i].length; j++) {
|
|
|
893 if (mapObjects[i][j].isGeospatial) {
|
|
|
894 c += mapObjects[i][j].weight;
|
|
|
895 this.objectCount++;
|
|
|
896 }
|
|
|
897 }
|
|
|
898 this.count += c;
|
|
|
899 this.zIndices.push(this.layerZIndex);
|
|
|
900 this.layerZIndex += 2;
|
|
|
901 }
|
|
|
902
|
|
|
903 this.mds.initialize(mapObjects);
|
|
|
904 var points = this.mds.getAllObjects();
|
|
|
905 if (points == null) {
|
|
|
906 return;
|
|
|
907 }
|
|
|
908
|
|
|
909 var getArea = function(radius) {
|
|
|
910 return Math.PI * radius * radius;
|
|
|
911 }
|
|
|
912 for (var i = 0; i < points.length; i++) {
|
|
|
913 var area = 0;
|
|
|
914 var maxRadius = 0;
|
|
|
915 for (var j = 0; j < points[i].length; j++) {
|
|
|
916 for (var k = 0; k < points[i][j].length; k++) {
|
|
|
917 if (points[i][j][k].radius > maxRadius) {
|
|
|
918 maxRadius = points[i][j][k].radius;
|
|
|
919 area = getArea(maxRadius);
|
|
|
920 }
|
|
|
921 }
|
|
|
922 }
|
|
|
923 var minArea = getArea(this.options.minimumRadius);
|
|
|
924 var areaDiff = area - minArea;
|
|
|
925 for (var j = 0; j < points[i].length; j++) {
|
|
|
926 for (var k = 0; k < points[i][j].length; k++) {
|
|
|
927 var point = points[i][j][k];
|
|
|
928 var c, shape, rotation, multiplier = 1;
|
|
|
929 if( this.options.useGraphics ){
|
|
|
930 var graphic = this.config.getGraphic(point.search);
|
|
|
931 c = graphic.color;
|
|
|
932 shape = graphic.shape;
|
|
|
933 rotation = graphic.rotation;
|
|
|
934 if( shape == 'square' ){
|
|
|
935 multiplier = 0.75;
|
|
|
936 }
|
|
|
937 }
|
|
|
938 else {
|
|
|
939 c = GeoTemConfig.getAverageDatasetColor(point.search,point.elements);
|
|
|
940 shape = 'circle';
|
|
|
941 rotation = 0;
|
|
|
942 }
|
|
|
943 var opacity;
|
|
|
944 if (this.options.circleOpacity == 'balloon') {
|
|
|
945 var min = this.options.minTransparency;
|
|
|
946 var max = this.options.maxTransparency;
|
|
|
947 opacity = min + Math.abs(min - max) * (1 - (getArea(point.radius) - minArea) / areaDiff);
|
|
|
948 }
|
|
|
949 else {
|
|
|
950 opacity = this.options.circleOpacity;
|
|
|
951 }
|
|
|
952 var col = false, ols = 0;
|
|
|
953 if( this.options.circleOutline ){
|
|
|
954 col = true;
|
|
|
955 ols = this.options.circleOutline;
|
|
|
956 }
|
|
|
957 var style = {
|
|
|
958 graphicName: shape,
|
|
|
959 rotation: rotation,
|
|
|
960 fillColor : 'rgb(' + c.r0 + ',' + c.g0 + ',' + c.b0 + ')',
|
|
|
961 fillOpacity : opacity,
|
|
|
962 strokeWidth : ols,
|
|
|
963 strokeColor : 'rgb(' + c.r1 + ',' + c.g1 + ',' + c.b1 + ')',
|
|
|
964 stroke : col,
|
|
|
965 pointRadius : point.radius * multiplier,
|
|
|
966 cursor : "pointer"
|
|
|
967 };
|
|
|
968 var pointGeometry = new OpenLayers.Geometry.Point(point.originX, point.originY, null);
|
|
|
969 var feature = new OpenLayers.Feature.Vector(pointGeometry);
|
|
|
970 feature.style = style;
|
|
|
971 feature.parent = point;
|
|
|
972 point.setFeature(feature);
|
|
|
973 var olStyle = {
|
|
|
974 graphicName: shape,
|
|
|
975 rotation: rotation,
|
|
|
976 fillColor : 'rgb(' + c.r1 + ',' + c.g1 + ',' + c.b1 + ')',
|
|
|
977 fillOpacity : opacity,
|
|
|
978 stroke : false,
|
|
|
979 pointRadius : 0,
|
|
|
980 cursor : "pointer"
|
|
|
981 };
|
|
|
982 var olPointGeometry = new OpenLayers.Geometry.Point(point.originX, point.originY, null);
|
|
|
983 var olFeature = new OpenLayers.Feature.Vector(olPointGeometry);
|
|
|
984 olFeature.style = olStyle;
|
|
|
985 olFeature.parent = point;
|
|
|
986 point.setOlFeature(olFeature);
|
|
|
987 }
|
|
|
988 }
|
|
|
989 }
|
|
|
990
|
|
|
991 /*
|
|
|
992 this.bins = this.mds.getAllBins();
|
|
|
993 for (var i = 0; i < this.bins.length; i++) {
|
|
|
994 for (var j = 0; j < this.bins[i].length; j++) {
|
|
|
995 var bin = this.bins[i][j];
|
|
|
996 var style = {
|
|
|
997 fillColor : 'rgb(140,140,140)',
|
|
|
998 fillOpacity : 0,
|
|
|
999 strokeWidth : 2,
|
|
|
1000 strokeOpacity : 0,
|
|
|
1001 strokeColor : 'rgb(140,140,140)',
|
|
|
1002 // stroke: false,
|
|
|
1003 pointRadius : bin.radius,
|
|
|
1004 cursor : "pointer"
|
|
|
1005 };
|
|
|
1006 var pointGeometry = new OpenLayers.Geometry.Point(bin.x, bin.y, null);
|
|
|
1007 var feature = new OpenLayers.Feature.Vector(pointGeometry);
|
|
|
1008 feature.style = style;
|
|
|
1009 feature.parent = bin;
|
|
|
1010 bin.feature = feature;
|
|
|
1011 }
|
|
|
1012 }
|
|
|
1013 */
|
|
|
1014
|
|
|
1015 this.gui.updateLegend(datasets);
|
|
|
1016
|
|
|
1017 if ( typeof zoom == "undefined") {
|
|
|
1018 this.drawObjectLayer(true);
|
|
|
1019 } else {
|
|
|
1020 this.drawObjectLayer(zoom);
|
|
|
1021 }
|
|
|
1022 this.gui.updateSpaceQuantity(this.count);
|
|
|
1023
|
|
|
1024 },
|
|
|
1025
|
|
|
1026 /**
|
|
|
1027 * resets the map by destroying all additional elements except the point objects, which are replaced
|
|
|
1028 */
|
|
|
1029 reset : function() {
|
|
|
1030 if ( typeof this.placenameTags != 'undefined') {
|
|
|
1031 this.placenameTags.remove();
|
|
|
1032 }
|
|
|
1033 this.objectLayer.removeFeatures(this.polygons);
|
|
|
1034 this.polygons = [];
|
|
|
1035 this.objectLayer.removeFeatures(this.connections);
|
|
|
1036 this.connections = [];
|
|
|
1037 this.selectFeature.unselectAll();
|
|
|
1038 this.selectedGlyph = false;
|
|
|
1039 if (this.dragControl.activated) {
|
|
|
1040 this.dragControl.deactivate();
|
|
|
1041 }
|
|
|
1042 if (this.popup) {
|
|
|
1043 this.popup.reset();
|
|
|
1044 }
|
|
|
1045 this.filterBar.reset(false);
|
|
|
1046 var points = this.mds.getObjectsByZoom();
|
|
|
1047 if (points == null) {
|
|
|
1048 return;
|
|
|
1049 }
|
|
|
1050 for (var i = 0; i < points.length; i++) {
|
|
|
1051 for (var j = 0; j < points[i].length; j++) {
|
|
|
1052 points[i][j].setSelection(false);
|
|
|
1053 }
|
|
|
1054 }
|
|
|
1055 },
|
|
|
1056
|
|
|
1057 /**
|
|
|
1058 * resets the map by destroying all elements
|
|
|
1059 */
|
|
|
1060 clearMap : function() {
|
|
|
1061 this.reset();
|
|
|
1062 this.selection = new Selection();
|
|
|
1063 this.zIndices = [];
|
|
|
1064 this.layerZIndex = 1;
|
|
|
1065 this.objectLayer.destroyFeatures();
|
|
|
1066 },
|
|
|
1067
|
|
|
1068 /**
|
|
|
1069 * updates the proportional selection status of a point object
|
|
|
1070 * @param {PointObject} point the point to update
|
|
|
1071 * @param {OpenLayers.Geometry.Polygon} polygon the actual displayed map polygon
|
|
|
1072 */
|
|
|
1073 updatePoint : function(point, polygon) {
|
|
|
1074 var olRadius = this.mds.binning.getRadius(point.overlay);
|
|
|
1075 if( this.options.useGraphics ){
|
|
|
1076 var graphic = this.config.getGraphic(point.search);
|
|
|
1077 if( graphic.shape == 'square' ){
|
|
|
1078 olRadius *= 0.75;
|
|
|
1079 }
|
|
|
1080 }
|
|
|
1081 point.olFeature.style.pointRadius = olRadius;
|
|
|
1082 var c = GeoTemConfig.getAverageDatasetColor(point.search, point.overlayElements);
|
|
|
1083 point.olFeature.style.fillColor = 'rgb(' + c.r1 + ',' + c.g1 + ',' + c.b1 + ')';
|
|
|
1084 if (polygon.containsPoint(point.feature.geometry)) {
|
|
|
1085 this.objectLayer.drawFeature(point.olFeature);
|
|
|
1086 }
|
|
|
1087 },
|
|
|
1088
|
|
|
1089 /**
|
|
|
1090 * updates the the object layer of the map after selections had been executed in timeplot or table or zoom level has changed
|
|
|
1091 */
|
|
|
1092 highlightChanged : function(mapObjects) {
|
|
|
1093 if( !GeoTemConfig.highlightEvents ){
|
|
|
1094 return;
|
|
|
1095 }
|
|
|
1096 this.mds.clearOverlay();
|
|
|
1097 if (this.selection.valid()) {
|
|
|
1098 this.mds.setOverlay(GeoTemConfig.mergeObjects(mapObjects, this.selection.getObjects()));
|
|
|
1099 } else {
|
|
|
1100 this.mds.setOverlay(mapObjects);
|
|
|
1101 }
|
|
|
1102 var points = this.mds.getObjectsByZoom();
|
|
|
1103 var polygon = this.openlayersMap.getExtent().toGeometry();
|
|
|
1104 for (var i in points ) {
|
|
|
1105 for (var j in points[i] ) {
|
|
|
1106 this.updatePoint(points[i][j], polygon);
|
|
|
1107 }
|
|
|
1108 }
|
|
|
1109 this.displayConnections();
|
|
|
1110 },
|
|
|
1111
|
|
|
1112 selectionChanged : function(selection) {
|
|
|
1113 if( !GeoTemConfig.selectionEvents ){
|
|
|
1114 return;
|
|
|
1115 }
|
|
|
1116 this.reset();
|
|
|
1117 this.selection = selection;
|
|
|
1118 this.highlightChanged(selection.objects);
|
|
|
1119 },
|
|
|
1120
|
|
|
1121 inPolygon : function(point) {
|
|
|
1122 for (var i = 0; i < this.polygons.length; i++) {
|
|
|
1123 var polygon = this.polygons[i].geometry;
|
|
|
1124 for (var j = 0; j < polygon.components.length; j++) {
|
|
|
1125 if (polygon.components[j].containsPoint(point.feature.geometry)) {
|
|
|
1126 return true;
|
|
|
1127 }
|
|
|
1128 }
|
|
|
1129 }
|
|
|
1130 return false;
|
|
|
1131 },
|
|
|
1132
|
|
|
1133 mapSelection : function() {
|
|
|
1134 var selectedObjects = [];
|
|
|
1135 for (var i = 0; i < this.mds.size(); i++) {
|
|
|
1136 selectedObjects.push([]);
|
|
|
1137 }
|
|
|
1138 var circles = this.mds.getObjectsByZoom();
|
|
|
1139 for (var i = 0; i < circles.length; i++) {
|
|
|
1140
|
|
|
1141 for (var j = 0; j < circles[i].length; j++) {
|
|
|
1142 var c = circles[i][j];
|
|
|
1143 if (c.selected) {
|
|
|
1144 selectedObjects[i] = selectedObjects[i].concat(c.elements);
|
|
|
1145 }
|
|
|
1146 }
|
|
|
1147 }
|
|
|
1148 this.selection = new Selection(selectedObjects, this);
|
|
|
1149 this.highlightChanged(selectedObjects);
|
|
|
1150 this.core.triggerSelection(this.selection);
|
|
|
1151 this.filterBar.reset(true);
|
|
|
1152 },
|
|
|
1153
|
|
|
1154 deselection : function() {
|
|
|
1155 this.reset();
|
|
|
1156 this.selection = new Selection();
|
|
|
1157 this.highlightChanged([]);
|
|
|
1158 this.core.triggerSelection(this.selection);
|
|
|
1159 },
|
|
|
1160
|
|
|
1161 filtering : function() {
|
|
|
1162 for (var i = 0; i < this.datasets.length; i++) {
|
|
|
1163 this.datasets[i].objects = this.selection.objects[i];
|
|
|
1164 }
|
|
|
1165 this.core.triggerRefining(this.datasets);
|
|
|
1166 },
|
|
|
1167
|
|
|
1168 inverseFiltering : function() {
|
|
|
1169 var selectedObjects = [];
|
|
|
1170 for (var i = 0; i < this.mds.size(); i++) {
|
|
|
1171 selectedObjects.push([]);
|
|
|
1172 }
|
|
|
1173 var circles = this.mds.getObjectsByZoom();
|
|
|
1174 for (var i = 0; i < circles.length; i++) {
|
|
|
1175 for (var j = 0; j < circles[i].length; j++) {
|
|
|
1176 var c = circles[i][j];
|
|
|
1177 if (!c.selected) {
|
|
|
1178 selectedObjects[i] = selectedObjects[i].concat(c.elements);
|
|
|
1179 }
|
|
|
1180 }
|
|
|
1181 }
|
|
|
1182 this.selection = new Selection(selectedObjects, this);
|
|
|
1183 this.filtering();
|
|
|
1184 },
|
|
|
1185
|
|
|
1186 mapCircleHighlight : function(circle, undo) {
|
|
|
1187 if (this.polygons.length > 0 && this.inPolygon(circle)) {
|
|
|
1188 return;
|
|
|
1189 }
|
|
|
1190 var mapObjects = [];
|
|
|
1191 for (var i = 0; i < this.mds.size(); i++) {
|
|
|
1192 mapObjects.push([]);
|
|
|
1193 }
|
|
|
1194 if (!undo && !circle.selected) {
|
|
|
1195 mapObjects[circle.search] = circle.elements;
|
|
|
1196 }
|
|
|
1197 this.objectLayer.drawFeature(circle.feature);
|
|
|
1198 this.core.triggerHighlight(mapObjects);
|
|
|
1199 },
|
|
|
1200
|
|
|
1201 mapLabelSelection : function(label) {
|
|
|
1202 var selectedObjects = [];
|
|
|
1203 for (var i = 0; i < this.mds.size(); i++) {
|
|
|
1204 selectedObjects.push([]);
|
|
|
1205 }
|
|
|
1206 selectedObjects[label.index] = label.elements;
|
|
|
1207 this.selection = new Selection(selectedObjects, this);
|
|
|
1208 this.highlightChanged(selectedObjects);
|
|
|
1209 this.core.triggerSelection(this.selection);
|
|
|
1210 this.filterBar.reset(true);
|
|
|
1211 },
|
|
|
1212
|
|
|
1213 triggerMapChanged : function(mapName) {
|
|
|
1214 Publisher.Publish('mapChanged', mapName, this);
|
|
|
1215 },
|
|
|
1216
|
|
|
1217 /**
|
|
|
1218 * displays connections between data objects
|
|
|
1219 */
|
|
|
1220 displayConnections : function() {
|
|
|
1221 return;
|
|
|
1222 if ( typeof this.connection != 'undefined') {
|
|
|
1223 this.objectLayer.removeFeatures(this.connections);
|
|
|
1224 this.connections = [];
|
|
|
1225 }
|
|
|
1226 if (this.options.connections) {
|
|
|
1227 var points = this.mds.getObjectsByZoom();
|
|
|
1228 for (var i in points ) {
|
|
|
1229 for (var j in points[i] ) {
|
|
|
1230
|
|
|
1231 }
|
|
|
1232 }
|
|
|
1233
|
|
|
1234 var slices = this.core.timeplot.getSlices();
|
|
|
1235 for (var i = 0; i < slices.length; i++) {
|
|
|
1236 for (var j = 0; j < slices[i].stacks.length; j++) {
|
|
|
1237 var e = slices[i].stacks[j].elements;
|
|
|
1238 if (e.length == 0) {
|
|
|
1239 continue;
|
|
|
1240 }
|
|
|
1241 var points = [];
|
|
|
1242 for (var k = 0; k < e.length; k++) {
|
|
|
1243 var point = this.mds.getCircle(j, e[k].index).feature.geometry;
|
|
|
1244 if (arrayIndex(points, point) == -1) {
|
|
|
1245 points.push(point);
|
|
|
1246 }
|
|
|
1247 }
|
|
|
1248 var matrix = new AdjMatrix(points.length);
|
|
|
1249 for (var k = 0; k < points.length - 1; k++) {
|
|
|
1250 for (var l = k + 1; l < points.length; l++) {
|
|
|
1251 matrix.setEdge(k, l, dist(points[k], points[l]));
|
|
|
1252 }
|
|
|
1253 }
|
|
|
1254 var tree = Prim(matrix);
|
|
|
1255 var lines = [];
|
|
|
1256 for (var z = 0; z < tree.length; z++) {
|
|
|
1257 lines.push(new OpenLayers.Geometry.LineString(new Array(points[tree[z].v1], points[tree[z].v2])));
|
|
|
1258 }
|
|
|
1259 this.connections[j].push({
|
|
|
1260 first : this.mds.getCircle(j, e[0].index).feature.geometry,
|
|
|
1261 last : this.mds.getCircle(j, e[e.length - 1].index).feature.geometry,
|
|
|
1262 lines : lines,
|
|
|
1263 time : slices[i].date
|
|
|
1264 });
|
|
|
1265 }
|
|
|
1266 }
|
|
|
1267 var ltm = this.core.timeplot.leftFlagTime;
|
|
|
1268 var rtm = this.core.timeplot.rightFlagTime;
|
|
|
1269 if (ltm == undefined || ltm == null) {
|
|
|
1270 return;
|
|
|
1271 } else {
|
|
|
1272 ltm = ltm.getTime();
|
|
|
1273 rtm = rtm.getTime();
|
|
|
1274 }
|
|
|
1275 // this.connectionLayer.destroyFeatures();
|
|
|
1276 if (thisConnections) {
|
|
|
1277 for (var i = 0; i < this.connections.length; i++) {
|
|
|
1278 var c = GeoTemConfig.colors[i];
|
|
|
1279 var style = {
|
|
|
1280 strokeColor : 'rgb(' + c.r1 + ',' + c.g1 + ',' + c.b1 + ')',
|
|
|
1281 strokeOpacity : 0.5,
|
|
|
1282 strokeWidth : 3
|
|
|
1283 };
|
|
|
1284 var pointsToConnect = [];
|
|
|
1285 var last = undefined;
|
|
|
1286 for (var j = 0; j < this.connections[i].length; j++) {
|
|
|
1287 var c = this.connections[i][j];
|
|
|
1288 var ct = c.time.getTime();
|
|
|
1289 if (ct >= ltm && ct <= rtm) {
|
|
|
1290 if (last != undefined) {
|
|
|
1291 var line = new OpenLayers.Geometry.LineString(new Array(last, c.first));
|
|
|
1292 this.connectionLayer.addFeatures([new OpenLayers.Feature.Vector(line, null, style)]);
|
|
|
1293 }
|
|
|
1294 for (var k = 0; k < c.lines.length; k++) {
|
|
|
1295 this.connectionLayer.addFeatures([new OpenLayers.Feature.Vector(c.lines[k], null, style)]);
|
|
|
1296 }
|
|
|
1297 last = c.last;
|
|
|
1298 }
|
|
|
1299 }
|
|
|
1300 }
|
|
|
1301 // this.connectionLayer.redraw();
|
|
|
1302 }
|
|
|
1303 }
|
|
|
1304 },
|
|
|
1305
|
|
|
1306 /**
|
|
|
1307 * performs a zoom on the map
|
|
|
1308 * @param {int} delta the change of zoom levels
|
|
|
1309 */
|
|
|
1310 zoom : function(delta) {
|
|
|
1311 var zoom = this.getZoom() + delta;
|
|
|
1312 if (this.openlayersMap.baseLayer instanceof OpenLayers.Layer.WMS) {
|
|
|
1313 this.openlayersMap.zoomTo(zoom);
|
|
|
1314 } else {
|
|
|
1315 this.openlayersMap.zoomTo(Math.round(zoom));
|
|
|
1316 if (this.zoomSlider) {
|
|
|
1317 this.zoomSlider.setValue(this.getZoom());
|
|
|
1318 }
|
|
|
1319 }
|
|
|
1320 return true;
|
|
|
1321 },
|
|
|
1322
|
|
|
1323 deactivateCountrySelector : function() {
|
|
|
1324 this.openlayersMap.removeControl(this.selectCountry);
|
|
|
1325 this.selectCountry = undefined;
|
|
|
1326 },
|
|
|
1327
|
|
|
1328 activateCountrySelector : function(layer) {
|
|
|
1329 var map = this;
|
|
|
1330 if (this.options.countrySelect && this.options.mapSelectionTools) {
|
|
|
1331 this.selectCountry = new OpenLayers.Control.GetFeature({
|
|
|
1332 protocol : OpenLayers.Protocol.WFS.fromWMSLayer(layer),
|
|
|
1333 click : true
|
|
|
1334 });
|
|
|
1335 this.selectCountry.events.register("featureselected", this, function(e) {
|
|
|
1336 map.snapper();
|
|
|
1337 map.drawnPolygonHandler(e.feature.geometry);
|
|
|
1338 });
|
|
|
1339 this.openlayersMap.addControl(this.selectCountry);
|
|
|
1340 this.countrySelectionControl.enable();
|
|
|
1341 }
|
|
|
1342 },
|
|
|
1343
|
|
|
1344 setMap : function(index) {
|
|
|
1345 this.baselayerIndex = index;
|
|
|
1346 if (this.selectCountry) {
|
|
|
1347 // if( this.wmsOverlays.length == 0 ){
|
|
|
1348 this.deactivateCountrySelector();
|
|
|
1349 // }
|
|
|
1350 }
|
|
|
1351 if (this.baseLayers[index] instanceof OpenLayers.Layer.WMS) {
|
|
|
1352 // if( this.wmsOverlays.length == 0 ){
|
|
|
1353 this.activateCountrySelector(this.baseLayers[index]);
|
|
|
1354 // }
|
|
|
1355 } else {
|
|
|
1356 if (this.countrySelectionControl) {
|
|
|
1357 this.countrySelectionControl.disable();
|
|
|
1358 }
|
|
|
1359 }
|
|
|
1360 this.openlayersMap.zoomTo(Math.floor(this.getZoom()));
|
|
|
1361 this.openlayersMap.setBaseLayer(this.baseLayers[index]);
|
|
|
1362 if (this.baseLayers[index].name == 'Open Street Map') {
|
|
|
1363 this.gui.osmLink.style.visibility = 'visible';
|
|
|
1364 } else {
|
|
|
1365 this.gui.osmLink.style.visibility = 'hidden';
|
|
|
1366 }
|
|
|
1367 if (this.baseLayers[index].name == 'Open Street Map (MapQuest)') {
|
|
|
1368 this.gui.osmMapQuestLink.style.visibility = 'visible';
|
|
|
1369 } else {
|
|
|
1370 this.gui.osmMapQuestLink.style.visibility = 'hidden';
|
|
|
1371 }
|
|
|
1372 this.triggerMapChanged(this.baseLayers[index].name);
|
|
|
1373 },
|
|
|
1374
|
|
|
1375 //vhz added title to buttons
|
|
|
1376 initSelectorTools : function() {
|
|
|
1377 var map = this;
|
|
|
1378 this.mapControls = [];
|
|
|
1379
|
|
|
1380 if (this.options.squareSelect) {
|
|
|
1381 var button = document.createElement("div");
|
|
|
1382 $(button).addClass('mapControl');
|
|
|
1383 var activate = function() {
|
|
|
1384 map.drawSquare.activate();
|
|
|
1385 }
|
|
|
1386 var deactivate = function() {
|
|
|
1387 map.drawSquare.deactivate();
|
|
|
1388 }
|
|
|
1389 this.mapControls.push(new MapControl(this, button, 'square', activate, deactivate));
|
|
|
1390 }
|
|
|
1391 if (this.options.circleSelect) {
|
|
|
1392 var button = document.createElement("div");
|
|
|
1393 $(button).addClass('mapControl');
|
|
|
1394 var activate = function() {
|
|
|
1395 map.drawCircle.activate();
|
|
|
1396 }
|
|
|
1397 var deactivate = function() {
|
|
|
1398 map.drawCircle.deactivate();
|
|
|
1399 }
|
|
|
1400 this.mapControls.push(new MapControl(this, button, 'circle', activate, deactivate));
|
|
|
1401 }
|
|
|
1402 if (this.options.polygonSelect) {
|
|
|
1403 var button = document.createElement("div");
|
|
|
1404 $(button).addClass('mapControl');
|
|
|
1405 var activate = function() {
|
|
|
1406 map.drawPolygon.activate();
|
|
|
1407 }
|
|
|
1408 var deactivate = function() {
|
|
|
1409 map.drawPolygon.deactivate();
|
|
|
1410 }
|
|
|
1411 this.mapControls.push(new MapControl(this, button, 'polygon', activate, deactivate));
|
|
|
1412 }
|
|
|
1413 if (this.options.countrySelect) {
|
|
|
1414 var button = document.createElement("div");
|
|
|
1415 $(button).addClass('mapControl');
|
|
|
1416 var activate = function() {
|
|
|
1417 map.selectCountry.activate();
|
|
|
1418 map.dragControl.disable();
|
|
|
1419 }
|
|
|
1420 var deactivate = function() {
|
|
|
1421 map.selectCountry.deactivate();
|
|
|
1422 map.dragControl.enable();
|
|
|
1423 }
|
|
|
1424 this.countrySelectionControl = new MapControl(this, button, 'country', activate, deactivate);
|
|
|
1425 this.mapControls.push(this.countrySelectionControl);
|
|
|
1426 /*
|
|
|
1427 if( !(this.openlayersMap.baseLayer instanceof OpenLayers.Layer.WMS) ){
|
|
|
1428 this.countrySelectionControl.disable();
|
|
|
1429 }
|
|
|
1430 */
|
|
|
1431 }
|
|
|
1432 return this.mapControls;
|
|
|
1433 },
|
|
|
1434
|
|
|
1435 getZoom : function() {
|
|
|
1436 //calculate zoom from active resolution
|
|
|
1437 var resolution = this.openlayersMap.getResolution();
|
|
|
1438 var zoom = this.resolutions.indexOf(resolution);
|
|
|
1439 if (zoom == -1){
|
|
|
1440 //fractional zoom
|
|
|
1441 for (zoom = 0; zoom < this.resolutions.length; zoom++){
|
|
|
1442 if (resolution>=this.resolutions[zoom]){
|
|
|
1443 break;
|
|
|
1444 }
|
|
|
1445 }
|
|
|
1446 if (zoom == this.resolutions.length){
|
|
|
1447 zoom--;
|
|
|
1448 }
|
|
|
1449 }
|
|
|
1450 return(zoom);
|
|
|
1451 },
|
|
|
1452
|
|
|
1453 setMarker : function(lon, lat) {
|
|
|
1454 var p = new OpenLayers.Geometry.Point(lon, lat, null);
|
|
|
1455 p.transform(this.openlayersMap.displayProjection, this.openlayersMap.projection);
|
|
|
1456 this.openlayersMap.setCenter(new OpenLayers.LonLat(p.x, p.y));
|
|
|
1457 var size = new OpenLayers.Size(22, 33);
|
|
|
1458 var offset = new OpenLayers.Pixel(-(size.w / 2), -size.h);
|
|
|
1459 var icon = new OpenLayers.Icon(GeoTemConfig.path + 'marker.png', size, offset);
|
|
|
1460 var marker = new OpenLayers.Marker(new OpenLayers.LonLat(p.x, p.y), icon);
|
|
|
1461 marker.setOpacity(0.9);
|
|
|
1462 this.markerLayer.setZIndex(parseInt(this.objectLayer.getZIndex()) + 1);
|
|
|
1463 this.markerLayer.addMarker(marker);
|
|
|
1464 // find nearest neighbor
|
|
|
1465 var nearestNeighbor;
|
|
|
1466 var points = this.mds.getAllObjects();
|
|
|
1467 if (points == null) {
|
|
|
1468 return;
|
|
|
1469 }
|
|
|
1470 var dist = function(p1, p2) {
|
|
|
1471 return Math.sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
|
|
|
1472 }
|
|
|
1473 var zoomLevels = this.openlayersMap.getNumZoomLevels();
|
|
|
1474 var pointSet = points[zoomLevels - 1];
|
|
|
1475 var closestDistance = undefined;
|
|
|
1476 var closestPoint;
|
|
|
1477 for (var i = 0; i < pointSet.length; i++) {
|
|
|
1478 for (var j = 0; j < pointSet[i].length; j++) {
|
|
|
1479 var point = pointSet[i][j].feature.geometry;
|
|
|
1480 var d = dist(point, p);
|
|
|
1481 if (!closestDistance || d < closestDistance) {
|
|
|
1482 closestDistance = d;
|
|
|
1483 closestPoint = point;
|
|
|
1484 }
|
|
|
1485 }
|
|
|
1486 }
|
|
|
1487 // find minimal zoom level
|
|
|
1488 var gap = 0;
|
|
|
1489 var x_s = this.gui.mapWindow.offsetWidth / 2 - gap;
|
|
|
1490 var y_s = this.gui.mapWindow.offsetHeight / 2 - gap;
|
|
|
1491 if (typeof closestPoint !== "undefined"){
|
|
|
1492 var xDist = Math.abs(p.x - closestPoint.x);
|
|
|
1493 var yDist = Math.abs(p.y - closestPoint.y);
|
|
|
1494 for (var i = 0; i < zoomLevels; i++) {
|
|
|
1495 var resolution = this.openlayersMap.getResolutionForZoom(zoomLevels - i - 1);
|
|
|
1496 if (xDist / resolution < x_s && yDist / resolution < y_s) {
|
|
|
1497 this.openlayersMap.zoomTo(zoomLevels - i - 1);
|
|
|
1498 if (this.zoomSlider) {
|
|
|
1499 this.zoomSlider.setValue(this.getZoom());
|
|
|
1500 }
|
|
|
1501 this.drawObjectLayer(false);
|
|
|
1502 break;
|
|
|
1503 }
|
|
|
1504 }
|
|
|
1505 } else {
|
|
|
1506 //if there are no points on the map, zoom to max
|
|
|
1507 this.openlayersMap.zoomTo(0);
|
|
|
1508 if (this.zoomSlider) {
|
|
|
1509 this.zoomSlider.setValue(this.getZoom());
|
|
|
1510 }
|
|
|
1511 this.drawObjectLayer(false);
|
|
|
1512 }
|
|
|
1513 },
|
|
|
1514
|
|
|
1515 removeMarker : function() {
|
|
|
1516 this.markerLayer.removeMarker(this.markerLayer.markers[0]);
|
|
|
1517 },
|
|
|
1518
|
|
|
1519 getLevelOfDetail : function() {
|
|
|
1520 var zoom = Math.floor(this.getZoom());
|
|
|
1521 if (zoom <= 1) {
|
|
|
1522 return 0;
|
|
|
1523 } else if (zoom <= 3) {
|
|
|
1524 return 1;
|
|
|
1525 } else if (zoom <= 8) {
|
|
|
1526 return 2;
|
|
|
1527 } else {
|
|
|
1528 return 3;
|
|
|
1529 }
|
|
|
1530 }
|
|
|
1531 }
|