1window.addEventListener('load', function(e) { 2 3 // FUNCTIONS 4 5 function iOS() { 6 return [ 7 'iPad Simulator', 8 'iPhone Simulator', 9 'iPod Simulator', 10 'iPad', 11 'iPhone', 12 'iPod' 13 ].includes(navigator.platform) 14 // iPad on iOS 13 detection 15 || 16 (navigator.userAgent.includes("Mac") && "ontouchend" in document) 17 } 18 19 function getParameterByName(name) { 20 name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); 21 const regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), 22 results = regex.exec(location.search); 23 return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); 24 } 25 26 function latLngToBounds(lat, lng, zoom, width, height){ 27 const EARTH_CIR_METERS = 40075016.686; 28 const degreesPerMeter = 360 / EARTH_CIR_METERS; 29 const metersPerPixelEW = EARTH_CIR_METERS / Math.pow(2, zoom + 8); 30 const metersPerPixelNS = EARTH_CIR_METERS / Math.pow(2, zoom + 8) * Math.cos(lat * Math.PI / 180); 31 32 const shiftMetersEW = width/2 * metersPerPixelEW; 33 const shiftMetersNS = height/2 * metersPerPixelNS; 34 35 const shiftDegreesEW = shiftMetersEW * degreesPerMeter; 36 const shiftDegreesNS = shiftMetersNS * degreesPerMeter; 37 38 // [[south, west], [north, east]] 39 return [[lat-shiftDegreesNS, lng-shiftDegreesEW], [lat+shiftDegreesNS, lng+shiftDegreesEW]]; 40 } 41 42 function customAutoSuggestText(text,val) { 43 return '<div><img src="' + val.layer.options.icon.options.iconUrl + '" />' + val.layer.options.title + '</div>'; 44 } 45 46 function updatePreview() { 47 this.nextElementSibling.classList.add('active'); 48 this.nextElementSibling.querySelector('span').textContent = this.files[0].name; 49 } 50 51 // Create leaflet markers based on "oum_all_locations" json 52 function addMarkers() { 53 oum_all_locations.forEach(location => { 54 let marker = L.marker([location.lat, location.lng], { 55 title: location.title, 56 post_id: location.post_id, 57 content: location.title + ' | ' + location.content.replace(/(<([^>]+)>)/gi, " ").replace(/\s\s+/g, " "), 58 icon: L.icon({ 59 iconUrl: location.icon, 60 iconSize: [26, 41], 61 iconAnchor: [13, 41], 62 popupAnchor: [0, -25], 63 shadowUrl: marker_shadow_url, 64 shadowSize: [41, 41], 65 shadowAnchor: [13, 41] 66 }), 67 types: location.types || [] 68 }); 69 let popup = L.responsivePopup().setContent(location.content); 70 marker.bindPopup(popup); 71 oumAllMarkers.push(marker); 72 }); 73 } 74 75 // Use this to initialize markers and add them to the map initially 76 function initializeMarkers() { 77 addMarkers(); // Fill the oumAllMarkers array 78 oumAllMarkers.forEach(marker => { 79 oumMarkersLayer.addLayer(marker); // Add all markers to the markers LayerGroup or ClusterGroup 80 }); 81 } 82 83 84 // VARIABLES 85 86 const POPUP_MARKER_ID = getParameterByName('markerid'); 87 const REGION_ID = getParameterByName('region'); 88 const enableFullscreen = (!iOS() && oum_enable_fullscreen) ? true : false; 89 const enableGestureHandlingMap = oum_enable_scrollwheel_zoom_map ? false : true; 90 91 // Handle "Add Location" popup DOM placement on fullscreen mode 92 const addLocationPopup = document.querySelector('#add-location-overlay'); 93 const originalContainer = addLocationPopup.parentElement; 94 const fullscreenContainer = document.querySelector('.open-user-map .map-wrap'); 95 96 // Handle Location Bubble on small screens (show in fullscreen) 97 const locationFullscreenContainer = document.querySelector('.open-user-map #location-fullscreen-container'); 98 99 100 101 // SETUP MAIN MAP 102 103 // Init Map 104 const map = L.map(map_el, { 105 gestureHandling: enableGestureHandlingMap, 106 zoomSnap: 0.5, 107 zoomDelta: 0.5, 108 attributionControl: true, 109 fullscreenControl: enableFullscreen, 110 fullscreenControlOptions: { 111 position: 'topleft', 112 fullscreenElement: fullscreenContainer, 113 } 114 }); 115 116 map.attributionControl.setPrefix(false); 117 118 // prevent moving/zoom outside main world bounds 119 let world_bounds = L.latLngBounds(L.latLng(-60, -190), L.latLng(80, 190)); 120 let world_min_zoom = map.getBoundsZoom(world_bounds);
121 map.setMaxBounds(world_bounds); 122 map.setMinZoom(Math.ceil(world_min_zoom)); 123 map.on('drag', function() { 124 map.panInsideBounds(world_bounds, { animate: false }); 125 }); 126 127 // make map reloadable (oumMap.invalidateSize()) after some preloader is ready 128 oumMap = map; 129 130 // Get Initial Map Bounds & Zoom 131 let start_bounds = latLngToBounds(parseFloat(start_lat), parseFloat(start_lng), parseFloat(start_zoom), 570, 372); 132 let start_bounds_zoom = map.getBoundsZoom(start_bounds); 133 134 oum_minimum_zoom_level = oum_minimum_zoom_level ? oum_minimum_zoom_level : 1; 135 136 if(oum_use_settings_start_location && !oum_has_regions) { 137 138 // START POSITION FROM SETTINGS AND REGIONS ARE DISABLED 139 140 // Make sure "Minimum zoom level" is lower than start zoom 141 if(oum_minimum_zoom_level > parseFloat(start_zoom)) { 142 oum_minimum_zoom_level = Math.floor(start_bounds_zoom); 143 } 144 145 // Set min zoom 146 map.setMinZoom(oum_minimum_zoom_level); 147 148 }else{ 149 150 // CUSTOM START POSITION 151 152 // Disable "Fixed Map Bounds" from Settings 153 oum_enable_fixed_map_bounds = false; 154 } 155 156 // Render Map 157 map.setView([start_lat, start_lng], start_bounds_zoom); 158 159 // Bound map to fixed position 160 if(oum_enable_fixed_map_bounds) { 161 map.setMaxBounds(map.getBounds().pad(0.1)); 162 } 163 164 // Create Bounds Object needed for Marker Search 165 let start_bounds_object = map.getBounds(); 166 167 // Set map style 168 if (mapStyle == 'Custom1') { 169 170 L.tileLayer('https://{s}.basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}.png').addTo(map); 171 L.tileLayer('https://{s}.basemaps.cartocdn.com/rastertiles/voyager_only_labels/{z}/{x}/{y}{r}.png', { 172 tileSize: 512, 173 zoomOffset: -1 174 }).addTo(map); 175 176 } else if (mapStyle == 'Custom2') { 177 178 L.tileLayer('https://{s}.basemaps.cartocdn.com/dark_nolabels/{z}/{x}/{y}.png').addTo(map); 179 L.tileLayer('https://{s}.basemaps.cartocdn.com/rastertiles/voyager_only_labels/{z}/{x}/{y}{r}.png', { 180 tileSize: 512, 181 zoomOffset: -1 182 }).addTo(map); 183 184 } else if (mapStyle == 'Custom3') { 185 186 L.tileLayer('https://{s}.basemaps.cartocdn.com/dark_nolabels/{z}/{x}/{y}.png').addTo(map); 187 L.tileLayer('https://{s}.basemaps.cartocdn.com/rastertiles/voyager_only_labels/{z}/{x}/{y}{r}.png', { 188 tileSize: 512, 189 zoomOffset: -1 190 }).addTo(map); 191 192 } else if (mapStyle == 'MapBox.streets') { 193 194 L.tileLayer.provider('MapBox', { 195 id: 'mapbox/streets-v12', 196 accessToken: oum_tile_provider_mapbox_key 197 }).addTo(map); 198 199 } else if (mapStyle == 'MapBox.outdoors') { 200 201 L.tileLayer.provider('MapBox', { 202 id: 'mapbox/outdoors-v12', 203 accessToken: oum_tile_provider_mapbox_key 204 }).addTo(map); 205 206 } else if (mapStyle == 'MapBox.light') { 207 208 L.tileLayer.provider('MapBox', { 209 id: 'mapbox/light-v11', 210 accessToken: oum_tile_provider_mapbox_key 211 }).addTo(map); 212 213 } else if (mapStyle == 'MapBox.dark') { 214 215 L.tileLayer.provider('MapBox', { 216 id: 'mapbox/dark-v11', 217 accessToken: oum_tile_provider_mapbox_key 218 }).addTo(map); 219 220 } else if (mapStyle == 'MapBox.satellite') { 221 222 L.tileLayer.provider('MapBox', { 223 id: 'mapbox/satellite-v9', 224 accessToken: oum_tile_provider_mapbox_key 225 }).addTo(map); 226 227 } else if (mapStyle == 'MapBox.satellite-streets') { 228 229 L.tileLayer.provider('MapBox', { 230 id: 'mapbox/satellite-streets-v12', 231 accessToken: oum_tile_provider_mapbox_key 232 }).addTo(map); 233 234 } else { 235 // Default 236 L.tileLayer.provider(mapStyle).addTo(map); 237 } 238 239 240 // ADD LOCATIONS 241 242 let oumAllMarkers = []; // holds all markers 243 let oumMarkersLayer; // Marker parent layer 244 245 if (!oum_enable_cluster) { 246 // clustering disabled 247 oumMarkersLayer = L.layerGroup({ 248 chunkedLoading: true 249 }); 250 } else { 251 // clustering enabled 252 oumMarkersLayer = L.markerClusterGroup({ 253 showCoverageOnHover: false, 254 removeOutsideVisibleBounds: false, 255 maxClusterRadius: 40, 256 chunkedLoading: true 257 }); 258 } 259 260 // Add markers layer to map 261 oumMarkersLayer.addTo(map); 262 263 // Call this function initially to set up markers 264 initializeMarkers(); 265 266 267 268 269 // ADD MAP CONTROLS 270 271 // Control: search markers 272 if (oum_enable_searchmarkers_button && (!oum_enable_searchbar || oum_searchbar_type !== 'markers')) { 273 L.control.search({ 274 textPlaceholder: oum_searchmarkers_label, 275 layer: oumMarkersLayer, 276 propertyName: 'content', 277 initial: false, 278 buildTip: customAutoSuggestText, 279 firstTipSubmit: true,
280 autoCollapse: true, // resets search field 281 zoom: oum_searchmarkers_zoom, 282 }).addTo(map); 283 } 284 285 // Searchbar: search markers 286 if (oum_enable_searchbar && oum_searchbar_type == 'markers') { 287 L.control.search({ 288 container: 'oum_search_marker', 289 collapsed: false, 290 textPlaceholder: oum_searchmarkers_label, 291 layer: oumMarkersLayer, 292 propertyName: 'content', 293 initial: false, 294 buildTip: customAutoSuggestText, 295 firstTipSubmit: true, 296 autoCollapse: true, // resets search field 297 zoom: oum_searchmarkers_zoom, 298 }).addTo(map); 299 } 300 301 // Geosearch Provider 302 switch (oum_geosearch_provider) { 303 case 'osm': 304 oum_geosearch_selected_provider = new GeoSearch.OpenStreetMapProvider(); 305 break; 306 case 'geoapify': 307 oum_geosearch_selected_provider = new GeoSearch.GeoapifyProvider({ 308 params: { 309 apiKey: oum_geosearch_provider_geoapify_key 310 } 311 }); 312 break; 313 case 'here': 314 oum_geosearch_selected_provider = new GeoSearch.HereProvider({ 315 params: { 316 apiKey: oum_geosearch_provider_here_key 317 } 318 }); 319 break; 320 case 'mapbox': 321 oum_geosearch_selected_provider = new GeoSearch.MapBoxProvider({ 322 params: { 323 access_token: oum_geosearch_provider_mapbox_key 324 } 325 }); 326 break; 327 default: 328 oum_geosearch_selected_provider = new GeoSearch.OpenStreetMapProvider(); 329 break; 330 } 331 332 // Control: search address 333 if (oum_enable_searchaddress_button && (!oum_enable_searchbar || oum_searchbar_type !== 'address')) { 334 const searchControl = new GeoSearch.GeoSearchControl({ 335 style: 'button', //bar, button 336 showMarker: false, 337 provider: oum_geosearch_selected_provider, 338 notFoundMessage: 'Sorry, that address could not be found.', 339 searchLabel: oum_searchaddress_label, 340 updateMap: false, 341 autoComplete: true 342 }); 343 map.addControl(searchControl); 344 } 345 346 // Searchbar: search address 347 if (oum_enable_searchbar && oum_searchbar_type == 'address') { 348 const searchControl = new GeoSearch.GeoSearchControl({ 349 style: 'bar', //bar, button 350 showMarker: false, 351 provider: oum_geosearch_selected_provider, 352 searchLabel: oum_searchaddress_label, 353 updateMap: false, 354 }); 355 map.addControl(searchControl); 356 } 357 358 // Control: get current location 359 if (oum_enable_currentlocation) { 360 L.control.locate({ 361 flyTo: true, 362 initialZoomLevel: 12, 363 drawCircle: false, 364 drawMarker: false, 365 showCompass: false, 366 showPopup: false 367 }).addTo(map); 368 } 369 370 371 // EVENTS 372 373 // Event: Enter Fullscreen 374 map.on('enterFullscreen', function () { 375 fullscreenContainer.appendChild(addLocationPopup); 376 }); 377 378 // Event: Exit Fullscreen 379 map.on('exitFullscreen', function () { 380 originalContainer.appendChild(addLocationPopup); 381 }); 382 383 // Event: Open Location Bubble 384 map.on('popupopen', function(locationBubble){ 385 var el = locationFullscreenContainer; 386 el.querySelector('.location-content-wrap').innerHTML = locationBubble.popup.getContent(); 387 locationFullscreenContainer.classList.add('visible'); 388 document.querySelector('body').classList.add('oum-location-opened'); 389 }); 390 391 // Event: Close Location Bubble 392 map.on('popupclose', function(locationBubble){ 393 var el = locationFullscreenContainer; 394 el.classList.remove('visible'); 395 document.querySelector('body').classList.remove('oum-location-opened'); 396 //map.setView(locationBubble.popup.getLatLng()); 397 }); 398 399 // Event: pan or zoom Map 400 map.on('moveend', function(ev) { 401 start_lat = map.getCenter().lat; 402 start_lng = map.getCenter().lng; 403 start_zoom = map.getZoom(); 404 }); 405 406 // Event: click on geosearch result 407 map.on('geosearch/showlocation', function(e) { 408 let coords = e.marker._latlng; 409 let isInBounds = start_bounds_object.contains(coords); 410 const searchBar = document.querySelector(`#${map_el} .leaflet-geosearch-bar form, #${map_el} .leaflet-geosearch-button form`); 411 412 if(!isInBounds && oum_enable_fixed_map_bounds) { 413 console.log('This search result is out of reach.'); 414 searchBar.style.boxShadow = "0 0 10px rgb(255, 111, 105)"; 415 setTimeout(function() { 416 searchBar.style.boxShadow = "0 1px 5px rgba(255, 255, 255, 0.65)"; 417 }, 2000); 418 }else{ 419 if(e.location.bounds !== null) { 420 map.flyToBounds(e.location.bounds); 421 }else{ 422 map.flyToBounds([ 423 [e.location.raw.mapView.south,e.location.raw.mapView.west], 424 [e.location.raw.mapView.north,e.location.raw.mapView.east] 425 ]); 426 } 427 } 428 }); 429 430 // Event: automatically open popup on ?markerid=123 431 oumMarkersLayer.eachLayer(function(layer) { 432 433 if(layer.options.post_id && layer.options.post_id === POPUP_MARKER_ID){ 434
435 map.setView(layer.getLatLng(), oum_searchmarkers_zoom); 436 layer.openPopup(); 437 438 } 439 }); 440 441 // Event: Change Region 442 document.querySelectorAll('.open-user-map .change_region').forEach(function(btn) { 443 btn.onclick = function(event) { 444 let el = event.currentTarget; 445 let region_lat = el.getAttribute('data-lat'); 446 let region_lng = el.getAttribute('data-lng'); 447 let region_zoom = el.getAttribute('data-zoom'); 448 449 let region_bounds = latLngToBounds(parseFloat(region_lat), parseFloat(region_lng), parseFloat(region_zoom), 570, 372); 450 let region_bounds_zoom = map.getBoundsZoom(region_bounds); 451 452 // Center Map 453 map.flyTo([region_lat, region_lng], region_bounds_zoom); 454 455 document.querySelectorAll('.open-user-map .change_region').forEach(function(el) { 456 el.classList.remove('active'); 457 }); 458 el.classList.add('active'); 459 }; 460 461 // Event: Change Region on ?region=Europe 462 if(btn.textContent == REGION_ID) { 463 btn.click(); 464 } 465 }); 466 467 // Event: Filter Markers 468 document.querySelectorAll('.open-user-map .oum-filter-controls [name="type"]').forEach(input => { 469 input.addEventListener('change', function() { 470 471 // Update function to control visibility based on filters 472 473 var checkedTypes = Array.from(document.querySelectorAll('.open-user-map .oum-filter-controls [name="type"]:checked')).map(input => input.value); 474 console.log('Checked Types:', checkedTypes); 475 476 oumAllMarkers.forEach(marker => { 477 // Check if the marker has types defined and if it matches any of the checked types 478 const hasTypes = marker.options.types && marker.options.types.length > 0; 479 const matchesCheckedTypes = marker.options.types.some(type => checkedTypes.includes(type)); 480 481 if (hasTypes && matchesCheckedTypes) { 482 // Marker has types and matches one of the checked types, ensure it's visible 483 if (!map.hasLayer(marker)) { 484 oumMarkersLayer.addLayer(marker); 485 } 486 } else if (hasTypes && !matchesCheckedTypes) { 487 // Marker has types but does not match the checked types, hide it 488 oumMarkersLayer.removeLayer(marker); 489 } else { 490 // Marker does not have types defined, it should always remain visible 491 if (!map.hasLayer(marker)) { 492 oumMarkersLayer.addLayer(marker); 493 } 494 } 495 }); 496 497 }); 498 }); 499 500 501 // ADD LOCATION 502 503 if (document.getElementById('open-add-location-overlay') != null) { 504 //init form map 505 const map2 = L.map('mapGetLocation', { 506 attributionControl: false, 507 gestureHandling: true, 508 zoomSnap: 1, 509 zoomDelta: 1, 510 }); 511 512 // Activate Map inside overlay 513 (function() { 514 515 let markerIsVisible = false; 516 517 // Set map style 518 if (mapStyle == 'Custom1') { 519 520 L.tileLayer('https://{s}.basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}.png').addTo(map2); 521 L.tileLayer('https://{s}.basemaps.cartocdn.com/rastertiles/voyager_only_labels/{z}/{x}/{y}{r}.png', { 522 tileSize: 512, 523 zoomOffset: -1 524 }).addTo(map2); 525 526 } else if (mapStyle == 'Custom2') { 527 528 L.tileLayer('https://{s}.basemaps.cartocdn.com/dark_nolabels/{z}/{x}/{y}.png').addTo(map2); 529 L.tileLayer('https://{s}.basemaps.cartocdn.com/rastertiles/voyager_only_labels/{z}/{x}/{y}{r}.png', { 530 tileSize: 512, 531 zoomOffset: -1 532 }).addTo(map2); 533 534 } else if (mapStyle == 'Custom3') { 535 536 L.tileLayer('https://{s}.basemaps.cartocdn.com/dark_nolabels/{z}/{x}/{y}.png').addTo(map2); 537 L.tileLayer('https://{s}.basemaps.cartocdn.com/rastertiles/voyager_only_labels/{z}/{x}/{y}{r}.png', { 538 tileSize: 512, 539 zoomOffset: -1 540 }).addTo(map2); 541 542 } else if (mapStyle == 'MapBox.streets') { 543 544 L.tileLayer.provider('MapBox', { 545 id: 'mapbox/streets-v12', 546 accessToken: oum_tile_provider_mapbox_key 547 }).addTo(map2); 548 549 } else if (mapStyle == 'MapBox.outdoors') { 550 551 L.tileLayer.provider('MapBox', { 552 id: 'mapbox/outdoors-v12',
553 accessToken: oum_tile_provider_mapbox_key 554 }).addTo(map2); 555 556 } else if (mapStyle == 'MapBox.light') { 557 558 L.tileLayer.provider('MapBox', { 559 id: 'mapbox/light-v11', 560 accessToken: oum_tile_provider_mapbox_key 561 }).addTo(map2); 562 563 } else if (mapStyle == 'MapBox.dark') { 564 565 L.tileLayer.provider('MapBox', { 566 id: 'mapbox/dark-v11', 567 accessToken: oum_tile_provider_mapbox_key 568 }).addTo(map2); 569 570 } else if (mapStyle == 'MapBox.satellite') { 571 572 L.tileLayer.provider('MapBox', { 573 id: 'mapbox/satellite-v9', 574 accessToken: oum_tile_provider_mapbox_key 575 }).addTo(map2); 576 577 } else if (mapStyle == 'MapBox.satellite-streets') { 578 579 L.tileLayer.provider('MapBox', { 580 id: 'mapbox/satellite-streets-v12', 581 accessToken: oum_tile_provider_mapbox_key 582 }).addTo(map2); 583 584 } else { 585 // Default 586 L.tileLayer.provider(mapStyle).addTo(map2); 587 } 588 589 // Add searchbar: address 590 const search = new GeoSearch.GeoSearchControl({ 591 style: 'bar', 592 showMarker: false, 593 provider: oum_geosearch_selected_provider, 594 searchLabel: oum_searchaddress_label, 595 updateMap: false, 596 }); 597 map2.addControl(search); 598 599 // Add control: get current location 600 if (oum_enable_currentlocation) { 601 L.control.locate({ 602 flyTo: true, 603 initialZoomLevel: 12, 604 drawCircle: false, 605 drawMarker: false, 606 showCompass: false, 607 showPopup: false 608 }).addTo(map2); 609 } 610 611 //define marker 612 613 // Marker Icon 614 let markerIcon = L.icon({ 615 iconUrl: marker_icon_url, 616 iconSize: [26, 41], 617 iconAnchor: [13, 41], 618 popupAnchor: [0, -25], 619 shadowUrl: marker_shadow_url, 620 shadowSize: [41, 41], 621 shadowAnchor: [13, 41] 622 }); 623 624 let locationMarker = L.marker([0, 0], { 625 icon: markerIcon 626 }, { 627 'draggable': true 628 }); 629 630 // move "Add Location"-Map to current Main map position 631 start_lat = map.getCenter().lat; 632 start_lng = map.getCenter().lng; 633 start_zoom = map.getZoom(); 634 635 let main_map_width = document.querySelector(`#${map_el}`).offsetWidth; 636 let main_map_height = document.querySelector(`#${map_el}`).offsetHeight; 637 let start_bounds = latLngToBounds(parseFloat(start_lat), parseFloat(start_lng), parseFloat(start_zoom), main_map_width, main_map_height); 638 let start_bounds_zoom = map2.getBoundsZoom(start_bounds); 639 640 map2.setView([start_lat, start_lng], start_bounds_zoom); 641 642 // prevent moving/zoom outside main world bounds 643 map2.setMaxBounds(world_bounds); 644 map2.setMinZoom(Math.ceil(world_min_zoom)); 645 map2.on('drag', function() { 646 map2.panInsideBounds(world_bounds, { animate: false }); 647 }); 648 649 // Bound map to fixed position 650 if(oum_enable_fixed_map_bounds) { 651 map2.setMaxBounds(map.getBounds()); 652 } 653 654 //Event: click on map to set marker OR location found 655 map2.on('click locationfound', function(e) { 656 let coords = e.latlng; 657 658 locationMarker.setLatLng(coords); 659 660 if (!markerIsVisible) { 661 locationMarker.addTo(map2); 662 markerIsVisible = true; 663 } 664 665 setLocationLatLng(coords); 666 }); 667 668 //Event: geosearch success 669 map2.on('geosearch/showlocation', function(e) { 670 let coords = e.marker._latlng; 671 let label = e.location.label; 672 let isInBounds = start_bounds_object.contains(coords); 673 const searchBar = document.querySelector(`#mapGetLocation .leaflet-geosearch-bar form`); 674 675 if(!isInBounds && oum_enable_fixed_map_bounds) { 676 console.log('This search result is out of reach.'); 677 searchBar.style.boxShadow = "0 0 10px rgb(255, 111, 105)"; 678 setTimeout(function() { 679 searchBar.style.boxShadow = "0 1px 5px rgba(255, 255, 255, 0.65)"; 680 }, 2000); 681 }else{ 682 if(e.location.bounds !== null) { 683 map2.flyToBounds(e.location.bounds); 684 }else{ 685 map2.flyToBounds([ 686 [e.location.raw.mapView.south,e.location.raw.mapView.west], 687 [e.location.raw.mapView.north,e.location.raw.mapView.east] 688 ]); 689 } 690 691 locationMarker.setLatLng(coords); 692 693 if (!markerIsVisible) { 694 locationMarker.addTo(map2); 695 markerIsVisible = true; 696 } 697 698 setLocationLatLng(coords); 699 700 //setAddress(label); 701 } 702 }); 703 704 oumMap2 = map2; 705 706 //execute custom JS from the settings here 707 let oum_custom_js = Function(custom_js.snippet)(); 708 709 //Event: drag marker 710 locationMarker.on('dragend', function(e) { 711 setLocationLatLng(e.target.getLatLng()); 712 }); 713 714 //Validation for required checkbox groups 715 jQuery('#oum_add_location input[type="submit"]').on('click', function() { 716 let required_fieldsets = jQuery('#oum_add_location fieldset.is-required'); 717 718 required_fieldsets.each(function() {
719 $cbx_group = jQuery(this).find('input:checkbox'); 720 $cbx_group.prop('required', true); 721 if($cbx_group.is(":checked")){ 722 $cbx_group.prop('required', false); 723 } 724 }); 725 }); 726 727 //set lat & lng input fields 728 function setLocationLatLng(markerLatLng) { 729 console.log(markerLatLng); 730 731 jQuery('#oum_location_lat').val(markerLatLng.lat); 732 jQuery('#oum_location_lng').val(markerLatLng.lng); 733 } 734 735 //set address field 736 function setAddress(label) { 737 jQuery('#oum_location_address').val(label); 738 } 739 740 })(); 741 742 // Event: click on "+ Add Location" button 743 document.getElementById('open-add-location-overlay').addEventListener('click', function(event) { 744 745 // show overlay 746 document.getElementById('add-location-overlay').classList.add('active'); 747 748 // prevent body scrolling 749 document.querySelector('body').classList.add('oum-add-location-opened'); 750 751 // scroll to top of overlay 752 window.scrollTo(0, document.getElementById('add-location-overlay').getBoundingClientRect().top + scrollY); 753 754 //reposition map 755 setTimeout(function() { 756 map2.invalidateSize(); 757 758 // move "Add Location"-Map to current Main map position 759 let main_map_width = document.querySelector(`#${map_el}`).offsetWidth; 760 let main_map_height = document.querySelector(`#${map_el}`).offsetHeight; 761 let start_bounds = latLngToBounds(parseFloat(start_lat), parseFloat(start_lng), parseFloat(start_zoom), main_map_width, main_map_height); 762 763 map2.fitBounds(start_bounds); 764 765 }, 0); 766 }); 767 768 // Event: click on "notify on publish" 769 if (document.getElementById('oum_location_notification') != null) { 770 document.getElementById('oum_location_notification').addEventListener('change', function(event) { 771 if (this.checked) { 772 document.getElementById('oum_author').classList.add('active'); 773 document.getElementById('oum_location_author_name').required = true; 774 document.getElementById('oum_location_author_email').required = true; 775 } else { 776 document.getElementById('oum_author').classList.remove('active'); 777 document.getElementById('oum_location_author_name').required = false; 778 document.getElementById('oum_location_author_email').required = false; 779 } 780 }); 781 } 782 783 // Events: close "Add location" overlay 784 if (document.getElementById('close-add-location-overlay') != null) { 785 786 // Event: Close "Add location" popup on X 787 document.getElementById('close-add-location-overlay').addEventListener('click', function(event) { 788 document.getElementById('add-location-overlay').classList.remove('active'); 789 790 // allow body scrolling 791 document.querySelector('body').classList.remove('oum-add-location-opened'); 792 }); 793 794 // Event: Close "Add location" popup on ESC key 795 document.onkeydown = function(evt) { 796 evt = evt || window.event; 797 if(evt.key === "Escape") { 798 document.getElementById('close-add-location-overlay').click(); 799 } 800 }; 801 802 // Event: CLose "Add location" popup on click on backdrop 803 document.getElementById('add-location-overlay').addEventListener('click', function(event) { 804 if (event.target !== this) return; 805 document.getElementById('close-add-location-overlay').click(); 806 }); 807 } 808 809 // Event: Remove uploaded image 810 if (document.getElementById('oum_remove_image') != null) { 811 document.getElementById('oum_remove_image').addEventListener('click', function() { 812 document.getElementById('oum_location_image').value = ''; 813 document.getElementById('oum_location_image').nextElementSibling.classList.remove('active'); 814 document.getElementById('oum_location_image').nextElementSibling.querySelector('span').textContent = ''; 815 }); 816 } 817 818 // Event: Remove uploaded audio 819 if (document.getElementById('oum_remove_audio') != null) { 820 document.getElementById('oum_remove_audio').addEventListener('click', function() { 821 document.getElementById('oum_location_audio').value = ''; 822 document.getElementById('oum_location_audio').nextElementSibling.classList.remove('active'); 823 document.getElementById('oum_location_audio').nextElementSibling.querySelector('span').textContent = ''; 824 }); 825 } 826 827 // Event: add another location 828 if (document.getElementById('oum_add_another_location') != null) { 829 document.getElementById('oum_add_another_location').addEventListener('click', function() { 830 document.getElementById('oum_add_location').style.display = 'block'; 831 document.getElementById('oum_add_location_error').style.display = 'none'; 832 document.getElementById('oum_add_location_thankyou').style.display = 'none'; 833 834 //reposition map 835 setTimeout(function() {
836 map2.invalidateSize(); 837 map2.setView([start_lat, start_lng], start_zoom); 838 }, 0); 839 840 //reset media previews 841 if(document.getElementById('oum_location_image')) { 842 document.getElementById('oum_location_image').value = ''; 843 document.getElementById('oum_location_image').nextElementSibling.classList.remove('active'); 844 document.getElementById('oum_location_image').nextElementSibling.querySelector('span').textContent = ''; 845 } 846 847 if(document.getElementById('oum_location_audio')) { 848 document.getElementById('oum_location_audio').value = ''; 849 document.getElementById('oum_location_audio').nextElementSibling.classList.remove('active'); 850 document.getElementById('oum_location_audio').nextElementSibling.querySelector('span').textContent = ''; 851 } 852 }); 853 } 854 855 if(document.getElementById('oum_location_image') != null) { 856 document.getElementById('oum_location_image').addEventListener('change', updatePreview); 857 } 858 859 if(document.getElementById('oum_location_audio') != null) { 860 document.getElementById('oum_location_audio').addEventListener('change', updatePreview) 861 } 862 } 863 864}, false);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.