1/* 2 * Copyright (c) 2008-2022 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/** 19 * Test for css support in the browser by sniffing for a css class we added 20 * using javascript added by the action plugin; this is an edge case because 21 * browsers that support javascript generally support css as well. 22 * 23 * @returns {Boolean} true when the browser supports css (and implicitly 24 * javascript) 25 */ 26function olTestCSSsupport() { 27 return (jQuery('.olCSSsupported').length > 0); 28} 29 30/** 31 * Creates a DocumentFragment to insert into the dom. 32 * 33 * @param mapid 34 * id for the map div 35 * @param width 36 * width for the map div 37 * @param height 38 * height for the map div 39 * @returns a {DocumentFragment} element that can be injected into the dom 40 */ 41function olCreateMaptag(mapid, width, height) { 42 const // fragment 43 frag = document.createDocumentFragment(), 44 // temp node 45 temp = document.createElement('div'); 46 temp.innerHTML = '<div id="' + mapid + '-olContainer" class="olContainer olWebOnly">' 47 // map 48 + '<div id="' + mapid + '" tabindex="0" style="width:' + width + ';height:' + height + ';" class="olMap"></div>' 49 + '</div>'; 50 while (temp.firstChild) { 51 frag.appendChild(temp.firstChild); 52 } 53 return frag; 54} 55 56/** 57 * Create the map based on the params given. 58 * 59 * @param mapOpts {Object} 60 * mapOpts MapOptions hash {id:'olmap', width:500px, height:500px, 61 * lat:6710200, lon:506500, zoom:13, controls:1, 62 * baselyr:'', kmlfile:'', gpxfile:'', geojsonfile, 63 * summary:''} 64 * @param poi {Array} 65 * OLmapPOI array with POI's [ {lat:6710300,lon:506000,txt:'instap 66 * punt',angle:180,opacity:.9,img:'', rowId:n},... ]); 67 * 68 * @return {ol.Map} the created map 69 */ 70function createMap(mapOpts, poi) { 71 72 // const mapOpts = olMapData[0].mapOpts; 73 // const poi = olMapData[0].poi; 74 75 if (!olEnable) { 76 return null; 77 } 78 if (!olTestCSSsupport()) { 79 olEnable = false; 80 return null; 81 } 82 83 // find map element location 84 const cleartag = document.getElementById(mapOpts.id + '-clearer'); 85 if (cleartag === null) { 86 return null; 87 } 88 // create map element and add to document 89 const fragment = olCreateMaptag(mapOpts.id, mapOpts.width, mapOpts.height); 90 cleartag.parentNode.insertBefore(fragment, cleartag); 91 92 /** dynamic map extent. */ 93 let extent = ol.extent.createEmpty(); 94 let overlayGroup = new ol.layer.Group({title: 'Overlays', fold: 'open', layers: []}); 95 const baseLyrGroup = new ol.layer.Group({'title': 'Base maps', layers: []}); 96 97 const map = new ol.Map({ 98 target: document.getElementById(mapOpts.id), 99 layers: [baseLyrGroup, overlayGroup], 100 view: new ol.View({ 101 center: ol.proj.transform([mapOpts.lon, mapOpts.lat], 'EPSG:4326', 'EPSG:3857'), 102 zoom: mapOpts.zoom, 103 projection: 'EPSG:3857' 104 }), 105 controls: [ 106 new ol.control.Attribution({ 107 collapsible: true, 108 collapsed: true 109 }) 110 ] 111 }); 112 113 if (osmEnable) { 114 baseLyrGroup.getLayers().push( 115 new ol.layer.Tile({ 116 visible: true, 117 title: 'OSM', 118 type: 'base', 119 source: new ol.source.OSM() 120 })); 121 122 baseLyrGroup.getLayers().push( 123 new ol.layer.Tile({ 124 visible: mapOpts.baselyr === "opentopomap", 125 title: 'opentopomap', 126 type: 'base', 127 source: new ol.source.OSM({ 128 url: 'https://{a-c}.tile.opentopomap.org/{z}/{x}/{y}.png', 129 attributions: 'Data ©ODbL <a href="https://openstreetmap.org/copyright" target="_blank">OpenStreetMap</a>, ' 130 + '<a href="http://viewfinderpanoramas.org" target="_blank">SRTM</a>, ' 131 + 'style ©<a href="https://opentopomap.org/" target="_blank">OpenTopoMap</a>' 132 + '(<a href="https://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA</a>)' 133 }) 134 })); 135 136 baseLyrGroup.getLayers().push( 137 new ol.layer.Tile({ 138 visible: mapOpts.baselyr === "cycle map", 139 title: 'cycle map', 140 type: 'base', 141 source: new ol.source.OSM({ 142 url: 'https://{a-c}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png?apikey=' + tfApiKey, 143 attributions: 'Data ©ODbL <a href="https://openstreetmap.org/copyright" target="_blank">OpenStreetMap</a>, ' 144 + 'Tiles ©<a href="https://www.thunderforest.com/" target="_blank">Thunderforest</a>' 145 + '<img src="https://www.thunderforest.com/favicon.ico" alt="Thunderforest logo"/>' 146 }) 147 })); 148 149 baseLyrGroup.getLayers().push( 150 new ol.layer.Tile({ 151 visible: mapOpts.baselyr === "transport", 152 title: 'transport', 153 type: 'base', 154 source: new ol.source.OSM({ 155 url: 'https://{a-c}.tile.thunderforest.com/transport/{z}/{x}/{y}.png?apikey=' + tfApiKey, 156 attributions: 'Data ©ODbL <a href="https://openstreetmap.org/copyright" target="_blank">OpenStreetMap</a>, ' 157 + 'Tiles ©<a href="https://www.thunderforest.com/" target="_blank">Thunderforest</a>' 158 + '<img src="https://www.thunderforest.com/favicon.ico" alt="Thunderforest logo"/>' 159 }) 160 })); 161 162 baseLyrGroup.getLayers().push( 163 new ol.layer.Tile({ 164 visible: mapOpts.baselyr === "landscape", 165 title: 'landscape', 166 type: 'base', 167 source: new ol.source.OSM({ 168 url: 'https://{a-c}.tile.thunderforest.com/landscape/{z}/{x}/{y}.png?apikey=' + tfApiKey, 169 attributions: 'Data ©ODbL <a href="https://openstreetmap.org/copyright" target="_blank">OpenStreetMap</a>, ' 170 + 'Tiles ©<a href="https://www.thunderforest.com/" target="_blank">Thunderforest</a>' 171 + '<img src="https://www.thunderforest.com/favicon.ico" alt="Thunderforest logo"/>' 172 }) 173 })); 174 175 baseLyrGroup.getLayers().push( 176 new ol.layer.Tile({ 177 visible: mapOpts.baselyr === "outdoors", 178 title: 'outdoors', 179 type: 'base', 180 source: new ol.source.OSM({ 181 url: 'https://{a-c}.tile.thunderforest.com/outdoors/{z}/{x}/{y}.png?apikey=' + tfApiKey, 182 attributions: 'Data ©ODbL <a href="https://openstreetmap.org/copyright" target="_blank">OpenStreetMap</a>, ' 183 + 'Tiles ©<a href="https://www.thunderforest.com/" target="_blank">Thunderforest</a>' 184 + '<img src="https://www.thunderforest.com/favicon.ico" alt="Thunderforest logo"/>' 185 }) 186 })); 187 } 188 189 if (bEnable && bApiKey !== '') { 190 baseLyrGroup.getLayers().push( 191 new ol.layer.Tile({ 192 visible: mapOpts.baselyr === "bing road", 193 title: 'bing road', 194 type: 'base', 195 source: new ol.source.BingMaps({ 196 key: bApiKey, 197 imagerySet: 'Road' 198 }) 199 })); 200 201 baseLyrGroup.getLayers().push( 202 new ol.layer.Tile({ 203 visible: mapOpts.baselyr === "bing sat", 204 title: 'bing sat', 205 type: 'base', 206 source: new ol.source.BingMaps({ 207 key: bApiKey, 208 imagerySet: 'Aerial' 209 }) 210 })); 211 212 baseLyrGroup.getLayers().push( 213 new ol.layer.Tile({ 214 visible: mapOpts.baselyr === "bing hybrid", 215 title: 'bing hybrid', 216 type: 'base', 217 source: new ol.source.BingMaps({ 218 key: bApiKey, 219 imagerySet: 'AerialWithLabels' 220 }) 221 })); 222 } 223 224 if (stamenEnable) { 225 baseLyrGroup.getLayers().push( 226 new ol.layer.Tile({ 227 visible: mapOpts.baselyr === "toner", 228 type: 'base', 229 title: 'toner', 230 source: new ol.source.Stamen({layer: 'toner'}) 231 }) 232 ); 233 234 baseLyrGroup.getLayers().push( 235 new ol.layer.Tile({ 236 visible: mapOpts.baselyr === "terrain", 237 type: 'base', 238 title: 'terrain', 239 source: new ol.source.Stamen({layer: 'terrain'}) 240 }) 241 ); 242 } 243 244 extent = ol.extent.extend(extent, map.getView().calculateExtent()); 245 246 const iconScale = 1.0; 247 const vectorSource = new ol.source.Vector(); 248 poi.forEach((p) => { 249 const f = new ol.Feature({ 250 geometry: new ol.geom.Point(ol.proj.fromLonLat([p.lon, p.lat])), 251 description: p.txt, 252 img: p.img, 253 rowId: p.rowId, 254 lat: p.lat, 255 lon: p.lon, 256 angle: p.angle, 257 opacity: p.opacity, 258 alt: p.img.substring(0, p.img.lastIndexOf(".")) 259 }); 260 f.setId(p.rowId); 261 vectorSource.addFeature(f); 262 }); 263 264 const vectorLayer = new ol.layer.Vector({ 265 title: 'POI', 266 visible: true, 267 source: vectorSource, 268 style(feature, resolution) { 269 const img = feature.get('img'); 270 const opacity = feature.get('opacity'); 271 const angle = feature.get('angle'); 272 const text = feature.get('rowId'); 273 274 return new ol.style.Style({ 275 image: new ol.style.Icon({ 276 src: `${DOKU_BASE}lib/plugins/openlayersmap/icons/${img}`, 277 crossOrigin: '', 278 opacity: opacity, 279 scale: iconScale, 280 rotation: angle * Math.PI / 180, 281 }), 282 text: new ol.style.Text({ 283 text: `${text}`, 284 textAlign: 'center', 285 textBaseline: 'middle', 286 offsetX: (8 + 4) * iconScale, 287 offsetY: -8 * iconScale, 288 scale: iconScale, 289 fill: new ol.style.Fill({color: 'rgb(0,0,0)'}), 290 font: 'bold 1em monospace', 291 backgroundFill: new ol.style.Fill({color: 'rgba(255,255,255,.4)'}) 292 }) 293 }); 294 } 295 }); 296 overlayGroup.getLayers().push(vectorLayer); 297 if (mapOpts.autozoom) { 298 extent = ol.extent.extend(extent, vectorSource.getExtent()); 299 map.getView().fit(extent); 300 } 301 302 if (mapOpts.controls === 1) { 303 map.addControl(new ol.control.Zoom()); 304 map.addControl(new ol.control.ScaleLine({bar: true, text: true})); 305 map.addControl(new ol.control.MousePosition({ 306 coordinateFormat: ol.coordinate.createStringXY(4), projection: 'EPSG:4326', 307 })); 308 map.addControl(new ol.control.FullScreen({ 309 label: '✈' 310 })); 311 map.addControl(new ol.control.OverviewMap({ 312 label: '+', 313 layers: [new ol.layer.Tile({ 314 source: new ol.source.OSM() 315 })] 316 })); 317 map.addControl(new ol.control.LayerSwitcher({ 318 activationMode: 'click', 319 label: '\u2630', 320 collapseLabel: '\u00BB', 321 })); 322 } 323 324 if (mapOpts.kmlfile.length > 0) { 325 try { 326 const kmlSource = new ol.source.Vector({ 327 url: DOKU_BASE + "lib/exe/fetch.php?media=" + mapOpts.kmlfile, 328 format: new ol.format.KML(), 329 }); 330 overlayGroup.getLayers().push(new ol.layer.Vector({title: 'KML file', visible: true, source: kmlSource})); 331 332 if (mapOpts.autozoom) { 333 kmlSource.once('change', function () { 334 extent = ol.extent.extend(extent, kmlSource.getExtent()); 335 map.getView().fit(extent); 336 }); 337 } 338 } catch (e) { 339 console.error(e); 340 } 341 } 342 343 if (mapOpts.geojsonfile.length > 0) { 344 try { 345 // these are the same colour as in StaticMap#drawJSON() 346 const geoJsonStyle = { 347 'Point': new ol.style.Style({ 348 image: new ol.style.Circle({ 349 fill: new ol.style.Fill({ 350 color: 'rgba(255,0,255,0.4)', 351 }), 352 radius: 5, 353 stroke: new ol.style.Stroke({ 354 color: 'rgba(255,0,255,0.9)', 355 width: 1, 356 }), 357 }), 358 }), 359 'LineString': new ol.style.Style({ 360 stroke: new ol.style.Stroke({ 361 color: 'rgba(255,0,255,0.9)', 362 width: 3, 363 }), 364 }), 365 'MultiLineString': new ol.style.Style({ 366 stroke: new ol.style.Stroke({ 367 color: 'rgba(255,0,255,0.9)', 368 width: 3, 369 }), 370 }), 371 'Polygon': new ol.style.Style({ 372 stroke: new ol.style.Stroke({ 373 color: 'rgba(255,0,255,0.9)', 374 width: 3, 375 }), 376 fill: new ol.style.Fill({ 377 color: 'rgba(255,0,255,0.4)', 378 }), 379 }), 380 'MultiPolygon': new ol.style.Style({ 381 stroke: new ol.style.Stroke({ 382 color: 'rgba(255,0,255,0.9)', 383 width: 3, 384 }), 385 fill: new ol.style.Fill({ 386 color: 'rgba(255,0,255,0.4)', 387 }), 388 }), 389 }; 390 const geoJsonSource = new ol.source.Vector({ 391 url: DOKU_BASE + "lib/exe/fetch.php?media=" + mapOpts.geojsonfile, 392 format: new ol.format.GeoJSON(), 393 }); 394 overlayGroup.getLayers().push(new ol.layer.Vector({ 395 title: 'GeoJSON file', visible: true, source: geoJsonSource, 396 style: function (feature) { 397 return geoJsonStyle[feature.getGeometry().getType()]; 398 }, 399 })); 400 401 if (mapOpts.autozoom) { 402 geoJsonSource.once('change', function () { 403 extent = ol.extent.extend(extent, geoJsonSource.getExtent()); 404 map.getView().fit(extent); 405 }); 406 } 407 } catch (e) { 408 console.error(e); 409 } 410 } 411 412 if (mapOpts.gpxfile.length > 0) { 413 try { 414 // these are the same colour as in StaticMap#drawGPX() 415 const gpxJsonStyle = { 416 'Point': new ol.style.Style({ 417 image: new ol.style.Circle({ 418 fill: new ol.style.Fill({ 419 color: 'rgba(0,0,255,0.4)', 420 }), 421 radius: 5, 422 stroke: new ol.style.Stroke({ 423 color: 'rgba(0,0,255,0.9)', 424 width: 1, 425 }), 426 }), 427 }), 428 'LineString': new ol.style.Style({ 429 stroke: new ol.style.Stroke({ 430 color: 'rgba(0,0,255,0.9)', 431 width: 3, 432 }), 433 }), 434 'MultiLineString': new ol.style.Style({ 435 stroke: new ol.style.Stroke({ 436 color: 'rgba(0,0,255,0.9)', 437 width: 3, 438 }), 439 }), 440 }; 441 const gpxSource = new ol.source.Vector({ 442 url: DOKU_BASE + "lib/exe/fetch.php?media=" + mapOpts.gpxfile, 443 format: new ol.format.GPX(), 444 }); 445 overlayGroup.getLayers().push(new ol.layer.Vector({ 446 title: 'GPS track', visible: true, source: gpxSource, 447 style: function (feature) { 448 return gpxJsonStyle[feature.getGeometry().getType()]; 449 }, 450 })); 451 452 if (mapOpts.autozoom) { 453 gpxSource.once('change', function () { 454 extent = ol.extent.extend(extent, gpxSource.getExtent()); 455 map.getView().fit(extent); 456 }); 457 } 458 } catch (e) { 459 console.error(e); 460 } 461 } 462 463 const container = document.getElementById('popup'); 464 const content = document.getElementById('popup-content'); 465 const closer = document.getElementById('popup-closer'); 466 467 const overlay = new ol.Overlay({ 468 element: container, 469 positioning: 'center-center', 470 stopEvent: true, 471 autoPan: { 472 animation: { 473 duration: 250, 474 } 475 }, 476 }); 477 map.addOverlay(overlay); 478 479 /** 480 * Add a click handler to hide the popup. 481 * @return {boolean} Don't follow the href. 482 */ 483 closer.onclick = function () { 484 overlay.setPosition(undefined); 485 closer.blur(); 486 return false; 487 }; 488 489 // display popup on click 490 map.on('singleclick', function (evt) { 491 const selFeature = map.forEachFeatureAtPixel(evt.pixel, function (feature) { 492 return feature; 493 }); 494 if (selFeature) { 495 overlay.setPosition(evt.coordinate); 496 497 let pContent = '<div class="spacer"> </div>'; 498 // let locDesc = ''; 499 500 if (selFeature.get('rowId') !== undefined) { 501 pContent += '<span class="rowId">' + selFeature.get('rowId') + ': </span>'; 502 } 503 if (selFeature.get('name') !== undefined) { 504 pContent += '<span class="txt">' + selFeature.get('name') + '</span>'; 505 // locDesc = selFeature.get('name'); 506 // TODO strip <p> tag from locDesc 507 // locDesc = selFeature.get('name').split(/\s+/).slice(0,2).join('+'); 508 } 509 if (selFeature.get('ele') !== undefined) { 510 pContent += '<div class="ele">elevation: ' + selFeature.get('ele') + '</div>'; 511 } 512 if (selFeature.get('type') !== undefined) { 513 pContent += '<div>' + selFeature.get('type') + '</div>'; 514 } 515 if (selFeature.get('time') !== undefined) { 516 pContent += '<div class="time">time: ' + selFeature.get('time') + '</div>'; 517 } 518 if (selFeature.get('description') !== undefined) { 519 pContent += '<div class="desc">' + selFeature.get('description') + '</div>'; 520 } 521 if (selFeature.get('img') !== undefined) { 522 const _alt = selFeature.get('alt'); 523 pContent += '<div class="coord" title="lat;lon">' + 524 '<img alt="' + _alt + '" src="' + DOKU_BASE + 'lib/plugins/openlayersmap/icons/' + selFeature.get('img') + 525 '" width="16" height="16" ' + 'style="transform:rotate(' + selFeature.get('angle') + 'deg)" /> ' + 526 '<a href="geo:' + selFeature.get('lat') + ',' + selFeature.get('lon') + '?q=' + selFeature.get('lat') + 527 ',' + selFeature.get('lon') + '(' + selFeature.get('alt') + ')" title="Open in navigation app">' + 528 ol.coordinate.format([selFeature.get('lon'), selFeature.get('lat')], '{x}º; {y}º', 4) + '</a></div>'; 529 } 530 content.innerHTML = pContent; 531 } else { 532 // do nothing... 533 } 534 }); 535 536 // change mouse cursor when over marker 537 map.on('pointermove', function (e) { 538 const pixel = map.getEventPixel(e.originalEvent); 539 const hit = map.hasFeatureAtPixel(pixel); 540 map.getTarget().style.cursor = hit ? 'pointer' : ''; 541 }); 542 543 return map; 544} 545 546/** 547 * add layers to the map based on the olMapOverlays object. 548 */ 549function olovAddToMap() { 550 for (const key in olMapOverlays) { 551 const overlay = olMapOverlays[key]; 552 const m = olMaps[overlay.id]; 553 554 switch (overlay.type) { 555 case 'osm': 556 m.addLayer(new ol.layer.Tile({ 557 title: overlay.name, 558 visible: (overlay.visible).toLowerCase() === 'true', 559 opacity: parseFloat(overlay.opacity), 560 source: new ol.source.OSM({ 561 url: overlay.url, 562 crossOrigin: 'Anonymous', 563 attributions: overlay.attribution 564 }) 565 })); 566 break; 567 case 'wms': 568 m.addLayer(new ol.layer.Image({ 569 title: overlay.name, 570 opacity: parseFloat(overlay.opacity), 571 visible: (overlay.visible).toLowerCase() === 'true', 572 source: new ol.source.ImageWMS({ 573 url: overlay.url, 574 params: { 575 'LAYERS': overlay.layers, 576 'VERSION': overlay.version, 577 'TRANSPARENT': overlay.transparent, 578 'FORMAT': overlay.format 579 }, 580 ratio: 1, 581 crossOrigin: 'Anonymous', 582 attributions: overlay.attribution 583 }) 584 })); 585 break; 586 case 'ags': 587 m.addLayer(new ol.layer.Image({ 588 title: overlay.name, 589 opacity: parseFloat(overlay.opacity), 590 visible: (overlay.visible).toLowerCase() === 'true', 591 source: new ol.source.ImageArcGISRest({ 592 url: overlay.url, 593 params: { 594 'LAYERS': overlay.layers, 595 'TRANSPARENT': overlay.transparent, 596 'FORMAT': overlay.format 597 }, 598 ratio: 1, 599 crossOrigin: 'Anonymous', 600 attributions: overlay.attribution 601 }) 602 })); 603 break; 604 // case 'mapillary': 605 // var mUrl = 'http://api.mapillary.com/v1/im/search?'; 606 // if (overlay.skey !== '') { 607 // mUrl = 'http://api.mapillary.com/v1/im/sequence?'; 608 // } 609 // var mLyr = new OpenLayers.Layer.Vector( 610 // "Mapillary", { 611 // projection: new OpenLayers.Projection("EPSG:4326"), 612 // strategies: [new OpenLayers.Strategy.BBOX({ 613 // ratio: 1.1, 614 // resFactor: 1.5 615 // }) /* ,new OpenLayers.Strategy.Cluster({}) */], 616 // protocol: new OpenLayers.Protocol.HTTP({ 617 // url: mUrl, 618 // format: new OpenLayers.Format.GeoJSON(), 619 // params: { 620 // // default to max. 250 locations 621 // 'max-results': 250, 622 // 'geojson': true, 623 // 'skey': overlay.skey 624 // }, 625 // filterToParams: function (filter, params) { 626 // if (filter.type === OpenLayers.Filter.Spatial.BBOX) { 627 // // override the bbox serialization of 628 // // the filter to give the Mapillary 629 // // specific bounds 630 // params['min-lat'] = filter.value.bottom; 631 // params['max-lat'] = filter.value.top; 632 // params['min-lon'] = filter.value.left; 633 // params['max-lon'] = filter.value.right; 634 // // if the width of our bbox width is 635 // // less than 0.15 degrees drop the max 636 // // results 637 // if (filter.value.top - filter.value.bottom < .15) { 638 // OpenLayers.Console.debug('dropping max-results parameter, width is: ', 639 // filter.value.top - filter.value.bottom); 640 // params['max-results'] = null; 641 // } 642 // } 643 // return params; 644 // } 645 // }), 646 // styleMap: new OpenLayers.StyleMap({ 647 // 'default': { 648 // cursor: 'help', 649 // rotation: '${ca}', 650 // externalGraphic: DOKU_BASE + 'lib/plugins/openlayersmapoverlays/icons/arrow-up-20.png', 651 // graphicHeight: 20, 652 // graphicWidth: 20, 653 // }, 654 // 'select': { 655 // externalGraphic: DOKU_BASE + 'lib/plugins/openlayersmapoverlays/icons/arrow-up-20-select.png', 656 // label: '${location}', 657 // fontSize: '1em', 658 // fontFamily: 'monospace', 659 // labelXOffset: '0.5', 660 // labelYOffset: '0.5', 661 // labelAlign: 'lb', 662 // } 663 // }), 664 // attribution: '<a href="http://www.mapillary.com/legal.html">' + 665 // '<img src="http://mapillary.com/favicon.ico" ' + 666 // 'alt="Mapillary" height="16" width="16" />Mapillary (CC-BY-SA)', 667 // visibility: (overlay.visible).toLowerCase() == 'true', 668 // }); 669 // m.addLayer(mLyr); 670 // selectControl.addLayer(mLyr); 671 // break; 672 // case 'search': 673 // m.addLayer(new OpenLayers.Layer.Vector( 674 // overlay.name, 675 // overlay.url, 676 // { 677 // layers: overlay.layers, 678 // version: overlay.version, 679 // transparent: overlay.transparent, 680 // format: overlay.format 681 // }, { 682 // opacity: parseFloat(overlay.opacity), 683 // visibility: (overlay.visible).toLowerCase() == 'true', 684 // isBaseLayer: !1, 685 // attribution: overlay.attribution 686 // } 687 // )); 688 // break; 689 } 690 } 691} 692 693/** init. */ 694function olInit() { 695 if (olEnable) { 696 // add info window to DOM 697 const frag = document.createDocumentFragment(), 698 temp = document.createElement('div'); 699 temp.innerHTML = '<div id="popup" class="olPopup"><a href="#" id="popup-closer" class="olPopupCloseBox"></a><div id="popup-content"></div></div>'; 700 while (temp.firstChild) { 701 frag.appendChild(temp.firstChild); 702 } 703 document.body.appendChild(frag); 704 705 let _i = 0; 706 // create the maps in the page 707 for (_i = 0; _i < olMapData.length; _i++) { 708 const _id = olMapData[_i].mapOpts.id; 709 olMaps[_id] = createMap(olMapData[_i].mapOpts, olMapData[_i].poi); 710 711 // set max-width on help pop-over 712 jQuery('#' + _id).parent().parent().find('.olMapHelp').css('max-width', olMapData[_i].mapOpts.width); 713 714 // shrink the map width to fit inside page container 715 const _w = jQuery('#' + _id + '-olContainer').parent().innerWidth(); 716 if (parseInt(olMapData[_i].mapOpts.width) > _w) { 717 jQuery('#' + _id).width(_w); 718 jQuery('#' + _id).parent().parent().find('.olMapHelp').width(_w); 719 olMaps[_id].updateSize(); 720 } 721 } 722 723 // add overlays 724 olovAddToMap(); 725 726 let resizeTimer; 727 jQuery(window).on('resize', function (e) { 728 clearTimeout(resizeTimer); 729 resizeTimer = setTimeout(function () { 730 for (_i = 0; _i < olMapData.length; _i++) { 731 const _id = olMapData[_i].mapOpts.id; 732 const _w = jQuery('#' + _id + '-olContainer').parent().innerWidth(); 733 if (parseInt(olMapData[_i].mapOpts.width) > _w) { 734 jQuery('#' + _id).width(_w); 735 jQuery('#' + _id).parent().parent().find('.olMapHelp').width(_w); 736 olMaps[_id].updateSize(); 737 } 738 } 739 }, 250); 740 }); 741 742 // hide the table(s) with POI by giving it a print-only style 743 jQuery('.olPOItableSpan').addClass('olPrintOnly'); 744 // hide the static map image(s) by giving it a print only style 745 jQuery('.olStaticMap').addClass('olPrintOnly'); 746 // add help button with toggle. 747 jQuery('.olWebOnly > .olMap') 748 .prepend( 749 '<div class="olMapHelpButtonDiv">' 750 + '<button onclick="jQuery(\'.olMapHelp\').toggle(500);" class="olMapHelpButton olHasTooltip"><span>' 751 + 'Show or hide help</span>?</button></div>'); 752 // toggle to switch dynamic vs. static map 753 jQuery('.olMapHelp').before( 754 '<div class="a11y"><button onclick="jQuery(\'.olPrintOnly\').toggle();jQuery(\'.olWebOnly\').toggle();">' 755 + 'Hide or show the dynamic map</button></div>'); 756 } 757} 758 759/** 760 * CSS support flag. 761 * 762 * @type {Boolean} 763 */ 764let olCSSEnable = true; 765 766/* register olInit to run with onload event. */ 767jQuery(olInit); 768