1(function () { 2 var mapNumber = 0, currentProtocol = document.location.protocol; 3 4 if (currentProtocol != 'http:' && currentProtocol != 'https:') { 5 currentProtocol = 'https:'; 6 } 7 8 function delayedExecutor(delay, callback) 9 { 10 var timeout; 11 12 return function () { 13 if (timeout) { 14 clearTimeout(timeout); 15 timeout = null; 16 } 17 18 timeout = setTimeout(callback, delay); 19 }; 20 } 21 22 function getBaseLayers() 23 { 24 var layers = [], tiles = jqueryTiki.mapTileSets, factories = { 25 openstreetmap: function () { 26 return new OpenLayers.Layer.OSM(); 27 }, 28 mapquest_street: function () { 29 return new OpenLayers.Layer.XYZ( 30 "MapQuest OpenStreetMap", 31 "http://otile1.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png", 32 {sphericalMercator: true} 33 ); 34 }, 35 mapquest_aerial: function () { 36 return new OpenLayers.Layer.XYZ( 37 "MapQuest Open Aerial", 38 "http://oatile1.mqcdn.com/tiles/1.0.0/sat/${z}/${x}/${y}.png", 39 {sphericalMercator: true} 40 ); 41 }, 42 google_street: function () { 43 return new OpenLayers.Layer.Google( 44 "Google Streets", 45 {numZoomLevels: 20} 46 ); 47 }, 48 google_satellite: function () { 49 return new OpenLayers.Layer.Google( 50 "Google Satellite", 51 {type: google.maps.MapTypeId.SATELLITE, numZoomLevels: 22} 52 ); 53 }, 54 google_hybrid: function () { 55 return new OpenLayers.Layer.Google( 56 "Google Hybrid", 57 {type: google.maps.MapTypeId.HYBRID, numZoomLevels: 20} 58 ); 59 }, 60 google_physical: function () { 61 return new OpenLayers.Layer.Google( 62 "Google Physical", 63 {type: google.maps.MapTypeId.TERRAIN} 64 ); 65 }, 66 blank: function () { 67 // Fake layer to hide all tiles 68 var layer = new OpenLayers.Layer.OSM(tr('Blank')); 69 layer.isBlank = true; 70 return layer; 71 /* Needs additional testing 72 }, 73 visualearth_road: function () { 74 return new OpenLayers.Layer.VirtualEarth( 75 "Virtual Earth Roads", 76 {'type': VEMapStyle.Road} 77 ); 78 */ 79 } 80 }; 81 82 if (tiles.length === 0) { 83 tiles.push('openstreetmap'); 84 } 85 86 $.each(tiles, function (k, name) { 87 var f = factories[name]; 88 89 if (f) { 90 layers.push(f()); 91 } 92 }); 93 94 return layers; 95 } 96 97 function parseCoordinates(value) { 98 var matching = value.match(/^(-?[0-9]*(\.[0-9]+)?),(-?[0-9]*(\.[0-9]+)?)(,(.*))?$/); 99 100 if (matching) { 101 var lat = parseFloat(matching[3]); 102 var lon = parseFloat(matching[1]); 103 var zoom = matching[6] ? parseInt(matching[6], 10) : 0; 104 105 return {lat: lat, lon: lon, zoom: zoom}; 106 } 107 108 return null; 109 } 110 111 function writeCoordinates(lonlat, map, fixProjection) { 112 var original = lonlat; 113 114 if (fixProjection) { 115 lonlat = lonlat.transform( 116 map.getProjectionObject(), 117 new OpenLayers.Projection("EPSG:4326") 118 ); 119 120 if (lonlat.lon < 0.01 && lonlat.lat < 0.01) { 121 lonlat = original; 122 } 123 } 124 125 return formatLocation(lonlat.lat, lonlat.lon, map.getZoom()); 126 } 127 128 function formatLocation (lat, lon, zoom) 129 { 130 // Convert , decimal points - where those are used 131 var strLon = '' + lon; 132 strLon.replace(',', '.'); 133 var strLat = '' + lat; 134 strLat.replace(',', '.'); 135 return strLon + ',' + strLat + ',' + zoom; 136 } 137 138 $.fn.createMap = function () { 139 this.each(function () { 140 var id = $(this).attr('id'), container = this, desiredControls; 141 $(container).css('background', 'white'); 142 desiredControls = $(this).data('map-controls'); 143 if (desiredControls === undefined) { 144 desiredControls = 'controls,layers,search_location,current_location,streetview,navigation'; 145 } 146 147 desiredControls = desiredControls.split(','); 148 149 var setupHeight = function () { 150 var height = $(container).height(); 151 if (0 === height) { 152 height = $(container).width() / 4.0 * 3.0; 153 } 154 155 $(container).closest('.height-size').each(function () { 156 height = $(this).data('available-height'); 157 $(this).css('padding', 0); 158 $(this).css('margin', 0); 159 }); 160 161 $(container).height(height); 162 }; 163 setupHeight(); 164 165 $(window).resize(setupHeight); 166 167 if (! id) { 168 ++mapNumber; 169 id = 'openlayers' + mapNumber; 170 $(this).attr('id', id); 171 } 172 173 setTimeout(function () { 174 OpenLayers.ImgPath = "lib/openlayers/theme/dark/"; 175 var map = container.map = new OpenLayers.Map(id, { 176 controls: [], 177 theme: null 178 }); 179 var layers = getBaseLayers(); 180 181 // these functions attempt to retrieve values for the style attributes, 182 // falling back to others if not all options are specified 183 // e.g. if "select-fill-color" is not provided it will use "fill-color", or just "color" attributes 184 185 var getColor = function (feature, intent, type) { 186 return feature.attributes[intent + "-" + type + "-color"] || 187 feature.attributes[intent + "-color"] || 188 feature.attributes[type + "-color"] || 189 feature.attributes["color"] || 190 "#6699cc"; 191 }; 192 193 var getStyleAttribute = function (feature, intent, type, def) { 194 return feature.attributes[intent + "-" + type] || 195 feature.attributes[type] || 196 def; 197 }; 198 199 container.defaultStyleMap = new OpenLayers.StyleMap({ 200 "default": new OpenLayers.Style(OpenLayers.Util.applyDefaults({ 201 cursor: "pointer" 202 }, OpenLayers.Feature.Vector.style['default']), { 203 context: { 204 getFillColor: function (feature) { 205 return getColor(feature, "default", "fill"); 206 }, 207 getStrokeColor: function (feature) { 208 return getColor(feature, "default", "stroke"); 209 }, 210 getStrokeWidth: function (feature) { 211 return getStyleAttribute(feature, "default", "stroke-width", 3); 212 }, 213 getStrokeDashstyle: function (feature) { 214 return getStyleAttribute(feature, "default", "stroke-dashstyle", "solid"); 215 }, 216 getPointRadius: function (feature) { 217 return getStyleAttribute(feature, "default", "point-radius", 5); 218 }, 219 getFillOpacity: function (feature) { 220 return getStyleAttribute(feature, "default", "fill-opacity", 0.5); 221 }, 222 getStrokeOpacity: function (feature) { 223 return getStyleAttribute(feature, "default", "stroke-opacity", 0.9); 224 } 225 } 226 }), 227 "select": new OpenLayers.Style(OpenLayers.Util.applyDefaults({ 228 cursor: "pointer" 229 }, OpenLayers.Feature.Vector.style['select']), { 230 context: { 231 getFillColor: function (feature) { 232 return getColor(feature, "select", "fill"); 233 }, 234 getStrokeColor: function (feature) { 235 return getColor(feature, "select", "stroke"); 236 }, 237 getStrokeWidth: function (feature) { 238 return getStyleAttribute(feature, "select", "stroke-width", 3); 239 }, 240 getStrokeDashstyle: function (feature) { 241 return getStyleAttribute(feature, "select", "stroke-dashstyle", "solid"); 242 }, 243 getPointRadius: function (feature) { 244 return getStyleAttribute(feature, "select", "point-radius", 5); 245 }, 246 getFillOpacity: function (feature) { 247 return getStyleAttribute(feature, "select", "fill-opacity", 0.9); 248 }, 249 getStrokeOpacity: function (feature) { 250 return getStyleAttribute(feature, "select", "stroke-opacity", 0.9); 251 } 252 } 253 }), 254 "temporary": new OpenLayers.Style(OpenLayers.Util.applyDefaults({ 255 cursor: "pointer" 256 }, OpenLayers.Feature.Vector.style['temporary']), { 257 context: { 258 getFillColor: function (feature) { 259 return getColor(feature, "temporary", "fill"); 260 }, 261 getStrokeColor: function (feature) { 262 return getColor(feature, "temporary", "stroke"); 263 }, 264 getStrokeWidth: function (feature) { 265 return getStyleAttribute(feature, "temporary", "stroke-width", 4); 266 }, 267 getStrokeDashstyle: function (feature) { 268 return getStyleAttribute(feature, "temporary", "stroke-dashstyle", "solid"); 269 }, 270 getPointRadius: function (feature) { 271 return getStyleAttribute(feature, "temporary", "point-radius", 5); 272 }, 273 getFillOpacity: function (feature) { 274 return getStyleAttribute(feature, "temporary", "fill-opacity", 0.3); 275 }, 276 getStrokeOpacity: function (feature) { 277 return getStyleAttribute(feature, "temporary", "stroke-opacity", 0.9); 278 } 279 } 280 }), 281 "vertex": new OpenLayers.Style(OpenLayers.Util.applyDefaults({ 282 fillColor: "#6699cc", 283 strokeColor: "#6699cc", 284 pointRadius: 5, 285 fillOpacity: ".7", 286 strokeDashstyle: "solid" 287 }, OpenLayers.Feature.Vector.style['temporary'])) 288 }); 289 290 var markerStyle = { 291 externalGraphic: "${url}", 292 graphicWidth: "${width}", 293 graphicHeight: "${height}", 294 graphicXOffset: "${offsetx}", 295 graphicYOffset: "${offsety}", 296 graphicOpacity: typeof window.chrome === "undefined" ? 0.9 : 1 297 // Google Chrome v34 makes some markers invisible if not 100% opaque 298 }, vectorStyle = { 299 fillColor: "${getFillColor}", 300 strokeColor: "${getStrokeColor}", 301 strokeDashstyle: "${getStrokeDashstyle}", 302 strokeWidth: "${getStrokeWidth}", 303 pointRadius: "${getPointRadius}", 304 fillOpacity: "${getFillOpacity}", 305 strokeOpacity: "${getStrokeOpacity}" 306 }; 307 308 container.defaultStyleMap.addUniqueValueRules("default", "intent", { 309 "marker": markerStyle, "vectors": vectorStyle 310 }); 311 312 container.defaultStyleMap.addUniqueValueRules("select", "intent", { 313 "marker": markerStyle, "vectors": vectorStyle 314 }); 315 316 container.defaultStyleMap.addUniqueValueRules("temporary", "intent", { 317 "marker": markerStyle, "vectors": vectorStyle 318 }); 319 320 container.layer = layers[0]; 321 container.vectors = new OpenLayers.Layer.Vector(tr("Editable"), { 322 styleMap: container.defaultStyleMap 323 }); 324 container.uniqueMarkers = {}; 325 container.layers = {};
326 try { 327 map.addLayers(layers); 328 map.addLayer(container.vectors); 329 } catch (e) { 330 console.log("Map error: problem adding layer " + e.message); 331 } 332 333 container.resetPosition = function () { 334 map.setCenter(new OpenLayers.LonLat(0, 0), 3); 335 }; 336 container.resetPosition(); 337 338 function setupLayerEvents(vectors) { 339 vectors.events.on({ 340 featureunselected: function (event) { 341 if (event.feature.executor) { 342 event.feature.executor(); 343 } 344 $(container).setMapPopup(null); 345 }, 346 featuremodified: function (event) { 347 if (event.feature.executor) { 348 event.feature.executor(); 349 } 350 }, 351 beforefeatureadded: function (event) { 352 if (! event.feature.attributes.color) { 353 event.feature.attributes.color = '#6699cc'; 354 } 355 if (! event.feature.attributes.intent) { 356 event.feature.attributes.intent = "vectors"; 357 } 358 } 359 }); 360 } 361 362 setupLayerEvents(container.vectors); 363 364 container.modeManager = { 365 modes: [], 366 activeMode: null, 367 addMode: function (options) { 368 var mode = $.extend({ 369 name: tr('Default'), 370 icon: null, 371 events: { 372 activate: [], 373 deactivate: [] 374 }, 375 controls: [], 376 layers: [] 377 }, options); 378 379 $.each(mode.layers, function (k, layer) { 380 layer.displayInLayerSwitcher = false;
381 layer.setVisibility(false); 382 map.addLayer(layer); 383 }); 384 385 $.each(mode.controls, function (k, control) { 386 control.autoActivate = false; 387 map.addControl(control); 388 }); 389 390 this.modes.push(mode); 391 392 this.register('activate', mode.name, mode.activate); 393 this.register('deactivate', mode.name, mode.deactivate); 394 395 if (! this.activeMode) { 396 this.activate(mode); 397 } 398 399 $(container).trigger('modechanged'); 400 401 return mode; 402 }, 403 switchTo: function (modeName) { 404 var manager = this; 405 $.each(this.modes, function (k, mode) { 406 if (mode.name === modeName) { 407 manager.activate(mode); 408 } 409 }); 410 }, 411 register: function (eventName, modeName, callback) { 412 $.each(this.modes, function (k, mode) { 413 if (mode.name === modeName && callback) { 414 mode.events[eventName].push(callback); 415 } 416 }); 417 }, 418 activate: function (mode) { 419 if (this.activeMode) { 420 this.deactivate(); 421 } 422 423 this.activeMode = mode; 424 425 $.each(mode.controls, function (k, control) { 426 control.activate(); 427 }); 428 $.each(mode.layers, function (k, layer) { 429 layer.setVisibility(true); 430 }); 431 $.each(mode.events.activate, function (k, f) { 432 f.apply([], container); 433 }); 434 435 $(container).trigger('modechanged'); 436 }, 437 deactivate: function () { 438 if (! this.activeMode) { 439 return; 440 } 441 442 $.each(this.activeMode.controls, function (k, control) { 443 control.deactivate(); 444 }); 445 $.each(this.activeMode.layers, function (k, layer) { 446 layer.setVisibility(false); 447 }); 448 $.each(this.activeMode.events.deactivate, function (k, f) { 449 f.apply([], container); 450 }); 451 452 this.activeMode = null; 453 } 454 }; 455 456 var defaultMode = { 457 controls: [] 458 }; 459 460 map.addControl(new OpenLayers.Control.Attribution()); 461 462 if (-1 !== $.inArray('coordinates', desiredControls)) { 463 map.addControl(new OpenLayers.Control.MousePosition({ 464 displayProjection: new OpenLayers.Projection("EPSG:4326") 465 })); 466 } 467 468 if (layers.length > 0 && -1 !== $.inArray('scale', desiredControls)) { 469 map.addControl(new OpenLayers.Control.ScaleLine()); 470 } 471 472 if (layers.length > 0 && -1 !== $.inArray('navigation', desiredControls)) { 473 defaultMode.controls.push(new OpenLayers.Control.NavToolbar()); 474 } 475 476 if (layers.length > 0 && -1 !== $.inArray('controls', desiredControls)) { 477 if (-1 !== $.inArray('levels', desiredControls)) { 478 map.addControl(new OpenLayers.Control.PanZoomBar()); 479 } else { 480 map.addControl(new OpenLayers.Control.PanZoom()); 481 } 482 } 483 484 if (layers.length > 1 && -1 !== $.inArray('layers', desiredControls)) { 485 map.addControl(new OpenLayers.Control.LayerSwitcher()); 486 } 487 488 var highlightControl, selectControl, vectorLayerList = [container.vectors]; 489 490 if ($(container).data("tooltips")) { 491 defaultMode.controls.push(highlightControl = new OpenLayers.Control.SelectFeature(vectorLayerList, { 492 hover: true, 493 highlightOnly: true, 494 renderIntent: "temporary", 495 clickout: true, 496 eventListeners: { 497 beforefeaturehighlighted: null, 498 featurehighlighted: function (evt) { 499 500 if (container.tooltipPopup) { 501 map.removePopup(container.tooltipPopup); 502 container.tooltipPopup = null; 503 } 504 505 if (evt.feature.layer.selectedFeatures.indexOf(evt.feature) > -1) { 506 return; 507 } 508 509 var lonlat = map.getLonLatFromPixel( 510 // get mouse position 511 this.handlers.feature.evt.xy 512 ); 513 var popup = new OpenLayers.Popup.Anchored( 514 'myPopup', 515 lonlat, 516 new OpenLayers.Size(150, 18), 517 "<small>" + evt.feature.attributes.content + "</small>", 518 {size: {w: 14, h: 14}, offset: {x: -7, y: -7}}, 519 false 520 ); 521 container.tooltipPopup = popup; 522 popup.autoSize = true; 523 popup.updateSize(); 524 map.addPopup(popup); 525 }, 526 featureunhighlighted: function (evt) { 527 if (container.tooltipPopup) { 528 map.removePopup(container.tooltipPopup); 529 container.tooltipPopup = null; 530 } 531 } 532 } 533 })); 534 } 535 536 defaultMode.controls.push(selectControl = new OpenLayers.Control.SelectFeature
536(vectorLayerList, { 537 onSelect: function (feature) { 538 if (container.tooltipPopup) { 539 map.removePopup(container.tooltipPopup); 540 container.tooltipPopup = null; 541 } 542 if (feature.attributes.url === container.markerIcons.loadedMarker["default"].url) { 543 feature.attributes.url = container.markerIcons.loadedMarker.selection.url; 544 feature.layer.redraw(); 545 } 546 var type = feature.attributes.type 547 , object = feature.attributes.object 548 , lonlat = feature.geometry.getBounds().getCenterLonLat() 549 , loaded = false 550 ; 551 552 if (feature.attributes.itemId) { 553 type = 'trackeritem'; 554 object = feature.attributes.itemId; 555 } 556 557 if (type && object) { 558 loaded = $(container).loadInfoboxPopup({ 559 type: type, 560 object: object, 561 lonlat: lonlat, 562 content: feature.attributes.content, 563 close: function () { 564 selectControl.unselect(feature); 565 }, 566 feature: feature 567 }); 568 } 569 570 if (! loaded && feature.attributes.content) { 571 var popup = new OpenLayers.Popup.FramedCloud('feature', lonlat, null, feature.attributes.content, null, true, function () { 572 $(container).setMapPopup(null); 573 }); 574 popup.autoSize = true; 575 576 $(container).setMapPopup(popup); 577 } 578 579 if (feature.clickHandler) { 580 feature.clickHandler(); 581 } 582 }, 583 onUnselect: function (feature) { 584 if (feature.attributes.url === container.markerIcons.loadedMarker.selection.url) { 585 feature.attributes.url = container.markerIcons.loadedMarker["default"].url; 586 feature.layer.redraw(); 587 } 588 } 589 })); 590 591 if (layers.length > 0 && -1 !== $.inArray('overview', desiredControls)) { 592 var overview = new OpenLayers.Control.OverviewMap({minRatio: 128, maxRatio: 256, maximized: true}); 593 overview.desiredZoom = function () { 594 return Math.min(Math.max(1, map.getZoom() - 6), 3); 595 }; 596 overview.isSuitableOverview = function() { 597 return this.ovmap.getZoom() === overview.desiredZoom() && this.ovmap.getExtent().contains(map.getExtent()); 598 }; 599 overview.updateOverview = function() { 600 overview.ovmap.setCenter(map.getCenter()); 601 overview.ovmap.zoomTo(overview.desiredZoom()); 602 this.updateRectToMap(); 603 }; 604 605 map.addControl(overview); 606 } 607 608 container.markerIcons = { 609 loadedMarker: {}, 610 actionQueue: {}, 611 loadingMarker: [], 612 loadMarker: function (name, src) { 613 this.loadingMarker.push(name); 614 this.actionQueue[name] = []; 615 616 var img = new Image(), me = this; 617 img.onload = function () { 618 var width = this.width, height = this.height, action; 619 me.loadedMarker[name] = { 620 intent: 'marker', 621 url: src, 622 width: width, 623 height: height, 624 offsetx: - width / 2, 625 offsety: - height 626 }; 627 628 while (action = me.actionQueue[name].pop()) { 629 action(); 630 } 631 }; 632 $(img).on("error", function () { 633 console.log("Map error loading marker image " + src); 634 var index = container.markerIcons.loadingMarker.indexOf(src), action; 635 if (index > -1) { 636 container.markerIcons.loadingMarker.splice(index, 1); 637 } 638 while (action = me.actionQueue[name].pop()) { 639 action(); 640 } 641 }); 642 img.src = src; 643 }, 644 createMarker: function (name, lonlat, callback) { 645 if (this.loadedMarker[name]) { 646 this._createMarker(name, lonlat, callback); 647 return; 648 } 649 650 if (-1 === $.inArray(name, this.loadingMarker)) { 651 this.loadMarker(name, name); 652 } 653 654 var me = this; 655 this.actionQueue[name].push(function () { 656 me._createMarker(name, lonlat, callback); 657 }); 658 }, 659 _createMarker: function (name, lonlat, callback) { 660 if (lonlat) { 661 var properties = $.extend(this.loadedMarker[name] || this.loadedMarker.default, {}), marker; 662 marker = new OpenLayers.Feature.Vector( 663 new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat), 664 properties 665 ); 666 callback(marker); 667 } 668 } 669 }; 670 671 container.getLayer = function (name) { 672 var vectors; 673 674 if (name) { 675 if (! container.layers[name]) { 676 vectors = container.layers[name] = new OpenLayers.Layer.Vector(name, { 677 styleMap: container.defaultStyleMap, 678 rendererOptions: {zIndexing: true} 679 }); 680 681 container.map.addLayer(vectors); 682 vectorLayerList.push(vectors); 683 container.map.setLayerZIndex(vectors, vectorLayerList.length * 1000); 684 setupLayerEvents(vectors); 685 686 if (highlightControl && highlightControl.active) { 687 highlightControl.deactivate(); 688 highlightControl.activate(); 689 } 690 if (selectControl.active) { 691 selectControl.deactivate(); 692 selectControl.activate(); 693 } 694 } 695 696 return container.layers[name]; 697 } 698 699 return container.vectors; 700 }; 701 702 container.clearLayer = function (name) { 703 var vectors = container.getLayer(name); 704 705 var toRemove = []; 706 $.each(vectors.features, function (k, f) { 707 if (f && f.attributes.itemId) { 708 toRemove.push(f); 709 } else if (f && f.attributes.type && f.attributes.object) { 710 toRemove.push(f); 711 } 712 }); 713 vectors.removeFeatures(toRemove); 714 }; 715 716 container.markerIcons.loadMarker('default', 'lib/openlayers/img/marker.svg'); 717 container.markerIcons.loadMarker('selection', 'lib/openlayers/img/marker-gold.svg'); 718 719 if (navigator.geolocation && navigator.geolocation.getCurrentPosition) { 720 container.toMyLocation = $('<a/>') 721 .css('display', 'block') 722 .attr('href', '') 723 .click(function () { 724 navigator.geolocation.getCurrentPosition(function (position) { 725 var lonlat = new OpenLayers.LonLat(position.coords.longitude, position.coords.latitude).transform( 726 new OpenLayers.Projection("EPSG:4326"), 727 map.getProjectionObject() 728 ); 729 730 map.setCenter(lonlat); 731 map.zoomToScale(position.coords.accuracy * OpenLayers.INCHES_PER_UNIT.m); 732 733 $(container).addMapMarker({ 734 lat: position.coords.latitude, 735 lon: position.coords.longitude, 736 unique: 'selection' 737 }); 738 }); 739 return false;
740 }) 741 .text(tr('To My Location')); 742 743 if (-1 !== $.inArray('current_location', desiredControls)) { 744 $(container).after(container.toMyLocation); 745 } 746 } 747 748 container.searchLocation = $('<a/>') 749 .css('display', 'block') 750 .attr('href', '') 751 .click(function () { 752 var address = prompt(tr('What address are you looking for?'), ""); 753 754 $(container).trigger('search', [ { address: address } ]); 755 return false; 756 }) 757 .text(tr('Search Location')); 758 759 if (-1 !== $.inArray('search_location', desiredControls)) { 760 $(container).after(container.searchLocation); 761 } 762 763 var field = $(container).data('target-field'); 764 var central = null, useMarker = true; 765 766 if (field) { 767 field = $($(container).closest('form')[0][field]); 768 769 $(container).setupMapSelection({ 770 field: field 771 }); 772 var value = field.val(); 773 central = parseCoordinates(value); 774 775 if (central) { // cope with zoom levels greater than what OSM layer[0] can cope with 776 var geLayer; 777 if (central.zoom > 19) { 778 geLayer = map.getLayersByName("Google Satellite"); 779 } else if (central.zoom > 18) { 780 geLayer = map.getLayersByName("Google Streets"); 781 } 782 if (geLayer) { 783 container.layer = geLayer[0]; 784 map.setBaseLayer(container.layer); 785 map.baseLayer.setVisibility(true); 786 } 787 } 788 } 789 790 if ($(container).data('marker-filter')) { 791 var filter = $(container).data('marker-filter'); 792 $(filter).each(function () { 793 var lat = $(this).data('geo-lat') 794 , lon = $(this).data('geo-lon') 795 , zoom = $(this).data('geo-zoom') 796 , extent = $(this).data('geo-extent') 797 , icon = $(this).data('icon-src') 798 , object = $(this).data('object') 799 , type = $(this).data('type') 800 , content = $(this).clone().data({}).wrap('<span/>').parent().html() 801 ; 802 803 if (! extent) { 804 if ($(this).hasClass('primary') || this.href === document.location.href) { 805 central = {lat: lat, lon: lon, zoom: zoom ? zoom : 0}; 806 } else { 807 $(container).addMapMarker({ 808 type: type, 809 object: object, 810 lon: lon, 811 lat: lat, 812 content: content, 813 icon: icon ? icon : null 814 }); 815 } 816 } else if ($(this).is('img')) { 817 var graphic = new OpenLayers.Layer.Image( 818 $(this).attr('alt'), 819 $(this).attr('src'), 820 OpenLayers.Bounds.fromString(extent), 821 new OpenLayers.Size($(this).width(), $(this).height()) 822 ); 823 824 graphic.isBaseLayer = false; 825 graphic.alwaysInRange = true; 826 container.map.addLayer(graphic); 827 } 828 }); 829 } 830 831 var provided = $(container).data('geo-center'); 832 833 if (provided && !central) { 834 central = parseCoordinates(provided); 835 useMarker = false;
836 } 837 838 if (central) { 839 container.resetPosition = function () { 840 var lonlat = new OpenLayers.LonLat(central.lon, central.lat).transform( 841 new OpenLayers.Projection("EPSG:4326"), 842 map.getProjectionObject() 843 ); 844 845 map.setCenter(lonlat, central.zoom); 846 }; 847 848 container.resetPosition(); 849 850 if (useMarker) { 851 var icon = icon = $(container).data('icon-src') || 'selection'; 852 $(container).addMapMarker({ 853 lon: central.lon, 854 lat: central.lat, 855 unique: icon 856 }); 857 } 858 } 859 860 container.modeManager.addMode(defaultMode); 861 862 if (jqueryTiki.googleStreetView) { 863 container.streetview = { 864 buttons: [] 865 }; 866 867 if (jqueryTiki.googleStreetViewOverlay) { 868 container.streetview.overlay = new OpenLayers.Layer.XYZ( 869 "StreetView Overlay", 870 currentProtocol + "//mts1.google.com/vt?hl=en-US&lyrs=svv|cb_client:apiv3&style=40,18&x=${x}&y=${y}&z=${z}", 871 {sphericalMercator: true, displayInLayerSwitcher: false} 872 ); 873 container.map.addLayer(container.streetview.overlay); 874 875 container.map.events.on({ 876 move: function () { 877 if (container.streetview.overlay.visibility) { 878 container.streetview.overlay.redraw(); 879 } 880 } 881 }); 882 } 883 884 var StreetViewHandler = OpenLayers.Class(OpenLayers.Control, { 885 defaultHandlerOptions: { 886 'single': true, 887 'double': false, 888 'pixelTolerance': 0, 889 'stopSingle': false, 890 'stopDouble': false 891 }, 892 initialize: function(options) { 893 this.handlerOptions = OpenLayers.Util.extend({}, this.defaultHandlerOptions); 894 OpenLayers.Control.prototype.initialize.apply(this, arguments); 895 this.handler = new OpenLayers.Handler.Click( 896 this, 897 { 898 'click': this.trigger 899 }, 900 this.handlerOptions 901 ); 902 }, 903 trigger: function(e) { 904 var width = 600, height = 500; 905 906 var lonlat = map.getLonLatFromViewPortPx(e.xy).transform( 907 map.getProjectionObject(), 908 new OpenLayers.Projection("EPSG:4326") 909 ); 910 911 var canvas = $('<div/>')[0]; 912 $(canvas) 913 .appendTo('body') 914 .dialog({ 915 title: tr('Panorama'), 916 width: width, 917 height: height + 30, 918 modal: true, 919 close: function () { 920 $(canvas).dialog('destroy'); 921 }, 922 buttons: container.streetview.getButtons(canvas) 923 }); 924 925 canvas.getImageUrl = function () { 926 var pov = canvas.panorama.getPov(); 927 var pos = canvas.panorama.getPosition(); 928 var base = currentProtocol + '//maps.googleapis.com/maps/api/streetview?' 929 + 'size=' + width + 'x' + height + '&' 930 + 'location=' + tiki_encodeURIComponent(pos.toUrlValue()) + '&' 931 + 'heading=' + tiki_encodeURIComponent(pov.heading) + '&' 932 + 'pitch=' + tiki_encodeURIComponent(pov.pitch) + '&' 933 + 'key=' + tiki_encodeURIComponent(jqueryTiki.googleMapsAPIKey) + '&' 934 + 'sensor=false' 935 ; 936 937 return base; 938 }; 939 940 canvas.getPosition = function () { 941 var pos = canvas.panorama.getPosition(); 942 943 return formatLocation(pos.lat(), pos.lng(), 12); 944 }; 945 946 canvas.panorama = new google.maps.StreetViewPanorama(canvas, { 947 position: new google.maps.LatLng(lonlat.lat, lonlat.lon), 948 zoomControl: false, 949 scrollwheel: false, 950 disableDoubleClickZoom: true 951 }); 952 var timeout = setTimeout(function () { 953 alert(tr('StreetView is not available at this specific point on the map. Zoom in as needed and make sure to click on a blue line.')); 954 $(canvas).dialog('close'); 955 }, 5000); 956 google.maps.event.addListener(canvas.panorama, 'pano_changed', function () { 957 if (! canvas.panorama.getPano()) { 958 alert(tr('StreetView is not available at this specific point on the map. Zoom in as needed and make sure to click on a blue line.')); 959 $(canvas).dialog('close'); 960 } 961 clearTimeout(timeout); 962 }); 963 } 964 }); 965 966 container.modeManager.addMode({ 967 name: 'StreetView', 968 controls: [ new StreetViewHandler(), new OpenLayers.Control.NavToolbar() ], 969 activate: function () { 970 if (container.streetview.overlay) { 971 container.streetview.overlay.setVisibility(true); 972 } 973 }, 974 deactivate: function () { 975 if (container.streetview.overlay) { 976 container.streetview.overlay.setVisibility(false); 977 } 978 } 979 }); 980 981 container.streetview.addButton = function (label, callback) { 982 container.streetview.buttons.unshift({ 983 label: label, 984 callback: callback 985 }); 986 }; 987 988 container.streetview.getButtons = function (canvas) { 989 var buttons = {}; 990 $.each(container.streetview.buttons, function (k, b) { 991 buttons[b.label] = function () { 992 b.callback(canvas); 993 } 994 }); 995 996 return buttons; 997 }; 998 999 container.streetview.addButton('Cancel', function (canvas) { 1000 $(canvas).dialog('close'); 1001 }); 1002 1003 container.streetViewToggle = $('<a/>') 1004 .css('display', 'block') 1005 .attr('href', '') 1006 .click(function () { 1007 if (container.modeManager.activeMode && container.modeManager.activeMode.name == 'StreetView') { 1008 container.modeManager.switchTo('Default'); 1009 $(this).text(tr('Enable StreetView')); 1010 } else { 1011 container.modeManager.switchTo('StreetView'); 1012 $(this).text(tr('Disable StreetView')); 1013 } 1014 return false;
1015 }) 1016 .text(tr('Enable StreetView')); 1017 1018 if (-1 !== $.inArray('streetview', desiredControls)) { 1019 $(container).after(container.streetViewToggle); 1020 } 1021 } 1022 1023 var searchboxes = $(container) 1024 .closest('.tab, #appframe, #tiki-center') 1025 .find('form.search-box') 1026 .filter(function () { 1027 return $(this).closest('.map-container').size() === 0; 1028 }); 1029 1030 searchboxes = searchboxes.add($('form.search-box', container)); 1031 1032 searchboxes 1033 .off('submit') 1034 .submit(function () { 1035 $(container).trigger("start.map.search"); 1036 var form = this; 1037 $.post('tiki-searchindex.php?filter~geo_located=y', $(this).serialize(), function (data) { 1038 1039 if (! form.autoLayers) { 1040 form.autoLayers = []; 1041 } 1042 1043 $(form.autoLayers).each(function (k, name) { 1044 container.clearLayer(name); 1045 }); 1046 1047 $.each(data.result, function (k, i) { 1048 var layerName = $(form).data('result-layer'), suffix = $(form).data('result-suffix'); 1049 1050 if (! layerName) { 1051 layerName = ''; 1052 } 1053 1054 if (suffix && i[suffix]) { 1055 layerName = layerName + i[suffix]; 1056 } 1057 1058 if (-1 === $.inArray(layerName, form.autoLayers)) { 1059 form.autoLayers.push(layerName); 1060 } 1061 1062 var icon; 1063 $(i.link).each(function () { // if the object has an img with it (tracker status for instance) then we need to find the <a> 1064 if ($(this).is("a")) { // and just using $(i.link).find("a") doesn't work for some reason 1065 icon = $(this).data('icon-src'); 1066 } 1067 }); 1068 1069 if (i.geo_location) { 1070 $(container).addMapMarker({ 1071 coordinates: i.geo_location, 1072 content: i.title, 1073 type: i.object_type, 1074 object: i.object_id, 1075 icon: icon ? icon : null, 1076 layer: layerName, 1077 dataSource: i, 1078 form: form 1079 }); 1080 } else if (i.geo_feature) { 1081 var wkt = new OpenLayers.Format.WKT 1082 , features 1083 , layer = container.getLayer(layerName) 1084 ; 1085 1086 format = new OpenLayers.Format.GeoJSON; 1087 1088 try { 1089 features = format.read(i.geo_feature); 1090 } catch (e) { 1091 features = null; 1092 } 1093 1094 if (! features) { 1095 // Corrupted feature - display plain marker 1096 $(container).addMapMarker({ 1097 coordinates: $(container).getMapCenter(), 1098 content: i.title, 1099 type: i.object_type, 1100 object: i.object_id, 1101 icon: null, 1102 layer: layerName, 1103 dataSource: i 1104 }); 1105 return; 1106 } 1107 1108 $.each(features, function (k, feature) { 1109 var initial; 1110 feature.attributes.itemId = i.object_id; 1111 feature.attributes.content = i.title; 1112 if (! feature.attributes.color) { 1113 feature.attributes.color = '#6699cc'; 1114 } 1115 if (! feature.attributes.intent) { 1116 feature.attributes.intent = "vectors"; 1117 } 1118 if (! feature.attributes.popup_config) { 1119 feature.attributes.popup_config = $(form).data("popup-config"); 1120 } 1121 1122 initial = wkt.write(feature) + feature.attributes.color; 1123 1124 feature.executor = delayedExecutor(5000, function () { 1125 var fields = {}, current = wkt.write(feature) + feature.attributes.color; 1126 fields[i.geo_feature_field] = format.write(feature); 1127 1128 if (current === initial || layer !== container.vectors) { 1129 return; 1130 } 1131 1132 $.post($.service('tracker', 'update_item'), { 1133 trackerId: i.tracker_id, 1134 itemId: i.object_id, 1135 fields: fields 1136 }, function () { 1137 initial = current; 1138 }, 'json') 1139 .error(function () { 1140 $(container).trigger('changed'); 1141 }); 1142 }); 1143 }); 1144 layer.addFeatures(features); 1145 1146 $.each(features, function (k, feature) { 1147 $(container).trigger('add', [i, feature]); 1148 }); 1149 1150 } else if (i.geo_file) { // load a file containing geometry, set using tracker Files indexGeometry option 1151 1152 var format, 1153 files = i.geo_file.split(","), 1154 proj4326 = new OpenLayers.Projection("EPSG:4326"), 1155 proj900913 = new OpenLayers.Projection("EPSG:900913"); 1156 1157 layer = container.getLayer(layerName); 1158 1159 if (i.geo_file_format == "geojson") { 1160 format = new OpenLayers.Format.GeoJSON; 1161 } else if (i.geo_file_format == "gpx") { 1162 format = new OpenLayers.Format.GPX; 1163 } 1164 for (var f = 0; f < files.length; f++) { 1165 1166 OpenLayers.Request.GET({ 1167 url: files[f],
1168 callback: function (request) { 1169 1170 try { 1171 let responseText = request.responseText; 1172 if (responseText.indexOf(""") > -1) { 1173 // decode html entities coming from file galleries 1174 responseText = $("<div/>").html(responseText).text(); 1175 } 1176 features = format.read(responseText); 1177 } catch (e) { 1178 // Corrupted feature - display plain marker 1179 $(container).addMapMarker({ 1180 coordinates: $(container).getMapCenter(), 1181 content: i.title, 1182 type: i.object_type, 1183 object: i.object_id, 1184 icon: null, 1185 layer: layerName, 1186 dataSource: i 1187 }); 1188 return; 1189 } 1190 $.each(features, function (k, feature) { 1191 1192 feature.attributes.itemId = i.object_id; 1193 feature.attributes.content = i.title; 1194 if (! feature.attributes.color) { 1195 feature.attributes.color = '#ffa500'; 1196 } 1197 if (! feature.attributes.intent) { 1198 feature.attributes.intent = "vectors"; 1199 } 1200 if (! feature.attributes.popup_config) { 1201 feature.attributes.popup_config = $(form).data("popup-config"); 1202 } 1203 // for some reason geometry needs to be in 900913 projection to correctly appear 1204 // in the "Editable" vector layer, even though layer.projection === "EPSG:4326" 1205 feature.geometry.transform(proj4326, proj900913); 1206 1207 }); 1208 layer.addFeatures(features); 1209 1210 $.each(features, function (k, feature) { 1211 $(container).trigger('add', [i, feature]); 1212 }); 1213 } 1214 }); 1215 } 1216 } 1217 }); 1218 }, 'json').complete(function () { 1219 $(container).trigger("complete.map.search"); 1220 }); 1221 return false; 1222 }) 1223 .each(function () { 1224 if ($(this).hasClass('onload')) { 1225 var fm = this, layerLoadDelay = parseInt($(fm).data("load-delay"), 10); 1226 1227 if (layerLoadDelay) { 1228 setTimeout(function () { $(fm).submit(); }, layerLoadDelay * 1000); 1229 } else { 1230 $(fm).submit(); 1231 } 1232 } 1233 1234 var skip = false; 1235 if ($(this).data('result-refresh')) { 1236 var form = this, refresh = parseInt($(this).data('result-refresh'), 10) * 1000, interval; 1237 interval = setInterval(function () { 1238 if (skip) { 1239 skip = false; 1240 } else { 1241 $(form).submit(); 1242 } 1243 }, refresh); 1244 1245 $(container).on('unregister', function () { 1246 clearInterval(interval); 1247 }); 1248 } 1249 1250 $(container).on('changed', function () { 1251 $(form).submit(); 1252 skip = true; 1253 }); 1254 }); 1255 $(container).on('search', function (e, data) { 1256 function markLocation (lat, lon, bounds) { 1257 var lonlat = new OpenLayers.LonLat(lon, lat).transform( 1258 new OpenLayers.Projection("EPSG:4326"), 1259 map.getProjectionObject() 1260 ), toViewport; 1261 1262 toViewport = function () { 1263 if (bounds) { 1264 map.zoomToExtent(bounds); 1265 } else { 1266 map.setCenter(lonlat); 1267 map.zoomToScale(500 * OpenLayers.INCHES_PER_UNIT.m); 1268 } 1269 }; 1270 1271 $(container).addMapMarker({ 1272 lat: lat, 1273 lon: lon, 1274 unique: 'selection', 1275 click: toViewport 1276 }); 1277 1278 if (typeof zoomToFoundLocation != 'undefined') { 1279 // Center map to the new location and zoom 1280 var zoomFactor = -1; 1281 switch (zoomToFoundLocation) { 1282 default: 1283 case 'street': 1284 zoomFactor = 250; 1285 break; 1286 case 'town': 1287 zoomFactor = 2500; 1288 break; 1289 case 'region': 1290 zoomFactor = 25000; 1291 break; 1292 case 'country': 1293 zoomFactor = 250000; 1294 break; 1295 case 'continent': 1296 zoomFactor = 1500000; 1297 break; 1298 case 'world': 1299 zoomFactor = -1; 1300 break; 1301 } 1302 if (zoomFactor < 0) { 1303 toViewport(); 1304 } else { 1305 map.setCenter(lonlat); 1306 map.zoomToScale(zoomFactor * OpenLayers.INCHES_PER_UNIT.m); 1307 } 1308 } else { 1309 if (!container.map.getExtent().containsLonLat(lonlat)) { 1310 // Show marker on world map 1311 toViewport(); 1312 } 1313 } 1314 } 1315 1316 function markGoogleLocation(result) 1317 { 1318 var loc = result.geometry.location
1319 , sw = result.geometry.viewport.getSouthWest() 1320 , ne = result.geometry.viewport.getNorthEast() 1321 , osw, one 1322 , left, bottom, right, top 1323 ; 1324 1325 osw = new OpenLayers.LonLat(sw.lng(), sw.lat()).transform( 1326 new OpenLayers.Projection("EPSG:4326"), 1327 map.getProjectionObject() 1328 ); 1329 one = new OpenLayers.LonLat(ne.lng(), ne.lat()).transform( 1330 new OpenLayers.Projection("EPSG:4326"), 1331 map.getProjectionObject() 1332 ); 1333 1334 left = osw.lon; 1335 bottom = osw.lat; 1336 right = one.lon; 1337 top = one.lat; 1338 1339 markLocation(loc.lat(), loc.lng(), new OpenLayers.Bounds(left, bottom, right, top)); 1340 } 1341 1342 function getBounds(bounds) 1343 { 1344 var osw, one 1345 ; 1346 1347 osw = new OpenLayers.LonLat(bounds.left, bounds.bottom).transform( 1348 map.getProjectionObject(), 1349 new OpenLayers.Projection("EPSG:4326") 1350 ); 1351 one = new OpenLayers.LonLat(bounds.right, bounds.top).transform( 1352 map.getProjectionObject(), 1353 new OpenLayers.Projection("EPSG:4326") 1354 ); 1355 1356 return new google.maps.LatLngBounds(new google.maps.LatLng(osw.lat, osw.lon), new google.maps.LatLng(one.lat, one.lon)); 1357 } 1358 1359 if (data.address) { 1360 if (window.google && google.maps && google.maps.Geocoder) { 1361 var geocoder = new google.maps.Geocoder() 1362 , loc = $(container).getMapCenter().split(','); 1363 1364 geocoder.geocode({ 1365 bounds: getBounds(map.getExtent()), 1366 address: data.address 1367 }, function(results, status) { 1368 var $list = $('<ul/>'); 1369 1370 if (status == google.maps.GeocoderStatus.OK) { 1371 if (results.length === 1) { 1372 markGoogleLocation(results[0]); 1373 return; 1374 } else if (results.length > 0) { 1375 $.each(results, function (k, result) { 1376 var $link = $('<a href="#"/>'); 1377 $link.text(result.formatted_address); 1378 $link.click(function () { 1379 markGoogleLocation(result); 1380 return false; 1381 }); 1382 $('<li/>').append($link).appendTo($list); 1383 }); 1384 } 1385 } 1386 1387 $('<div/>') 1388 .append($list) 1389 .dialog({title: data.address}); 1390 }); 1391 } else { 1392 $.getJSON('tiki-ajax_services.php', {geocode: data.address}, function (data) { 1393 markLocation(data.lat, data.lon, 500); 1394 }); 1395 } 1396 } 1397 }); 1398 1399 $(container).trigger('initialized'); 1400 }, 250); 1401 }); 1402 1403 return this; 1404 }; 1405 1406 $.fn.addMapMarker = function (options) { 1407 this.each(function () { 1408 var container = this, 1409 lonlat, 1410 iconModel = "default"; 1411 1412 if (options.unique) { 1413 iconModel = options.unique; 1414 } 1415 1416 if (options.icon) { 1417 iconModel = options.icon; 1418 } 1419 1420 if (options.coordinates) { 1421 var parts = options.coordinates.split(','); 1422 if (parts.length >= 2) { 1423 options.lon = parts[0]; 1424 options.lat = parts[1]; 1425 } 1426 } 1427 1428 if (options.lat && options.lon) { 1429 lonlat = new OpenLayers.LonLat(options.lon, options.lat).transform( 1430 new OpenLayers.Projection("EPSG:4326"), 1431 container.map.getProjectionObject() 1432 ); 1433 } 1434 1435 container.markerIcons.createMarker(iconModel, lonlat, function (feature) { 1436 if (options.type && options.object) { 1437 feature.attributes.type = options.type; 1438 feature.attributes.object = options.object; 1439 } 1440 if (! feature.attributes.popup_config && options.form) { 1441 feature.attributes.popup_config = $(options.form).data("popup-config"); 1442 } 1443 1444 var markerLayer = container.getLayer(options.layer), initial = writeCoordinates(lonlat.clone(), container.map, true); 1445 markerLayer.addFeatures([feature]); 1446 1447 if (options.unique) { 1448 if (container.uniqueMarkers[options.unique]) { 1449 markerLayer.removeFeatures([container.uniqueMarkers[options.unique]]); 1450 } 1451 1452 container.uniqueMarkers[options.unique] = feature; 1453 $(container).trigger(options.unique + 'Change', options); 1454 } 1455 1456 if (options.type === 'trackeritem' && options.object && markerLayer === container.vectors) { 1457 feature.executor = delayedExecutor(5000, function () { 1458 var current = writeCoordinates(feature.geometry.getBounds().getCenterLonLat().clone(), container.map, true); 1459 1460 if (current === initial) { 1461 return; 1462 } 1463 1464 $.post($.service('tracker', 'set_location'), { 1465 itemId: options.object, 1466 location: current 1467 }, function () { 1468 initial = current; 1469 }, 'json') 1470 .error(function () { 1471 $(container).trigger('changed'); 1472 }); 1473 }); 1474 } 1475 1476 if (options.content) { 1477 feature.attributes.content = options.content; 1478 } 1479 1480 if (options.click) { 1481 feature.clickHandler = options.click; 1482 } 1483 1484 if (options.dataSource) { 1485 $(container).trigger('add', [options.dataSource, feature]); 1486 } 1487 }); 1488 }); 1489 1490 return this; 1491 }; 1492 1493 $.fn.setupMapSelection = function (options) { 1494 var control; 1495 this.each(function () { 1496 var container = this, field = options.field, map = this.map; 1497 1498 if (! field.attr('disabled')) { 1499 $(container).on('selectionChange', function (e, lonlat) { 1500 if (lonlat) { 1501 field.val(writeCoordinates(lonlat, map)).change(); 1502 } else { 1503 field.val('').change(); 1504 } 1505 }); 1506 map.events.register('zoomend', map, function (e, lonlat) { 1507 var coords = field.val().split(","), lon = 0, lat = 0; 1508 if (coords.length > 1) { 1509 lon = coords[0]; 1510 lat = coords[1]; 1511 } 1512 field.val(formatLocation(lat, lon, map.getZoom())).change(); 1513 }); 1514 1515 var ClickHandler = OpenLayers.Class(OpenLayers.Control, { 1516 defaultHandlerOptions: { 1517 'single': true, 1518 'double': false, 1519 'pixelTolerance': 0, 1520 'stopSingle': false, 1521 'stopDouble': false 1522 }, 1523 initialize: function(options) { 1524 this.handlerOptions = OpenLayers.Util.extend({}, this.defaultHandlerOptions); 1525 OpenLayers.Control.prototype.initialize.apply(this, arguments); 1526 this.handler = new OpenLayers.Handler.Click( 1527 this, 1528 { 1529 'click': this.trigger 1530 }, 1531 this.handlerOptions 1532 ); 1533 }, 1534 trigger: function(e) {
1535 var lonlat = map.getLonLatFromViewPortPx(e.xy).transform( 1536 map.getProjectionObject(), 1537 new OpenLayers.Projection("EPSG:4326") 1538 ); 1539 $(container).addMapMarker({ 1540 lat: lonlat.lat, 1541 lon: lonlat.lon, 1542 unique: 'selection' 1543 }); 1544 1545 if (options.click) { 1546 options.click(); 1547 } 1548 } 1549 }); 1550 1551 control = new ClickHandler(); 1552 map.addControl(control); 1553 control.activate(); 1554 } 1555 }); 1556 1557 return control; 1558 }; 1559 1560 $.fn.removeMapSelection = function () { 1561 this.each(function () { 1562 var container = this; 1563 1564 if (container.uniqueMarkers['selection']) { 1565 container.vectors.removeFeatures([container.uniqueMarkers['selection']]); 1566 } 1567 1568 $(container).trigger('selectionChange', {}); 1569 }); 1570 1571 return this; 1572 }; 1573 1574 $.fn.getMapCenter = function () { 1575 var val; 1576 1577 this.each(function () { 1578 var coordinates = this.map.getCenter(); 1579 val = writeCoordinates(coordinates, this.map, true); 1580 }); 1581 1582 return val; 1583 }; 1584 1585 $.fn.setMapPopup = function (popup, old) { 1586 this.each(function () { 1587 var handler = $(this).getMapPopupHandler(); 1588 1589 // Replacement attempt, if not the same one, skip the operation 1590 if (old && old !== this.activePopup) { 1591 return; 1592 } 1593 1594 if (this.activePopup) { 1595 if (this.activePopup.myclose) { 1596 var f = this.activePopup.myclose; 1597 this.activePopup.myclose = null; 1598 f(); 1599 } else { 1600 try { 1601 handler.remove(this.activePopup); 1602 } catch (e) {} // catch error when dialog not initialised 1603 } 1604 1605 this.activePopup = null; 1606 } 1607 1608 if (popup) { 1609 this.activePopup = popup; 1610 1611 handler.add(popup); 1612 } 1613 }); 1614 }; 1615 1616 $.fn.loadInfoboxPopup = function (options) { 1617 if (options.type && options.object && $.inArray(options.type, jqueryTiki.infoboxTypes) !== -1) { 1618 1619 if (! options.content) { 1620 options.content = ''; 1621 } 1622 1623 this.each(function () { 1624 var container = this, popup; 1625 popup = new OpenLayers.Popup('marker', options.lonlat, null, options.content + '<img src="img/spinner.gif"/>'); 1626 popup.autoSize = true; 1627 $(container).setMapPopup(popup); 1628 1629 $.get($.service('object', 'infobox', { 1630 type: options.type, 1631 object: options.object 1632 }), function (data) { 1633 var newPopup 1634 , close = function () { 1635 $(container).setMapPopup(null); 1636 1637 if (options.close) { 1638 options.close.apply([], container); 1639 } 1640 } 1641 , injectionId = ('popupInjection' + Math.random()).replace('.', '') 1642 , content 1643 , handler = $(container).getMapPopupHandler() 1644 ; 1645 1646 content = '<div id="' + injectionId + '"></div>'; 1647 1648 newPopup = handler.create(options.lonlat, content, options.hook, close, options.feature); 1649 1650 newPopup.myclose = close; 1651 $(container).setMapPopup(newPopup, popup); 1652 1653 content = $('#' + injectionId); 1654 content.html(data); 1655 1656 handler.resize(newPopup); 1657 1658 content.find('.svgImage') 1659 .css('text-align', 'center') 1660 .css('margin', 'auto'); 1661 1662 content.find('.service-dialog').click(function () { 1663 $(container).setMapPopup(null); 1664 1665 $(this).serviceDialog({ 1666 title: $(this).attr('title').replace(/^.*\:/, ''), // trim off leading text up to a : which is the tooltip title 1667 success: function () { 1668 $(container).trigger('changed'); 1669 } 1670 }); 1671 return false; 1672 }); 1673 1674 // re-colorbox *box images 1675 $("a[rel*='box'][rel*='type=img'], a[rel*='box'][rel!='type=']", content).colorbox({ 1676 photo: true 1677 }); 1678 1679 }, 'html'); 1680 }); 1681 1682 return true; 1683 } else { 1684 return false; 1685 } 1686 }; 1687 1688 $.fn.getMapPopupHandler = function () { 1689 var handler; 1690 1691 this.each(function () { 1692 var map = this.map; 1693 1694 switch ($(this).data('popup-style')) { 1695 case 'dialog': 1696 handler = { 1697 type: 'dialog', 1698 add: function (popup) { 1699 }, 1700 create: function (lonlat, content, hook, close, feature) { 1701 var dialog = $(content), w = '80%', h = 600; 1702 this.feature = feature; 1703 if (this.feature.attributes.popup_config) { 1704 w = this.feature.attributes.popup_config.width; 1705 h = this.feature.attributes.popup_config.height; 1706 } 1707 1708 dialog.dialog({ 1709 modal: true, 1710 width: w, 1711 height: h, 1712 close: close 1713 }); 1714 1715 return dialog[0]; 1716 }, 1717 remove: function (popup) { 1718 $(popup).dialog('destroy'); 1719 }, 1720 resize: function (popup) { 1721 $(popup).find('h1, h2, h3, h4, h5').first().each(function () { 1722 $(this).hide(); 1723 $(popup).dialog('option', 'title', $(this).text()); 1724 }); 1725 } 1726 }; 1727 break; 1728 case 'popup': 1729 default: 1730 handler = { 1731 type: 'popup', 1732 add: function (popup) { 1733 map.addPopup(popup); 1734 }, 1735 create: function (lonlat, content, hook, close, feature) { 1736 this.feature = feature; 1737 return new OpenLayers.Popup.FramedCloud('marker', lonlat, null, content, hook, true, close); 1738 }, 1739 remove: function (popup) { 1740 map.removePopup(popup); 1741 }, 1742 resize: function (popup) { 1743 var w = 300, h = 260; 1744 if (this.feature.attributes.popup_config) { 1745 w = this.feature.attributes.popup_config.width; 1746 h = this.feature.attributes.popup_config.height; 1747 } 1748 popup.setSize(new OpenLayers.Size(w, h)); 1749 } 1750 }; 1751 break; 1752 } 1753 }); 1754 1755 return handler; 1756 }; 1757 1758 $.fn.finalMapRefresh = function (collector) { 1759 1760 this.each(function () { 1761 var container = this; 1762 1763 $(container).trigger('unregister'); 1764 $(container).on('add', function (e, data, feature) { 1765 collector(data, $.extend({}, feature)); 1766 }); 1767 $(container).trigger('changed'); 1768 }); 1769 1770 return this; 1771 }; 1772 1773 $('body').on("DOMNodeInserted", function (event) { 1774 var $target = $(event.target); 1775 if ($target.is(".popover")) { 1776 $target.find(".map-container:not(.done)").addClass("done").createMap(); 1777 } 1778 }) 1779})(); 1780
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.