1var FWP_MAP = FWP_MAP || {}; // This needs to be var 2 3/* 4 * Load global listeners 5 */ 6rdposmInit(); 7//rdpGetLocation(); 8 9 10(function ($) { 11// if ('undefined'!==FWP_MAP.is_filtering){ 12// console.log(FWP_MAP); 13// return; 14// } 15 FWP_MAP.markersArray = []; 16 FWP_MAP.markerLookup = []; 17 FWP_MAP.initView = {}; 18 FWP_MAP.allBounds = {}; 19 FWP_MAP.popups = []; 20 21 FWP_MAP.is_filtering = false; 22 FWP_MAP.is_zooming = false; 23 FWP_MAP.mapHasMoved = false; 24 25 FWP_MAP.trigger = {type: 'init', postID: false, refresh: true} 26 FWP_MAP.hasOpenPopup = false; 27 FWP_MAP.openedPopup = false; 28 FWP_MAP.proximityActive = false 29 30 FWP_MAP.firstLoad = true; 31 FWP_MAP.mapReset = false; // Map action triggered reset 32 33 FWP_MAP.mouseState = '' 34 FWP_MAP.moveInfo = {start: {x: 0, y: 0}, end: {x: 0, y: 0}, dist: {x: 0, y: 0, h: 0}} 35 36 FWP_MAP.muteState = {button: 'all', state: {mt: [], ms: []}} 37 38 /*********************************** 39 * LOCAL HOOKS 40 * ********************************/ 41 /* 42 * Called after FacetWP has loaded 43 */ 44 $().on('facetwp-loaded', eventOnFacetWPLoaded); 45 46 /* 47 * Hook to fire on map refresh to update the bounds 48 */ 49 FWP.hooks.addAction('facetwp/refresh/rdposm_map', actionOnMapRefresh); 50 51 /* 52 * Hook into reset 53 */ 54 FWP.hooks.addAction('facetwp/reset', actionOnResetClicked); 55 56 /* 57 * rdposm_map hook to update its selections text 58 * This fires after everything else in Facet's processes 59 */ 60 FWP.hooks.addFilter('facetwp/selections/rdposm_map', function (label, params) { 61 return 'Clear map bounds'; 62 }); 63 64 if (window.history && window.history.pushState) { 65 66 jQuery(window).on('popstate', function () { 67 FWP_MAP.trigger = {type: 'browser', postID: false, refresh: 'browsing'}; 68 }); 69 70 } 71 72 73 /**************************************** 74 * LOCAL FUNCTIONS 75 ****************************************/ 76 77 /** 78 * Called on FacetWP loaded 79 */ 80 function eventOnFacetWPLoaded() { 81 82 // console.log('On FacetWP Loaded',FWP_MAP.trigger) 83 84 let update_markers = true; 85 86 /* 87 * Add listing hover listener 88 */ 89 jQuery(".hcx_listing_item").hover(rdpListingHover, rdpListingUnhover); 90 91 /* 92 * Initialise the map if first load 93 */ 94 if (FWP_MAP.firstLoad) { 95 FWP_MAP.facets = { 96 map: Object.keys(FWP.facet_type)[(Object.values(FWP.facet_type).indexOf('rdposm_map'))], 97 proximity: Object.keys(FWP.facet_type)[(Object.values(FWP.facet_type).indexOf('proximity'))] 98 } 99 renderMap(false); 100 } else if (FWP_MAP.trigger.type === 'browser') { 101 renderMap(true) 102 update_markers = processBounds(); 103 updateMarkersLayer(update_markers) 104 105 } else { 106 update_markers = processBounds(); 107 updateMarkersLayer(update_markers) 108 } 109 110 /* 111 * Sometimes the final update of the markers needs to be done after map reset 112 */ 113 if (FWP_MAP.mapReset) { 114 updateMarkersLayer(true) 115 } 116 // console.log(FWP_MAP.trigger); 117 /* 118 * Reset the proximity facet if necessary 119 */ 120 //TODO: Make it all happen at once - not two 121 122 if (!FWP_MAP.firstLoad && 123 'undefined' === typeof FWP_MAP.config.preset_filters[FWP_MAP.facets.proximity] && 124 'undefined' !== typeof FWP_MAP.facets.proximity && 125 FWP.facets[FWP_MAP.facets.proximity].length > 0 && 126 FWP_MAP.trigger.type === 'zoom-reset') { 127 // console.log('ðµ reset proximity') 128 FWP.reset(FWP_MAP.facets.proximity); 129 FWP_MAP.proximityActive = false; 130 } 131 132 FWP_MAP.trigger = {type: 'idle', postID: FWP_MAP.trigger.postID, refresh: false}; 133 134 jQuery('.facetwp-type-rdposm_map').removeClass('is-loading'); 135 136 // console.log('End Facet Loaded', FWP_MAP.trigger) 137 } // End on'facetwp-loaded' 138 139 /** 140 * Draw the map 141 * This is only called on first load and when the browser back/forward button are pressed 142 */ 143 function renderMap(browser) { 144 if (!browser) { 145 /* 146 * Load config 147 * 148 * Note: You must add settings in the PHP get_settings_and_markers() function 149 * 150 * Note: Moved to a global coz something was changing FWP.settings.rdposm_map.config.preset_filters 151 * This could be masking another problem... 152 * 153 */ 154 FWP_MAP.config = FWP.settings.rdposm_map.config; 155 156 157 /* 158 * Set filtering from facet's settings 159 */ 160 FWP_MAP.is_filtering = FWP_MAP.config.filtering; 161 162 } 163 164 // if (browser){ 165 // FWP_MAP.trigger = {type: 'browser', postID: false, refresh: 'browsing'} 166 // } else { 167 // FWP_MAP.trigger = {type: 'firstload', postID: false, refresh: false} 168 // } 169 // 170 let bounds; 171 if (browser) { 172 bounds = FWP_MAP.map.getBounds(); 173 // console.log(bounds); 174 175 } 176 initialiseMap(browser); 177 178 // TODO: What was this here for? 179 if (typeof FWP_MAP.customSettings !== "undefined") { 180 FWP_MAP.config.default_lat = FWP_MAP.customSettings.lat 181 FWP_MAP.config.default_lng = FWP_MAP.customSettings.lng 182 FWP_MAP.config.default_zoom = FWP_MAP.customSettings.zoom 183 } 184 185 /* 186 * Set map to default if no listings 187 */ 188 if (FWP.settings.rdposm_map.locations !== false && FWP.settings.rdposm_map.locations.length === 0) {
189 FWP_MAP.map.setView([parseFloat(FWP_MAP.config.default_lat), parseFloat(FWP_MAP.config.default_lng)], FWP_MAP.config.default_zoom); 190 } 191 192 intilialiseMarkersLayer(); 193 194 if ('' == FWP.buildQueryString()) { 195 /* hide */ 196 } else { 197 /* unhide */ 198 } 199 200 addMarkersLayer(); 201 202 /* 203 * Map load is complete so get initial zoom level if first load 204 */ 205 processBounds(); 206 207 /* 208 * Get user's location 209 */ 210// FWP_MAP.map.locate({setView: true,maxZoom:14}); 211 212 /* 213 * Initialise bounds for the map 214 */ 215 if (browser) { 216 217 218 if (FWP.facets[FWP_MAP.facets.map].length > 0) { 219 220 221 bounds._southWest.lat = FWP.facets[FWP_MAP.facets.map][0]; 222 bounds._southWest.lng = FWP.facets[FWP_MAP.facets.map][1]; 223 bounds._northEast.lat = FWP.facets[FWP_MAP.facets.map][2]; 224 bounds._northEast.lng = FWP.facets[FWP_MAP.facets.map][3]; 225 FWP_MAP.map.fitBounds(bounds); 226 } else { 227 FWP_MAP.map.fitBounds(FWP_MAP.initView.bounds) 228 } 229 rdpResetMuteToggles() 230 } 231 232 /* 233 * Add trail. Must be full URL 234 */ 235 if (typeof FWP_MAP.config.trail_kmls !== 'undefined' && Object.keys(FWP_MAP.config.trail_kmls).length > 0) { 236 const mapBounds = FWP_MAP.map.getBounds(); 237 FWP_MAP.allBounds = mapBounds; 238 for (const [key, val] of Object.entries(FWP_MAP.config.trail_kmls)) { 239 fetch(val.trail_kml) 240 .then(res => res.text()) 241 .then(kmltext => { 242 // Create new kml overlay 243 const parser = new DOMParser(); 244 const kml = parser.parseFromString(kmltext, 'text/xml'); 245 // TODO: Replace this with leaflet elevation 246 const track = new L.KML(kml); 247 FWP_MAP.map.addLayer(track); 248 // Adjust map to show the kml 249 const trackBounds = track.getBounds(); 250 FWP_MAP.allBounds = { 251 _northEast: { 252 lat: Math.max(mapBounds._northEast.lat, FWP_MAP.allBounds._northEast.lat, trackBounds._northEast.lat), 253 lng: Math.max(mapBounds._northEast.lng, FWP_MAP.allBounds._northEast.lng, trackBounds._northEast.lng) 254 }, 255 _southWest: { 256 lat: Math.min(mapBounds._southWest.lat, FWP_MAP.allBounds._southWest.lat, trackBounds._southWest.lat), 257 lng: Math.min(mapBounds._southWest.lng, FWP_MAP.allBounds._southWest.lng, trackBounds._southWest.lng) 258 } 259 } 260 const allBounds = [ 261 [FWP_MAP.allBounds._northEast.lat, FWP_MAP.allBounds._northEast.lng], 262 [FWP_MAP.allBounds._southWest.lat, FWP_MAP.allBounds._southWest.lng] 263 264 ] 265 // Because this is in a promise, the ZoomBar home won't be set to this bounds 266 FWP_MAP.map.fitBounds(allBounds); 267 }); 268 269 } 270 } 271 272 /* 273 * Add zoom controls 274 */ 275 if (browser || 'undefined' === typeof FWP_MAP.zoomBar) { 276 FWP_MAP.zoomBar = new L.Control.ZoomBar({position: 'bottomright'}).addTo(FWP_MAP.map); 277 // Deactivated 0.7.13 278 // FWP_MAP.map.addControl(new L.Control.ZoomMin()); 279 } 280 281 // console.log('Render End', browser, FWP_MAP.trigger) 282 283 if (!browser) { 284 /* 285 * Get initial map view for resets 286 */ 287 FWP_MAP.initView.zoom = FWP_MAP.map.getZoom(); 288 FWP_MAP.initView.bounds = FWP_MAP.map.getBounds(); 289 FWP_MAP.initView.centre = FWP_MAP.map.getCenter(); 290 FWP_MAP.trigger = {type: 'idle', postID: false, refresh: false}; 291 } 292 FWP_MAP.firstLoad = false;
293 } 294 295 /** 296 * Initialise map 297 */ 298 function initialiseMap(browser = false) { 299 300 if (browser) { 301 FWP_MAP.map.remove(); 302 FWP_MAP.map = null; 303 } 304 /* 305 * Initialise basic leaflet map 306 */ 307 FWP_MAP.map = L.map('rdposm-map-facet', { 308 scrollWheelZoom: false, 309 zoomControl: false, 310 doubleClickZoom: false, 311 maxZoom: FWP.settings.rdposm_map.init.maxZoom, 312 minZoom: FWP.settings.rdposm_map.init.minZoom, 313 // preferCanvas: true, // googling said this might make drawing faster. Didn't 314 }); 315 316 /* 317 * Add basic tile layer 318 */ 319 L.tileLayer( 320 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', 321 { 322 attribution: '© OpenStreetMap', 323 maxZoom: FWP.settings.rdposm_map.init.maxZoom, 324 minZoom: FWP.settings.rdposm_map.init.minZoom, 325 } 326 ).addTo(FWP_MAP.map); 327 328 /* 329 * Add scale 330 */ 331 L.control.scale({imperial: false, position: 'bottomright'}).addTo(FWP_MAP.map); 332 333 334 /* 335 * Add polygons or geojson 336 */ 337 switch (FWP_MAP.config.polygon) { 338 case '': 339 case false: 340 case null: 341 break; 342 case 'custom': 343 case 'vhc': 344 FWP_MAP.polygon = L.polygon(FWP_MAP.config.polygon_data, { 345 fillColor: FWP_MAP.config.polygon_fill_colour, 346 color: FWP_MAP.config.polygon_border_colour, 347 weight: FWP_MAP.config.polygon_border_width, 348 interactive: false, 349 dashArray: FWP_MAP.config.polygon_border_style 350 }).addTo(FWP_MAP.map); 351 break; 352 default: 353 L.geoJSON(FWP_MAP.config.polygon_data, { 354 style: function (feature) { 355 console.log(feature); 356 return { 357 fillColor: FWP_MAP.config.polygon_fill_colour, 358 color: FWP_MAP.config.polygon_border_colour, 359 weight: FWP_MAP.config.polygon_border_width, 360 interactive: true, 361 dashArray: FWP_MAP.config.polygon_border_style 362 }; 363 } 364 }).bindPopup(function (layer) { 365 return "<h5><strong>" + layer.feature.properties.LGA_NAME + "</strong></h5>"; 366 }).addTo(FWP_MAP.map); 367 } 368 369 // FWP_MAP.map.fitBounds(FWP_MAP.polygon.getBounds()); 370 371 /* 372 * Add marker to defaul location is label set 373 */ 374 if (FWP_MAP.config.default_label) { 375 const defaultLocPopup = L.popup({offset: [0, 0]}).setLatLng([FWP_MAP.config.default_lat, FWP_MAP.config.default_lng]).setContent('<h5><strong>'+FWP_MAP.config.default_label+'</strong></h5>')//.openOn(FWP_MAP.map); 376 const defaultLoc = L.marker([FWP_MAP.config.default_lat, FWP_MAP.config.default_lng], { 377 alt: 'marker', 378 riseOnHover: true 379 }).addTo(FWP_MAP.map); 380 defaultLoc.bindPopup(defaultLocPopup).openPopup(); 381 } 382 /* 383 * Add spiderfy layer 384 */ 385 FWP_MAP.oms = new OverlappingMarkerSpiderfier(FWP_MAP.map, { 386 keepSpiderfied: true, 387 nearbyDistance: 5, 388 // circleSpiralSwitchover: Infinity, 389 legColors: {usual: '#ff00ff', highlighted: '#00ff00'}, 390 legWeight: 2, 391 // circleFootSeparation: 40 392 }); 393 394 FWP_MAP.oms.addListener('spiderfy', function (active, inactive) { 395 rdpPopupClose(); 396 // FWP_MAP.map.closePopup(); 397 jQuery('.marker-type').removeClass('mt-hidden'); 398 if (FWP_MAP.muteState.button !== 'all') { 399 jQuery('.btn-marker-type-' + FWP_MAP.muteState.button).addClass('btn-selected'); 400 if (typeof FWP_MAP.muteState.state.mt[1] !== 'undefined' && FWP_MAP.muteState.state.mt[1] === 'mt-hidden') { 401 FWP_MAP.muteState.state.mt.splice(1, 1); 402 } 403 } 404 405 }); 406 FWP_MAP.oms.addListener('unspiderfy', function (active, inactive) { 407 }); 408 409 /* 410 * Add map move ended listener 411 */ 412 FWP_MAP.map.on('moveend', eventOnMoveEnd); 413 414 /* 415 * Add map move start listener 416 */ 417 FWP_MAP.map.on('movestart', eventOnMoveStart); 418 419 /* 420 * Add map zoom ended listener 421 * With Leafleat, we do not need zoom end as it always seems to trigger move end 422 */ 423 FWP_MAP.map.on('zoomend', function (e) { 424 // doRefresh('zoomend'); 425 }); 426 FWP_MAP.map.on('mousedown', function (e) { 427 // console.log('Mousedown') 428 FWP_MAP.mouseState = 'mousedown'; 429 }); 430 431 FWP_MAP.map.on('mouseup', function (e) { 432 // console.log('Mouseup') 433 FWP_MAP.mouseState = 'mouseup'; 434 }); 435 436 FWP_MAP.map.on('popupclose', function (e) { 437// console.log(e); 438 FWP_MAP.openedPopup = false;
439 FWP_MAP.hasOpenPopup = false; 440 441 }); 442 443 /* 444 * Leaflet docs: Fired when the map needs to redraw its content (this usually happens on map zoom or load). Very useful for creating custom overlays. 445 * 446 * This isn't always triggered. Really only when a proper full reset. S, isn't reliable for any map redraw 447 */ 448 FWP_MAP.map.on('viewreset', function (e) { 449 // doRefresh('viewreset'); 450 }); 451 452 /* 453 * Leflet docs: Fired when the map is initialized (when its center and zoom are set for the first time). 454 */ 455 FWP_MAP.map.on('load', function (e) { 456 // doRefresh('load'); 457 FWP_MAP.mapHasMoved = false; 458 }); 459 460 461 } // End initialiseMap() 462 463 /** 464 * Called by listener on move start 465 * @param e 466 */ 467 function eventOnMoveStart(e) { 468 // console.log('Move start 1', FWP_MAP.trigger) 469 470 if (wp.hooks.applyFilters('rdp.showSpinner', FWP_MAP.is_filtering)) { // Activate the loading spinner early. 471 jQuery('.facetwp-type-rdposm_map').addClass('is-loading'); 472 } 473 474 let facetInfo = rdpActiveFacet(); 475 // console.log(facetInfo); 476 if (facetInfo.type !== null) { 477 FWP_MAP.trigger = { 478 type: facetInfo.type + ' : ' + facetInfo.name, 479 postID: FWP_MAP.trigger.postID, 480 refresh: FWP_MAP.trigger.refresh 481 } 482 } 483 FWP_MAP.prevZoom = FWP_MAP.map.getZoom(); 484 FWP_MAP.mapHasMoved = true; 485 if (!FWP_MAP.firstLoad && FWP_MAP.trigger.type !== 'browser' && FWP_MAP.trigger.type !== 'firstload') { 486 let pixelBounds = FWP_MAP.map.getPixelBounds(); 487 FWP_MAP.moveInfo.start = {x: pixelBounds.max.x, y: pixelBounds.max.y}; 488 } 489 switch (true) { 490 491 case FWP_MAP.firstLoad: 492 FWP_MAP.trigger = {type: 'firstload', postID: false, refresh: false} 493 break; 494 495 case FWP_MAP.mouseState === 'mousedown': 496 FWP_MAP.trigger = {type: 'mapdrag', postID: FWP_MAP.openedPopup, refresh: true} 497 break; 498 499 default: 500 } 501 /* 502 * Close markers unless opened by click marker or click listing or doing a mapdrag 503 */ 504 if (!FWP_MAP.trigger.postID) { 505 FWP_MAP.map.closePopup(); 506 } 507 // console.log('Move start 2', FWP_MAP.trigger) 508 509 } 510 511 /** 512 * Called by listener on move end 513 * @param e 514 */ 515 function eventOnMoveEnd(e) {
516 const newZoom = FWP_MAP.map.getZoom(); 517 let facetInfo = rdpActiveFacet(); 518 /* 519 * Check if we're zooming 520 */ 521 // console.log('Move End 1', FWP_MAP.trigger, facetInfo) 522 if (FWP_MAP.config.use_type === 'search' && 523 facetInfo.type !== 'proximity' && 524 !FWP_MAP.firstload && 525 FWP_MAP.map.getZoom() !== FWP_MAP.prevZoom && 526 FWP_MAP.trigger.refresh !== 'browsing') { 527 if ((FWP_MAP.trigger.type === 'listing' || FWP_MAP.trigger.type === 'zoomto') && FWP_MAP.map.getZoom() > FWP_MAP.prevZoom) { 528 FWP_MAP.trigger.refresh = true; 529 } else { 530 if (newZoom === FWP_MAP.initView.zoom) { 531 FWP_MAP.trigger = {type: 'zoom-reset', postID: FWP_MAP.openedPopup, refresh: true}; 532 } else { 533 FWP_MAP.trigger = { 534 type: (FWP_MAP.map.getZoom() > FWP_MAP.prevZoom ? 'zoom-in' : 'zoom-out'), 535 postID: FWP_MAP.openedPopup, 536 refresh: true 537 }; 538 } 539 } 540 } else { 541 FWP_MAP.trigger.refresh = false; 542 jQuery('.facetwp-type-rdposm_map').removeClass('is-loading'); 543 } 544 545 FWP_MAP.prevZoom = FWP_MAP.map.getZoom(); 546 547 548 if (!FWP_MAP.firstLoad && (FWP_MAP.trigger.type !== 'browser')) { 549 let pixelBounds = FWP_MAP.map.getPixelBounds(); 550 FWP_MAP.moveInfo.end = {x: pixelBounds.max.x, y: pixelBounds.max.y}; 551 FWP_MAP.moveInfo.dist = { 552 x: Math.abs(FWP_MAP.moveInfo.start.x - FWP_MAP.moveInfo.end.x), 553 y: Math.abs(FWP_MAP.moveInfo.start.y - FWP_MAP.moveInfo.end.y), 554 h: Math.hypot(FWP_MAP.moveInfo.start.x - FWP_MAP.moveInfo.end.x, FWP_MAP.moveInfo.start.y - FWP_MAP.moveInfo.end.y) 555 } 556 } 557 558 if (FWP_MAP.trigger.refresh === true) { 559 doRefresh(facetInfo); 560 } 561 // console.log('Move End 2', FWP_MAP.trigger) 562 if (FWP_MAP.trigger.type === 'zoom-in') { 563 //console.log(FWP_MAP.trigger); 564 jQuery('.facetwp-type-rdposm_map').removeClass('is-loading'); 565 } 566 567 } 568 569 /** 570 * Called when reset is clicked 571 */ 572 function actionOnResetClicked() { 573 let facetInfo = rdpActiveFacet(); 574 575 if (facetInfo.type === 'reset') { 576 FWP_MAP.trigger = {type: 'reset', postID: false, refresh: true}; 577 let presetFilters = FWP_MAP.config.preset_filters; 578 $.each(FWP.facet_type, function (type, name) { 579 if ('rdposm_map' === type) { 580 FWP.frozen_facets[name] = 'hard'; 581 } 582 }); 583 584 rdpResetMuteToggles(); 585 const resetFacets = FWP_MAP.config.reset_facets; 586 587 /* 588 * Reset filters to defaults if required 589 */ 590 for (const filterName in presetFilters) { 591 592 const foundReset = resetFacets.find(element => element === filterName); 593 594 if (FWP_MAP.mapReset && foundReset === filterName && FWP.facet_type[foundReset] !== 'proximity') { 595 FWP.facets[filterName] = emptify(presetFilters[filterName]); 596 } else { 597 FWP.facets[filterName] = presetFilters[filterName]; 598 } 599 } 600 } 601 } 602 603 /** 604 * Called when map is refreshed 605 * @param $this 606 * @param facet_name 607 */ 608 function actionOnMapRefresh($this, facet_name) { 609 610 let selected_values = []; 611 612 if (FWP_MAP.is_filtering && 'undefined' !== typeof FWP_MAP.map) { 613 let bounds = FWP_MAP.map.getBounds(); 614 615 selected_values = [bounds._southWest.lat, bounds._southWest.lng, bounds._northEast.lat, bounds._northEast.lng]; 616 } 617 618 FWP.facets[facet_name] = selected_values; 619 FWP.frozen_facets[facet_name] = 'hard'; 620 } 621 622 623 /** 624 * Process bounds 625 */ 626 function processBounds() { 627 628 // const has_locations = typeof FWP.settings.rdposm_map.locations === 'undefined' || FWP.settings.rdposm_map.locations.length > 0; 629 const has_locations = typeof FWP.settings.rdposm_map.locations !== 'undefined' && FWP.settings.rdposm_map.locations.length > 0; 630 631 632 let fit_bounds = FWP.hooks.applyFilters('facetwp_map/fit_bounds', !FWP_MAP.is_filtering); 633 634 /* 635 * Update map when filtering is off 636 * Either with bounds, or defaults 637 */ 638 639 let facetInfo = rdpActiveFacet(); 640 641 if ((fit_bounds && has_locations) || FWP_MAP.firstLoad) { 642 /* 643 * Get bounds from data 644 */ 645 646 const dataBounds = getDataBounds(); 647 const latBAdj = (dataBounds._northEast.lat - dataBounds._southWest.lat) * FWP_MAP.config.boun
647ds_expand; 648 const lngBAdj = (dataBounds._northEast.lng - dataBounds._southWest.lng) * FWP_MAP.config.bounds_expand; 649 const mapBounds = [[dataBounds._southWest.lat - latBAdj, dataBounds._southWest.lng - lngBAdj], [dataBounds._northEast.lat + latBAdj, dataBounds._northEast.lng + lngBAdj]]; 650 651 // console.log(FWP_MAP.config.bounds_expand); 652 // console.log(dataBounds); 653 // console.log(latBAdj,lngBAdj); 654 // console.log(mapBounds); 655 FWP_MAP.map.fitBounds(mapBounds); 656 657 } else if (!FWP_MAP.is_filtering && (0 !== FWP_MAP.config.default_lat || 0 !== FWP_MAP.config.default_lng) && FWP.settings.rdposm_map.locations !== false) { 658 FWP_MAP.map.setView([parseFloat(FWP_MAP.config.default_lat), parseFloat(FWP_MAP.config.default_lng)], FWP_MAP.config.default_zoom); 659 FWP_MAP.is_zooming = true; 660 661 } else if (facetInfo.type === 'proximity') { 662 663 const radius = parseInt(FWP.facets[facetInfo.name][2]); 664 // This is inexact as the size and shape of the map could have some impact, but it should be sufficient 665 let zoom = 8; // 100km radius 666 switch (true) { 667 case (radius <= 1): 668 zoom = 15; 669 break; 670 case (radius <= 2): 671 zoom = 14; 672 break; 673 case (radius <= 5): 674 zoom = 13; 675 break; 676 case (radius <= 10): 677 zoom = 12; 678 break; 679 case (radius <= 20): 680 zoom = 11; 681 break; 682 case (radius <= 50): 683 zoom = 10; 684 break; 685 } 686 687 if (FWP.facets[facetInfo.name].length === 0 || isNaN(radius)) { 688 FWP_MAP.map.setView(FWP_MAP.initView.centre, FWP_MAP.initView.zoom); 689 FWP_MAP.trigger = {type: 'proximity-reset', postID: false, refresh: true}; 690 FWP_MAP.proximityActive = false; 691 692 } else { 693 FWP_MAP.map.setView([parseFloat(FWP.facets[facetInfo.name][0]), parseFloat(FWP.facets[facetInfo.name][1])], zoom); 694 FWP_MAP.proximityActive = true; 695 } 696 697 } else if (facetInfo.type === 'reset') { 698 if (FWP_MAP.proximityActive) { 699 // TODO: Reset markers 700 } 701 FWP_MAP.map.setView(FWP_MAP.initView.centre, FWP_MAP.initView.zoom); 702 FWP_MAP.is_zooming = true; 703 704 } 705 if (FWP_MAP.firstLoad && FWP_MAP.config.override_initial_zoom_level) { 706 FWP_MAP.map.setZoom(FWP_MAP.config.override_initial_zoom_level); 707 } 708 709 // console.log(FWP_MAP.trigger) 710 return has_locations; 711 } 712 713 /** 714 * Refresh 715 */ 716 function doRefresh(facetInfo) { 717 if (FWP_MAP.trigger.refresh) { 718 const mapContainerSize = FWP_MAP.map.getSize(); 719 const xMovePercent = 100 * FWP_MAP.moveInfo.dist.x / mapContainerSize.x; 720 const yMovePercent = 100 * FWP_MAP.moveInfo.dist.y / mapContainerSize.y; 721 const doAutoload = (FWP_MAP.is_filtering && !FWP_MAP.is_zooming && Math.max(xMovePercent, yMovePercent) > FWP_MAP.config.move_allowance); 722 723 if (wp.hooks.applyFilters('rdp.doAutoload', doAutoload)) { 724 console.log(FWP_MAP); 725 wp.hooks.doAction('rdp.beforeAutoload'); 726 // if ('undefined' !== typeof hcx_submit) { 727 // hcx_submit.submitData(); 728 // } 729 FWP.autoload(); 730 } 731 } 732 733 FWP_MAP.is_zooming = false; 734 735 } 736 737 738 /** 739 * Reset markers layer if necessary 740 */ 741 function updateMarkersLayer(update_markers) { 742 let facetInfo = rdpActiveFacet(); 743 if (FWP_MAP.trigger.type === 'proximity-reset') { 744 FWP_MAP.map.closePopup(); 745 } else if (!(facetInfo.type === null || facetInfo.type === 'rdposm_map')) { 746 FWP_MAP.trigger = {type: facetInfo.type + ':' + facetInfo.name, postID: false, refresh: true}; 747 FWP_MAP.map.closePopup(); 748 } 749 750 FWP_MAP.is_zooming = false;
751 if (update_markers) { 752 resetMarkers(); 753 addMarkersLayer(); 754 } 755 756 if (FWP_MAP.muteState.button !== 'all') { 757 rdpSetMuteClasses(FWP_MAP.muteState.button, FWP_MAP.muteState.state.mt, FWP_MAP.muteState.state.ms) 758 } else { 759 rdpResetMuteToggles(); 760 } 761 762 // console.log('*** TRIGGER:', FWP_MAP.trigger.type); 763 // console.log('Update Markers', FWP_MAP.trigger) 764 765 } 766 767 function resetMarkers() { 768 FWP_MAP.markersLayer.clearLayers() 769 FWP_MAP.map.removeLayer(FWP_MAP.markersLayer) 770 FWP_MAP.markersArray = []; 771 FWP_MAP.markerLookup = []; 772 773 } 774 775 /** 776 * 777 */ 778 function resetTrackers() { 779 FWP_MAP.trigger = {type: '', postID: false, refresh: true}; 780 FWP_MAP.mapHasMoved = false; 781 FWP_MAP.openedPopup = false; 782 FWP_MAP.hasOpenPopup = false; 783 } 784 785 /** 786 * 787 */ 788 function resetPopups() { 789 FWP_MAP.openedPopup = false; 790 FWP_MAP.hasOpenPopup = false; 791 FWP_MAP.map.closePopup(); 792 } 793 794 /** 795 * Not used. Nitt sure why it's here! 796 * @param query_string 797 */ 798 function resetHash(query_string) { 799 if ('' !== query_string) { 800 query_string = '?' + query_string; 801 } 802 803 if (history.pushState) { 804 history.pushState(null, null, window.location.pathname + query_string); 805 } 806 807 // Update FWP_HTTP.get 808 FWP_HTTP.get = {}; 809 window.location.search.replace('?', '').split('&').forEach((el) => { 810 var item = el.split('='); 811 812 if ('' !== item[0]) { 813 FWP_HTTP.get[item[0]] = item[1]; 814 } 815 }); 816 } 817 818 819 /** 820 * 821 */ 822 function intilialiseMarkersLayer() { 823 /* 824 * Intialise markers cluster group layer 825 */ 826 827 if (FWP_MAP.config.clusterise) { 828 829 /* 830 * Initialise clusters layer 831 *
832 * Without the disableClusteringAtZoom and no zoom to marker, 833 * markers on the same point are clustered but selecting a listing doesn't show the popup 834 * With it, they overlap and can't be individually selected 835 * No solution yet. Maybe just have to decide which is preferable 836 */ 837 FWP_MAP.markersLayer = L.markerClusterGroup({ 838 showCoverageOnHover: false, 839 maxClusterRadius: FWP_MAP.config.cluster_radius, 840 disableClusteringAtZoom: FWP_MAP.config.disable_clustering_zoom, 841 spiderfyOnMaxZoom: false, 842 removeOutsideVisibleBounds: true 843 }); 844 845 /* 846 * Zoom to cluster when clicked 847 * 848 */ 849 FWP_MAP.markersLayer.on('clusterclick', function (a) { 850 /// this breaks and redraws or shows clusters even when filtered if disableClusteringAtZoom not set 851 if ('undefined' !== typeof FWP_MAP.markersLayer.options.disableClusteringAtZoom) { 852 } 853 FWP_MAP.trigger = {type: 'cluster', postID: false, refresh: true}; 854 }); 855 } else { 856 FWP_MAP.markersLayer = L.layerGroup(); 857 } 858 859 } 860 861 /** 862 * 863 * @returns {*} 864 */ 865 function addMarkersLayer() { 866 867 /* 868 * Clear spiderfy markers 869 */ 870 FWP_MAP.oms.clearMarkers(); 871 872 /* 873 * Loop thru each location and create marker 874 */ 875 $.each(FWP.settings.rdposm_map.locations, function (loc, idx) { 876 877 /* 878 * Set local args variable (This is the way Facet did it) 879 */ 880 let args = Object.assign({}, loc); 881 args.map = FWP_MAP.map; 882 883 /* 884 * Only include locations with valid lat,lng 885 * Note: This does not remove them from the search queries 886 * https://support.advancedcustomfields.com/forums/topic/query-posts-by-custom-field-google-map/ 887 */ 888 if (validLatLng(loc.position.lat, loc.position.lng) && null !== args.type) { 889 890 let marker = createMarker(loc, args) 891 892 /* 893 * Add the marker to the markers layer 894 */ 895 FWP_MAP.markersLayer.addLayer(marker); 896 897 /* 898 * Add marker to markers lookup object (based on post ID) 899 */ 900 if ('undefined' !== typeof FWP_MAP.markerLookup[loc.post_id]) { 901 FWP_MAP.markerLookup[loc.post_id].push([idx, marker]); 902 } else { 903 FWP_MAP.markerLookup[loc.post_id] = [[idx, marker]]; 904 } 905 906 } else { 907 console.log('Listing has no coords: '+loc.post_id,loc) 908 } 909 }); // End create markers 910 911 /* 912 * Add markers layer to the map 913 */ 914 FWP_MAP.map.addLayer(FWP_MAP.markersLayer) 915 916 /* 917 * Show popup again if there is one and it's still on the map 918 */ 919 920 if (FWP_MAP.trigger.postID > 0 && typeof FWP_MAP.markerLookup[FWP_MAP.trigger.postID] !== 'undefined') { 921 let m = FWP_MAP.markerLookup[FWP_MAP.trigger.postID][0][1]; 922 rdpPopupOpen(m, FWP_MAP.trigger.postID); 923 } else { 924 FWP_MAP.trigger.postID = false; 925 } 926 } 927 928 929 /** 930 * Get data bounds of current markers 931 */ 932 function getDataBounds() { 933 let c; 934 if (FWP.settings.rdposm_map.locations.length > 0) { 935 let loc = FWP.settings.rdposm_map.locations[0] 936 /* 937 * Set initial boundaries from first marker 938 */ 939 c = { 940 northernLat: loc.position.lat, 941 southernLat: loc.position.lat, 942 easternLng: loc.position.lng, 943 westernLng: loc.position.lng 944 }; 945 /* 946 * If more than one marker, calculate boundaries using each 947 */ 948 if (FWP.settings.rdposm_map.locations.length > 1) { 949 $.each(FWP.settings.rdposm_map.locations, function (loc, idx) { 950 if (validLatLng(loc.position.lat, loc.position.lng)) { 951 /* 952 * Update max/min lat and lng 953 */ 954 c.northernLat = Math.max(loc.position.lat, c.northernLat); // maxLat 955 c.southernLat = Math.min(loc.position.lat, c.southernLat); // minLat 956 c.easternLng = Math.max(loc.position.lng, c.easternLng); // maxLng 957 c.westernLng = Math.min(loc.position.lng, c.westernLng); // minLng 958 } 959 }); 960 } 961 } else { 962 let b = FWP_MAP.map.getBounds(); 963 c = { 964 northernLat: b._northEast.lat, 965 southernLat: b._southWest.lat, 966 easternLng: b._northEast.lng, 967 westernLng: b._southWest.lng 968 }; 969 } 970 971 return { 972 _southWest: {lat: c.southernLat, lng: c.westernLng}, 973 _northEast: {lat: c.northernLat, lng: c.easternLng} 974 }; 975 } 976 977 /** 978 * Validate latitude and longitude. Note: For our purposes, if they're zero that indicates a problem 979 * @param lat 980 * @param lng 981 * @returns {boolean} 982 */ 983 function validLatLng(lat, lng) { 984 return Math.abs(lat) > 0 && Math.abs(lat) <= 90 && Math.abs(lng) > 0 && Math.abs(lng) <= 180; 985 } 986 987 /** 988 * 989 * @param loc 990 * @param args 991 * @returns {*} 992 */ 993 function createMarker(loc, args) { 994 let type = args.type.toLowerCase(); 995 let iconOptions = L.ExtraMarkers.icon({ 996 icon: 'fa-' + loc.marker.icon,
997 markerColor: loc.marker.colour, 998 shape: 'circle', 999 prefix: 'fa-solid', 1000 svg: true, 1001 iconSize: [28, 42], 1002 iconAnchor: [11, 37], 1003 shadowAnchor: [7, 10], 1004 shadowSize: [39, 24], // bizzarely, increasing this reduces the size 1005 className: 'marker-type marker-type-' + type + ' marker-id-' + args.post_id 1006 }); 1007 1008 let marker = new L.marker([loc.position.lat, loc.position.lng], {icon: iconOptions}); 1009 1010 FWP_MAP.oms.addMarker(marker); 1011 1012 /* 1013 * Populate popup when marker is clicked 1014 */ 1015 marker.on('click', function (m) { 1016 rdpClickMarker(m, args); 1017 }); 1018 1019 1020 return marker; 1021 } 1022 1023 /** 1024 * 1025 * @param facets 1026 */ 1027 function resetFacets(facets) { 1028 for (const key in facets) { 1029 const facet = facets[key]; 1030 if (facet !== '') { 1031 FWP.facets[facet] = emptify(FWP.facets[facet]); 1032 FWP.fetchData() 1033 } 1034 } 1035 } 1036 1037 /** 1038 * Return a variable's null value 1039 * @param value 1040 * @returns {null} 1041 */ 1042 function emptify(value) { 1043 let r = null; 1044 if (Array.isArray.value) { 1045 r = []; 1046 } else { 1047 switch (typeof value) { 1048 case "boolean": 1049 r = false; 1050 break; 1051 case "number": 1052 r = 0; 1053 break; 1054 case "string": 1055 r = ''; 1056 break; 1057 case "object": 1058 r = {}; 1059 break; 1060 } 1061 } 1062 return r; 1063 } 1064 1065 1066}) 1067(fUtil); 1068 1069/***************************************************************************************************** 1070 * GLOBAL FUNCTIONS 1071 * **************************************************************************************************/ 1072 1073 1074/** 1075 * 1076 * @param m 1077 * @param args 1078 */ 1079function rdpClickMarker(m, args) { 1080 FWP_MAP.trigger = {type: 'marker', postID: args.post_id, refresh: false}; 1081 rdpPopupOpen(m.target, args.post_id, args.title, args.content); 1082 // console.log('*** TRIGGER:', FWP_MAP.trigger.type); 1083 // console.log('Marker clicked', FWP_MAP.trigger); 1084 wp.hooks.doAction('rdp.clickMarker', {m: m.target, id: args.post_id}); 1085 1086 // if (typeof hcx_submit !== 'undefined' && typeof hcx_submit.scrollToItem === 'function') { 1087 // hcx_submit.scrollToItem(args.post_id) 1088 // } 1089 1090} 1091 1092/** 1093 * On clicking a listing, go to it on the map and show its popup 1094 * 1095 * @param id 1096 */ 1097function rdpSelectListing(id) { 1098 FWP_MAP.trigger = {type: 'listing', postID: id, refresh: !FWP_MAP.config.disable_zoom_to_listing}; 1099 1100 if ('undefined' === typeof FWP_MAP.markerLookup[id]) { 1101 console.log('Error: Could not find popup for post id: ' + id); 1102 } else { 1103 let m = FWP_MAP.markerLookup[id][0][1]; 1104 1105 1106 FWP_MAP.map.closePopup(); 1107 1108 if (FWP_MAP.config.disable_zoom_to_listing && !FWP_MAP.config.cluster) { 1109 FWP_MAP.map.setView([m._latlng.lat, m._latlng.lng]); 1110 } else { 1111 let zoomTo = Math.max(FWP_MAP.map.getZoom(), FWP_MAP.config.listing_zoom_level); 1112 FWP_MAP.map.setView([m._latlng.lat, m._latlng.lng], zoomTo); 1113 } 1114 1115 rdpPopupOpen(m, id); 1116 1117 let scrollTo = jQuery(".rdp-tab-container"); 1118 if (scrollTo.length === 1) { 1119 jQuery('html,body').animate({scrollTop: scrollTo.offset().top - 50}, 'fast'); 1120 } else { 1121 scrollTo = jQuery("#rdposm-map-facet"); 1122 /* Not doing this yet as might interfere with Karl's */ 1123 // jQuery('html,body').animate({scrollTop: scrollTo.offset().top - 50}, 'fast'); 1124 } 1125 1126 wp.hooks.doAction('rdp.selectListing', {m: m, id: id}); 1127 } 1128 // if (typeof toggle_map_list === 'function') { 1129 // toggle_map_list('Maptab'); 1130 // rdpPopupOpen(m,id); 1131 // } 1132} 1133 1134/** 1135 * 1136 * @param id 1137 */ 1138function rdpZoomToMarker(id) { 1139 FWP_MAP.trigger = {type: 'zoomto', postID: id, refresh: true}; 1140 FWP_MAP.oms.unspiderfy();
1141 let m = FWP_MAP.markerLookup[id][0][1]; 1142 1143 let zoomTo = Math.max(FWP_MAP.map.getZoom(), FWP_MAP.config.listing_zoom_level); 1144 if (FWP_MAP.map.getZoom() === FWP_MAP.config.listing_zoom_level) { 1145 zoomTo = FWP_MAP.initView.zoom; 1146 } 1147 1148 FWP_MAP.map.setView([m._latlng.lat, m._latlng.lng], zoomTo); 1149 1150 wp.hooks.doAction('rdp.zoomToMarker', {m: m, id: id}); 1151 1152 // if (typeof toggle_map_list === 'function') { 1153 // toggle_map_list('Maptab'); 1154 // } 1155} 1156 1157/** 1158 * 1159 * @param m 1160 * @param id 1161 * @param title 1162 * @param content 1163 */ 1164function rdpPopupOpen(m, id, title = '', content = '') { 1165 let p; 1166 if (typeof FWP_MAP.popups['id-' + id] !== 'undefined') { 1167 m.closePopup() 1168 m.unbindPopup() 1169 m.bindPopup(FWP_MAP.popups['id-' + id]._popup, { 1170 autoPan: true, 1171 closeButton: false, 1172 closeOnClick: true, 1173 className: 'rdp-popup rdp-popup-' + id 1174 }).openPopup() 1175 } 1176 1177 p = m.getPopup(); 1178 1179 if (!m.isPopupOpen()) { 1180 if ('undefined' !== typeof p) { 1181 if (typeof p.openPopup === 'function') { 1182 p.openPopup(); 1183 } else if (typeof m.openPopup === 'function') { 1184 m.openPopup(); 1185 } else { 1186 console.log('Popup might be broken'); 1187 } 1188 } else { 1189 rdpPopupGet(m, id, FWP_JSON.rdposm_map.ajaxurl, FWP_JSON.rdposm_map.facet_name, title, content) 1190 } 1191 } 1192 1193 FWP_MAP.hasOpenPopup = true; 1194 FWP_MAP.openedPopup = id; 1195 1196} 1197 1198/** 1199 * 1200 * @param m 1201 * @param id 1202 * @param url 1203 * @param facet 1204 * @param title 1205 * @param content 1206 */ 1207function rdpPopupGet(m, id, url, facet, title, content) { 1208 if (typeof id !== 'undefined' && id !== null && id) { 1209 //console.log(m, id, url, facet); 1210 m.bindPopup('<div>Loading...</div>', {autoPan: true, closeButton: false}).openPopup(); 1211 jQuery.ajax({ 1212 type: 'POST', 1213 url: url, 1214 data: { 1215 action: 'rdposm_map_marker_content', 1216 facet_name: facet, 1217 post_id: id 1218 }, success: function (result) { 1219 m.closePopup(); 1220 m.unbindPopup(); 1221 /* 1222 * Add the popup to the marker 1223 */ 1224 m.bindPopup(result, { 1225 autoPan: true, 1226 closeButton: false, 1227 closeOnClick: true, 1228 className: 'rdp-popup rdp-popup-' + id 1229 }).openPopup(); 1230 FWP_MAP.popups['id-' + id] = Object.assign({}, m); 1231 }, 1232 error: function () { 1233 m.closePopup(); 1234 m.unbindPopup(); 1235 // m.bindPopup('<div>Not loaded. Try again</div>', {keepInView: true}).openPopup(); 1236 } 1237 }); 1238 1239 } else { 1240 console.log(m, title, content); 1241 // This is needed if ever using proximity markers which don't have IDs 1242 let popupContent = '<div class="rdposm-mf-popup"><div class="rdposm-mf-popup-main"><div class="rdposm-mf-popup-content"><h5 class="rdposm-mf-popup-title">' + title + '</h5><p class="rdposm-mf-popup-address">' + content + '</p></div></div><div class="rdposm-icon-band"><div class="rdposm-popup-icons rdposm-popup-close close-9999999" onclick="rdpPopupClose(9999999)" title="Close popup"><i class="fa-regular fa-xmark"></i></div></div>'; 1243 m.bindPopup(popupContent, { 1244 keepInView: true, 1245 closeButton: false, 1246 className: 'rdp-popup rdp-popup-9999999' 1247 }).openPopup(); 1248 1249 } 1250} 1251 1252/** 1253 * 1254 * @param id 1255 * @param caller 1256 */ 1257function rdpToggleWishlist(id, caller) { 1258 if (caller === 'popup') { 1259 let p = jQuery('.wish-' + id); 1260 let i = jQuery('.wish-' + id + ' i'); 1261 if (p.hasClass('wish-no')) { 1262 p.removeClass('wish-no'); 1263 p.addClass('wish-yes'); 1264 p.children('i').removeClass('fa-solid'); 1265 p.children('i').addClass('fa-solid'); 1266 } else { 1267 p.removeClass('wish-yes'); 1268 p.addClass('wish-no'); 1269 p.children('i').removeClass('fa-solid'); 1270 p.children('i').addClass('fa-solid'); 1271 } 1272 } 1273 1274 1275} 1276 1277/** 1278 * Close the popup. 1279 * This will trigger the event to handle other changes 1280 * @param id 1281 */ 1282function rdpPopupClose(id) { 1283 FWP_MAP.trigger = {type: 'idle', postID: false, refresh: false} 1284 FWP_MAP.openedPopup = false;
1285 FWP_MAP.hasOpenPopup = false; 1286 FWP_MAP.map.closePopup(); 1287} 1288 1289/** 1290 * 1291 * @returns {{name: null, type: null}|{name: *, type: *}} 1292 */ 1293function rdpActiveFacet() { 1294 if (null !== FWP.active_facet) { 1295 let facet = FWP.active_facet; 1296 return {name: facet.attr('data-name'), type: facet.attr('data-type')} 1297 } else { 1298 return {name: null, type: null}; 1299 } 1300 1301} 1302 1303/** 1304 * Toggle marker visibility 1305 * @param t 1306 */ 1307function rdpToggleMarkers(t) { 1308 let bs = jQuery('.btn-marker-type-' + t); 1309 let ms = jQuery('.marker-type-' + t); 1310 let mt = jQuery('.marker-type'); 1311 let bmt = jQuery('.btn-marker-type'); 1312 1313 FWP_MAP.oms.unspiderfy(); 1314 rdpPopupClose(); 1315 // FWP_MAP.map.closePopup(); 1316 1317 if (typeof t === 'undefined' || t === 'all') { 1318 // set all marker types opacity 1; 1319 rdpResetMuteToggles(); 1320 } else { 1321 1322 /* 1323 * Button pressed second time 1324 * Hide muted markers 1325 */ 1326 if (bs.hasClass('btn-selected')) { 1327 bs.removeClass('btn-selected'); 1328 rdpResetMuteToggles(); 1329 FWP_MAP.muteState = {button: 'all', state: {mt: [], ms: []}} 1330 } else { 1331 mt.removeClass('mt-mute').removeClass('mt-highlighted').removeClass('mt-hidden'); 1332 bmt.removeClass('btn-selected'); 1333 bs.addClass('btn-selected'); 1334 if (FWP_MAP.config.muting === 'colour') { 1335 rdpSetMuteClasses(t, ['mt-mute'], ['mt-highlighted']) 1336 FWP_MAP.muteState = {button: t, state: {mt: ['mt-mute'], ms: ['mt-highlighted']}} 1337 } else if (FWP_MAP.config.muting === 'hide') { 1338 rdpSetMuteClasses(t, ['mt-mute', 'mt-hidden'], ['mt-highlighted']) 1339 FWP_MAP.muteState = {button: t, state: {mt: ['mt-mute', 'mt-hidden'], ms: ['mt-highlighted']}} 1340 } 1341 } 1342 1343 } 1344} 1345 1346/** 1347 * 1348 * @param t 1349 * @param mtp 1350 * @param msp 1351 */ 1352function rdpSetMuteClasses(t, mtp, msp) { 1353 let mt = jQuery('.marker-type'); 1354 let ms = jQuery('.marker-type-' + t); 1355 for (let p of mtp) { 1356 mt.addClass(p) 1357 ms.removeClass(p) 1358 } 1359 for (let p of msp) { 1360 ms.addClass(p) 1361 } 1362} 1363 1364/** 1365 * 1366 */ 1367function rdpResetMuteToggles() { 1368 jQuery('.btn-marker-type').removeClass('btn-selected'); 1369 jQuery('.btn-marker-type-all').addClass('btn-selected'); 1370 jQuery('.marker-type').removeClass('mt-mute').removeClass('mt-highlighted').removeClass('mt-hidden'); 1371 FWP_MAP.muteState = {button: 'all', state: {mt: [], ms: []}} 1372} 1373 1374/** 1375 * 1376 */ 1377function rdposmInit() { 1378 1379 document.addEventListener('facetwp-refresh', function () { 1380 let facetInfo = rdpActiveFacet(); 1381 if (facetInfo.type === 'reset') { 1382 FWP_MAP.mapReset = false; 1383 } 1384 }); 1385} 1386 1387/** 1388 * 1389 * @param f : function name 1390 * @param p : prefix 1391 * @param t: show trigger info 1392 * @param a: set trigger to active facet 1393 */ 1394function fHeaderInfo(f, p = '', t = true, a = false) { 1395 return null; 1396 console.log('') 1397 p = p ? p : 'ð·'; 1398 let facetInfo = rdpActiveFacet(); 1399 console.log(p + ' FUNCTION:', f); 1400 console.log(facetInfo) 1401 if (a) { 1402 // FWP_MAP.trigger = {type: 'facet', postID: facetInfo.type + ' : ' + facetInfo.name}; 1403 } 1404 if (t) { 1405 console.log('ð¸Trigger: ', FWP_MAP.trigger) 1406 console.log('ð¸Active facet: ', facetInfo.name) 1407 } 1408 return facetInfo; 1409 1410} 1411 1412/** 1413 * 1414 * @param f 1415 * @returns {*} 1416 */ 1417function rdpGetFunctionName(f) { 1418 f = f.slice('function '.length); 1419 f = f.slice(0, f.indexOf('(')); 1420 return f; 1421} 1422 1423 1424/** 1425 * 1426 * @param lat1 1427 * @param lon1 1428 * @param lat2 1429 * @param lon2 1430 * @param R 1431 * @returns {number} 1432 */ 1433 1434/* This isn't needed!! Leaflet hass a method, distance, that does this */ 1435function rdpGetDistanceBetweenEarthPoints(lat1, lon1, lat2, lon2, R = 6371000) { 1436 // R== 6371000; // Radius of the earth in m 1437 1438 const dLat = rdpDeg2Rad(lat2 - lat1); // deg2rad below 1439 const dLon = rdpDeg2Rad(lon2 - lon1); 1440 const a = 1441 Math.sin(dLat / 2) * Math.sin(dLat / 2) + 1442 Math.cos(rdpDeg2Rad(lat1)) * Math.cos(rdpDeg2Rad(lat2)) * 1443 Math.sin(dLon / 2) * Math.sin(dLon / 2) 1444 ; 1445 const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); 1446 const d = R * c; // Distance in m 1447 return d; 1448} 1449 1450/** 1451 * 1452 * @param deg 1453 * @returns {number} 1454 */ 1455function rdpDeg2Rad(deg) { 1456 return deg * (Math.PI / 180) 1457} 1458 1459 1460function rdpListingHover() { 1461 const id = jQuery(this).data('id'); 1462 let ms = jQuery('.marker-id-' + id); 1463 let mt = jQuery('.marker-type'); 1464 1465 jQuery(mt).addClass('mt-mute') 1466 jQuery(ms).removeClass('mt-mute') 1467 1468} 1469 1470function rdpListingUnhover() { 1471 rdpResetMuteToggles(); 1472 1473 jQuery('.marker-type').removeClass('mt-mute') 1474} 1475 1476/** 1477 * Get location of device calling the page 1478 */ 1479function rdpGetLocation() { 1480 if (navigator.geolocation) { 1481 console.log(navigator.geolocation) 1482 navigator.geolocation.getCurrentPosition(rdpShowPosition, rdpShowGeoLocError); 1483 } else { 1484 FWP_MAP.userLocation = {error: 'Unsupported browser'} 1485 } 1486} 1487 1488/*** 1489 * @param position 1490 * @returns {{name: null, type: null}|{name: *, type: *}} 1491 */ 1492function rdpShowPosition(position) { 1493 console.log(position) 1494 1495 FWP_MAP.userLocation = {lat: position.coords.latitude, lng: position.coords.longitude} 1496 1497 FWP_MAP.userPip = L.circleMarker(FWP_MAP.userLocation, { 1498 radius: 7, 1499 color: '#ffffff', 1500 weight: 1, 1501 fillColor: '#0000dd', 1502 fillOpacity: 0.8 1503 }).addTo(FWP_MAP.map); 1504 // TODO: WHy this not work?! 1505// let userLocPopup = L.popup({lat: position.coords.latitude, lng: position.coords.longitude}, {content: '<p>Your location</p>'}).addTo(FWP_MAP.map); 1506} 1507 1508/** 1509 * 1510 * @param error 1511 */ 1512function rdpShowGeoLocError(error) { 1513 console.timeLog('From load') 1514 console.log(error) 1515 console.log(FWP_MAP.userLocation) 1516 FWP_MAP.userLocation = {error: error.message} 1517 console.log(FWP_MAP.userLocation); 1518}
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.