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