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