1/* 2 * Copyright (c) 2008-2013 Mark C. Prins <mprins@users.sf.net> 3 * 4 * Permission to use, copy, modify, and distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17/** 18 * @fileoverview Javascript voor OpenLayers plugin. 19 * 20 * @requires {lib/OpenLayers.js} or a full openlayers build 21 * @author Mark C. Prins <mprins@users.sf.net> 22 * 23 */ 24 25/** 26 * Openlayers selectcontrol. 27 * 28 * @type {OpenLayers.Control.SelectFeature} 29 * @private 30 */ 31var selectControl; 32 33/** 34 * handle feature select event. 35 * 36 * @param {OpenLayers.Feature.Vector} 37 * feature the selected feature 38 */ 39function onFeatureSelect(feature) { 40 var selectedFeature = feature; 41 // 'this' is selectFeature control 42 var pPos = selectedFeature.geometry.getBounds().getCenterLonLat(); 43 // != OpenLayers.Geometry.Point 44 if (selectedFeature.geometry.CLASS_NAME === "OpenLayers.Geometry.LineString") { 45 try { 46 // for lines make the popup show at the cursor position 47 pPos = feature.layer.map.getLonLatFromViewPortPx(this.handlers.feature.evt.xy); 48 } catch (anErr) { 49 OpenLayers.Console.warn("unable to get event position; reverting to boundingbox center."); 50 pPos = selectedFeature.geometry.getBounds().getCenterLonLat(); 51 } 52 } 53 54 var pContent = '<div class="spacer"> </div>'; 55 if (feature.data.rowId !== undefined) { 56 pContent += '<span class="rowId">' + feature.data.rowId + ': </span>'; 57 } 58 if (feature.data.name !== undefined) { 59 pContent += '<span class="txt">' + feature.data.name + '</span>'; 60 } 61 if (feature.data.ele !== undefined) { 62 pContent += '<div class="ele">elevation: ' + feature.data.ele + '</div>'; 63 } 64 if (feature.data.type !== undefined) { 65 pContent += '<div>' + feature.data.type + '</div>'; 66 } 67 if (feature.data.time !== undefined) { 68 pContent += '<div class="time">time: ' + feature.data.time + '</div>'; 69 } 70 if (feature.data.description !== undefined) { 71 pContent += '<div class="desc">' + feature.data.description + '</div>'; 72 } 73 74 if (pContent.length > 0) { 75 // only show when there is something to show... 76 var popup = new OpenLayers.Popup.FramedCloud("olPopup", pPos, null, pContent, null, !0, function() { 77 selectControl.unselect(selectedFeature); 78 }); 79 feature.popup = popup; 80 feature.layer.map.addPopup(popup); 81 } 82} 83 84/** 85 * handle feature unselect event. remove & destroy the popup. 86 * 87 * @param {OpenLayers.Feature.Vector} 88 * feature the un-selected feature 89 */ 90function onFeatureUnselect(feature) { 91 if (feature.popup !== null) { 92 feature.layer.map.removePopup(feature.popup); 93 feature.popup.destroy(); 94 feature.popup = null; 95 } 96} 97/** 98 * Test for css support in the browser by sniffing for a css class we added 99 * using javascript added by the action plugin; this is an edge case because 100 * browsers that support javascript generally support css as well. 101 * 102 * @returns {Boolean} true when the browser supports css (and implicitly 103 * javascript) 104 */ 105function olTestCSSsupport() { 106 return (jQuery('.olCSSsupported').length > 0); 107} 108 109/** 110 * Creates a DocumentFragment to insert into the dom. 111 * 112 * @param mapid 113 * id for the map div 114 * @param width 115 * width for the map div 116 * @param height 117 * height for the map div 118 * @returns a {DocumentFragment} element that can be injected into the dom 119 */ 120function olCreateMaptag(mapid, width, height) { 121 // TODO: use OpenLayers.i18n() 122 var mEl = '<div id="' + mapid + '-olContainer" class="olContainer olWebOnly">' + '<div id="' + mapid 123 + '-olToolbar" class="olToolbar"></div>' + '<div class="clearer"></div>' + '<div id="' + mapid 124 + '" tabindex="0" style="width:' + width + ';height:' + height + ';" class="olMap">' 125 + '<a class="olAccesskey" href="" accesskey="1" onclick="document.getElementById("' + mapid 126 + '").focus(); return false;" title="Activate map">Activate map</a>' + '</div>' + '<div id="' + mapid 127 + '-olStatusBar" style="width:' + width + ';"class="olStatusBarContainer">' + '<div id="' + mapid 128 + '-statusbar-scale" class="olStatusBar olStatusBarScale">scale</div>' + '<div id="' + mapid 129 + '-statusbar-link" class="olStatusBar olStatusBarPermalink">' + '<a href="" id="' + mapid 130 + '-statusbar-link-ref">link</a></div>' + '<div id="' + mapid 131 + '-statusbar-mouseposition" class="olStatusBar olStatusBarMouseposition"></div>' + '<div id="' + mapid 132 + '-statusbar-projection" class="olStatusBar olStatusBarProjection">proj</div>' + '<div id="' + mapid 133 + '-statusbar-text" class="olStatusBar olStatusBarText">txt</div>' + '</div></div>', 134 // fragment 135 frag = document.createDocumentFragment(), 136 // temp node 137 temp = document.createElement('div'); 138 temp.innerHTML = mEl; 139 while (temp.firstChild) { 140 frag.appendChild(temp.firstChild); 141 } 142 return frag; 143} 144 145/** 146 * Create the map based on the params given. 147 * 148 * @param {Object} 149 * mapOpts MapOptions hash {id:'olmap', width:500px, height:500px, 150 * lat:6710200, lon:506500, zoom:13, toolbar:1, statusbar:1, 151 * controls:1, poihoverstyle:1, baselyr:'', kmlfile:'', gpxfile:'', 152 * geojsonfile, summary:''} 153 * @param {Array} 154 * OLmapPOI array with POI's [ {lat:6710300,lon:506000,txt:'instap 155 * punt',angle:180,opacity:.9,img:'', rowId:n},... ]); 156 * 157 * @return {OpenLayers.Map} the created map 158 */ 159function createMap(mapOpts, OLmapPOI) { 160 if (!olEnable) { 161 return; 162 } 163 if (!olTestCSSsupport()) { 164 olEnable = !1; 165 return; 166 } 167 168 var DocBase = DOKU_BASE; 169 170 OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3; 171 // OpenLayers.Layer.Vector.prototype.renderers = ["SVG", "VML"]; 172 173 // find map element location 174 var cleartag = document.getElementById(mapOpts.id + '-clearer'); 175 if (cleartag === null) { 176 return; 177 } 178 // create map element and add to document 179 var fragment = olCreateMaptag(mapOpts.id, mapOpts.width, mapOpts.height); 180 cleartag.parentNode.insertBefore(fragment, cleartag); 181 182 /** dynamic map extent. */ 183 var extent = new OpenLayers.Bounds(), 184 185 /** map. */ 186 m = new OpenLayers.Map({ 187 div : mapOpts.id, 188 projection : 'EPSG:900913', 189 displayProjection : new OpenLayers.Projection("EPSG:4326"), 190 numZoomLevels : 22, 191 controls : [ new OpenLayers.Control.ArgParser(), new OpenLayers.Control.KeyboardDefaults({ 192 observeElement : mapOpts.id 193 }), new OpenLayers.Control.Navigation({ 194 dragPanOptions : { 195 enableKinetic : !0 196 } 197 }), new OpenLayers.Control.ScaleLine({ 198 geodesic : !0 199 }) ], 200 theme : null 201 }); 202 203 if (osmEnable) { 204 /* add OSM map layers */ 205 m.addLayer(new OpenLayers.Layer.OSM("OpenStreetMap", null, { 206 transitionEffect : "resize", 207 visibility : mapOpts.baselyr === "OpenStreetMap" 208 })); 209 210 m.addLayer(new OpenLayers.Layer.OSM("transport", [ 211 "http://a.tile2.opencyclemap.org/transport/${z}/${x}/${y}.png", 212 "http://b.tile2.opencyclemap.org/transport/${z}/${x}/${y}.png", 213 "http://c.tile2.opencyclemap.org/transport/${z}/${x}/${y}.png" ], { 214 transitionEffect : "resize", 215 attribution : 'Data CC-By-SA <a href="http://openstreetmap.org/" target="_blank">OpenStreetMap</a>, ' 216 + 'Tiles <a href="http://opencyclemap.org/" target="_blank">OpenCycleMap</a>' 217 + '<img src="http://opencyclemap.org/favicon.ico" alt="OpenCycleMap logo"/>', 218 visibility : mapOpts.baselyr === "transport", 219 tileOptions : { 220 crossOriginKeyword : null 221 } 222 })); 223 m.addLayer(new OpenLayers.Layer.OSM("landscape", [ 224 "http://a.tile3.opencyclemap.org/landscape/${z}/${x}/${y}.png", 225 "http://b.tile3.opencyclemap.org/landscape/${z}/${x}/${y}.png", 226 "http://c.tile3.opencyclemap.org/landscape/${z}/${x}/${y}.png" ], { 227 transitionEffect : "resize", 228 attribution : 'Data CC-By-SA <a href="http://openstreetmap.org/" target="_blank">OpenStreetMap</a>, ' 229 + 'Tiles <a href="http://opencyclemap.org/" target="_blank">OpenCycleMap</a>' 230 + '<img src="http://opencyclemap.org/favicon.ico" alt="OpenCycleMap logo"/>', 231 visibility : mapOpts.baselyr === "transport", 232 tileOptions : { 233 crossOriginKeyword : null 234 } 235 })); 236 m.addLayer(new OpenLayers.Layer.OSM("cycle map", [ "http://a.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png", 237 "http://b.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png", 238 "http://c.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png" ], { 239 transitionEffect : "resize", 240 attribution : 'Data CC-By-SA <a href="http://openstreetmap.org/" target="_blank">OpenStreetMap</a>, ' 241 + 'Tiles <a href="http://opencyclemap.org/" target="_blank">OpenCycleMap</a>' 242 + '<img src="http://opencyclemap.org/favicon.ico" alt="OpenCycleMap logo"/>', 243 visibility : mapOpts.baselyr === "cycle map", 244 tileOptions : { 245 crossOriginKeyword : null 246 } 247 })); 248 // CloudMade Fine Line 249 m.addLayer(new OpenLayers.Layer.OSM("cloudmade map", [ 250 "http://a.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/2/256/${z}/${x}/${y}.png", 251 "http://b.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/2/256/${z}/${x}/${y}.png", 252 "http://c.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/2/256/${z}/${x}/${y}.png" ], { 253 transitionEffect : "resize", 254 attribution : 'Tiles © 2012 <a target="_blank" href="http://cloudmade.com">CloudMade</a>' 255 + '<img src="http://cloudmade.com/favicon.ico" alt="CloudMade logo"/>' 256 + ' Data CC-BY-SA <a href="http://openstreetmap.org/" target="_blank">OpenStreetMap</a>', 257 visibility : mapOpts.baselyr === "cloudmade map", 258 tileOptions : { 259 crossOriginKeyword : null 260 } 261 })); 262 m.addLayer(new OpenLayers.Layer.OSM("cloudmade fresh", [ 263 "http://a.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/${z}/${x}/${y}.png", 264 "http://b.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/${z}/${x}/${y}.png", 265 "http://c.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/${z}/${x}/${y}.png" ], { 266 transitionEffect : "resize", 267 attribution : 'Tiles © 2012 <a target="_blank" href="http://cloudmade.com">CloudMade</a>' 268 + '<img src="http://cloudmade.com/favicon.ico" alt="CloudMade logo"/>' 269 + ' Data CC-BY-SA <a href="http://openstreetmap.org/" target="_blank">OpenStreetMap</a>', 270 visibility : mapOpts.baselyr === "cloudmade fresh", 271 tileOptions : { 272 crossOriginKeyword : null 273 } 274 })); 275 276 m.addLayer(new OpenLayers.Layer.OSM( 277 "hike and bike map", "http://toolserver.org/tiles/hikebike/${z}/${x}/${y}.png", { 278 transitionEffect : "resize", 279 visibility : mapOpts.baselyr === "hike and bike map", 280 tileOptions : { 281 crossOriginKeyword : null 282 } 283 })); 284 } 285 /* 286 * add MapQuest map layers, see: 287 * http://developer.mapquest.com/web/products/open/map 288 */ 289 if (mqEnable) { 290 m.addLayer(new OpenLayers.Layer.OSM("mapquest road", [ 291 "http://otile1.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg", 292 "http://otile2.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg", 293 "http://otile3.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg", 294 "http://otile4.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg" ], { 295 transitionEffect : "resize", 296 attribution : 'Data CC-By-SA <a href="http://openstreetmap.org/" target="_blank">OpenStreetMap</a>, ' 297 + 'Tiles <a href="http://www.mapquest.com/" target="_blank">MapQuest</a>' 298 + '<img src="http://developer.mapquest.com/content/osm/mq_logo.png" alt="MapQuest logo"/>', 299 visibility : mapOpts.baselyr === "mapquest road", 300 tileOptions : { 301 crossOriginKeyword : null 302 } 303 })); 304 // note that global coverage is provided at zoom levels 0-11. Zoom 305 // Levels 12+ are provided only in the United States (lower 48). 306 m.addLayer(new OpenLayers.Layer.OSM("mapquest sat", [ 307 "http://otile1.mqcdn.com/tiles/1.0.0/sat/${z}/${x}/${y}.jpg", 308 "http://otile2.mqcdn.com/tiles/1.0.0/sat/${z}/${x}/${y}.jpg", 309 "http://otile3.mqcdn.com/tiles/1.0.0/sat/${z}/${x}/${y}.jpg", 310 "http://otile4.mqcdn.com/tiles/1.0.0/sat/${z}/${x}/${y}.jpg" ], { 311 transitionEffect : "resize", 312 attribution : 'Tiles Courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a>' 313 + '<img src="http://developer.mapquest.com/content/osm/mq_logo.png" alt="MapQuest logo"/>', 314 visibility : mapOpts.baselyr === "mapquest sat", 315 numZoomLevels : 12, 316 tileOptions : { 317 crossOriginKeyword : null 318 } 319 })); 320 } 321 322 if (gEnable) { 323 /* load google maps */ 324 try { 325 m.addLayer(new OpenLayers.Layer.Google("google relief", { 326 type : google.maps.MapTypeId.TERRAIN, 327 // transitionEffect : "resize", 328 numZoomLevels : 16, 329 animationEnabled : !0, 330 visibility : mapOpts.baselyr === "google relief" 331 })); 332 m.addLayer(new OpenLayers.Layer.Google("google sat", { 333 type : google.maps.MapTypeId.SATELLITE, 334 // transitionEffect : "resize", 335 // numZoomLevels : 22, 336 animationEnabled : !0, 337 visibility : mapOpts.baselyr === "google sat" 338 })); 339 m.addLayer(new OpenLayers.Layer.Google("google hybrid", { 340 type : google.maps.MapTypeId.HYBRID, 341 // transitionEffect : "resize", 342 // numZoomLevels : 20, 343 animationEnabled : !0, 344 visibility : mapOpts.baselyr === "google hybrid" 345 })); 346 m.addLayer(new OpenLayers.Layer.Google("google road", { 347 // transitionEffect : "resize", 348 // numZoomLevels : 20, 349 animationEnabled : !0, 350 visibility : mapOpts.baselyr === "google road" 351 })); 352 } catch (ol_err1) { 353 Openlayers.Console.userError('Error loading Google maps' + ol_err1); 354 } 355 } 356 357 if (bEnable && bApiKey !== '') { 358 try { 359 /* add Bing tiles */ 360 m.addLayer(new OpenLayers.Layer.Bing({ 361 key : bApiKey, 362 type : "Road", 363 name : "bing road", 364 transitionEffect : "resize", 365 visibility : mapOpts.baselyr === "bing road", 366 wrapDateLine : !0, 367 attributionTemplate : '<a target="_blank" href="http://www.bing.com/maps/">' 368 + 'Bing™</a><img src="http://www.bing.com/favicon.ico" alt="Bing logo"/> ${copyrights}' 369 + '<a target="_blank" href="http://www.microsoft.com/maps/product/terms.html">Terms of Use</a>' 370 })); 371 m.addLayer(new OpenLayers.Layer.Bing({ 372 key : bApiKey, 373 type : "Aerial", 374 name : "bing sat", 375 transitionEffect : "resize", 376 visibility : mapOpts.baselyr === "bing sat", 377 wrapDateLine : !0, 378 attributionTemplate : '<a target="_blank" href="http://www.bing.com/maps/">' 379 + 'Bing™</a><img src="http://www.bing.com/favicon.ico" alt="Bing logo"/> ${copyrights}' 380 + '<a target="_blank" href="http://www.microsoft.com/maps/product/terms.html">Terms of Use</a>' 381 })); 382 m.addLayer(new OpenLayers.Layer.Bing({ 383 key : bApiKey, 384 type : "AerialWithLabels", 385 name : "bing hybrid", 386 transitionEffect : "resize", 387 visibility : mapOpts.baselyr === "bing hybrid", 388 wrapDateLine : !0, 389 attributionTemplate : '<a target="_blank" href="http://www.bing.com/maps/">' 390 + 'Bing™</a><img src="http://www.bing.com/favicon.ico" alt="Bing logo"/> ${copyrights}' 391 + '<a target="_blank" href="http://www.microsoft.com/maps/product/terms.html">Terms of Use</a>' 392 })); 393 } catch (ol_errBing) { 394 Openlayers.Console.userError('Error loading Bing maps: ' + ol_errBing); 395 } 396 } 397 398 m.setCenter(new OpenLayers.LonLat(mapOpts.lon, mapOpts.lat).transform(m.displayProjection, m.projection), 399 mapOpts.zoom); 400 extent.extend(m.getExtent()); 401 402 // change/set alternative baselyr 403 try { 404 m.setBaseLayer(((m.getLayersByName(mapOpts.baselyr))[0])); 405 } catch (ol_err4) { 406 m.setBaseLayer(m.layers[0]); 407 } 408 409 if (mapOpts.controls === 1) { 410 /* add base controls to map */ 411 m.addControl(new OpenLayers.Control.LayerSwitcher()); 412 m.addControl(new OpenLayers.Control.PanZoomBar()); 413 m.addControl(new OpenLayers.Control.Graticule({ 414 visible : !1 415 })); 416 417 // add hillshade, since this is off by default only add when we have a 418 // layerswitcher 419 m.addLayer(new OpenLayers.Layer.OSM("Hillshade", "http://toolserver.org/~cmarqu/hill/${z}/${x}/${y}.png", { 420 transitionEffect : "resize", 421 isBaseLayer : !1, // false 422 transparent : !0, // true 423 visibility : !1, 424 displayOutsideMaxExtent : !0, 425 attribution : '', 426 tileOptions : { 427 crossOriginKeyword : null 428 } 429 })); 430 m.addControl(new OpenLayers.Control.OverviewMap({ 431 size : new OpenLayers.Size(140, 140), 432 minRectSize : 10 433 })); 434 } 435 436 if (mapOpts.statusbar === 1) { 437 // statusbar control: permalink 438 m.addControl(new OpenLayers.Control.Permalink(mapOpts.id + '-statusbar-link-ref')); 439 // statusbar control: mouse pos. 440 m.addControl(new OpenLayers.Control.MousePosition({ 441 'div' : OpenLayers.Util.getElement(mapOpts.id + '-statusbar-mouseposition') 442 })); 443 // statusbar control: scale 444 m.addControl(new OpenLayers.Control.Scale(mapOpts.id + '-statusbar-scale')); 445 // statusbar control: attribution 446 m.addControl(new OpenLayers.Control.Attribution({ 447 'div' : OpenLayers.Util.getElement(mapOpts.id + '-statusbar-text') 448 })); 449 // statusbar control: projection 450 OpenLayers.Util.getElement(mapOpts.id + '-statusbar-projection').innerHTML = m.displayProjection; 451 } else { 452 OpenLayers.Util.getElement(mapOpts.id + '-olStatusBar').display = 'none'; 453 } 454 455 if (mapOpts.toolbar === 1) { 456 // add buttons + panel 457 var /* zoom in btn */ 458 zoomin = new OpenLayers.Control.ZoomBox({ 459 title : "Zoom in" 460 }), /* zoom out btn */ 461 zoomout = new OpenLayers.Control.ZoomBox({ 462 out : !0, 463 title : "Zoom uit", 464 displayClass : "olControlZoomOut" 465 }), /* pan btn */ 466 pan = new OpenLayers.Control.DragPan({ 467 title : "Verschuif" 468 }), /* do "nothing" button... */ 469 info = new OpenLayers.Control.Button({ 470 type : OpenLayers.Control.TYPE_TOOL, 471 displayClass : "olControlFeatureInfo", 472 title : "Info" 473 }), /* navigation history btns */ 474 nav = new OpenLayers.Control.NavigationHistory(); 475 m.addControl(nav); 476 var panel = new OpenLayers.Control.Panel({ 477 defaultControl : pan, 478 displayClass : "olToolbar", 479 "div" : OpenLayers.Util.getElement(mapOpts.id + "-olToolbar") 480 }); 481 panel.addControls([ zoomin, zoomout, pan, info, nav.next, nav.previous ]); 482 m.addControl(panel); 483 } else { 484 OpenLayers.Util.getElement(mapOpts.id + '-olToolbar').display = 'none'; 485 } 486 487 if (OLmapPOI.length > 0) { 488 var markers = new OpenLayers.Layer.Vector("POI", { 489 styleMap : new OpenLayers.StyleMap({ 490 "default" : { 491 externalGraphic : "${img}", 492 graphicHeight : 16, 493 graphicWidth : 16, 494 graphicXOffset : 0, 495 graphicYOffset : -8, 496 graphicOpacity : "${opacity}", 497 rotation : "${angle}", 498 backgroundGraphic : DocBase + "lib/plugins/openlayersmap/icons/marker_shadow.png", 499 backgroundXOffset : 0, 500 backgroundYOffset : -4, 501 backgroundRotation : "${angle}", 502 pointRadius : 10, 503 labelXOffset : 8, 504 labelYOffset : 8, 505 labelAlign : "lb", 506 label : "${label}", 507 // fontColor : "", 508 fontFamily : "monospace", 509 fontSize : "12px", 510 fontWeight : "bold" 511 }, 512 "select" : { 513 cursor : "crosshair", 514 externalGraphic : DocBase + "lib/plugins/openlayersmap/icons/marker-red.png", 515 graphicHeight : 16, 516 graphicWidth : 16, 517 graphicXOffset : 0, 518 graphicYOffset : -8, 519 graphicOpacity : 1.0, 520 rotation : "${angle}" 521 } 522 }), 523 isBaseLayer : !1, 524 rendererOptions : { 525 yOrdering : !0 526 } 527 }); 528 m.addLayer(markers); 529 var features = []; 530 for ( var j = 0; j < OLmapPOI.length; j++) { 531 var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(OLmapPOI[j].lon, OLmapPOI[j].lat) 532 .transform(m.displayProjection, m.projection), { 533 angle : OLmapPOI[j].angle, 534 opacity : OLmapPOI[j].opacity, 535 img : DocBase + "lib/plugins/openlayersmap/icons/" + OLmapPOI[j].img, 536 label : OLmapPOI[j].rowId 537 }); 538 feat.data = { 539 name : OLmapPOI[j].txt, 540 rowId : OLmapPOI[j].rowId 541 }; 542 features.push(feat); 543 } 544 markers.addFeatures(features); 545 extent.extend(markers.getDataExtent()); 546 m.zoomToExtent(extent); 547 } 548 549 /* GPX layer */ 550 if (mapOpts.gpxfile.length > 0) { 551 var layerGPX = new OpenLayers.Layer.Vector("GPS route", { 552 protocol : new OpenLayers.Protocol.HTTP({ 553 url : DocBase + "lib/exe/fetch.php?media=" + mapOpts.gpxfile, 554 format : new OpenLayers.Format.GPX({ 555 extractWaypoints : !0, 556 extractTracks : !0, 557 extractStyles : !0, 558 extractAttributes : !0, 559 handleHeight : !0, 560 maxDepth : 3 561 }) 562 }), 563 style : { 564 strokeColor : "#0000FF", 565 strokeWidth : 3, 566 strokeOpacity : 0.7, 567 pointRadius : 4, 568 fillColor : "#0099FF", 569 fillOpacity : 0.7 570 // , label:"${name}" 571 }, 572 projection : new OpenLayers.Projection("EPSG:4326"), 573 strategies : [ new OpenLayers.Strategy.Fixed() ] 574 }); 575 m.addLayer(layerGPX); 576 layerGPX.events.register('loadend', m, function() { 577 extent.extend(layerGPX.getDataExtent()); 578 m.zoomToExtent(extent); 579 }); 580 } 581 582 /* GeoJSON layer */ 583 if (mapOpts.geojsonfile.length > 0) { 584 var layerGJS = new OpenLayers.Layer.Vector("json data", { 585 protocol : new OpenLayers.Protocol.HTTP({ 586 url : DocBase + "lib/exe/fetch.php?media=" + mapOpts.geojsonfile, 587 format : new OpenLayers.Format.GeoJSON({ 588 ignoreExtraDims : true 589 }) 590 }), 591 style : { 592 strokeColor : "#FF00FF", 593 strokeWidth : 3, 594 strokeOpacity : 0.7, 595 pointRadius : 4, 596 fillColor : "#FF99FF", 597 fillOpacity : 0.7 598 // , label:"${name}" 599 }, 600 projection : new OpenLayers.Projection("EPSG:4326"), 601 strategies : [ new OpenLayers.Strategy.Fixed() ] 602 }); 603 m.addLayer(layerGJS); 604 layerGJS.events.register('loadend', m, function() { 605 extent.extend(layerGJS.getDataExtent()); 606 m.zoomToExtent(extent); 607 }); 608 } 609 610 /* KML layer */ 611 if (mapOpts.kmlfile.length > 0) { 612 var layerKML = new OpenLayers.Layer.Vector("KML file", { 613 protocol : new OpenLayers.Protocol.HTTP({ 614 url : DocBase + "lib/exe/fetch.php?media=" + mapOpts.kmlfile, 615 format : new OpenLayers.Format.KML({ 616 extractStyles : !0, 617 extractAttributes : !0, 618 maxDepth : 3 619 }) 620 }), 621 style : { 622 label : "${name}" 623 }, 624 projection : new OpenLayers.Projection("EPSG:4326"), 625 strategies : [ new OpenLayers.Strategy.Fixed() ] 626 }); 627 m.addLayer(layerKML); 628 layerKML.events.register('loadend', m, function() { 629 extent.extend(layerKML.getDataExtent()); 630 m.zoomToExtent(extent); 631 }); 632 } 633 634 // selectcontrol for layers 635 if ((m.getLayersByClass('OpenLayers.Layer.GML').length > 0) 636 || m.getLayersByClass('OpenLayers.Layer.Vector').length > 0) { 637 selectControl = new OpenLayers.Control.SelectFeature((m.getLayersByClass('OpenLayers.Layer.Vector')).concat(m 638 .getLayersByClass('OpenLayers.Layer.GML')), { 639 hover : mapOpts.poihoverstyle, 640 onSelect : onFeatureSelect, 641 onUnselect : onFeatureUnselect 642 }); 643 m.addControl(selectControl); 644 selectControl.activate(); 645 } 646 return m; 647} 648 649var olTimerId = -1; 650 651/** init. */ 652function olInit() { 653 // TODO: check is this is still needed now that we have jQuery 654 if (navigator.userAgent.indexOf('MSIE') !== -1) { 655 if (olTimerId === -1) { 656 olTimerId = setTimeout("olInit()", 3000); 657 olEnable = !1; 658 } else { 659 clearTimeout(olTimerId); 660 olEnable = !0; 661 } 662 } 663 664 if (olEnable) { 665 var _i = 0; 666 // create the maps in the page 667 for (_i = 0; _i < olMapData.length; _i++) { 668 olMaps[olMapData[_i].mapOpts.id] = createMap(olMapData[_i].mapOpts, olMapData[_i].poi); 669 } 670 671 // hide the table(s) with POI by giving it a print-only style 672 // var tbls = getElementsByClass('olPOItableSpan', null, null); 673 var tbls = jQuery('.olPOItableSpan'); 674 for (_i = 0; _i < tbls.length; _i++) { 675 tbls[_i].className += ' olPrintOnly'; 676 } 677 // hide the static map image(s) by giving it a print only style 678 // var statImgs = getElementsByClass('olStaticMap', null, null); 679 var statImgs = jQuery('.olStaticMap'); 680 for (_i = 0; _i < statImgs.length; _i++) { 681 statImgs[_i].className += ' olPrintOnly'; 682 } 683 } 684} 685 686/** 687 * ol api flag. 688 * 689 * @type {Boolean} 690 */ 691var olEnable = !1, 692/** 693 * An array with data for each map in the page. 694 * 695 * @type {Array} 696 */ 697olMapData = [], 698/** 699 * Holds a reference to all of the maps on this page with the map's id as key. 700 * Can be used as an extension point. 701 * 702 * @type {Object} 703 */ 704olMaps = new Object(), 705/** 706 * MapQuest tiles flag. 707 * 708 * @type {Boolean} 709 */ 710mqEnable = !1, 711/** 712 * google map api flag. 713 * 714 * @type {Boolean} 715 */ 716gEnable = !1, 717/** 718 * Bing tiles flag. 719 * 720 * @type {Boolean} 721 */ 722bEnable = !1, 723/** 724 * Bing API key. 725 * 726 * @type {String} 727 */ 728bApiKey = '', 729/** 730 * OSM tiles flag. 731 * 732 * @type {Boolean} 733 */ 734osmEnable = !0, 735/** 736 * CSS support flag. 737 * 738 * @type {Boolean} 739 */ 740olCSSEnable = !0; 741/** 742 * yahoo map api flag. 743 * 744 * @type {Boolean} 745 */ 746// yEnable = false; 747/* register olInit to run with onload event. */ 748jQuery(olInit); 749