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