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, true, 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 var mEl = '<div id="' + mapid + '-olContainer" class="olContainer olWebOnly">' + '<div id="' + mapid 122 + '-olToolbar" class="olToolbar"></div>' + '<div class="clearer"></div>' + '<div id="' + mapid 123 + '" tabindex="0" style="width:' + width + ';height:' + height + ';" class="olMap">' 124 + '<a class="olAccesskey" href="" accesskey="1" onclick="document.getElementById("' + mapid 125 + '").focus(); return false;" title="' + OpenLayers.i18n("activate_map") + '">' 126 + OpenLayers.i18n("activate_map") + '</a>' + '</div>' + '<div id="' + mapid + '-olStatusBar" style="width:' 127 + width + ';"class="olStatusBarContainer">' + '<div id="' + mapid 128 + '-statusbar-scale" class="olStatusBar olStatusBarScale">scale</div>' 129 // + '<div id="' + mapid + '-statusbar-link" class="olStatusBar 130 // olStatusBarPermalink">' + '<a href="" id="' + mapid + 131 // '-statusbar-link-ref">link</a></div>' 132 + '<div id="' + mapid + '-statusbar-mouseposition" class="olStatusBar olStatusBarMouseposition"></div>' 133 + '<div id="' + mapid + '-statusbar-projection" class="olStatusBar olStatusBarProjection">proj</div>' 134 + '<div id="' + mapid + '-statusbar-text" class="olStatusBar olStatusBarText">txt</div>' + '</div></div>', 135 // fragment 136 frag = document.createDocumentFragment(), 137 // temp node 138 temp = document.createElement('div'); 139 temp.innerHTML = mEl; 140 while (temp.firstChild) { 141 frag.appendChild(temp.firstChild); 142 } 143 return frag; 144} 145 146/** 147 * Create the map based on the params given. 148 * 149 * @param {Object} 150 * mapOpts MapOptions hash {id:'olmap', width:500px, height:500px, 151 * lat:6710200, lon:506500, zoom:13, toolbar:1, statusbar:1, 152 * controls:1, poihoverstyle:1, baselyr:'', kmlfile:'', gpxfile:'', 153 * geojsonfile, summary:''} 154 * @param {Array} 155 * OLmapPOI array with POI's [ {lat:6710300,lon:506000,txt:'instap 156 * punt',angle:180,opacity:.9,img:'', rowId:n},... ]); 157 * 158 * @return {OpenLayers.Map} the created map 159 */ 160function createMap(mapOpts, OLmapPOI) { 161 if (!olEnable) { 162 return; 163 } 164 if (!olTestCSSsupport()) { 165 olEnable = false; 166 return; 167 } 168 169 var DocBase = DOKU_BASE; 170 171 OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3; 172 // OpenLayers.Layer.Vector.prototype.renderers = ["SVG", "VML"]; 173 174 // find map element location 175 var cleartag = document.getElementById(mapOpts.id + '-clearer'); 176 if (cleartag === null) { 177 return; 178 } 179 // create map element and add to document 180 var fragment = olCreateMaptag(mapOpts.id, mapOpts.width, mapOpts.height); 181 cleartag.parentNode.insertBefore(fragment, cleartag); 182 183 /** dynamic map extent. */ 184 var extent = new OpenLayers.Bounds(), 185 186 /** map. */ 187 m = new OpenLayers.Map({ 188 div : mapOpts.id, 189 projection : 'EPSG:900913', 190 displayProjection : new OpenLayers.Projection("EPSG:4326"), 191 numZoomLevels : 22, 192 controls : [], 193 theme : null, 194 tileManager : new OpenLayers.TileManager() 195 }); 196 197 if (osmEnable) { 198 /* add OSM map layers */ 199 m.addLayer(new OpenLayers.Layer.OSM()); 200 201 m.addLayer(new OpenLayersMap.Layer.OCM()); 202 /* open cycle map */ 203 m.addLayer(new OpenLayersMap.Layer.OCM("transport", [ 204 "http://a.tile2.opencyclemap.org/transport/${z}/${x}/${y}.png", 205 "http://b.tile2.opencyclemap.org/transport/${z}/${x}/${y}.png", 206 "http://c.tile2.opencyclemap.org/transport/${z}/${x}/${y}.png" ], { 207 visibility : mapOpts.baselyr === "transport" 208 })); 209 m.addLayer(new OpenLayersMap.Layer.OCM("landscape", [ 210 "http://a.tile3.opencyclemap.org/landscape/${z}/${x}/${y}.png", 211 "http://b.tile3.opencyclemap.org/landscape/${z}/${x}/${y}.png", 212 "http://c.tile3.opencyclemap.org/landscape/${z}/${x}/${y}.png" ], { 213 visibility : mapOpts.baselyr === "landscape" 214 })); 215 216 m.addLayer(new OpenLayersMap.Layer.CloudMade()); 217 m.addLayer(new OpenLayersMap.Layer.CloudMade("cloudmade fresh", [ 218 "http://a.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/${z}/${x}/${y}.png", 219 "http://b.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/${z}/${x}/${y}.png", 220 "http://c.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/${z}/${x}/${y}.png" ], { 221 visibility : mapOpts.baselyr === "cloudmade fresh" 222 })); 223 224 m.addLayer(new OpenLayers.Layer.OSM( 225 "hike and bike map", "http://toolserver.org/tiles/hikebike/${z}/${x}/${y}.png", { 226 visibility : mapOpts.baselyr === "hike and bike map", 227 tileOptions : { 228 crossOriginKeyword : null 229 } 230 })); 231 } 232 /* 233 * add MapQuest map layers, see: 234 * http://developer.mapquest.com/web/products/open/map 235 */ 236 if (mqEnable) { 237 m.addLayer(new OpenLayersMap.Layer.MapQuest()); 238 m.addLayer(new OpenLayersMap.Layer.MapQuest("mapquest sat", [ 239 "http://otile1.mqcdn.com/tiles/1.0.0/sat/${z}/${x}/${y}.jpg", 240 "http://otile2.mqcdn.com/tiles/1.0.0/sat/${z}/${x}/${y}.jpg", 241 "http://otile3.mqcdn.com/tiles/1.0.0/sat/${z}/${x}/${y}.jpg", 242 "http://otile4.mqcdn.com/tiles/1.0.0/sat/${z}/${x}/${y}.jpg" ], { 243 // note that global coverage is provided at zoom levels 0-11. Zoom 244 // Levels 12+ are provided only in the United States (lower 48). 245 numZoomLevels : 12, 246 visibility : mapOpts.baselyr === "mapquest sat" 247 })); 248 249 } 250 251 if (gEnable) { 252 /* load google maps */ 253 try { 254 m.addLayer(new OpenLayers.Layer.Google("google relief", { 255 type : google.maps.MapTypeId.TERRAIN, 256 // transitionEffect : "resize", 257 numZoomLevels : 16, 258 animationEnabled : true, 259 visibility : mapOpts.baselyr === "google relief" 260 })); 261 m.addLayer(new OpenLayers.Layer.Google("google sat", { 262 type : google.maps.MapTypeId.SATELLITE, 263 // transitionEffect : "resize", 264 // numZoomLevels : 22, 265 animationEnabled : true, 266 visibility : mapOpts.baselyr === "google sat" 267 })); 268 m.addLayer(new OpenLayers.Layer.Google("google hybrid", { 269 type : google.maps.MapTypeId.HYBRID, 270 // transitionEffect : "resize", 271 // numZoomLevels : 20, 272 animationEnabled : true, 273 visibility : mapOpts.baselyr === "google hybrid" 274 })); 275 m.addLayer(new OpenLayers.Layer.Google("google road", { 276 // transitionEffect : "resize", 277 // numZoomLevels : 20, 278 animationEnabled : true, 279 visibility : mapOpts.baselyr === "google road" 280 })); 281 } catch (ol_err1) { 282 Openlayers.Console.userError('Error loading Google maps' + ol_err1); 283 } 284 } 285 286 if (bEnable && bApiKey !== '') { 287 try { 288 /* add Bing tiles */ 289 m.addLayer(new OpenLayers.Layer.Bing({ 290 key : bApiKey, 291 type : "Road", 292 name : "bing road", 293 visibility : mapOpts.baselyr === "bing road", 294 wrapDateLine : true, 295 attributionTemplate : '<a target="_blank" href="http://www.bing.com/maps/">' 296 + 'Bing™</a><img src="http://www.bing.com/favicon.ico" alt="Bing logo"/> ${copyrights}' 297 + '<a target="_blank" href="http://www.microsoft.com/maps/product/terms.html">Terms of Use</a>' 298 })); 299 m.addLayer(new OpenLayers.Layer.Bing({ 300 key : bApiKey, 301 type : "Aerial", 302 name : "bing sat", 303 visibility : mapOpts.baselyr === "bing sat", 304 wrapDateLine : true, 305 attributionTemplate : '<a target="_blank" href="http://www.bing.com/maps/">' 306 + 'Bing™</a><img src="http://www.bing.com/favicon.ico" alt="Bing logo"/> ${copyrights}' 307 + '<a target="_blank" href="http://www.microsoft.com/maps/product/terms.html">Terms of Use</a>' 308 })); 309 m.addLayer(new OpenLayers.Layer.Bing({ 310 key : bApiKey, 311 type : "AerialWithLabels", 312 name : "bing hybrid", 313 visibility : mapOpts.baselyr === "bing hybrid", 314 wrapDateLine : true, 315 attributionTemplate : '<a target="_blank" href="http://www.bing.com/maps/">' 316 + 'Bing™</a><img src="http://www.bing.com/favicon.ico" alt="Bing logo"/> ${copyrights}' 317 + '<a target="_blank" href="http://www.microsoft.com/maps/product/terms.html">Terms of Use</a>' 318 })); 319 } catch (ol_errBing) { 320 Openlayers.Console.userError('Error loading Bing maps: ' + ol_errBing); 321 } 322 } 323 324 m.setCenter(new OpenLayers.LonLat(mapOpts.lon, mapOpts.lat).transform(m.displayProjection, m.projection), 325 mapOpts.zoom); 326 extent.extend(m.getExtent()); 327 328 // change/set alternative baselyr 329 try { 330 m.setBaseLayer(((m.getLayersByName(mapOpts.baselyr))[0])); 331 } catch (ol_err4) { 332 m.setBaseLayer(m.layers[0]); 333 } 334 335 m.addControls([ new OpenLayers.Control.ScaleLine({ 336 geodesic : true 337 }), new OpenLayers.Control.KeyboardDefaults({ 338 observeElement : mapOpts.id 339 }), new OpenLayers.Control.Navigation() ]); 340 341 if (mapOpts.controls === 1) { 342 /* add base controls to map */ 343 m.addControls([ new OpenLayers.Control.LayerSwitcher(), new OpenLayers.Control.Graticule({ 344 visible : false 345 }), new OpenLayersMap.Control.OverviewMap(), new OpenLayers.Control.PanZoomBar() 346 // issue31: new OpenLayers.Control.Zoom() 347 ]); 348 349 // add hillshade, since this is off by default only add when we have a 350 // layerswitcher 351 m.addLayer(new OpenLayers.Layer.OSM("Hillshade", "http://toolserver.org/~cmarqu/hill/${z}/${x}/${y}.png", { 352 isBaseLayer : false, 353 transparent : true, 354 visibility : false, 355 displayOutsideMaxExtent : true, 356 attribution : '', 357 tileOptions : { 358 crossOriginKeyword : null 359 } 360 })); 361 } 362 363 if (mapOpts.statusbar === 1) { 364 // statusbar control: permalink 365 // m.addControl(new OpenLayers.Control.Permalink(mapOpts.id + 366 // '-statusbar-link-ref')); 367 368 // statusbar control: mouse pos. 369 m.addControl(new OpenLayers.Control.MousePosition({ 370 'div' : OpenLayers.Util.getElement(mapOpts.id + '-statusbar-mouseposition') 371 })); 372 // statusbar control: scale 373 m.addControl(new OpenLayers.Control.Scale(mapOpts.id + '-statusbar-scale')); 374 // statusbar control: attribution 375 m.addControl(new OpenLayers.Control.Attribution({ 376 'div' : OpenLayers.Util.getElement(mapOpts.id + '-statusbar-text') 377 })); 378 // statusbar control: projection 379 OpenLayers.Util.getElement(mapOpts.id + '-statusbar-projection').innerHTML = m.displayProjection; 380 } else { 381 OpenLayers.Util.getElement(mapOpts.id + '-olStatusBar').display = 'none'; 382 } 383 384 if (mapOpts.toolbar === 1) { 385 // add buttons + panel 386 var /* zoom in btn */ 387 zoomin = new OpenLayers.Control.ZoomBox({ 388 title : OpenLayers.i18n("zoom_in") 389 }), /* zoom out btn */ 390 zoomout = new OpenLayers.Control.ZoomBox({ 391 out : true, 392 title : OpenLayers.i18n("zoom_out"), 393 displayClass : "olControlZoomOut" 394 }), /* pan btn */ 395 pan = new OpenLayers.Control.DragPan({ 396 title : OpenLayers.i18n("move") 397 }), /* do "nothing" button... */ 398 info = new OpenLayers.Control.Button({ 399 type : OpenLayers.Control.TYPE_TOOL, 400 displayClass : "olControlFeatureInfo", 401 title : OpenLayers.i18n("info") 402 }), /* navigation history btns */ 403 nav = new OpenLayers.Control.NavigationHistory(); 404 m.addControl(nav); 405 var panel = new OpenLayers.Control.Panel({ 406 defaultControl : pan, 407 displayClass : "olToolbar", 408 "div" : OpenLayers.Util.getElement(mapOpts.id + "-olToolbar") 409 }); 410 panel.addControls([ zoomin, zoomout, pan, info, nav.next, nav.previous ]); 411 m.addControl(panel); 412 } else { 413 OpenLayers.Util.getElement(mapOpts.id + '-olToolbar').display = 'none'; 414 } 415 416 if (OLmapPOI.length > 0) { 417 var markers = new OpenLayers.Layer.Vector("POI", { 418 styleMap : new OpenLayers.StyleMap({ 419 "default" : { 420 externalGraphic : "${img}", 421 graphicHeight : 16, 422 graphicWidth : 16, 423 graphicXOffset : 0, 424 graphicYOffset : -8, 425 graphicOpacity : "${opacity}", 426 rotation : "${angle}", 427 backgroundGraphic : DocBase + "lib/plugins/openlayersmap/icons/marker_shadow.png", 428 backgroundXOffset : 0, 429 backgroundYOffset : -4, 430 backgroundRotation : "${angle}", 431 pointRadius : 10, 432 labelXOffset : 8, 433 labelYOffset : 8, 434 labelAlign : "lb", 435 label : "${label}", 436 // fontColor : "", 437 fontFamily : "monospace", 438 fontSize : "12px", 439 fontWeight : "bold" 440 }, 441 "select" : { 442 cursor : "crosshair", 443 externalGraphic : DocBase + "lib/plugins/openlayersmap/icons/marker-red.png", 444 graphicHeight : 16, 445 graphicWidth : 16, 446 graphicXOffset : 0, 447 graphicYOffset : -8, 448 graphicOpacity : 1.0, 449 rotation : "${angle}" 450 } 451 }), 452 isBaseLayer : false, 453 rendererOptions : { 454 yOrdering : true 455 } 456 }); 457 m.addLayer(markers); 458 var features = []; 459 for ( var j = 0; j < OLmapPOI.length; j++) { 460 var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(OLmapPOI[j].lon, OLmapPOI[j].lat) 461 .transform(m.displayProjection, m.projection), { 462 angle : OLmapPOI[j].angle, 463 opacity : OLmapPOI[j].opacity, 464 img : DocBase + "lib/plugins/openlayersmap/icons/" + OLmapPOI[j].img, 465 label : OLmapPOI[j].rowId 466 }); 467 feat.data = { 468 name : OLmapPOI[j].txt, 469 rowId : OLmapPOI[j].rowId 470 }; 471 features.push(feat); 472 } 473 markers.addFeatures(features); 474 extent.extend(markers.getDataExtent()); 475 m.zoomToExtent(extent); 476 } 477 478 /* GPX layer */ 479 if (mapOpts.gpxfile.length > 0) { 480 var layerGPX = new OpenLayers.Layer.Vector("GPS route", { 481 protocol : new OpenLayers.Protocol.HTTP({ 482 url : DocBase + "lib/exe/fetch.php?media=" + mapOpts.gpxfile, 483 format : new OpenLayers.Format.GPX({ 484 extractWaypoints : true, 485 extractTracks : true, 486 extractStyles : true, 487 extractAttributes : true, 488 handleHeight : true, 489 maxDepth : 3 490 }) 491 }), 492 style : { 493 strokeColor : "#0000FF", 494 strokeWidth : 3, 495 strokeOpacity : 0.7, 496 pointRadius : 4, 497 fillColor : "#0099FF", 498 fillOpacity : 0.7 499 // , label:"${name}" 500 }, 501 projection : new OpenLayers.Projection("EPSG:4326"), 502 strategies : [ new OpenLayers.Strategy.Fixed() ] 503 }); 504 m.addLayer(layerGPX); 505 layerGPX.events.register('loadend', m, function() { 506 extent.extend(layerGPX.getDataExtent()); 507 m.zoomToExtent(extent); 508 }); 509 } 510 511 /* GeoJSON layer */ 512 if (mapOpts.geojsonfile.length > 0) { 513 var layerGJS = new OpenLayers.Layer.Vector("json data", { 514 protocol : new OpenLayers.Protocol.HTTP({ 515 url : DocBase + "lib/exe/fetch.php?media=" + mapOpts.geojsonfile, 516 format : new OpenLayers.Format.GeoJSON({ 517 ignoreExtraDims : true 518 }) 519 }), 520 style : { 521 strokeColor : "#FF00FF", 522 strokeWidth : 3, 523 strokeOpacity : 0.7, 524 pointRadius : 4, 525 fillColor : "#FF99FF", 526 fillOpacity : 0.7 527 // , label:"${name}" 528 }, 529 projection : new OpenLayers.Projection("EPSG:4326"), 530 strategies : [ new OpenLayers.Strategy.Fixed() ] 531 }); 532 m.addLayer(layerGJS); 533 layerGJS.events.register('loadend', m, function() { 534 extent.extend(layerGJS.getDataExtent()); 535 m.zoomToExtent(extent); 536 }); 537 } 538 539 /* KML layer */ 540 if (mapOpts.kmlfile.length > 0) { 541 var layerKML = new OpenLayers.Layer.Vector("KML file", { 542 protocol : new OpenLayers.Protocol.HTTP({ 543 url : DocBase + "lib/exe/fetch.php?media=" + mapOpts.kmlfile, 544 format : new OpenLayers.Format.KML({ 545 extractStyles : true, 546 extractAttributes : true, 547 maxDepth : 3 548 }) 549 }), 550 style : { 551 label : "${name}" 552 }, 553 projection : new OpenLayers.Projection("EPSG:4326"), 554 strategies : [ new OpenLayers.Strategy.Fixed() ] 555 }); 556 m.addLayer(layerKML); 557 layerKML.events.register('loadend', m, function() { 558 extent.extend(layerKML.getDataExtent()); 559 m.zoomToExtent(extent); 560 }); 561 } 562 563 // selectcontrol for layers 564 if ((m.getLayersByClass('OpenLayers.Layer.GML').length > 0) 565 || m.getLayersByClass('OpenLayers.Layer.Vector').length > 0) { 566 selectControl = new OpenLayers.Control.SelectFeature((m.getLayersByClass('OpenLayers.Layer.Vector')).concat(m 567 .getLayersByClass('OpenLayers.Layer.GML')), { 568 hover : mapOpts.poihoverstyle, 569 onSelect : onFeatureSelect, 570 onUnselect : onFeatureUnselect 571 }); 572 m.addControl(selectControl); 573 selectControl.activate(); 574 } 575 return m; 576} 577 578// var olTimerId = -1; 579 580/** init. */ 581function olInit() { 582 // TODO: check is this is still needed now that we have jQuery 583 // if (navigator.userAgent.indexOf('MSIE') !== -1) { 584 // if (olTimerId === -1) { 585 // olTimerId = setTimeout("olInit()", 3000); 586 // olEnable = false; 587 // } else { 588 // clearTimeout(olTimerId); 589 // olEnable = true; 590 // } 591 // } 592 593 if (olEnable) { 594 var _i = 0; 595 // create the maps in the page 596 for (_i = 0; _i < olMapData.length; _i++) { 597 olMaps[olMapData[_i].mapOpts.id] = createMap(olMapData[_i].mapOpts, olMapData[_i].poi); 598 } 599 // hide the table(s) with POI by giving it a print-only style 600 var tbls = jQuery('.olPOItableSpan'); 601 for (_i = 0; _i < tbls.length; _i++) { 602 tbls[_i].className += ' olPrintOnly'; 603 } 604 // hide the static map image(s) by giving it a print only style 605 var statImgs = jQuery('.olStaticMap'); 606 for (_i = 0; _i < statImgs.length; _i++) { 607 statImgs[_i].className += ' olPrintOnly'; 608 } 609 } 610} 611 612/** 613 * ol api flag. 614 * 615 * @type {Boolean} 616 */ 617var olEnable = false, 618/** 619 * An array with data for each map in the page. 620 * 621 * @type {Array} 622 */ 623olMapData = [], 624/** 625 * Holds a reference to all of the maps on this page with the map's id as key. 626 * Can be used as an extension point. 627 * 628 * @type {Object} 629 */ 630olMaps = new Object(), 631/** 632 * MapQuest tiles flag. 633 * 634 * @type {Boolean} 635 */ 636mqEnable = false, 637/** 638 * google map api flag. 639 * 640 * @type {Boolean} 641 */ 642gEnable = false, 643/** 644 * Bing tiles flag. 645 * 646 * @type {Boolean} 647 */ 648bEnable = false, 649/** 650 * Bing API key. 651 * 652 * @type {String} 653 */ 654bApiKey = '', 655/** 656 * OSM tiles flag. 657 * 658 * @type {Boolean} 659 */ 660osmEnable = true, 661/** 662 * CSS support flag. 663 * 664 * @type {Boolean} 665 */ 666olCSSEnable = true; 667/** 668 * yahoo map api flag. 669 * 670 * @type {Boolean} 671 */ 672// yEnable = false; 673/* register olInit to run with onload event. */ 674jQuery(olInit); 675