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