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