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 <mc.prins@gmail.com> 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 var mEl = '<div id="' + mapid + '-olContainer" class="olContainer olWebOnly">' 125 + '<div id="' + mapid + '-olToolbar" class="olToolbar"></div>' 126 + '<div class="clearer"></div>' 127 + '<div id="' + mapid + '" style="width:' + width + ';height:' + height + ';" class="olMap"></div>' 128 + '<div id="' + mapid + '-olStatusBar" class="olStatusBarContainer">' 129 + '<div id="' + mapid + '-statusbar-scale" class="olStatusBar olStatusBarScale">scale</div>' 130 + '<div id="' + mapid + '-statusbar-link" class="olStatusBar olStatusBarPermalink">' 131 + '<a href="" id="' + mapid + '-statusbar-link-ref">map 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>' 135 + '</div>\n</div>', 136 // fragment 137 frag = document.createDocumentFragment(), 138 // temp node 139 temp = document.createElement('div'); 140 temp.innerHTML = mEl; 141 while (temp.firstChild) { 142 frag.appendChild(temp.firstChild); 143 } 144 return frag; 145} 146 147/** 148 * create the map based on the params given. 149 * 150 * @param {Object}mapOpts 151 * MapOptions hash {id:'olmap', width:500px, height:500px, 152 * lat:6710200, lon:506500, zoom:13, toolbar:1, statusbar:1, 153 * controls:1, poihoverstyle:1, baselyr:'', kmlfile:'', gpxfile:'', 154 * summary:''} 155 * @param {Array}OLmapPOI 156 * array with POI's [ {lat:6710300,lon:506000,txt:'instap 157 * punt',angle:180,opacity:.9,img:'', rowId:n},... ]); 158 * 159 */ 160function createMap(mapOpts, OLmapPOI) { 161 if (!olEnable) { 162 return; 163 } 164 if (!olTestCSSsupport()) { 165 olEnable = !1; 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 : [ new OpenLayers.Control.ArgParser(), 193 new OpenLayers.Control.KeyboardDefaults(), 194 new OpenLayers.Control.Navigation({ 195 dragPanOptions : { 196 enableKinetic : !0 197 } 198 }), new OpenLayers.Control.ScaleLine({ 199 geodesic : !0 200 }) ], 201 theme : null 202 }); 203 204 if (osmEnable) { 205 /* add OSM map layers */ 206 m.addLayer(new OpenLayers.Layer.OSM("OpenStreetMap", null, { 207 transitionEffect : 'resize', 208 visibility : mapOpts.baselyr === "OpenStreetMap" 209 })); 210 211 m.addLayer(new OpenLayers.Layer.OSM("transport", 212 [ 213 "http://a.tile2.opencyclemap.org/transport/${z}/${x}/${y}.png", 214 "http://b.tile2.opencyclemap.org/transport/${z}/${x}/${y}.png", 215 "http://c.tile2.opencyclemap.org/transport/${z}/${x}/${y}.png" ], 216 { 217 transitionEffect : 'resize', 218 attribution : 'Data CC-By-SA <a href="http://openstreetmap.org/" target="_blank">OpenStreetMap</a>, ' 219 + 'Tiles <a href="http://opencyclemap.org/" target="_blank">OpenCycleMap</a>' 220 + '<img src="http://opencyclemap.org/favicon.ico" alt="OpenCycleMap logo"/>', 221 visibility : mapOpts.baselyr === "transport", 222 tileOptions : { 223 crossOriginKeyword : null 224 } 225 })); 226 m.addLayer(new OpenLayers.Layer.OSM("landscape", 227 [ 228 "http://a.tile3.opencyclemap.org/landscape/${z}/${x}/${y}.png", 229 "http://b.tile3.opencyclemap.org/landscape/${z}/${x}/${y}.png", 230 "http://c.tile3.opencyclemap.org/landscape/${z}/${x}/${y}.png" ], 231 { 232 transitionEffect : 'resize', 233 attribution : 'Data CC-By-SA <a href="http://openstreetmap.org/" target="_blank">OpenStreetMap</a>, ' 234 + 'Tiles <a href="http://opencyclemap.org/" target="_blank">OpenCycleMap</a>' 235 + '<img src="http://opencyclemap.org/favicon.ico" alt="OpenCycleMap logo"/>', 236 visibility : mapOpts.baselyr === "transport", 237 tileOptions : { 238 crossOriginKeyword : null 239 } 240 })); 241 m.addLayer(new OpenLayers.Layer.OSM("cycle map", 242 [ 243 "http://a.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png", 244 "http://b.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png", 245 "http://c.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png" ], 246 { 247 transitionEffect : 'resize', 248 attribution : 'Data CC-By-SA <a href="http://openstreetmap.org/" target="_blank">OpenStreetMap</a>, ' 249 + 'Tiles <a href="http://opencyclemap.org/" target="_blank">OpenCycleMap</a>' 250 + '<img src="http://opencyclemap.org/favicon.ico" alt="OpenCycleMap logo"/>', 251 visibility : mapOpts.baselyr === "cycle map", 252 tileOptions : { 253 crossOriginKeyword : null 254 } 255 })); 256 257 m.addLayer(new OpenLayers.Layer.OSM("cloudmade map", 258 [ 259 "http://a.tile.cloudmade.com/2f59745a6b525b4ebdb100891d5b6711/3/256/${z}/${x}/${y}.png", 260 "http://b.tile.cloudmade.com/2f59745a6b525b4ebdb100891d5b6711/3/256/${z}/${x}/${y}.png", 261 "http://c.tile.cloudmade.com/2f59745a6b525b4ebdb100891d5b6711/3/256/${z}/${x}/${y}.png" ], 262 { 263 transitionEffect : 'resize', 264 attribution : 'Tiles © 2012 <a target="_blank" href="http://cloudmade.com">CloudMade</a>' 265 + '<img src="http://cloudmade.com/favicon.ico" alt="CloudMade logo"/>' 266 + ' Data CC-BY-SA <a href="http://openstreetmap.org/" target="_blank">OpenStreetMap</a>', 267 visibility : mapOpts.baselyr === "cloudmade map", 268 tileOptions : { 269 crossOriginKeyword : null 270 } 271 })); 272 273 m.addLayer(new OpenLayers.Layer.OSM("hike and bike map", 274 "http://toolserver.org/tiles/hikebike/${z}/${x}/${y}.png", { 275 transitionEffect : 'resize', 276 visibility : mapOpts.baselyr === "hike and bike map", 277 tileOptions : { 278 crossOriginKeyword : null 279 } 280 })); 281 } 282 /* 283 * add MapQuest map layers, see: 284 * http://developer.mapquest.com/web/products/open/map 285 */ 286 if (mqEnable) { 287 m.addLayer(new OpenLayers.Layer.OSM("mapquest road", 288 [ 289 "http://otile1.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png", 290 "http://otile2.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png", 291 "http://otile3.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png", 292 "http://otile4.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png" ], 293 { 294 transitionEffect : 'resize', 295 attribution : 'Data CC-By-SA <a href="http://openstreetmap.org/" target="_blank">OpenStreetMap</a>, ' 296 + 'Tiles <a href="http://www.mapquest.com/" target="_blank">MapQuest</a>' 297 + '<img src="http://developer.mapquest.com/content/osm/mq_logo.png" alt="MapQuest logo"/>', 298 visibility : mapOpts.baselyr === "mapquest road", 299 tileOptions : { 300 crossOriginKeyword : null 301 } 302 })); 303 // note that global coverage is provided at zoom levels 0-11. Zoom 304 // Levels 12+ are provided only in the United States (lower 48). 305 m.addLayer(new OpenLayers.Layer.OSM("mapquest sat", 306 [ 307 "http://oatile1.mqcdn.com/naip/${z}/${x}/${y}.jpg", 308 "http://oatile2.mqcdn.com/naip/${z}/${x}/${y}.jpg", 309 "http://oatile3.mqcdn.com/naip/${z}/${x}/${y}.jpg", 310 "http://oatile4.mqcdn.com/naip/${z}/${x}/${y}.jpg" ], 311 { 312 transitionEffect : 'resize', 313 attribution : 'Tiles Courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a>' 314 + '<img src="http://developer.mapquest.com/content/osm/mq_logo.png" alt="MapQuest logo"/>', 315 visibility : mapOpts.baselyr === "mapquest sat", 316 numZoomLevels : 12, 317 tileOptions : { 318 crossOriginKeyword : null 319 } 320 })); 321 } 322 323 if (gEnable) { 324 /* load google maps */ 325 try { 326 m.addLayer(new OpenLayers.Layer.Google("google relief", { 327 type : google.maps.MapTypeId.TERRAIN, 328 // transitionEffect : 'resize', 329 numZoomLevels : 16, 330 animationEnabled : !0, 331 visibility : mapOpts.baselyr === "google relief" 332 })); 333 m.addLayer(new OpenLayers.Layer.Google("google sat", { 334 type : google.maps.MapTypeId.SATELLITE, 335 // transitionEffect : 'resize', 336 // numZoomLevels : 22, 337 animationEnabled : !0, 338 visibility : mapOpts.baselyr === "google sat" 339 })); 340 m.addLayer(new OpenLayers.Layer.Google("google hybrid", { 341 type : google.maps.MapTypeId.HYBRID, 342 // transitionEffect : 'resize', 343 // numZoomLevels : 20, 344 animationEnabled : !0, 345 visibility : mapOpts.baselyr === "google hybrid" 346 })); 347 m.addLayer(new OpenLayers.Layer.Google("google road", { 348 // transitionEffect : 'resize', 349 // numZoomLevels : 20, 350 animationEnabled : !0, 351 visibility : mapOpts.baselyr === "google road" 352 })); 353 } catch (ol_err1) { 354 Openlayers.Console.userError('Error loading Google maps' + ol_err1); 355 } 356 } 357 358 if (bEnable && bApiKey !== '') { 359 try { 360 /* add Bing tiles */ 361 m.addLayer(new OpenLayers.Layer.Bing( 362 { 363 key : bApiKey, 364 type : "Road", 365 name : 'bing road', 366 transitionEffect : 'resize', 367 visibility : mapOpts.baselyr === "bing road", 368 wrapDateLine : !0, 369 attributionTemplate : '<a target="_blank" href="http://www.bing.com/maps/">' 370 + 'Bing™</a><img src="http://www.bing.com/favicon.ico" alt="Bing logo"/> ${copyrights}' 371 + '<a target="_blank" href="http://www.microsoft.com/maps/product/terms.html">Terms of Use</a>' 372 })); 373 m.addLayer(new OpenLayers.Layer.Bing( 374 { 375 key : bApiKey, 376 type : "Aerial", 377 name : 'bing sat', 378 transitionEffect : 'resize', 379 visibility : mapOpts.baselyr === "bing sat", 380 wrapDateLine : !0, 381 attributionTemplate : '<a target="_blank" href="http://www.bing.com/maps/">' 382 + 'Bing™</a><img src="http://www.bing.com/favicon.ico" alt="Bing logo"/> ${copyrights}' 383 + '<a target="_blank" href="http://www.microsoft.com/maps/product/terms.html">Terms of Use</a>' 384 })); 385 m.addLayer(new OpenLayers.Layer.Bing( 386 { 387 key : bApiKey, 388 type : "AerialWithLabels", 389 name : "bing hybrid", 390 transitionEffect : 'resize', 391 visibility : mapOpts.baselyr === "bing hybrid", 392 wrapDateLine : !0, 393 attributionTemplate : '<a target="_blank" href="http://www.bing.com/maps/">' 394 + 'Bing™</a><img src="http://www.bing.com/favicon.ico" alt="Bing logo"/> ${copyrights}' 395 + '<a target="_blank" href="http://www.microsoft.com/maps/product/terms.html">Terms of Use</a>' 396 })); 397 } catch (ol_errBing) { 398 Openlayers.Console.userError('Error loading Bing maps: ' 399 + ol_errBing); 400 } 401 } 402 403 m.setCenter(new OpenLayers.LonLat(mapOpts.lon, mapOpts.lat).transform( 404 m.displayProjection, m.projection), mapOpts.zoom); 405 extent.extend(m.getExtent()); 406 407 // change/set alternative baselyr 408 try { 409 m.setBaseLayer(((m.getLayersByName(mapOpts.baselyr))[0])); 410 } catch (ol_err4) { 411 m.setBaseLayer(m.layers[0]); 412 } 413 414 if (mapOpts.controls === 1) { 415 /* add base controls to map */ 416 m.addControl(new OpenLayers.Control.LayerSwitcher()); 417 m.addControl(new OpenLayers.Control.PanZoomBar()); 418 m.addControl(new OpenLayers.Control.Graticule({ 419 visible : !1 420 })); 421 422 // add hillshade, since this is off by default only add when we have a 423 // layerswitcher 424 m.addLayer(new OpenLayers.Layer.OSM("Hillshade", 425 "http://toolserver.org/~cmarqu/hill/${z}/${x}/${y}.png", { 426 transitionEffect : 'resize', 427 isBaseLayer : !1, // false 428 transparent : !0, // true 429 visibility : !1, 430 displayOutsideMaxExtent : !0, 431 attribution : '', 432 tileOptions : { 433 crossOriginKeyword : null 434 } 435 })); 436 437 m.addControl(new OpenLayers.Control.OverviewMap({ 438 size : new OpenLayers.Size(140, 140), 439 minRectSize : 10 440 })); 441 } 442 443 if (mapOpts.statusbar === 1) { 444 // statusbar control: permalink 445 m.addControl(new OpenLayers.Control.Permalink(mapOpts.id 446 + '-statusbar-link-ref')); 447 // statusbar control: mouse pos. 448 // TODO kijken naar afronding met aNumber.toFixed(0) 449 m.addControl(new OpenLayers.Control.MousePosition({ 450 'div' : OpenLayers.Util.getElement(mapOpts.id 451 + '-statusbar-mouseposition') 452 })); 453 // statusbar control: scale 454 m.addControl(new OpenLayers.Control.Scale(mapOpts.id 455 + '-statusbar-scale')); 456 // statusbar control: attribution 457 m.addControl(new OpenLayers.Control.Attribution({ 458 'div' : OpenLayers.Util.getElement(mapOpts.id + '-statusbar-text') 459 })); 460 // statusbar control: projection 461 OpenLayers.Util.getElement(mapOpts.id + '-statusbar-projection').innerHTML = m.displayProjection; 462 } else { 463 OpenLayers.Util.getElement(mapOpts.id + '-olStatusBar').display = 'none'; 464 } 465 466 if (mapOpts.toolbar === 1) { 467 // add buttons + panel 468 var /* zoom in btn */ 469 zoomin = new OpenLayers.Control.ZoomBox({ 470 title : "Zoom in" 471 }), /* zoom out btn */ 472 zoomout = new OpenLayers.Control.ZoomBox({ 473 out : !0, 474 title : "Zoom uit", 475 displayClass : "olControlZoomOut" 476 }), /* pan btn */pan = new OpenLayers.Control.DragPan({ 477 title : "Verschuif" 478 }), /* do "nothing" button... */info = new OpenLayers.Control.Button({ 479 type : OpenLayers.Control.TYPE_TOOL, 480 displayClass : "olControlFeatureInfo", 481 title : "Info" 482 }), /* navigation history btns */ 483 nav = new OpenLayers.Control.NavigationHistory(); 484 m.addControl(nav); 485 var panel = new OpenLayers.Control.Panel({ 486 defaultControl : pan, 487 displayClass : "olToolbar", 488 "div" : OpenLayers.Util.getElement(mapOpts.id + "-olToolbar") 489 }); 490 panel 491 .addControls([ zoomin, zoomout, pan, info, nav.next, 492 nav.previous ]); 493 m.addControl(panel); 494 } else { 495 OpenLayers.Util.getElement(mapOpts.id + '-olToolbar').display = 'none'; 496 } 497 498 if (OLmapPOI.length > 0) { 499 var markers = new OpenLayers.Layer.Vector( 500 "POI", 501 { 502 styleMap : new OpenLayers.StyleMap( 503 { 504 "default" : { 505 externalGraphic : "${img}", 506 graphicHeight : 16, 507 graphicWidth : 16, 508 graphicXOffset : 0, 509 graphicYOffset : -8, 510 graphicOpacity : "${opacity}", 511 rotation : "${angle}", 512 backgroundGraphic : DocBase 513 + "lib/plugins/openlayersmap/icons/marker_shadow.png", 514 backgroundXOffset : 0, 515 backgroundYOffset : -4, 516 backgroundRotation : "${angle}", 517 pointRadius : 10, 518 labelXOffset : 8, 519 labelYOffset : 8, 520 labelAlign : "lb", 521 label : "${label}", 522 // fontColor : "", 523 fontFamily : "monospace", 524 fontSize : "12px", 525 fontWeight : "bold" 526 }, 527 "select" : { 528 cursor : "crosshair", 529 externalGraphic : DocBase 530 + "lib/plugins/openlayersmap/icons/marker-red.png", 531 graphicHeight : 16, 532 graphicWidth : 16, 533 graphicXOffset : 0, 534 graphicYOffset : -8, 535 graphicOpacity : 1.0, 536 rotation : "${angle}" 537 } 538 }), 539 isBaseLayer : !1, 540 rendererOptions : { 541 yOrdering : !0 542 } 543 }); 544 m.addLayer(markers); 545 var features = []; 546 var lonLat; 547 for ( var j = 0; j < OLmapPOI.length; j++) { 548 var feat = new OpenLayers.Feature.Vector( 549 new OpenLayers.Geometry.Point(OLmapPOI[j].lon, 550 OLmapPOI[j].lat).transform(m.displayProjection, 551 m.projection), { 552 angle : OLmapPOI[j].angle, 553 opacity : OLmapPOI[j].opacity, 554 img : DocBase + "lib/plugins/openlayersmap/icons/" 555 + OLmapPOI[j].img, 556 label : OLmapPOI[j].rowId 557 }); 558 feat.data = { 559 name : OLmapPOI[j].txt, 560 rowId : OLmapPOI[j].rowId 561 }; 562 features.push(feat); 563 } 564 markers.addFeatures(features); 565 extent.extend(markers.getDataExtent()); 566 m.zoomToExtent(extent); 567 } 568 569 /* 570 * map.addLayer(new OpenLayers.Layer.Vector("GML", { protocol: new 571 * OpenLayers.Protocol.HTTP({ url: "gml/polygon.xml", format: new 572 * OpenLayers.Format.GML() }), strategies: [new OpenLayers.Strategy.Fixed()] 573 * })); 574 */ 575 576 /* GPX layer */ 577 if (mapOpts.gpxfile.length > 0) { 578 var layerGPX = new OpenLayers.Layer.Vector("GPS route", { 579 protocol : new OpenLayers.Protocol.HTTP({ 580 url : DocBase + "lib/exe/fetch.php?media=" + mapOpts.gpxfile, 581 format : new OpenLayers.Format.GPX({ 582 extractWaypoints : !0, 583 extractTracks : !0, 584 extractStyles : !0, 585 extractAttributes : !0, 586 handleHeight : !0, 587 maxDepth : 3 588 }) 589 }), 590 style : { 591 strokeColor : "#0000FF", 592 strokeWidth : 3, 593 strokeOpacity : 0.7, 594 pointRadius : 4, 595 fillColor : "#0099FF", 596 fillOpacity : 0.7 597 // , label:"${name}" 598 }, 599 projection : new OpenLayers.Projection("EPSG:4326"), 600 strategies : [ new OpenLayers.Strategy.Fixed() ] 601 }); 602 m.addLayer(layerGPX); 603 layerGPX.events.register('loadend', m, function() { 604 extent.extend(layerGPX.getDataExtent()); 605 m.zoomToExtent(extent); 606 }); 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 638 .getLayersByClass('OpenLayers.Layer.Vector')).concat(m 639 .getLayersByClass('OpenLayers.Layer.GML')), { 640 hover : mapOpts.poihoverstyle, 641 onSelect : onFeatureSelect, 642 onUnselect : onFeatureUnselect 643 }); 644 m.addControl(selectControl); 645 selectControl.activate(); 646 } 647 return m; 648} 649 650var olTimerId = -1; 651 652/** init. */ 653function olInit() { 654 if (navigator.userAgent.indexOf('MSIE') !== -1) { 655 // console.log("need to sleep"); 656 if (olTimerId === -1) { 657 olTimerId = setTimeout("olInit()", 3000); 658 olEnable = !1; 659 } else { 660 // console.log("done sleeping"); 661 clearTimeout(olTimerId); 662 olEnable = !0; 663 } 664 } 665 666 if (olEnable) { 667 var _i = 0; 668 // create the maps in the page 669 for (_i = 0; _i < olMapData.length; _i++) { 670 // console.log(olMapData); 671 createMap(olMapData[_i].mapOpts, olMapData[_i].poi); 672 } 673 674 // hide the table(s) with POI by giving it a print-only style 675 // var tbls = getElementsByClass('olPOItableSpan', null, null); 676 var tbls = jQuery('.olPOItableSpan'); 677 for (_i = 0; _i < tbls.length; _i++) { 678 tbls[_i].className += ' olPrintOnly'; 679 } 680 // hide the static map image(s) by giving it a print only style 681 // var statImgs = getElementsByClass('olStaticMap', null, null); 682 var statImgs = jQuery('.olStaticMap'); 683 for (_i = 0; _i < statImgs.length; _i++) { 684 statImgs[_i].className += ' olPrintOnly'; 685 } 686 } 687} 688 689/** 690 * ol api flag. 691 * 692 * @type {Boolean} 693 */ 694var olEnable = !1, 695/** 696 * array with data for each map in the page. 697 * 698 * @type {Array} 699 */ 700olMapData = [], 701/** 702 * MapQuest tiles flag. 703 * 704 * @type {Boolean} 705 */ 706mqEnable = !1, 707/** 708 * google map api flag. 709 * 710 * @type {Boolean} 711 */ 712gEnable = !1, 713/** 714 * virtual earth map api flag. 715 * 716 * @type {Boolean} 717 */ 718veEnable = !1, 719/** 720 * Bing tiles flag. 721 * 722 * @type {Boolean} 723 */ 724bEnable = !1, 725/** 726 * Bing API key. 727 * 728 * @type {String} 729 */ 730bApiKey = '', 731/** 732 * OSM tiles flag. 733 * 734 * @type {Boolean} 735 */ 736osmEnable = !0, 737/** 738 * CSS support flag. 739 * 740 * @type {Boolean} 741 */ 742olCSSEnable = !0; 743/** 744 * yahoo map api flag. 745 * 746 * @type {Boolean} 747 */ 748// yEnable = false; 749/* register olInit to run with onload event. */ 750// addInitEvent(olInit); 751jQuery(olInit); 752