comparison d3s_examples/python-neo4jrestclient/static/platin/js/Map/MapWidget.js @ 8:18ef6948d689

new d3s examples
author Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
date Thu, 01 Oct 2015 17:17:27 +0200
parents
children
comparison
equal deleted inserted replaced
7:45dad9e38c82 8:18ef6948d689
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 var hideEmptyCircles = false;
1094
1095 if (this.config.options.hideUnselected){
1096 var overallCnt = 0;
1097 for (var i in mapObjects){
1098 overallCnt += mapObjects[i].length;
1099 }
1100 if (overallCnt > 0){
1101 hideEmptyCircles = true;
1102 }
1103 }
1104
1105 if( !GeoTemConfig.highlightEvents ){
1106 return;
1107 }
1108 this.mds.clearOverlay();
1109 if (this.selection.valid()) {
1110 this.mds.setOverlay(GeoTemConfig.mergeObjects(mapObjects, this.selection.getObjects()));
1111 } else {
1112 this.mds.setOverlay(mapObjects);
1113 }
1114 var points = this.mds.getObjectsByZoom();
1115 var polygon = this.openlayersMap.getExtent().toGeometry();
1116 for (var i in points ) {
1117 for (var j in points[i] ) {
1118 var point = points[i][j];
1119
1120 if (hideEmptyCircles){
1121 point.feature.style.display = 'none';
1122 } else {
1123 point.feature.style.display = '';
1124 }
1125
1126 this.updatePoint(points[i][j], polygon);
1127 }
1128 }
1129 this.displayConnections();
1130 this.objectLayer.redraw();
1131 },
1132
1133 selectionChanged : function(selection) {
1134 if( !GeoTemConfig.selectionEvents ){
1135 return;
1136 }
1137 this.reset();
1138 this.selection = selection;
1139 this.highlightChanged(selection.objects);
1140 },
1141
1142 inPolygon : function(point) {
1143 for (var i = 0; i < this.polygons.length; i++) {
1144 var polygon = this.polygons[i].geometry;
1145 for (var j = 0; j < polygon.components.length; j++) {
1146 if (polygon.components[j].containsPoint(point.feature.geometry)) {
1147 return true;
1148 }
1149 }
1150 }
1151 return false;
1152 },
1153
1154 mapSelection : function() {
1155 var selectedObjects = [];
1156 for (var i = 0; i < this.mds.size(); i++) {
1157 selectedObjects.push([]);
1158 }
1159 var circles = this.mds.getObjectsByZoom();
1160 for (var i = 0; i < circles.length; i++) {
1161
1162 for (var j = 0; j < circles[i].length; j++) {
1163 var c = circles[i][j];
1164 if (c.selected) {
1165 selectedObjects[i] = selectedObjects[i].concat(c.elements);
1166 }
1167 }
1168 }
1169 this.selection = new Selection(selectedObjects, this);
1170 this.highlightChanged(selectedObjects);
1171 this.core.triggerSelection(this.selection);
1172 this.filterBar.reset(true);
1173 },
1174
1175 deselection : function() {
1176 this.reset();
1177 this.selection = new Selection();
1178 this.highlightChanged([]);
1179 this.core.triggerSelection(this.selection);
1180 },
1181
1182 filtering : function() {
1183 for (var i = 0; i < this.datasets.length; i++) {
1184 this.datasets[i].objects = this.selection.objects[i];
1185 }
1186 this.core.triggerRefining(this.datasets);
1187 },
1188
1189 inverseFiltering : function() {
1190 var selectedObjects = [];
1191 for (var i = 0; i < this.mds.size(); i++) {
1192 selectedObjects.push([]);
1193 }
1194 var circles = this.mds.getObjectsByZoom();
1195 for (var i = 0; i < circles.length; i++) {
1196 for (var j = 0; j < circles[i].length; j++) {
1197 var c = circles[i][j];
1198 if (!c.selected) {
1199 selectedObjects[i] = selectedObjects[i].concat(c.elements);
1200 }
1201 }
1202 }
1203 this.selection = new Selection(selectedObjects, this);
1204 this.filtering();
1205 },
1206
1207 mapCircleHighlight : function(circle, undo) {
1208 if (this.polygons.length > 0 && this.inPolygon(circle)) {
1209 return;
1210 }
1211 var mapObjects = [];
1212 for (var i = 0; i < this.mds.size(); i++) {
1213 mapObjects.push([]);
1214 }
1215 if (!undo && !circle.selected) {
1216 mapObjects[circle.search] = circle.elements;
1217 }
1218 this.objectLayer.drawFeature(circle.feature);
1219 this.core.triggerHighlight(mapObjects);
1220 },
1221
1222 mapLabelSelection : function(label) {
1223 var selectedObjects = [];
1224 for (var i = 0; i < this.mds.size(); i++) {
1225 selectedObjects.push([]);
1226 }
1227 selectedObjects[label.index] = label.elements;
1228 this.selection = new Selection(selectedObjects, this);
1229 this.highlightChanged(selectedObjects);
1230 this.core.triggerSelection(this.selection);
1231 this.filterBar.reset(true);
1232 },
1233
1234 triggerMapChanged : function(mapName) {
1235 Publisher.Publish('mapChanged', mapName, this);
1236 },
1237
1238 /**
1239 * displays connections between data objects
1240 */
1241 displayConnections : function() {
1242 return;
1243 if ( typeof this.connection != 'undefined') {
1244 this.objectLayer.removeFeatures(this.connections);
1245 this.connections = [];
1246 }
1247 if (this.options.connections) {
1248 var points = this.mds.getObjectsByZoom();
1249 for (var i in points ) {
1250 for (var j in points[i] ) {
1251
1252 }
1253 }
1254
1255 var slices = this.core.timeplot.getSlices();
1256 for (var i = 0; i < slices.length; i++) {
1257 for (var j = 0; j < slices[i].stacks.length; j++) {
1258 var e = slices[i].stacks[j].elements;
1259 if (e.length == 0) {
1260 continue;
1261 }
1262 var points = [];
1263 for (var k = 0; k < e.length; k++) {
1264 var point = this.mds.getCircle(j, e[k].index).feature.geometry;
1265 if (arrayIndex(points, point) == -1) {
1266 points.push(point);
1267 }
1268 }
1269 var matrix = new AdjMatrix(points.length);
1270 for (var k = 0; k < points.length - 1; k++) {
1271 for (var l = k + 1; l < points.length; l++) {
1272 matrix.setEdge(k, l, dist(points[k], points[l]));
1273 }
1274 }
1275 var tree = Prim(matrix);
1276 var lines = [];
1277 for (var z = 0; z < tree.length; z++) {
1278 lines.push(new OpenLayers.Geometry.LineString(new Array(points[tree[z].v1], points[tree[z].v2])));
1279 }
1280 this.connections[j].push({
1281 first : this.mds.getCircle(j, e[0].index).feature.geometry,
1282 last : this.mds.getCircle(j, e[e.length - 1].index).feature.geometry,
1283 lines : lines,
1284 time : slices[i].date
1285 });
1286 }
1287 }
1288 var ltm = this.core.timeplot.leftFlagTime;
1289 var rtm = this.core.timeplot.rightFlagTime;
1290 if (ltm == undefined || ltm == null) {
1291 return;
1292 } else {
1293 ltm = ltm.getTime();
1294 rtm = rtm.getTime();
1295 }
1296 // this.connectionLayer.destroyFeatures();
1297 if (thisConnections) {
1298 for (var i = 0; i < this.connections.length; i++) {
1299 var c = GeoTemConfig.colors[i];
1300 var style = {
1301 strokeColor : 'rgb(' + c.r1 + ',' + c.g1 + ',' + c.b1 + ')',
1302 strokeOpacity : 0.5,
1303 strokeWidth : 3
1304 };
1305 var pointsToConnect = [];
1306 var last = undefined;
1307 for (var j = 0; j < this.connections[i].length; j++) {
1308 var c = this.connections[i][j];
1309 var ct = c.time.getTime();
1310 if (ct >= ltm && ct <= rtm) {
1311 if (last != undefined) {
1312 var line = new OpenLayers.Geometry.LineString(new Array(last, c.first));
1313 this.connectionLayer.addFeatures([new OpenLayers.Feature.Vector(line, null, style)]);
1314 }
1315 for (var k = 0; k < c.lines.length; k++) {
1316 this.connectionLayer.addFeatures([new OpenLayers.Feature.Vector(c.lines[k], null, style)]);
1317 }
1318 last = c.last;
1319 }
1320 }
1321 }
1322 // this.connectionLayer.redraw();
1323 }
1324 }
1325 },
1326
1327 /**
1328 * performs a zoom on the map
1329 * @param {int} delta the change of zoom levels
1330 */
1331 zoom : function(delta) {
1332 var zoom = this.getZoom() + delta;
1333 if (this.openlayersMap.baseLayer instanceof OpenLayers.Layer.WMS) {
1334 this.openlayersMap.zoomTo(zoom);
1335 } else {
1336 this.openlayersMap.zoomTo(Math.round(zoom));
1337 if (this.zoomSlider) {
1338 this.zoomSlider.setValue(this.getZoom());
1339 }
1340 }
1341 return true;
1342 },
1343
1344 deactivateCountrySelector : function() {
1345 this.openlayersMap.removeControl(this.selectCountry);
1346 this.selectCountry = undefined;
1347 },
1348
1349 activateCountrySelector : function(layer) {
1350 var map = this;
1351 if (this.options.countrySelect && this.options.mapSelectionTools) {
1352 this.selectCountry = new OpenLayers.Control.GetFeature({
1353 protocol : OpenLayers.Protocol.WFS.fromWMSLayer(layer),
1354 click : true
1355 });
1356 this.selectCountry.events.register("featureselected", this, function(e) {
1357 map.snapper();
1358 map.drawnPolygonHandler(e.feature.geometry);
1359 });
1360 this.openlayersMap.addControl(this.selectCountry);
1361 this.countrySelectionControl.enable();
1362 }
1363 },
1364
1365 setMap : function(index) {
1366 this.baselayerIndex = index;
1367 if (this.selectCountry) {
1368 // if( this.wmsOverlays.length == 0 ){
1369 this.deactivateCountrySelector();
1370 // }
1371 }
1372 if (this.baseLayers[index] instanceof OpenLayers.Layer.WMS) {
1373 // if( this.wmsOverlays.length == 0 ){
1374 this.activateCountrySelector(this.baseLayers[index]);
1375 // }
1376 } else {
1377 if (this.countrySelectionControl) {
1378 this.countrySelectionControl.disable();
1379 }
1380 }
1381 this.openlayersMap.zoomTo(Math.floor(this.getZoom()));
1382 this.openlayersMap.setBaseLayer(this.baseLayers[index]);
1383 if (this.baseLayers[index].name == 'Open Street Map') {
1384 this.gui.osmLink.style.visibility = 'visible';
1385 } else {
1386 this.gui.osmLink.style.visibility = 'hidden';
1387 }
1388 if (this.baseLayers[index].name == 'Open Street Map (MapQuest)') {
1389 this.gui.osmMapQuestLink.style.visibility = 'visible';
1390 } else {
1391 this.gui.osmMapQuestLink.style.visibility = 'hidden';
1392 }
1393 this.triggerMapChanged(this.baseLayers[index].name);
1394 },
1395
1396 //vhz added title to buttons
1397 initSelectorTools : function() {
1398 var map = this;
1399 this.mapControls = [];
1400
1401 if (this.options.squareSelect) {
1402 var button = document.createElement("div");
1403 $(button).addClass('mapControl');
1404 var activate = function() {
1405 map.drawSquare.activate();
1406 }
1407 var deactivate = function() {
1408 map.drawSquare.deactivate();
1409 }
1410 this.mapControls.push(new MapControl(this, button, 'square', activate, deactivate));
1411 }
1412 if (this.options.circleSelect) {
1413 var button = document.createElement("div");
1414 $(button).addClass('mapControl');
1415 var activate = function() {
1416 map.drawCircle.activate();
1417 }
1418 var deactivate = function() {
1419 map.drawCircle.deactivate();
1420 }
1421 this.mapControls.push(new MapControl(this, button, 'circle', activate, deactivate));
1422 }
1423 if (this.options.polygonSelect) {
1424 var button = document.createElement("div");
1425 $(button).addClass('mapControl');
1426 var activate = function() {
1427 map.drawPolygon.activate();
1428 }
1429 var deactivate = function() {
1430 map.drawPolygon.deactivate();
1431 }
1432 this.mapControls.push(new MapControl(this, button, 'polygon', activate, deactivate));
1433 }
1434 if (this.options.countrySelect) {
1435 var button = document.createElement("div");
1436 $(button).addClass('mapControl');
1437 var activate = function() {
1438 map.selectCountry.activate();
1439 map.dragControl.disable();
1440 }
1441 var deactivate = function() {
1442 map.selectCountry.deactivate();
1443 map.dragControl.enable();
1444 }
1445 this.countrySelectionControl = new MapControl(this, button, 'country', activate, deactivate);
1446 this.mapControls.push(this.countrySelectionControl);
1447 /*
1448 if( !(this.openlayersMap.baseLayer instanceof OpenLayers.Layer.WMS) ){
1449 this.countrySelectionControl.disable();
1450 }
1451 */
1452 }
1453 return this.mapControls;
1454 },
1455
1456 getZoom : function() {
1457 //calculate zoom from active resolution
1458 var resolution = this.openlayersMap.getResolution();
1459 var zoom = this.resolutions.indexOf(resolution);
1460 if (zoom == -1){
1461 //fractional zoom
1462 for (zoom = 0; zoom < this.resolutions.length; zoom++){
1463 if (resolution>=this.resolutions[zoom]){
1464 break;
1465 }
1466 }
1467 if (zoom == this.resolutions.length){
1468 zoom--;
1469 }
1470 }
1471 return(zoom);
1472 },
1473
1474 setMarker : function(lon, lat) {
1475 var p = new OpenLayers.Geometry.Point(lon, lat, null);
1476 p.transform(this.openlayersMap.displayProjection, this.openlayersMap.projection);
1477 this.openlayersMap.setCenter(new OpenLayers.LonLat(p.x, p.y));
1478 var size = new OpenLayers.Size(22, 33);
1479 var offset = new OpenLayers.Pixel(-(size.w / 2), -size.h);
1480 var icon = new OpenLayers.Icon(GeoTemConfig.path + 'marker.png', size, offset);
1481 var marker = new OpenLayers.Marker(new OpenLayers.LonLat(p.x, p.y), icon);
1482 marker.setOpacity(0.9);
1483 this.markerLayer.setZIndex(parseInt(this.objectLayer.getZIndex()) + 1);
1484 this.markerLayer.addMarker(marker);
1485 // find nearest neighbor
1486 var nearestNeighbor;
1487 var points = this.mds.getAllObjects();
1488 if (points == null) {
1489 return;
1490 }
1491 var dist = function(p1, p2) {
1492 return Math.sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
1493 }
1494 var zoomLevels = this.openlayersMap.getNumZoomLevels();
1495 var pointSet = points[zoomLevels - 1];
1496 var closestDistance = undefined;
1497 var closestPoint;
1498 for (var i = 0; i < pointSet.length; i++) {
1499 for (var j = 0; j < pointSet[i].length; j++) {
1500 var point = pointSet[i][j].feature.geometry;
1501 var d = dist(point, p);
1502 if (!closestDistance || d < closestDistance) {
1503 closestDistance = d;
1504 closestPoint = point;
1505 }
1506 }
1507 }
1508 // find minimal zoom level
1509 var gap = 0;
1510 var x_s = this.gui.mapWindow.offsetWidth / 2 - gap;
1511 var y_s = this.gui.mapWindow.offsetHeight / 2 - gap;
1512 if (typeof closestPoint !== "undefined"){
1513 var xDist = Math.abs(p.x - closestPoint.x);
1514 var yDist = Math.abs(p.y - closestPoint.y);
1515 for (var i = 0; i < zoomLevels; i++) {
1516 var resolution = this.openlayersMap.getResolutionForZoom(zoomLevels - i - 1);
1517 if (xDist / resolution < x_s && yDist / resolution < y_s) {
1518 this.openlayersMap.zoomTo(zoomLevels - i - 1);
1519 if (this.zoomSlider) {
1520 this.zoomSlider.setValue(this.getZoom());
1521 }
1522 this.drawObjectLayer(false);
1523 break;
1524 }
1525 }
1526 } else {
1527 //if there are no points on the map, zoom to max
1528 this.openlayersMap.zoomTo(0);
1529 if (this.zoomSlider) {
1530 this.zoomSlider.setValue(this.getZoom());
1531 }
1532 this.drawObjectLayer(false);
1533 }
1534 },
1535
1536 removeMarker : function() {
1537 this.markerLayer.removeMarker(this.markerLayer.markers[0]);
1538 },
1539
1540 getLevelOfDetail : function() {
1541 var zoom = Math.floor(this.getZoom());
1542 if (zoom <= 1) {
1543 return 0;
1544 } else if (zoom <= 3) {
1545 return 1;
1546 } else if (zoom <= 8) {
1547 return 2;
1548 } else {
1549 return 3;
1550 }
1551 },
1552
1553
1554 getConfig : function(inquiringWidget){
1555 var mapWidget = this;
1556 var config = {};
1557
1558 //save widget specific configurations here into the config object
1559 config.mapIndex = this.baselayerIndex;
1560 config.mapCenter = this.openlayersMap.center;
1561 config.mapZoom = this.openlayersMap.zoom;
1562 //send config to iquiring widget
1563 if (typeof inquiringWidget.sendConfig !== "undefined"){
1564 inquiringWidget.sendConfig({widgetName: "map", 'config': config});
1565 }
1566 },
1567
1568 setConfig : function(configObj){
1569 var mapWidget = this;
1570
1571 if (configObj.widgetName === "map"){
1572 var config = configObj.config;
1573
1574 //set widgets configuration provided by config
1575 this.setMap(config.mapIndex);
1576 this.gui.mapTypeDropdown.setEntry(config.mapIndex);
1577
1578 this.openlayersMap.setCenter(config.mapCenter);
1579 this.openlayersMap.zoomTo(config.mapZoom);
1580 }
1581 },
1582
1583 }