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 * @return a reference to the map 162 */ 163function createMap(mapOpts, OLmapPOI) { 164 if (!olEnable) { 165 return; 166 } 167 if (!olTestCSSsupport()) { 168 olEnable = !1; 169 return; 170 } 171 172 var DocBase = DOKU_BASE; 173 174 OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3; 175 // OpenLayers.Layer.Vector.prototype.renderers = ["SVG", "VML"]; 176 177 // find map element location 178 var cleartag = document.getElementById(mapOpts.id + '-clearer'); 179 if (cleartag === null) { 180 return; 181 } 182 // create map element and add to document 183 var fragment = olCreateMaptag(mapOpts.id, mapOpts.width, mapOpts.height); 184 cleartag.parentNode.insertBefore(fragment, cleartag); 185 186 /** dynamic map extent. */ 187 var extent = new OpenLayers.Bounds(), 188 189 /** map. */ 190 m = new OpenLayers.Map({ 191 div : mapOpts.id, 192 projection : 'EPSG:900913', 193 displayProjection : new OpenLayers.Projection("EPSG:4326"), 194 numZoomLevels : 22, 195 controls : [ 196 new OpenLayers.Control.ArgParser(), 197 new OpenLayers.Control.KeyboardDefaults({observeElement: mapOpts.id}), 198 new OpenLayers.Control.Navigation({dragPanOptions: {enableKinetic: !0}}), 199 new OpenLayers.Control.ScaleLine({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 // CloudMade Fine Line 257 m.addLayer(new OpenLayers.Layer.OSM("cloudmade map", 258 [ 259 "http://a.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/2/256/${z}/${x}/${y}.png", 260 "http://b.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/2/256/${z}/${x}/${y}.png", 261 "http://c.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/2/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 m.addLayer(new OpenLayers.Layer.OSM("cloudmade fresh", 273 [ 274 "http://a.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/${z}/${x}/${y}.png", 275 "http://b.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/${z}/${x}/${y}.png", 276 "http://c.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/${z}/${x}/${y}.png" ], 277 { 278 transitionEffect : "resize", 279 attribution : 'Tiles © 2012 <a target="_blank" href="http://cloudmade.com">CloudMade</a>' 280 + '<img src="http://cloudmade.com/favicon.ico" alt="CloudMade logo"/>' 281 + ' Data CC-BY-SA <a href="http://openstreetmap.org/" target="_blank">OpenStreetMap</a>', 282 visibility : mapOpts.baselyr === "cloudmade fresh", 283 tileOptions : { 284 crossOriginKeyword : null 285 } 286 })); 287 288 m.addLayer(new OpenLayers.Layer.OSM("hike and bike map", 289 "http://toolserver.org/tiles/hikebike/${z}/${x}/${y}.png", { 290 transitionEffect : "resize", 291 visibility : mapOpts.baselyr === "hike and bike map", 292 tileOptions : { 293 crossOriginKeyword : null 294 } 295 })); 296 } 297 /* 298 * add MapQuest map layers, see: 299 * http://developer.mapquest.com/web/products/open/map 300 */ 301 if (mqEnable) { 302 m.addLayer(new OpenLayers.Layer.OSM("mapquest road", 303 [ 304 "http://otile1.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.jpg", 305 "http://otile2.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.jpg", 306 "http://otile3.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.jpg", 307 "http://otile4.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.jpg" ], 308 { 309 transitionEffect : "resize", 310 attribution : 'Data CC-By-SA <a href="http://openstreetmap.org/" target="_blank">OpenStreetMap</a>, ' 311 + 'Tiles <a href="http://www.mapquest.com/" target="_blank">MapQuest</a>' 312 + '<img src="http://developer.mapquest.com/content/osm/mq_logo.png" alt="MapQuest logo"/>', 313 visibility : mapOpts.baselyr === "mapquest road", 314 tileOptions : { 315 crossOriginKeyword : null 316 } 317 })); 318 // note that global coverage is provided at zoom levels 0-11. Zoom 319 // Levels 12+ are provided only in the United States (lower 48). 320 m.addLayer(new OpenLayers.Layer.OSM("mapquest sat", 321 [ 322 "http://otile1.mqcdn.com/tiles/1.0.0/sat/${z}/${x}/${y}.jpg", 323 "http://otile2.mqcdn.com/tiles/1.0.0/sat/${z}/${x}/${y}.jpg", 324 "http://otile3.mqcdn.com/tiles/1.0.0/sat/${z}/${x}/${y}.jpg", 325 "http://otile4.mqcdn.com/tiles/1.0.0/sat/${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" alt="MapQuest logo"/>', 330 visibility : mapOpts.baselyr === "mapquest sat", 331 numZoomLevels : 12, 332 tileOptions : { 333 crossOriginKeyword : null 334 } 335 })); 336 } 337 338 if (gEnable) { 339 /* load google maps */ 340 try { 341 m.addLayer(new OpenLayers.Layer.Google("google relief", { 342 type : google.maps.MapTypeId.TERRAIN, 343 // transitionEffect : "resize", 344 numZoomLevels : 16, 345 animationEnabled : !0, 346 visibility : mapOpts.baselyr === "google relief" 347 })); 348 m.addLayer(new OpenLayers.Layer.Google("google sat", { 349 type : google.maps.MapTypeId.SATELLITE, 350 // transitionEffect : "resize", 351 // numZoomLevels : 22, 352 animationEnabled : !0, 353 visibility : mapOpts.baselyr === "google sat" 354 })); 355 m.addLayer(new OpenLayers.Layer.Google("google hybrid", { 356 type : google.maps.MapTypeId.HYBRID, 357 // transitionEffect : "resize", 358 // numZoomLevels : 20, 359 animationEnabled : !0, 360 visibility : mapOpts.baselyr === "google hybrid" 361 })); 362 m.addLayer(new OpenLayers.Layer.Google("google road", { 363 // transitionEffect : "resize", 364 // numZoomLevels : 20, 365 animationEnabled : !0, 366 visibility : mapOpts.baselyr === "google road" 367 })); 368 } catch (ol_err1) { 369 Openlayers.Console.userError('Error loading Google maps' + ol_err1); 370 } 371 } 372 373 if (bEnable && bApiKey !== '') { 374 try { 375 /* add Bing tiles */ 376 m.addLayer(new OpenLayers.Layer.Bing( 377 { 378 key : bApiKey, 379 type : "Road", 380 name : "bing road", 381 transitionEffect : "resize", 382 visibility : mapOpts.baselyr === "bing road", 383 wrapDateLine : !0, 384 attributionTemplate : '<a target="_blank" href="http://www.bing.com/maps/">' 385 + 'Bing™</a><img src="http://www.bing.com/favicon.ico" alt="Bing logo"/> ${copyrights}' 386 + '<a target="_blank" href="http://www.microsoft.com/maps/product/terms.html">Terms of Use</a>' 387 })); 388 m.addLayer(new OpenLayers.Layer.Bing( 389 { 390 key : bApiKey, 391 type : "Aerial", 392 name : "bing sat", 393 transitionEffect : "resize", 394 visibility : mapOpts.baselyr === "bing sat", 395 wrapDateLine : !0, 396 attributionTemplate : '<a target="_blank" href="http://www.bing.com/maps/">' 397 + 'Bing™</a><img src="http://www.bing.com/favicon.ico" alt="Bing logo"/> ${copyrights}' 398 + '<a target="_blank" href="http://www.microsoft.com/maps/product/terms.html">Terms of Use</a>' 399 })); 400 m.addLayer(new OpenLayers.Layer.Bing( 401 { 402 key : bApiKey, 403 type : "AerialWithLabels", 404 name : "bing hybrid", 405 transitionEffect : "resize", 406 visibility : mapOpts.baselyr === "bing hybrid", 407 wrapDateLine : !0, 408 attributionTemplate : '<a target="_blank" href="http://www.bing.com/maps/">' 409 + 'Bing™</a><img src="http://www.bing.com/favicon.ico" alt="Bing logo"/> ${copyrights}' 410 + '<a target="_blank" href="http://www.microsoft.com/maps/product/terms.html">Terms of Use</a>' 411 })); 412 } catch (ol_errBing) { 413 Openlayers.Console.userError('Error loading Bing maps: ' 414 + ol_errBing); 415 } 416 } 417 418 m.setCenter(new OpenLayers.LonLat(mapOpts.lon, mapOpts.lat).transform(m.displayProjection, m.projection), mapOpts.zoom); 419 extent.extend(m.getExtent()); 420 421 // change/set alternative baselyr 422 try { 423 m.setBaseLayer(((m.getLayersByName(mapOpts.baselyr))[0])); 424 } catch (ol_err4) { 425 m.setBaseLayer(m.layers[0]); 426 } 427 428 if (mapOpts.controls === 1) { 429 /* add base controls to map */ 430 m.addControl(new OpenLayers.Control.LayerSwitcher()); 431 m.addControl(new OpenLayers.Control.PanZoomBar()); 432 m.addControl(new OpenLayers.Control.Graticule({ 433 visible : !1 434 })); 435 436 // add hillshade, since this is off by default only add when we have a 437 // layerswitcher 438 m.addLayer(new OpenLayers.Layer.OSM("Hillshade", 439 "http://toolserver.org/~cmarqu/hill/${z}/${x}/${y}.png", { 440 transitionEffect : "resize", 441 isBaseLayer : !1, // false 442 transparent : !0, // true 443 visibility : !1, 444 displayOutsideMaxExtent : !0, 445 attribution : '', 446 tileOptions : { 447 crossOriginKeyword : null 448 } 449 })); 450 m.addControl(new OpenLayers.Control.OverviewMap({ 451 size : new OpenLayers.Size(140, 140), 452 minRectSize : 10 453 })); 454 } 455 456 if (mapOpts.statusbar === 1) { 457 // statusbar control: permalink 458 m.addControl(new OpenLayers.Control.Permalink(mapOpts.id + '-statusbar-link-ref')); 459 // statusbar control: mouse pos. 460 m.addControl(new OpenLayers.Control.MousePosition({ 461 'div' : OpenLayers.Util.getElement(mapOpts.id + '-statusbar-mouseposition') 462 })); 463 // statusbar control: scale 464 m.addControl(new OpenLayers.Control.Scale(mapOpts.id + '-statusbar-scale')); 465 // statusbar control: attribution 466 m.addControl(new OpenLayers.Control.Attribution({ 467 'div' : OpenLayers.Util.getElement(mapOpts.id + '-statusbar-text') 468 })); 469 // statusbar control: projection 470 OpenLayers.Util.getElement(mapOpts.id + '-statusbar-projection').innerHTML = m.displayProjection; 471 } else { 472 OpenLayers.Util.getElement(mapOpts.id + '-olStatusBar').display = 'none'; 473 } 474 475 if (mapOpts.toolbar === 1) { 476 // add buttons + panel 477 var /* zoom in btn */ 478 zoomin = new OpenLayers.Control.ZoomBox({ 479 title : "Zoom in" 480 }), /* zoom out btn */ 481 zoomout = new OpenLayers.Control.ZoomBox({ 482 out : !0, 483 title : "Zoom uit", 484 displayClass : "olControlZoomOut" 485 }), /* pan btn */ 486 pan = new OpenLayers.Control.DragPan({ 487 title : "Verschuif" 488 }), /* do "nothing" button... */ 489 info = new OpenLayers.Control.Button({ 490 type : OpenLayers.Control.TYPE_TOOL, 491 displayClass : "olControlFeatureInfo", 492 title : "Info" 493 }), /* navigation history btns */ 494 nav = new OpenLayers.Control.NavigationHistory(); 495 m.addControl(nav); 496 var panel = new OpenLayers.Control.Panel({ 497 defaultControl : pan, 498 displayClass : "olToolbar", 499 "div" : OpenLayers.Util.getElement(mapOpts.id + "-olToolbar") 500 }); 501 panel.addControls([ zoomin, zoomout, pan, info, nav.next, nav.previous ]); 502 m.addControl(panel); 503 } else { 504 OpenLayers.Util.getElement(mapOpts.id + '-olToolbar').display = 'none'; 505 } 506 507 if (OLmapPOI.length > 0) { 508 var markers = new OpenLayers.Layer.Vector( 509 "POI", 510 { 511 styleMap : new OpenLayers.StyleMap( 512 { 513 "default" : { 514 externalGraphic : "${img}", 515 graphicHeight : 16, 516 graphicWidth : 16, 517 graphicXOffset : 0, 518 graphicYOffset : -8, 519 graphicOpacity : "${opacity}", 520 rotation : "${angle}", 521 backgroundGraphic : DocBase 522 + "lib/plugins/openlayersmap/icons/marker_shadow.png", 523 backgroundXOffset : 0, 524 backgroundYOffset : -4, 525 backgroundRotation : "${angle}", 526 pointRadius : 10, 527 labelXOffset : 8, 528 labelYOffset : 8, 529 labelAlign : "lb", 530 label : "${label}", 531 // fontColor : "", 532 fontFamily : "monospace", 533 fontSize : "12px", 534 fontWeight : "bold" 535 }, 536 "select" : { 537 cursor : "crosshair", 538 externalGraphic : DocBase 539 + "lib/plugins/openlayersmap/icons/marker-red.png", 540 graphicHeight : 16, 541 graphicWidth : 16, 542 graphicXOffset : 0, 543 graphicYOffset : -8, 544 graphicOpacity : 1.0, 545 rotation : "${angle}" 546 } 547 }), 548 isBaseLayer : !1, 549 rendererOptions : { 550 yOrdering : !0 551 } 552 }); 553 m.addLayer(markers); 554 var features = []; 555 var lonLat; 556 for ( var j = 0; j < OLmapPOI.length; j++) { 557 var feat = new OpenLayers.Feature.Vector( 558 new OpenLayers.Geometry.Point(OLmapPOI[j].lon, 559 OLmapPOI[j].lat).transform(m.displayProjection, 560 m.projection), { 561 angle : OLmapPOI[j].angle, 562 opacity : OLmapPOI[j].opacity, 563 img : DocBase + "lib/plugins/openlayersmap/icons/" 564 + OLmapPOI[j].img, 565 label : OLmapPOI[j].rowId 566 }); 567 feat.data = { 568 name : OLmapPOI[j].txt, 569 rowId : OLmapPOI[j].rowId 570 }; 571 features.push(feat); 572 } 573 markers.addFeatures(features); 574 extent.extend(markers.getDataExtent()); 575 m.zoomToExtent(extent); 576 } 577 578 /* 579 * map.addLayer(new OpenLayers.Layer.Vector("GML", { protocol: new 580 * OpenLayers.Protocol.HTTP({ url: "gml/polygon.xml", format: new 581 * OpenLayers.Format.GML() }), strategies: [new OpenLayers.Strategy.Fixed()] 582 * })); 583 */ 584 585 /* GPX layer */ 586 if (mapOpts.gpxfile.length > 0) { 587 var layerGPX = new OpenLayers.Layer.Vector("GPS route", { 588 protocol : new OpenLayers.Protocol.HTTP({ 589 url : DocBase + "lib/exe/fetch.php?media=" + mapOpts.gpxfile, 590 format : new OpenLayers.Format.GPX({ 591 extractWaypoints : !0, 592 extractTracks : !0, 593 extractStyles : !0, 594 extractAttributes : !0, 595 handleHeight : !0, 596 maxDepth : 3 597 }) 598 }), 599 style : { 600 strokeColor : "#0000FF", 601 strokeWidth : 3, 602 strokeOpacity : 0.7, 603 pointRadius : 4, 604 fillColor : "#0099FF", 605 fillOpacity : 0.7 606 // , label:"${name}" 607 }, 608 projection : new OpenLayers.Projection("EPSG:4326"), 609 strategies : [ new OpenLayers.Strategy.Fixed() ] 610 }); 611 m.addLayer(layerGPX); 612 layerGPX.events.register('loadend', m, function() { 613 extent.extend(layerGPX.getDataExtent()); 614 m.zoomToExtent(extent); 615 }); 616 617 } 618 619 /* KML layer */ 620 if (mapOpts.kmlfile.length > 0) { 621 var layerKML = new OpenLayers.Layer.Vector("KML file", { 622 protocol : new OpenLayers.Protocol.HTTP({ 623 url : DocBase + "lib/exe/fetch.php?media=" + mapOpts.kmlfile, 624 format : new OpenLayers.Format.KML({ 625 extractStyles : !0, 626 extractAttributes : !0, 627 maxDepth : 3 628 }) 629 }), 630 style : { 631 label : "${name}" 632 }, 633 projection : new OpenLayers.Projection("EPSG:4326"), 634 strategies : [ new OpenLayers.Strategy.Fixed() ] 635 }); 636 m.addLayer(layerKML); 637 layerKML.events.register('loadend', m, function() { 638 extent.extend(layerKML.getDataExtent()); 639 m.zoomToExtent(extent); 640 }); 641 } 642 643 // selectcontrol for layers 644 if ((m.getLayersByClass('OpenLayers.Layer.GML').length > 0) 645 || m.getLayersByClass('OpenLayers.Layer.Vector').length > 0) { 646 selectControl = new OpenLayers.Control.SelectFeature((m 647 .getLayersByClass('OpenLayers.Layer.Vector')).concat(m 648 .getLayersByClass('OpenLayers.Layer.GML')), { 649 hover : mapOpts.poihoverstyle, 650 onSelect : onFeatureSelect, 651 onUnselect : onFeatureUnselect 652 }); 653 m.addControl(selectControl); 654 selectControl.activate(); 655 } 656 return m; 657} 658 659var olTimerId = -1; 660 661/** init. */ 662function olInit() { 663 // TODO: check is this is still needed now that we have jQuery 664 if (navigator.userAgent.indexOf('MSIE') !== -1) { 665 if (olTimerId === -1) { 666 olTimerId = setTimeout("olInit()", 3000); 667 olEnable = !1; 668 } else { 669 clearTimeout(olTimerId); 670 olEnable = !0; 671 } 672 } 673 674 if (olEnable) { 675 var _i = 0; 676 // create the maps in the page 677 for (_i = 0; _i < olMapData.length; _i++) { 678 olMaps[olMapData[_i].mapOpts.id] = createMap(olMapData[_i].mapOpts, olMapData[_i].poi); 679 } 680 681 // hide the table(s) with POI by giving it a print-only style 682 // var tbls = getElementsByClass('olPOItableSpan', null, null); 683 var tbls = jQuery('.olPOItableSpan'); 684 for (_i = 0; _i < tbls.length; _i++) { 685 tbls[_i].className += ' olPrintOnly'; 686 } 687 // hide the static map image(s) by giving it a print only style 688 // var statImgs = getElementsByClass('olStaticMap', null, null); 689 var statImgs = jQuery('.olStaticMap'); 690 for (_i = 0; _i < statImgs.length; _i++) { 691 statImgs[_i].className += ' olPrintOnly'; 692 } 693 } 694} 695 696/** 697 * ol api flag. 698 * 699 * @type {Boolean} 700 */ 701var olEnable = !1, 702/** 703 * An array with data for each map in the page. 704 * 705 * @type {Array} 706 */ 707olMapData = [], 708/** 709 * Holds a reference to all of the maps on this page with the map's id as key. 710 * Can be used as an extension point. 711 * 712 * @type {Object} 713 */ 714olMaps = new Object(), 715/** 716 * MapQuest tiles flag. 717 * 718 * @type {Boolean} 719 */ 720mqEnable = !1, 721/** 722 * google map api flag. 723 * 724 * @type {Boolean} 725 */ 726gEnable = !1, 727/** 728 * Bing tiles flag. 729 * 730 * @type {Boolean} 731 */ 732bEnable = !1, 733/** 734 * Bing API key. 735 * 736 * @type {String} 737 */ 738bApiKey = '', 739/** 740 * OSM tiles flag. 741 * 742 * @type {Boolean} 743 */ 744osmEnable = !0, 745/** 746 * CSS support flag. 747 * 748 * @type {Boolean} 749 */ 750olCSSEnable = !0; 751/** 752 * yahoo map api flag. 753 * 754 * @type {Boolean} 755 */ 756// yEnable = false; 757/* register olInit to run with onload event. */ 758jQuery(olInit); 759