1var w2dc_draws = []; 2var w2dc_draw_features = []; 3 4//mapboxgl_edit.js ------------------------------------------------------------------------------------------------------------------------------------------- 5(function($) { 6 "use strict"; 7 8 window.w2dc_load_maps_api_backend = function() { 9 if ($("#w2dc-map-canvas").length) { 10 mapboxgl.accessToken = w2dc_maps_objects.mapbox_api_key; 11 w2dc_map_backend = new mapboxgl.Map({ 12 container: "w2dc-map-canvas", 13 style: w2dc_maps_objects.map_style 14 }); 15 if (w2dc_js_objects.is_rtl) { 16 mapboxgl.setRTLTextPlugin('https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.10.1/mapbox-gl-rtl-text.js'); 17 } 18 if (typeof MapboxLanguage != "undefined") { 19 var options = {}; 20 if (w2dc_js_objects.lang) { 21 options = { defaultLanguage: w2dc_js_objects.lang}; 22 } 23 w2dc_map_backend.addControl(new MapboxLanguage(options)); 24 } 25 var navigationControl = new mapboxgl.NavigationControl({ 26 showCompass: false, 27 showZoom: true, 28 }); 29 w2dc_map_backend.addControl(navigationControl); 30 31 if (w2dc_isAnyLocation_backend()) { 32 w2dc_generateMap_backend(); 33 } else { 34 w2dc_map_backend.setCenter([w2dc_maps_objects.default_longitude, w2dc_maps_objects.default_latitude]); 35 } 36 37 w2dc_map_backend.on('zoom', function() { 38 if (w2dc_allow_map_zoom_backend) { 39 $(".w2dc-map-zoom").val(Math.round(w2dc_map_backend.getZoom())); 40 } 41 }); 42 43 } 44 w2dc_setupAutocomplete(); 45 } 46 47 window.w2dc_collect_locations_predictions = function(predictions, autocomplete_input, place_id_input) { 48 autocomplete_input.next(".w2dc-mapbox-suggestions").remove(); 49 50 var menu_ul = $("<ul />") 51 .addClass("w2dc-mapbox-suggestions"); 52 53 $.map(predictions, function (prediction, i) { 54 var menu_li = $("<li>") 55 .addClass("w2dc-mapbox-suggestions-item") 56 .prop("data-value", prediction.value) 57 .prop("data-place-id", prediction.place_id) 58 .text(prediction.label+' - '+prediction.sublabel); 59 60 menu_ul.append(menu_li); 61 62 menu_li.on("click", function(e) { 63 $(this).focus(); 64 autocomplete_input.val($(this).prop("data-value")); 65 place_id_input.val($(this).prop("data-place-id")); 66 67 autocomplete_input.next(".w2dc-mapbox-suggestions").remove(); 68 }); 69 }); 70 71 autocomplete_input.after(menu_ul); 72 73 $('html').on("click", function(e) { 74 if (!menu_ul.is(e.target) && menu_ul.has(e.target).length === 0) { 75 autocomplete_input.next(".w2dc-mapbox-suggestions").remove(); 76 } 77 }); 78 } 79 80 window.w2dc_setupAutocomplete = function() { 81 82 $(".w2dc-listing-field-autocomplete").each( function() { 83 var autocomplete_input = $(this); 84 var place_id_input = autocomplete_input.parent().find(".w2dc-place-id-input"); 85 86 autocomplete_input 87 .on("click change paste keyup", function() { 88 if ($(this).val() == '') { 89 place_id_input.val(''); 90 } else { 91 var term = $(this).val(); 92 93 if (!autocomplete_input.next(".w2dc-mapbox-suggestions").length) { 94 w2dc_autocompleteService(term, w2dc_maps_objects.address_autocomplete_code, autocomplete_input, place_id_input, w2dc_collect_locations_predictions); 95 } 96 } 97 }); 98 }); 99 } 100 101 function w2dc_setMapCenter_backend(w2dc_coords_array_1, w2dc_coords_array_2) { 102 var count = 0; 103 var bounds = new mapboxgl.LngLatBounds(); 104 for (count == 0; count<w2dc_coords_array_1.length; count++) { 105 bounds.extend([w2dc_coords_array_2[count], w2dc_coords_array_1[count]]); 106 } 107 if (count == 1) { 108 // required workaround: first zoom, then setCenter for initial load when single marker 109 if ($(".w2dc-map-zoom").val() == '' || $(".w2dc-map-zoom").val() == 0) { 110 var zoom_level = 1; 111 } else { 112 var zoom_level = parseInt($(".w2dc-map-zoom").val()); 113 } 114 115 // allow/disallow map zoom in listener, this option needs because w2dc_map.setZoom() also calls this listener 116 w2dc_allow_map_zoom_backend = false; 117 w2dc_map_backend.setZoom(zoom_level); 118 w2dc_allow_map_zoom_backend = true; 119 120 w2dc_map_backend.setCenter([w2dc_coords_array_2[0], w2dc_coords_array_1[0]]); 121 } else { 122 w2dc_map_backend.fitBounds(bounds, {padding: 50, duration: 0}); 123 } 124 } 125 126 var w2dc_coords_array_1 = new Array(); 127 var w2dc_coords_array_2 = new Array(); 128 var w2dc_attempts = 0; 129 window.w2dc_generateMap_backend = function() { 130 w2dc_ajax_loader_target_show($("#w2dc-map-canvas")); 131 w2dc_coords_array_1 = new Array(); 132 w2dc_coords_array_2 = new Array(); 133 w2dc_attempts = 0; 134 w2dc_clearOverlays_backend(); 135 w2dc_geocodeAddress_backend(0); 136 } 137 138 function w2dc_setFoundPoint(point, location_obj, i) { 139 $(".w2dc-map-coords-1:eq("+i+")").val(point.lat); 140 $(".w2dc-map-coords-2:eq("+i+")").val(point.lng); 141 var map_coords_1 = point.lat; 142 var map_coords_2 = point.lng; 143 w2dc_coords_array_1.push(map_coords_1); 144 w2dc_coords_array_2.push(map_coords_2); 145 location_obj.setPoint(point); 146 location_obj.w2dc_placeMarker(); 147 w2dc_geocodeAddress_backend(i+1); 148 149 if ((i+1) == $(".w2dc-location-in-metabox").length) { 150 w2dc_setMapCenter_backend(w2dc_coords_array_1, w2dc_coords_array_2); 151 w2dc_ajax_loader_target_hide("w2dc-map-canvas"); 152 } 153 } 154 155 function w2dc_validateLatitude(lat) { 156 if ($.isNumeric(lat)) { 157 if (lat >= -90 && lat <= 90) { 158 return lat; 159 } else { 160 alert("Invalid latitude value: must be between -90 and 90"); 161 } 162 } 163 } 164 function w2dc_validateLongitude(lng) { 165 if ($.isNumeric(lng)) { 166 if (lng >= -180 && lng <= 180) { 167 return lng; 168 } else { 169 alert("Invalid longitude value: must be between -180 and 180"); 170 } 171 } 172 } 173 174 window.w2dc_geocodeAddress_backend = function(i) { 175 if ($(".w2dc-location-in-metabox:eq("+i+")").length) { 176 var locations_drop_boxes = []; 177 $(".w2dc-location-in-metabox:eq("+i+")").find("select").each(function(j, val) { 178 if ($(this).val()) 179 locations_drop_boxes.push($(this).children(":selected").text()); 180 }); 181 182 var location_string = locations_drop_boxes.reverse().join(', '); 183 184 if ($(".w2dc-manual-coords:eq("+i+")").is(":checked") && $(".w2dc-map-coords-1:eq("+i+")").val()!='' && $(".w2dc-map-coords-2:eq("+i+")").val()!='' && ($(".w2dc-map-coords-1:eq("+i+")").val()!=0 || $(".w2dc-map-coords-2:eq("+i+")").val()!=0)) { 185 var map_coords_1 = $(".w2dc-map-coords-1:eq("+i+")").val(); 186 var map_coords_2 = $(".w2dc-map-coords-2:eq("+i+")").val(); 187 if (w2dc_validateLatitude(map_coords_1) && w2dc_validateLongitude(map_coords_2)) { 188 var point = new mapboxgl.LngLat(map_coords_2, map_coords_1); 189 w2dc_coords_array_1.push(map_coords_1); 190 w2dc_coords_array_2.push(map_coords_2); 191 192 var location_obj = new w2dc_glocation_backend(i, point, 193 location_string, 194 $(".w2dc-address-line-1:eq("+i+")").val(), 195 $(".w2dc-address-line-2:eq("+i+")").val(), 196 $(".w2dc-zip-or-postal-index:eq("+i+")").val(), 197 $(".w2dc-map-icon-file:eq("+i+")").val() 198 ); 199 location_obj.w2dc_placeMarker(); 200 } 201 w2dc_geocodeAddress_backend(i+1); 202 if ((i+1) == $(".w2dc-location-in-metabox").length) { 203 w2dc_setMapCenter_backend(w2dc_coords_array_1, w2dc_coords_array_2); 204 w2dc_ajax_loader_target_hide("w2dc-map-canvas"); 205 } 206 } else if (location_string || $(".w2dc-address-line-1:eq("+i+")").val() || $(".w2dc-address-line-2:eq("+i+")").val() || $(".w2dc-zip-or-postal-index:eq("+i+")").val()) { 207 var location_obj = new w2dc_glocation_backend(i, null, 208 location_string, 209 $(".w2dc-address-line-1:eq("+i+")").val(), 210 $(".w2dc-address-line-2:eq("+i+")").val(), 211 $(".w2dc-zip-or-postal-index:eq("+i+")").val(), 212 $(".w2dc-map-icon-file:eq("+i+")").val() 213 ); 214 215 // Geocode by address 216 function _w2dc_geocodeAddress_backend(status, lat, lng) { 217 if (status) { 218 w2dc_setFoundPoint(new mapboxgl.LngLat(lng, lat), location_obj, i); 219 } else { 220 alert("Sorry, we are unable to geocode address (address line: "+location_obj.compileAddress()+" #"+(i)+")"); 221 w2dc_ajax_loader_target_hide("w2dc-map-canvas"); 222 } 223 } 224 225 w2dc_geocodeAddress(location_obj.compileAddress(), _w2dc_geocodeAddress_backend, w2dc_maps_objects.address_autocomplete_code); 226 } else 227 w2dc_ajax_loader_target_hide("w2dc-map-canvas"); 228 } 229 } 230 231 window.w2dc_placeMarker_backend = function(w2dc_glocation) { 232 if (w2dc_maps_objects.map_markers_type != 'icons') { 233 if (w2dc_maps_objects.global_map_icons_path != '') { 234 var re = /(?:\.([^.]+))?$/; 235 if (w2dc_glocation.map_icon_file && typeof re.exec(w2dc_maps_objects.global_map_icons_path+'icons/'+w2dc_glocation.map_icon_file)[1] != "undefined") 236 var icon_file = w2dc_maps_objects.global_map_icons_path+'icons/'+w2dc_glocation.map_icon_file; 237 else 238 var icon_file = w2dc_maps_objects.global_map_icons_path+"blank.png"; 239 240 var el = $("<div>", { 241 id: 'marker-id-'+w2dc_glocation.index, 242 style: 'background-image: url('+icon_file+'); width: '+parseInt(w2dc_maps_objects.marker_image_width)+'px; height: '+parseInt(w2dc_maps_objects.marker_image_height)+'px', 243 class: 'w2dc-mapbox-marker' 244 }); 245 var marker_div = el[0]; 246 247 var marker_options = { 248 anchor: 'bottom', 249 offset: [0, -20], 250 element: marker_div, 251 draggable: true 252 }; 253 254 var popup = new mapboxgl.Popup({ offset: 25 }) 255 .setText(w2dc_glocation.compileAddress()); 256 257 var marker = new mapboxgl.Marker(marker_options) 258 .setLngLat(w2dc_glocation.point) 259 .addTo(w2dc_map_backend) 260 .setPopup(popup); 261 } else { 262 var marker = new mapboxgl.Marker() 263 .setLngLat(location.point) 264 .addTo(w2dc_map_backend); 265 } 266 } else { 267 var map_marker_color = w2dc_maps_objects.default_marker_color; 268 269 if (typeof w2dc_glocation.map_icon_file == 'string' && w2dc_glocation.map_icon_file.indexOf("w2dc-fa-") != -1) { 270 var map_marker_icon = '<span class="w2dc-map-marker-icon w2dc-fa '+w2dc_glocation.map_icon_file+'" style="color: '+map_marker_color+';"></span>'; 271 var map_marker_class = 'w2dc-map-marker'; 272 } else { 273 if (w2dc_maps_objects.default_marker_icon) { 274 var map_marker_icon = '<span class="w2dc-map-marker-icon w2dc-fa '+w2dc_maps_objects.default_marker_icon+'" style="color: '+map_marker_color+';"></span>'; 275 var map_marker_class = 'w2dc-map-marker'; 276 } else { 277 var map_marker_icon = ''; 278 var map_marker_class = 'w2dc-map-marker-empty'; 279 } 280 } 281 282 var el = $("<div>", { 283 id: 'marker-id-'+w2dc_glocation.index, 284 class: 'w2dc-mapbox-marker', 285 html: '<div class="'+map_marker_class+'" style="background: '+map_marker_color+' none repeat scroll 0 0;">'+map_marker_icon+'</div>' 286 }); 287 var marker_div = el[0]; 288 289 var marker_options = { 290 anchor: 'bottom', 291 offset: [0, -20], 292 element: marker_div, 293 draggable: true 294 }; 295 296 var popup = new mapboxgl.Popup({ offset: 25 }) 297 .setText(w2dc_glocation.compileAddress()); 298 299 var marker = new mapboxgl.Marker(marker_options) 300 .setLngLat(w2dc_glocation.point) 301 .addTo(w2dc_map_backend) 302 .setPopup(popup); 303 } 304 305 w2dc_markersArray_backend.push(marker); 306 307 marker.on('drag', function() { 308 var point = marker.getLngLat(); 309 if (point !== undefined) { 310 var selected_location_num = w2dc_glocation.index; 311 $(".w2dc-manual-coords:eq("+w2dc_glocation.index+")").prop("checked", true); 312 $(".w2dc-manual-coords:eq("+w2dc_glocation.index+")").parents(".w2dc-manual-coords-wrapper").find(".w2dc-manual-coords-block").show(200); 313 314 $(".w2dc-map-coords-1:eq("+w2dc_glocation.index+")").val(point.lat); 315 $(".w2dc-map-coords-2:eq("+w2dc_glocation.index+")").val(point.lng); 316 } 317 }); 318 } 319 320 function w2dc_clearOverlays_backend() { 321 if (w2dc_markersArray_backend) { 322 for(var i = 0; i<w2dc_markersArray_backend.length; i++){ 323 w2dc_markersArray_backend[i].remove(); 324 } 325 } 326 } 327 328 function w2dc_isAnyLocation_backend() { 329 var is_location = false;
330 $(".w2dc-location-in-metabox").each(function(i, val) { 331 var locations_drop_boxes = []; 332 $(this).find("select").each(function(j, val) { 333 if ($(this).val()) { 334 is_location = true; 335 return false; 336 } 337 }); 338 339 if ($(".w2dc-manual-coords:eq("+i+")").is(":checked") && $(".w2dc-map-coords-1:eq("+i+")").val()!='' && $(".w2dc-map-coords-2:eq("+i+")").val()!='' && ($(".w2dc-map-coords-1:eq("+i+")").val()!=0 || $(".w2dc-map-coords-2:eq("+i+")").val()!=0)) { 340 is_location = true; 341 return false; 342 } 343 }); 344 if (is_location) 345 return true; 346 347 if ($(".w2dc-address-line-1[value!='']").length != 0) 348 return true; 349 350 if ($(".w2dc-address-line-2[value!='']").length != 0) 351 return true; 352 353 if ($(".w2dc-zip-or-postal-index[value!='']").length != 0) 354 return true; 355 } 356})(jQuery); 357 358(function($) { 359 "use strict"; 360 361 window.w2dc_buildPoint = function(lat, lng) { 362 return [lng, lat]; 363 } 364 365 window.w2dc_buildBounds = function() { 366 return new mapboxgl.LngLatBounds(); 367 } 368 369 window.w2dc_extendBounds = function(bounds, point) { 370 bounds.extend(point); 371 } 372 373 window.w2dc_mapFitBounds = function(map_id, bounds) { 374 var left_offset = 50; 375 var right_offset = 50; 376 if ($("#w2dc-map-wrapper-"+map_id).hasClass("w2dc-map-sidebar-open") && screen.width >= w2dc_js_objects.mobile_screen_width) { 377 if (w2dc_js_objects.is_rtl) { 378 right_offset = 415; 379 } else { 380 left_offset = 415; 381 } 382 } 383 w2dc_maps[map_id].fitBounds(bounds, {padding: {top: 50, bottom: 50, left: left_offset, right: right_offset}, duration: 0}); 384 } 385 386 window.w2dc_getMarkerPosition = function(marker) { 387 return marker.getLngLat(); 388 } 389 390 window.w2dc_closeInfoWindow = function(map_id) { 391 // we use global infoWindow, not to close/open it - just to set new content (in order to prevent blinking) 392 if (typeof w2dc_infoWindows[map_id] != 'undefined' && w2dc_infoWindows[map_id]) { 393 w2dc_infoWindows[map_id].remove(); 394 w2dc_infoWindows[map_id] = false; 395 } 396 } 397 398 class w2dc_point { 399 constructor(lng, lat) { 400 this.coord_1 = lng; 401 this.coord_2 = lat; 402 } 403 lng() { 404 return this.coord_1; 405 } 406 lat() { 407 return this.coord_2; 408 } 409 } 410 411 window.w2dc_geocodeAddress = function(address, callback, address_autocomplete_code) { 412 var code = address_autocomplete_code; 413 if (!code || code === "0") { 414 var country = ''; 415 } else { 416 var country = '&country='+address_autocomplete_code; 417 } 418 419 $.get("https://api.mapbox.com/geocoding/v5/mapbox.places/"+address+".json?access_token="+w2dc_maps_objects.mapbox_api_key+country, function(data) { 420 if (data.features.length) { 421 // ------------- data.features[0].geometry.coordinates[0] - longitude 422 // ------------- data.features[0].geometry.coordinates[1] - latitude 423 callback(true, data.features[0].geometry.coordinates[1], data.features[0].geometry.coordinates[0]); 424 } else { 425 callback(false, 0, 0); 426 } 427 }).fail(function() { 428 callback(false, 0, 0); 429 }); 430 } 431 432 window.w2dc_callMapResize = function(map_id) { 433 w2dc_maps[map_id].resize(); 434 } 435 436 window.w2dc_setMapCenter = function(map_id, center) { 437 w2dc_maps[map_id].setCenter(center); 438 } 439 440 window.w2dc_setMapZoom = function(map_id, zoom) { 441 w2dc_maps[map_id].setZoom(parseInt(zoom)); 442 } 443 444 window.w2dc_panTo = function(map_id, map_coords_1, map_coords_2) { 445 w2dc_maps[map_id].panTo([map_coords_2, map_coords_1]); 446 } 447 448 window.w2dc_autocompleteService = function(term, address_autocomplete_code, common_array, response, callback) { 449 var code = address_autocomplete_code; 450 if (!code || code === "0") { 451 var country = ''; 452 } else { 453 var country = '&country='+address_autocomplete_code; 454 } 455 456 if (w2dc_js_objects.lang) 457 var language = '&language='+w2dc_js_objects.lang; 458 else 459 var language = ''; 460 461 var output_predictions = []; 462 $.get("https://api.mapbox.com/geocoding/v5/mapbox.places/"+encodeURIComponent(term)+".json?access_token="+w2dc_maps_objects.mapbox_api_key+country+language, function(data) { 463 $.map(data.features, function (prediction, i) { 464 var output_prediction = { 465 label: prediction.text, 466 value: prediction.place_name, 467 name: prediction.place_name, 468 sublabel: prediction.place_name.replace(prediction.text + ", ", ""), 469 place_id: prediction.id 470 }; 471 output_predictions.push(output_prediction); 472 }); 473 474 callback(output_predictions, common_array, response); 475 }).fail(function() { 476 callback(output_predictions, common_array, response); 477 });; 478 } 479 480 function w2dc_addPolygon(map_id) { 481 var map = w2dc_maps[map_id]; 482 483 map.addSource('geo-poly-'+map_id, { 484 'type': 'geojson', 485 'data': w2dc_draw_features[map_id] 486 }); 487 map.addLayer({ 488 'id': 'geo-poly-'+map_id, 489 'type': 'fill', 490 'source': 'geo-poly-'+map_id, 491 'layout': {}, 492 'paint': { 493 'fill-color': '#0099FF', 494 'fill-opacity': 0.3, 495 'fill-outline-color': '#AA2143' 496 } 497 }); 498 499 w2dc_polygons[map_id] = true; 500 } 501 502 function w2dc_drawFreeHandPolygon(map_id) { 503 var geojson = { 504 "type": "FeatureCollection", 505 "features": [] 506 }; 507 508 var linestring = { 509 "type": "Feature", 510 "geometry": { 511 "type": "LineString", 512 "coordinates": [] 513 } 514 }; 515 516 var map = w2dc_maps[map_id]; 517 518 map.addSource('geo-lines', { 519 "type": "geojson", 520 "data": geojson 521 }); 522 523 map.addLayer({ 524 id: 'geo-lines', 525 type: 'line', 526 source: 'geo-lines', 527 layout: { 528 'line-cap': 'round', 529 'line-join': 'round' 530 }, 531 paint: { 532 'line-color': '#AA2143', 533 'line-width': 2 534 }, 535 filter: ['in', '$type', 'LineString'] 536 }); 537 538 var draw_move_event = function(e) { 539 var features = map.queryRenderedFeatures(e.point, { layers: ['geo-lines'] }); 540 541 // Remove the linestring from the group 542 // So we can redraw it based on the points collection 543 if (geojson.features.length > 1) geojson.features.pop(); 544 545 var point = { 546 "type": "Feature", 547 "geometry": { 548 "type": "Point", 549 "coordinates": [ 550 e.lngLat.lng, 551 e.lngLat.lat 552 ] 553 }, 554 "properties": { 555 "id": String(new Date().getTime()) 556 } 557 }; 558 559 geojson.features.push(point); 560 561 if (geojson.features.length > 1) { 562 linestring.geometry.coordinates = geojson.features.map(function(point) { 563 return point.geometry.coordinates; 564 }); 565 566 geojson.features.push(linestring); 567 } 568 569 map.getSource('geo-lines').setData(geojson); 570 }; 571 map.on('mousemove', draw_move_event); 572 map.on('touchmove', draw_move_event); 573 574 var draw_up_event = function(e) { 575 map.off('mousemove', draw_move_event); 576 map.off('touchmove', draw_move_event); 577 map.removeLayer('geo-lines'); 578 map.removeSource('geo-lines'); 579 580 var theArrayofLngLat = []; 581 linestring.geometry.coordinates.map(function(point_feature) { 582 theArrayofLngLat.push(new w2dc_point(point_feature[0], point_feature[1])); 583 }); 584 var ArrayforPolygontoUse = w2dc_GDouglasPeucker(theArrayofLngLat, 1); 585 586 var geo_poly_json = []; 587 var geo_poly_ajax = []; 588 if (ArrayforPolygontoUse.length) { 589 var lat_lng; 590 for (lat_lng in ArrayforPolygontoUse) { 591 geo_poly_json.push([ArrayforPolygontoUse[lat_lng].lng(), ArrayforPolygontoUse[lat_lng].lat()]); 592 geo_poly_ajax.push({ 'lat': ArrayforPolygontoUse[lat_lng].lat(), 'lng': ArrayforPolygontoUse[lat_lng].lng() }); 593 } 594 geo_poly_json.push([ArrayforPolygontoUse[0].lng(), ArrayforPolygontoUse[0].lat()]); 595 } 596 597 if (geo_poly_json.length) { 598 w2dc_sendGeoPolyAJAX(map_id, geo_poly_ajax); 599 600 var geo_poly_feature = { 601 'id': 'geo-poly-feature-'+map_id, 602 'type': 'Feature', 603 'properties': {}, 604 'geometry': { 605 'type': 'Polygon',
606 'coordinates': [geo_poly_json] 607 } 608 }; 609 610 w2dc_draw_features[map_id] = geo_poly_feature; 611 612 w2dc_addPolygon(map_id); 613 614 var editButton = $(map.getContainer()).find('.w2dc-map-edit').get(0); 615 $(editButton).removeAttr('disabled'); 616 } 617 var drawButton = $(map.getContainer()).find('.w2dc-map-draw').get(0); 618 drawButton.drawing_state = 0; 619 window.removeEventListener('touchmove', w2dc_stop_touchmove_listener, { passive: false }); 620 map.getCanvas().style.cursor = ''; 621 $(drawButton).removeClass('w2dc-btn-active'); 622 w2dc_disableDrawingMode(map_id); 623 }; 624 map.once('mouseup', draw_up_event); 625 map.once('touchend', draw_up_event); 626 } 627 function w2dc_enableDrawingMode(map_id) { 628 $(w2dc_maps[map_id].getContainer()).find('.w2dc-map-custom-controls').hide(); 629 630 var map = w2dc_maps[map_id]; 631 632 map.scrollZoom.disable(); 633 map.dragRotate.disable(); 634 map.touchZoomRotate.disable(); 635 map.dragPan.disable(); 636 } 637 function w2dc_disableDrawingMode(map_id) { 638 var map = w2dc_maps[map_id]; 639 640 $(map.getContainer()).find('.w2dc-map-custom-controls').show(); 641 642 var attrs_array = w2dc_get_map_markers_attrs_array(map_id); 643 var enable_wheel_zoom = attrs_array.enable_wheel_zoom; 644 var enable_dragging_touchscreens = attrs_array.enable_dragging_touchscreens; 645 if (enable_dragging_touchscreens || !('ontouchstart' in document.documentElement)) { 646 map.dragRotate.enable(); 647 map.dragPan.enable(); 648 map.touchZoomRotate.enable(); 649 } 650 if (enable_wheel_zoom) { 651 map.scrollZoom.enable(); 652 } 653 } 654 655 window.w2dc_setMapZoomCenter = function(map_id, map_attrs, markers_array) { 656 if (typeof map_attrs.start_zoom != 'undefined' && map_attrs.start_zoom > 0) 657 var zoom_level = map_attrs.start_zoom; 658 else if (markers_array.length == 1) 659 var zoom_level = markers_array[0][5]; 660 else if (markers_array.length > 1) 661 // fitbounds does not need zoom 662 var zoom_level = false; 663 else 664 var zoom_level = 2; 665 666 if (typeof map_attrs.start_latitude != 'undefined' && map_attrs.start_latitude && typeof map_attrs.start_longitude != 'undefined' && map_attrs.start_longitude) { 667 668 if (wcsearch_get_uri_param('swLat')) { 669 var uri_bounds = w2dc_buildBounds(); 670 var sw_point = [wcsearch_get_uri_param('swLng'), wcsearch_get_uri_param('swLat')]; 671 var ne_point = [wcsearch_get_uri_param('neLng'), wcsearch_get_uri_param('neLat')]; 672 w2dc_extendBounds(uri_bounds, sw_point); 673 w2dc_extendBounds(uri_bounds, ne_point); 674 675 w2dc_mapFitBounds(map_id, uri_bounds); 676 } else { 677 var start_latitude = map_attrs.start_latitude; 678 var start_longitude = map_attrs.start_longitude; 679 if (zoom_level == false) { 680 zoom_level = 12; 681 } 682 // required workaround: first zoom, then setCenter 683 w2dc_setMapZoom(map_id, zoom_level); 684 w2dc_setMapCenter(map_id, [start_longitude, start_latitude]); 685 } 686 687 if (typeof map_attrs.ajax_map_loading != 'undefined' && map_attrs.ajax_map_loading == 1) { 688 // use closures here 689 w2dc_setMapAjaxListener(w2dc_maps[map_id], map_id); 690 } 691 } else if (typeof map_attrs.start_address != 'undefined' && map_attrs.start_address) { 692 // use closures here 693 w2dc_geocodeStartAddress(map_attrs, map_id, zoom_level); 694 } else if (markers_array.length == 1) { 695 w2dc_setMapZoom(map_id, zoom_level); 696 } else if (zoom_level && markers_array.length == 0) { 697 // no fitbounds here 698 // required workaround: first zoom, then setCenter for initial load when single marker 699 w2dc_setMapZoom(map_id, zoom_level); 700 w2dc_setMapCenter(map_id, [w2dc_maps_objects.default_longitude, w2dc_maps_objects.default_latitude]); 701 } 702 } 703 704 window.w2dc_show_on_map_links = function() { 705 $(".w2dc-show-on-map").each(function() { 706 var location_id = $(this).data("location-id"); 707 708 var passed = false; 709 for (var map_id in w2dc_maps) { 710 if (typeof w2dc_global_locations_array[map_id] != 'undefined') { 711 for (var i=0; i<w2dc_global_locations_array[map_id].length; i++) { 712 if (typeof w2dc_global_locations_array[map_id][i] == 'object') { 713 if (location_id == w2dc_global_locations_array[map_id][i].id) { 714 passed = true; 715 } 716 } 717 } 718 } 719 } 720 if (passed) { 721 $(this).parent('.w2dc-listing-logo-caption-option-marker').show(); 722 } else { 723 $(this).css({'cursor': 'auto'}); 724 if ($(this).hasClass('w2dc-btn')) { 725 $(this).hide(); 726 } 727 } 728 }); 729 } 730 731 window.w2dc_load_maps = function() { 732 for (var i=0; i<w2dc_map_markers_attrs_array.length; i++) { 733 if (typeof w2dc_maps[w2dc_map_markers_attrs_array[i].map_id] == 'undefined') { // workaround for "tricky" themes and plugins to load maps twice 734 w2dc_load_map(i); 735 } 736 } 737 738 w2dc_show_on_map_links(); 739 740 w2dc_geolocatePosition(); 741 } 742 743 window.w2dc_load_maps_api = function() { 744 $(document).trigger('w2dc_mapbox_api_loaded'); 745 746 // are there any markers? 747 if (typeof w2dc_map_markers_attrs_array != 'undefined' && w2dc_map_markers_attrs_array.length) { 748 _w2dc_map_markers_attrs_array = JSON.parse(JSON.stringify(w2dc_map_markers_attrs_array)); 749 750 w2dc_load_maps(); 751 } 752 753 w2dc_load_ajax_initial_elements(); 754 755 w2dc_setupAutocomplete(); 756 757 $('body').on('click', '.w2dc-show-on-map', function() { 758 var location_id = $(this).data("location-id"); 759 var do_scroll_to_map = $(this).data("scroll-to-map"); 760 var location_obj; 761 762 for (var map_id in w2dc_maps) { 763 if (typeof w2dc_global_locations_array[map_id] != 'undefined') { 764 for (var i=0; i<w2dc_global_locations_array[map_id].length; i++) { 765 if (typeof w2dc_global_locations_array[map_id][i] == 'object') { 766 if (location_id == w2dc_global_locations_array[map_id][i].id) { 767 location_obj = w2dc_global_locations_array[map_id][i]; 768 var side_offset = 0; 769 if ($("#w2dc-map-wrapper-"+map_id).hasClass("w2dc-map-sidebar-open")) { 770 if (w2dc_js_objects.is_rtl) { 771 side_offset = 200; 772 } else { 773 side_offset = -200; 774 } 775 } 776 var map_attrs = w2dc_maps_attrs[map_id]; 777 if (typeof map_attrs.start_zoom != 'undefined' && map_attrs.start_zoom > 0) { 778 w2dc_setMapZoom(map_id, map_attrs.start_zoom); 779 } 780 w2dc_maps[map_id].panToWithOffset(location_obj.marker.getLngLat(), side_offset, -100); 781 w2dc_setInfoWindow(location_obj, location_obj.marker, map_id, 'bottom', 'onbuttonclick'); 782 if (do_scroll_to_map) { 783 var offest_top = 80; 784 $('html,body').animate({scrollTop: $('#w2dc-map-canvas-'+map_id).offset().top - offest_top}, 'slow'); 785 } 786 } 787 } 788 } 789 } 790 } 791 792 if (!location_obj) {
793 var lat = $(this).data("coordinate-lat"); 794 var lng = $(this).data("coordinate-lng"); 795 if (lat && lng) { 796 window.open("https://www.openstreetmap.org/?mlat="+lat+"&mlon="+lng, "_blank"); 797 } 798 } 799 }); 800 } 801 802 document.addEventListener("DOMContentLoaded", function() { 803 if (w2dc_maps_callback.callback) { 804 window[w2dc_maps_callback.callback](); 805 } 806 }); 807 808 window.w2dc_load_map = function(i) { 809 var map_id = w2dc_map_markers_attrs_array[i].map_id; 810 var markers_array = w2dc_map_markers_attrs_array[i].markers_array; 811 var enable_radius_circle = w2dc_map_markers_attrs_array[i].enable_radius_circle; 812 var enable_clusters = w2dc_map_markers_attrs_array[i].enable_clusters; 813 var show_summary_button = w2dc_map_markers_attrs_array[i].show_summary_button; 814 var map_style = w2dc_map_markers_attrs_array[i].map_style; 815 var draw_panel = w2dc_map_markers_attrs_array[i].draw_panel; 816 var show_readmore_button = w2dc_map_markers_attrs_array[i].show_readmore_button; 817 var enable_full_screen = w2dc_map_markers_attrs_array[i].enable_full_screen; 818 var enable_wheel_zoom = w2dc_map_markers_attrs_array[i].enable_wheel_zoom; 819 var enable_dragging_touchscreens = w2dc_map_markers_attrs_array[i].enable_dragging_touchscreens; 820 var show_directions = w2dc_map_markers_attrs_array[i].show_directions; 821 var map_attrs = w2dc_map_markers_attrs_array[i].map_attrs; 822 var min_zoom = map_attrs.min_zoom; 823 var max_zoom = map_attrs.max_zoom; 824 825 if (document.getElementById("w2dc-map-canvas-"+map_id)) { 826 if (typeof w2dc_fullScreens[map_id] == "undefined" || !w2dc_fullScreens[map_id]) { 827 828 if (typeof w2dc_maps[map_id] != 'undefined') { 829 w2dc_maps[map_id].remove(); 830 } 831 832 mapboxgl.accessToken = w2dc_maps_objects.mapbox_api_key; 833 834 var mapOptions = { 835 container: "w2dc-map-canvas-"+map_id, 836 style: map_style 837 } 838 839 if (min_zoom > 0) { 840 mapOptions.minZoom = parseInt(min_zoom); 841 } 842 if (max_zoom > 0) { 843 mapOptions.maxZoom = parseInt(max_zoom); 844 } 845 846 var map = new mapboxgl.Map(mapOptions); 847 848 if ( 849 $("#w2dc-map-wrapper-"+map_id).hasClass("w2dc-sticky-scroll") && 850 $("#w2dc-map-canvas-wrapper-"+map_id).data("height") == "100%" 851 ) { 852 map.on('load', function() { 853 var mapDiv = map.getContainer(); 854 mapDiv.style.height = "100%"; 855 856 map.resize(); 857 858 w2dc_sticky_scroll(); 859 }); 860 } 861 862 if (w2dc_js_objects.is_rtl) { 863 if (mapboxgl.getRTLTextPluginStatus() != 'loaded') { 864 mapboxgl.setRTLTextPlugin('https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.1.0/mapbox-gl-rtl-text.js'); 865 } 866 } 867 if (typeof MapboxLanguage != "undefined") { 868 var options = {}; 869 if (w2dc_js_objects.lang) { 870 options = { defaultLanguage: w2dc_js_objects.lang}; 871 } 872 map.addControl(new MapboxLanguage(options)); 873 } 874 875 if (!enable_wheel_zoom) { 876 map.scrollZoom.disable(); 877 } 878 879 w2dc_maps[map_id] = map; 880 w2dc_maps_attrs[map_id] = map_attrs; 881 882 if (show_directions) { 883 884 if (w2dc_maps_objects.dimension_unit == "kilometers") { 885 var dimension_unit = "metric"; 886 } else { 887 var dimension_unit = "imperial"; 888 } 889 890 var directions = new MapboxDirections({ 891 accessToken: mapboxgl.accessToken, 892 language: w2dc_js_objects.lang, 893 interactive: false, 894 geocoder: { 895 language: w2dc_js_objects.lang 896 }, 897 unit: dimension_unit, 898 placeholderOrigin: w2dc_maps_objects.mapbox_directions_placeholder_origin, 899 placeholderDestination: w2dc_maps_objects.mapbox_directions_placeholder_destination 900 }).on('profile', function() { 901 $('label[for="mapbox-directions-profile-driving-traffic"]').text(w2dc_maps_objects.mapbox_directions_profile_driving_traffic); 902 $('label[for="mapbox-directions-profile-driving"]').text(w2dc_maps_objects.mapbox_directions_profile_driving); 903 $('label[for="mapbox-directions-profile-walking"]').text(w2dc_maps_objects.mapbox_directions_profile_walking); 904 $('label[for="mapbox-directions-profile-cycling"]').text(w2dc_maps_objects.mapbox_directions_profile_cycling); 905 }); 906 907 if (w2dc_js_objects.is_rtl) { 908 var cposition = 'top-right'; 909 } else { 910 var cposition = 'top-left'; 911 } 912 map.addControl(directions, cposition); 913 914 w2dc_directions_display[map_id] = { 915 directions: directions, 916 geolocation_field: $("<input>").attr("type", "hidden") 917 }; 918 w2dc_geocodeField(w2dc_directions_display[map_id].geolocation_field, w2dc_maps_objects.my_location_button_error, map_id); 919 } 920 921 class w2dc_custom_controls {
922 onAdd(map) { 923 this.map = map; 924 925 var customControls = document.createElement('div'); 926 $(customControls).addClass('mapboxgl-ctrl w2dc-map-custom-controls'); 927 $(customControls).html('<div class="w2dc-btn-group"><button class="w2dc-btn w2dc-btn-primary w2dc-map-btn-zoom-in"><span class="w2dc-glyphicon w2dc-glyphicon-plus"></span></button><button class="w2dc-btn w2dc-btn-primary w2dc-map-btn-zoom-out"><span class="w2dc-glyphicon w2dc-glyphicon-minus"></span></button></div> <div class="w2dc-btn-group">'+(enable_full_screen ? '<button class="w2dc-btn w2dc-btn-primary w2dc-map-btn-fullscreen"><span class="w2dc-glyphicon w2dc-glyphicon-fullscreen"></span></button>' : '')+'</div>'); 928 929 this.container = customControls; 930 return this.container; 931 } 932 onRemove() { 933 this.container.parentNode.removeChild(this.container); 934 this.map = undefined; 935 } 936 } 937 var customControls = new w2dc_custom_controls(); 938 939 if (w2dc_js_objects.is_rtl) { 940 var cposition = 'top-left'; 941 } else { 942 var cposition = 'top-right'; 943 } 944 map.addControl(customControls, cposition); 945 946 $(customControls.container).find('.w2dc-map-btn-zoom-in').on("click", function() { 947 w2dc_maps[map_id].zoomIn(); 948 }); 949 $(customControls.container).find('.w2dc-map-btn-zoom-out').on("click", function() { 950 w2dc_maps[map_id].zoomOut(); 951 }); 952 953 var bodyStyle = document.body.style; 954 if (document.body.runtimeStyle) 955 bodyStyle = document.body.runtimeStyle; 956 var originalOverflow = bodyStyle.overflow; 957 958 function openFullScreen() { 959 960 var center = w2dc_maps[map_id].getCenter(); 961 962 document.body.style.overflow = "hidden"; 963 $(customControls.container).find('.w2dc-map-btn-fullscreen span').removeClass('w2dc-glyphicon-fullscreen'); 964 $(customControls.container).find('.w2dc-map-btn-fullscreen span').addClass('w2dc-glyphicon-resize-small'); 965 966 $("#w2dc-map-wrapper-"+map_id).addClass("w2dc-map-wrapper-full-screen"); 967 968 $(window).trigger('resize'); 969 970 $("body").addClass("w2dc-body-fullscreen-map"); 971 972 w2dc_callMapResize(map_id); 973 w2dc_setMapCenter(map_id, center); 974 resizeSidebarHeight(); 975 } 976 function closeFullScreen() { 977 var center = w2dc_maps[map_id].getCenter(); 978 979 document.body.style.overflow = originalOverflow; 980 $(customControls.container).find('.w2dc-map-btn-fullscreen span').removeClass('w2dc-glyphicon-resize-small'); 981 $(customControls.container).find('.w2dc-map-btn-fullscreen span').addClass('w2dc-glyphicon-fullscreen'); 982 983 $("#w2dc-map-wrapper-"+map_id).removeClass("w2dc-map-wrapper-full-screen"); 984 985 $(window).trigger('resize'); 986 987 $("body").removeClass("w2dc-body-fullscreen-map"); 988 989 w2dc_callMapResize(map_id); 990 w2dc_setMapCenter(map_id, center); 991 resizeSidebarHeight(); 992 } 993 function resizeSidebarHeight() { 994 // resize listings wrapper in sidebar 995 if ($("div[class*='-map-sidebar']").length) { 996 var map_sidebar = $("div[class*='-map-sidebar']"); 997 var search_wrapper = map_sidebar.find(".wcsearch-search-wrapper"); 998 var listings_wrapper = map_sidebar.find("div[class*='-map-sidebar-listings-wrapper']"); 999 1000 if (listings_wrapper.length && search_wrapper.length) { 1001 var listings_wrapper_height = map_sidebar.height() - search_wrapper.outerHeight(); 1002 listings_wrapper.height(listings_wrapper_height); 1003 } 1004 } 1005 } 1006 if (enable_full_screen) { 1007 $(customControls.container).find('.w2dc-map-btn-fullscreen').on("click", function() { 1008 if (typeof w2dc_fullScreens[map_id] == "undefined" || !w2dc_fullScreens[map_id]) { 1009 $("#w2dc-map-canvas-wrapper-"+map_id).addClass("w2dc-map-full-screen"); 1010 w2dc_fullScreens[map_id] = true; 1011 openFullScreen(); 1012 } else { 1013 $("#w2dc-map-canvas-wrapper-"+map_id).removeClass("w2dc-map-full-screen"); 1014 w2dc_fullScreens[map_id] = false;
1015 closeFullScreen(); 1016 } 1017 }); 1018 $(document).on("keyup", function(e) { 1019 if (typeof w2dc_fullScreens[map_id] != "undefined" && w2dc_fullScreens[map_id] && e.keyCode == 27) { 1020 $("#w2dc-map-canvas-wrapper-"+map_id).removeClass("w2dc-map-full-screen"); 1021 w2dc_fullScreens[map_id] = false; 1022 closeFullScreen(); 1023 } 1024 }); 1025 } 1026 1027 if (draw_panel) { 1028 var drawPanel = document.createElement('div'); 1029 $(drawPanel).addClass('w2dc-map-draw-panel'); 1030 1031 class w2dc_dummy_control { 1032 constructor(drawPanel) { 1033 this.drawPanel = drawPanel; 1034 } 1035 onAdd(map){ 1036 this.map = map; 1037 1038 var customControls = document.createElement('div'); 1039 $(customControls).addClass('mapboxgl-ctrl w2dc-map-draw-panel'); 1040 customControls.appendChild(this.drawPanel); 1041 1042 this.container = customControls; 1043 return this.container; 1044 } 1045 onRemove(){ 1046 this.container.parentNode.removeChild(this.container); 1047 this.map = undefined; 1048 } 1049 } 1050 var dummyDiv = new w2dc_dummy_control(drawPanel); 1051 map.addControl(dummyDiv, cposition); 1052 1053 var drawButton = document.createElement('button'); 1054 $(drawButton) 1055 .addClass('w2dc-btn w2dc-btn-primary w2dc-map-draw') 1056 .attr("title", w2dc_maps_objects.draw_area_button) 1057 .html('<span class="w2dc-glyphicon w2dc-glyphicon-pencil"></span>'); 1058 1059 drawPanel.appendChild(drawButton); 1060 drawButton.map_id = map_id; 1061 drawButton.drawing_state = 0; 1062 $(drawButton).on("click", function(e) { 1063 var map_id = drawButton.map_id; 1064 if (this.drawing_state == 0) { 1065 this.drawing_state = 1; 1066 window.addEventListener('touchmove', w2dc_stop_touchmove_listener, { passive: false }); 1067 w2dc_clearMarkers(map_id); 1068 w2dc_closeInfoWindow(map_id); 1069 w2dc_removeShapes(map_id); 1070 w2dc_removeCircles(map_id); 1071 1072 w2dc_enableDrawingMode(map_id); 1073 1074 var editButton = $(w2dc_maps[map_id].getContainer()).find('.w2dc-map-edit').get(0); 1075 $(editButton).removeClass('w2dc-btn-active'); 1076 $(editButton).attr('disabled', 'disabled'); 1077 $(editButton).find('.w2dc-map-edit-label').text(w2dc_maps_objects.edit_area_button); 1078 editButton.editing_state = 0; 1079 1080 // remove ajax_map_loading and set drawing_state 1081 var map_attrs_array; 1082 if (map_attrs_array = w2dc_get_map_markers_attrs_array(map_id)) { 1083 map_attrs_array.map_attrs.drawing_state = 1; 1084 delete map_attrs_array.map_attrs.ajax_map_loading; 1085 } 1086 1087 w2dc_maps[map_id].getCanvas().style.cursor = 'crosshair'; 1088 $(this).toggleClass('w2dc-btn-active'); 1089 1090 w2dc_maps[map_id].getContainer().map_id = map_id; 1091 1092 var draw_down_event = function(e) { 1093 var el = e.target; 1094 do { 1095 if ($(el).hasClass('w2dc-map-draw-panel')) { 1096 return; 1097 } 1098 } while (el = el.parentNode); 1099 w2dc_drawFreeHandPolygon(map_id); 1100 }; 1101 1102 w2dc_maps[map_id].once('mousedown', draw_down_event); 1103 w2dc_maps[map_id].once('touchstart', draw_down_event); 1104 } else if (this.drawing_state == 1) { 1105 this.drawing_state = 0; 1106 window.removeEventListener('touchmove', w2dc_stop_touchmove_listener, { passive: false }); 1107 map.getCanvas().style.cursor = ''; 1108 $(drawButton).removeClass('w2dc-btn-active'); 1109 w2dc_disableDrawingMode(map_id); 1110 1111 // repair ajax_map_loading and set drawing_state 1112 var map_attrs_array; 1113 if (map_attrs_array = w2dc_get_map_markers_attrs_array(map_id)) { 1114 map_attrs_array.map_attrs.drawing_state = 0; 1115 if (typeof w2dc_get_original_map_markers_attrs_array(map_id).map_attrs.ajax_map_loading != 'undefined' && w2dc_get_original_map_markers_attrs_array(map_id).map_attrs.ajax_map_loading == 1) { 1116 map_attrs_array.map_attrs.ajax_map_loading = 1; 1117 } 1118 } 1119 } 1120 }); 1121 1122 var editButton = document.createElement('button'); 1123 $(editButton) 1124 .addClass('w2dc-btn w2dc-btn-primary w2dc-map-edit') 1125 .attr("title", w2dc_maps_objects.edit_area_button) 1126 .html('<span class="w2dc-glyphicon w2dc-glyphicon-edit"></span>') 1127 .attr('disabled', 'disabled'); 1128 1129 drawPanel.appendChild(editButton); 1130 editButton.map_id = map_id; 1131 editButton.editing_state = 0; 1132 $(editButton).on("click", function(e) { 1133 var map_id = editButton.map_id; 1134 if (this.editing_state == 0) { 1135 this.editing_state = 1; 1136 $(this).toggleClass('w2dc-btn-active'); 1137 $(this).attr("title", w2dc_maps_objects.apply_area_button); 1138 1139 w2dc_removeShapes(map_id); 1140 w2dc_removeCircles(map_id); 1141 1142 var draw = new MapboxDraw({ 1143 displayControlsDefault: false, 1144 styles: [ 1145 // line stroke 1146 { 1147 "id": "gl-draw-line", 1148 "type": "line", 1149 "filter": ["all", ["==", "$type", "LineString"], ["!=", "mode", "static"]], 1150 "layout": { 1151 "line-cap": "round", 1152 "line-join": "round" 1153 }, 1154 "paint": { 1155 "line-color": "#AA2143", 1156 "line-dasharray": [0.2, 2], 1157 "line-width": 1 1158 } 1159 }, 1160 // polygon fill 1161 { 1162 "id": "gl-draw-polygon-fill", 1163 "type": "fill", 1164 "filter": ["all", ["==", "$type", "Polygon"], ["!=", "mode", "static"]], 1165 "paint": { 1166 "fill-color": "#0099FF", 1167 "fill-outline-color": "#AA2143", 1168 "fill-opacity": 0.3 1169 } 1170 }, 1171 // vertex point halos 1172 { 1173 "id": "gl-draw-polygon-and-line-vertex-halo-active", 1174 "type": "circle", 1175 "filter": ["all", ["==", "meta", "vertex"], ["==", "$type", "Point"], ["!=", "mode", "static"]], 1176 "paint": { 1177 "circle-radius": 5, 1178 "circle-color": "#FFF" 1179 } 1180 }, 1181 // vertex points 1182 { 1183 "id": "gl-draw-polygon-and-line-vertex-active", 1184 "type": "circle", 1185 "filter": ["all", ["==", "meta", "vertex"], ["==", "$type", "Point"], ["!=", "mode", "static"]], 1186 "paint": { 1187 "circle-radius": 3, 1188 "circle-color": "#AA2143", 1189 } 1190 } 1191 ] 1192 }); 1193 map.addControl(draw); 1194 draw.add(w2dc_draw_features[map_id]); 1195 draw.changeMode('direct_select', { featureId: w2dc_draw_features[map_id].id }); 1196 1197 w2dc_draws[map_id] = draw; 1198 1199 } else if (this.editing_state == 1) { 1200 this.editing_state = 0; 1201 $(this).toggleClass('w2dc-btn-active'); 1202 $(this).attr("title", w2dc_maps_objects.edit_area_button); 1203 if (typeof w2dc_draws[map_id] != 'undefined' && w2dc_draws[map_id]) { 1204 var draw = w2dc_draws[map_id]; 1205 draw.changeMode('simple_select', { featureId: w2dc_draw_features[map_id].id }); 1206 w2dc_draw_features[map_id] = draw.get(w2dc_draw_features[map_id].id); 1207 w2dc_addPolygon(map_id); 1208 1209 var geo_poly_ajax = []; 1210 w2dc_draw_features[map_id].geometry.coordinates[0].map(function(point_feature) { 1211 geo_poly_ajax.push({ 'lat': point_feature[1], 'lng': point_feature[0] }); 1212 }); 1213 1214 if (geo_poly_ajax.length) { 1215 w2dc_sendGeoPolyAJAX(map_id, geo_poly_ajax); 1216 } 1217 } 1218 map.removeControl(w2dc_draws[map_id]); 1219 w2dc_draws[map_id] = false;
1220 } 1221 }); 1222 1223 var reloadButton = document.createElement('button'); 1224 $(reloadButton) 1225 .addClass('w2dc-btn w2dc-btn-primary w2dc-map-reload') 1226 .attr("title", w2dc_maps_objects.reload_map_button) 1227 .html('<span class="w2dc-glyphicon w2dc-glyphicon-refresh"></span>'); 1228 1229 drawPanel.appendChild(reloadButton); 1230 reloadButton.map_id = map_id; 1231 $(reloadButton).on("click", function(e) { 1232 var map_id = reloadButton.map_id; 1233 for (var i=0; i<w2dc_map_markers_attrs_array.length; i++) { 1234 if (w2dc_map_markers_attrs_array[i].map_id == map_id) { 1235 w2dc_map_markers_attrs_array[i] = JSON.parse(JSON.stringify(_w2dc_map_markers_attrs_array[i])); 1236 1237 window.removeEventListener('touchmove', w2dc_stop_touchmove_listener, { passive: false }); 1238 1239 var editButton = $(w2dc_maps[map_id].getContainer()).find('.w2dc-map-edit').get(0); 1240 $(editButton).removeClass('w2dc-btn-active'); 1241 $(editButton).find('.w2dc-map-edit-label').text(w2dc_maps_objects.edit_area_button); 1242 $(editButton).attr('disabled', 'disabled'); 1243 1244 w2dc_disableDrawingMode(map_id); 1245 w2dc_clearMarkers(map_id); 1246 w2dc_closeInfoWindow(map_id); 1247 w2dc_removeShapes(map_id); 1248 w2dc_removeCircles(map_id); 1249 w2dc_load_map(i); 1250 if (w2dc_global_markers_array[map_id].length) { 1251 var markers_array = []; 1252 var bounds = w2dc_buildBounds(); 1253 for (var j=0; j<w2dc_global_markers_array[map_id].length; j++) { 1254 var marker = w2dc_global_markers_array[map_id][j]; 1255 w2dc_extendBounds(bounds, w2dc_getMarkerPosition(marker)); 1256 markers_array.push(marker); 1257 } 1258 w2dc_mapFitBounds(map_id, bounds); 1259 1260 var map_attrs = w2dc_map_markers_attrs_array[i].map_attrs; 1261 var markers_array = w2dc_map_markers_attrs_array[i].markers_array; 1262 w2dc_setMapZoomCenter(map_id, map_attrs, markers_array); 1263 } 1264 1265 if (typeof w2dc_controller_args_array[map_id].geo_poly != 'undefined') { 1266 w2dc_controller_args_array[map_id].geo_poly = []; 1267 } 1268 1269 break; 1270 } 1271 } 1272 1273 }); 1274 1275 if (w2dc_maps_objects.enable_my_location_button) { 1276 var locationButton = document.createElement('button'); 1277 $(locationButton) 1278 .addClass('w2dc-btn w2dc-btn-primary w2dc-map-location') 1279 .attr("title", w2dc_maps_objects.my_location_button) 1280 .html('<span class="w2dc-glyphicon w2dc-glyphicon-screenshot"></span>'); 1281 1282 drawPanel.appendChild(locationButton); 1283 1284 locationButton.map_id = map_id; 1285 $(locationButton).on("click", function(e) { 1286 var map_id = locationButton.map_id; 1287 if (navigator.geolocation) { 1288 navigator.geolocation.getCurrentPosition( 1289 function(position) { 1290 var start_latitude = position.coords.latitude; 1291 var start_longitude = position.coords.longitude; 1292 w2dc_setMapCenter(map_id, w2dc_buildPoint(start_latitude, start_longitude)); 1293 }, 1294 function(e) { 1295 1296 }, 1297 {timeout: 10000} 1298 ); 1299 } 1300 }); 1301 } 1302 } 1303 } // end of (!fullScreen) 1304 1305 w2dc_global_markers_array[map_id] = []; 1306 w2dc_global_locations_array[map_id] = []; 1307 1308 if (markers_array.length) { 1309 var bounds = w2dc_buildBounds(); 1310 1311 if (typeof map_attrs.ajax_markers_loading != 'undefined' && map_attrs.ajax_markers_loading == 1) { 1312 var is_ajax_markers = true; 1313 } else { 1314 var is_ajax_markers = false; 1315 } 1316 1317 var markers = []; 1318 for (var j=0; j<markers_array.length; j++) { 1319 var map_coords_1 = markers_array[j][1]; 1320 var map_coords_2 = markers_array[j][2]; 1321 if ($.isNumeric(map_coords_1) && $.isNumeric(map_coords_2)) { 1322 var point = [map_coords_2, map_coords_1]; 1323 w2dc_extendBounds(bounds, point); 1324 1325 var location_obj = new w2dc_glocation( 1326 markers_array[j][0], // location ID 1327 point, 1328 markers_array[j][3], // map icon file 1329 markers_array[j][4], // map icon color 1330 markers_array[j][6], // listing title 1331 markers_array[j][7], // logo image 1332 markers_array[j][8], // listing link 1333 markers_array[j][9], // content fields output 1334 markers_array[j][10], // listing link anchor 1335 markers_array[j][11], // is nofollow link 1336 show_summary_button, 1337 show_readmore_button, 1338 map_id, 1339 is_ajax_markers 1340 ); 1341 var marker = location_obj.w2dc_placeMarker(map_id); 1342 markers.push(marker); 1343 1344 w2dc_global_locations_array[map_id].push(location_obj); 1345 } 1346 } 1347 1348 w2dc_mapFitBounds(map_id, bounds); 1349
1350 w2dc_setClusters(enable_clusters, map_id, w2dc_global_locations_array[map_id]); 1351 1352 if (enable_radius_circle && typeof window['radius_params'] != 'undefined') { 1353 var radius_params = window['radius_params']; 1354 1355 w2dc_maps[map_id].on('load', function() { 1356 w2dc_drawRadius(radius_params, map_id); 1357 }); 1358 } 1359 } 1360 1361 w2dc_setMapZoomCenter(map_id, map_attrs, markers_array); 1362 } 1363 } 1364 1365 function w2dc_setMapAjaxListener(map, map_id) { 1366 1367 function makeAjaxMarkersListenerCallback(map, map_id) { 1368 return function() { 1369 w2dc_setAjaxMarkers(map, map_id); 1370 } 1371 } 1372 1373 var ajaxMarkersListenerCallback = makeAjaxMarkersListenerCallback(map, map_id); 1374 1375 map.on('load', function() { 1376 ajaxMarkersListenerCallback(); 1377 }); 1378 map.on('moveend', function() { 1379 ajaxMarkersListenerCallback(); 1380 }); 1381 map.on('zoomend', function() { 1382 ajaxMarkersListenerCallback(); 1383 }); 1384 } 1385 function w2dc_geocodeStartAddress(map_attrs, map_id, zoom_level) { 1386 var start_address = map_attrs.start_address; 1387 function _geocodeStartAddress(status, start_latitude, start_longitude) { 1388 if (status == true) { 1389 if (!zoom_level) { 1390 zoom_level = 13; 1391 } 1392 w2dc_setMapZoom(map_id, zoom_level); 1393 w2dc_setMapCenter(map_id, [start_longitude, start_latitude]); 1394 1395 if (typeof map_attrs.ajax_map_loading != 'undefined' && map_attrs.ajax_map_loading == 1) { 1396 // use closures here 1397 w2dc_setMapAjaxListener(w2dc_maps[map_id], map_id); 1398 } 1399 } 1400 } 1401 w2dc_geocodeAddress(start_address, _geocodeStartAddress); 1402 } 1403 function w2dc_geolocatePosition() { 1404 if (navigator.geolocation) { 1405 var geolocation_maps = []; 1406 for (var map_id in w2dc_maps_attrs) { 1407 if (typeof w2dc_maps_attrs[map_id].geolocation != 'undefined' && w2dc_maps_attrs[map_id].geolocation == 1) { 1408 geolocation_maps.push({ 'map': w2dc_maps[map_id], 'map_id': map_id}); 1409 } 1410 } 1411 if (geolocation_maps.length) { 1412 navigator.geolocation.getCurrentPosition( 1413 function(position) { 1414 var start_latitude = position.coords.latitude; 1415 var start_longitude = position.coords.longitude; 1416 for (var i in geolocation_maps) { 1417 var map_id = geolocation_maps[i].map_id; 1418 1419 w2dc_setMapCenter(geolocation_maps[i].map_id, [start_longitude, start_latitude]); 1420 1421 if (typeof w2dc_maps_attrs[map_id].start_zoom != 'undefined' && w2dc_maps_attrs[map_id].start_zoom > 0) { 1422 w2dc_setMapZoom(map_id, w2dc_maps_attrs[map_id].start_zoom); 1423 } 1424 1425 for (var j=0; j<w2dc_map_markers_attrs_array.length; j++) { 1426 if (w2dc_map_markers_attrs_array[j].map_id == map_id) { 1427 w2dc_map_markers_attrs_array[j].map_attrs.start_latitude = start_latitude; 1428 w2dc_map_markers_attrs_array[j].map_attrs.start_longitude = start_longitude; 1429 1430 var post_params = w2dc_collectAJAXParams({ hash: map_id, from_ajax_map: 1 }); 1431 post_params.ajax_action = 'ajax_markers'; 1432 w2dc_startAJAXSearchOnMap(map_id, post_params); 1433 } 1434 } 1435 } 1436 }, 1437 function(e) { 1438 1439 }, 1440 {timeout: 10000} 1441 ); 1442 } 1443 } 1444 } 1445 1446 window.w2dc_setAjaxMarkers = function(map, map_id) { 1447 var attrs_array = w2dc_get_map_markers_attrs_array(map_id); 1448 var map_attrs = attrs_array.map_attrs; 1449 1450 var address_string = ''; 1451 if (address_string = wcsearch_get_query_string_param('address')) { 1452 if (typeof w2dc_searchAddresses[map_id] == "undefined" || w2dc_searchAddresses[map_id] != address_string) { 1453 function _geocodeSearchAddress(status, latitude, longitude) { 1454 if (status == true) { 1455 map.panTo([longitude, latitude]); 1456 1457 w2dc_setAjaxMarkers(map, map_id); 1458 } 1459 } 1460 w2dc_geocodeAddress(address_string, _geocodeSearchAddress); 1461 1462 w2dc_searchAddresses[map_id] = address_string; 1463 1464 return false; 1465 } 1466 } 1467 1468 var bounds_new = map.getBounds(); 1469 if (bounds_new) {
1470 var south_west = bounds_new.getSouthWest(); 1471 var north_east = bounds_new.getNorthEast(); 1472 } else { 1473 return false; 1474 } 1475 1476 wcsearch_insert_param_in_uri( 1477 ['swLat', south_west.lat], 1478 ['swLng', south_west.lng], 1479 ['neLat', north_east.lat], 1480 ['neLng', north_east.lng] 1481 ); 1482 1483 function inBoundingBox(bl, tr, p) { 1484 // in case longitude 180 is inside the box 1485 function isLongInRange(bl, tr, p) { 1486 if (tr.lng < bl.lng) { 1487 if (p.lng >= bl.lng || p.lng <= tr.lng) { 1488 return true; 1489 } 1490 } else 1491 if (p.lng >= bl.lng && p.lng <= tr.lng) { 1492 return true; 1493 } 1494 } 1495 1496 if (p.lat >= bl.lat && p.lat <= tr.lat && isLongInRange(bl, tr, p)) { 1497 return true; 1498 } else { 1499 return false; 1500 } 1501 } 1502 1503 if (typeof map_attrs.swLat != 'undefined' && typeof map_attrs.swLng != 'undefined' && typeof map_attrs.neLat != 'undefined' && typeof map_attrs.neLng != 'undefined') { 1504 var sw_point = new mapboxgl.LngLat(map_attrs.swLng, map_attrs.swLat); 1505 var ne_point = new mapboxgl.LngLat(map_attrs.neLng, map_attrs.neLat); 1506 1507 var worldCoordinate_new = map.project(sw_point); 1508 var worldCoordinate_old = map.project(south_west); 1509 var _sw_bb = inBoundingBox(sw_point, ne_point, south_west); 1510 var _ne_bb = inBoundingBox(sw_point, ne_point, north_east); 1511 if ( 1512 (_sw_bb && _ne_bb) 1513 || 1514 (140 > Math.abs(Math.floor(worldCoordinate_new.x) - Math.floor(worldCoordinate_old.x)) 1515 && 1516 140 > Math.abs(Math.floor(worldCoordinate_new.y) - Math.floor(worldCoordinate_old.y))) 1517 ) { 1518 return false; 1519 } 1520 } 1521 1522 // save bounds 1523 for (var i=0; i<w2dc_map_markers_attrs_array.length; i++) { 1524 if (w2dc_map_markers_attrs_array[i].map_id == map_id) { 1525 w2dc_map_markers_attrs_array[i].map_attrs.swLat = south_west.lat; 1526 w2dc_map_markers_attrs_array[i].map_attrs.swLng = south_west.lng; 1527 w2dc_map_markers_attrs_array[i].map_attrs.neLat = north_east.lat; 1528 w2dc_map_markers_attrs_array[i].map_attrs.neLng = north_east.lng; 1529 } 1530 } 1531 1532 var post_params = w2dc_collectAJAXParams({ hash: map_id, from_ajax_map: 1 }); 1533 post_params.ajax_action = 'ajax_markers'; 1534 1535 // set to first page after collection 1536 post_params.paged = 1; 1537 1538 post_params.swLat = south_west.lat; 1539 post_params.swLng = south_west.lng; 1540 post_params.neLat = north_east.lat; 1541 post_params.neLng = north_east.lng; 1542 1543 w2dc_startAJAXSearchOnMap(map_id, post_params); 1544 } 1545 var w2dc_startAJAXSearchOnMap = function(map_id, post_params) { 1546 1547 var attrs_array = w2dc_get_map_markers_attrs_array(map_id); 1548 var map_attrs = attrs_array.map_attrs; 1549 var enable_radius_circle = attrs_array.enable_radius_circle; 1550 var enable_clusters = attrs_array.enable_clusters; 1551 var show_summary_button = attrs_array.show_summary_button; 1552 var show_readmore_button = attrs_array.show_readmore_button; 1553 1554 $.ajax({ 1555 type: "POST", 1556 url: w2dc_js_objects.ajaxurl, 1557 data: post_params, 1558 dataType: 'json', 1559 success: function(response_from_the_action_function) { 1560 if (response_from_the_action_function) { 1561 var response_hash = response_from_the_action_function.hash; 1562 1563 // check opened info window 1564 var opened_location_id; 1565 if (typeof w2dc_infoWindows[map_id] != 'undefined') { 1566 opened_location_id = w2dc_infoWindows[map_id].location.id; 1567 } 1568 1569 if (response_from_the_action_function.html) { 1570 var listings_block = $('#w2dc-controller-'+response_hash); 1571 listings_block.replaceWith(response_from_the_action_function.html); 1572 } 1573 1574 var map_listings_block = $('#w2dc-map-listings-panel-'+response_hash); 1575 if (map_listings_block.length) { 1576 map_listings_block.html(response_from_the_action_function.map_listings); 1577 } 1578 1579 w2dc_clearMarkers(map_id); 1580 w2dc_removeShapes(map_id); 1581 w2dc_removeCircles(map_id); 1582 1583 if (typeof map_attrs.ajax_markers_loading != 'undefined' && map_attrs.ajax_markers_loading == 1) 1584 var is_ajax_markers = true; 1585 else 1586 var is_ajax_markers = false; 1587 1588 var markers_array = response_from_the_action_function.map_markers; 1589 w2dc_global_locations_array[map_id] = []; 1590 for (var j=0; j<markers_array.length; j++) { 1591 var map_coords_1 = markers_array[j][1]; 1592 var map_coords_2 = markers_array[j][2]; 1593 if ($.isNumeric(map_coords_1) && $.isNumeric(map_coords_2)) { 1594 var point = w2dc_buildPoint(map_coords_1, map_coords_2); 1595 1596 var location_obj = new w2dc_glocation(markers_array[j][0], point, 1597 markers_array[j][3], 1598 markers_array[j][4], 1599 markers_array[j][6], 1600 markers_array[j][7], 1601 markers_array[j][8], 1602 markers_array[j][9], 1603 markers_array[j][10], 1604 markers_array[j][11], 1605 show_summary_button, 1606 show_readmore_button, 1607 map_id, 1608 is_ajax_markers 1609 ); 1610 var marker = location_obj.w2dc_placeMarker(map_id); 1611 1612 w2dc_global_locations_array[map_id].push(location_obj); 1613 1614 // check opened info window 1615 if (opened_location_id == location_obj.id) { 1616 // re-open info Window 1617 w2dc_showInfoWindow(location_obj, location_obj.marker, map_id, '', 'onbuttonclick'); 1618 } 1619 } 1620 } 1621
1622 w2dc_setClusters(enable_clusters, map_id, w2dc_global_markers_array[map_id]); 1623 1624 if (enable_radius_circle && typeof response_from_the_action_function.radius_params != 'undefined') { 1625 var radius_params = response_from_the_action_function.radius_params; 1626 w2dc_drawRadius(radius_params, response_hash); 1627 } 1628 } 1629 }, 1630 complete: w2dc_completeAJAXSearchOnMap(map_id) 1631 }); 1632 } 1633 var w2dc_completeAJAXSearchOnMap = function(map_id) { 1634 return function() { 1635 w2dc_equalColumnsHeight(); 1636 w2dc_listings_carousel(); 1637 w2dc_show_on_map_links(); 1638 } 1639 } 1640 window.w2dc_drawRadius = function(radius_params, map_id) { 1641 var map_radius = parseFloat(radius_params.radius_value); 1642 1643 if (radius_params.dimension == 'miles') { 1644 map_radius *= 1.609344; 1645 } 1646 1647 var map_coords_1 = radius_params.map_coords_1; 1648 var map_coords_2 = radius_params.map_coords_2; 1649 1650 if ($.isNumeric(map_coords_1) && $.isNumeric(map_coords_2)) { 1651 var map = w2dc_maps[map_id]; 1652 map.addSource("source-circle-"+map_id, { 1653 "type": "geojson", 1654 "data": { 1655 "type": "FeatureCollection", 1656 "features": [{ 1657 "type": "Feature", 1658 "geometry": { 1659 "type": "Point", 1660 "coordinates": [map_coords_2, map_coords_1] 1661 } 1662 }] 1663 } 1664 }); 1665 1666 const metersToPixelsAtMaxZoom = (meters, latitude) => 1667 meters / 0.075 / Math.cos(latitude * Math.PI / 180) 1668 1669 map.addLayer({ 1670 "id": "radius-circle-"+map_id, 1671 "type": "circle", 1672 "source": "source-circle-"+map_id, 1673 "paint": { 1674 "circle-radius": { 1675 stops: [ 1676 [0, 0], 1677 [20, metersToPixelsAtMaxZoom(map_radius*1000, map_coords_1)] 1678 ], 1679 base: 2 1680 }, 1681 "circle-color": "#FF0000", 1682 "circle-opacity": 0.1, 1683 "circle-stroke-width": 1, 1684 "circle-stroke-color": "#FF0000", 1685 "circle-stroke-opacity": 0.25 1686 } 1687 }); 1688 1689 w2dc_drawCircles[map_id] = true; 1690 } 1691 } 1692 mapboxgl.Map.prototype.panToWithOffset = function(lnglat, offsetX, offsetY) { 1693 var map = this; 1694 var aPoint = map.project(lnglat); 1695 aPoint.x = aPoint.x+offsetX; 1696 aPoint.y = aPoint.y+offsetY; 1697 map.panTo(map.unproject(aPoint)); 1698 }; 1699 window.w2dc_placeMarker = function(location, map_id) { 1700 if (w2dc_maps_objects.map_markers_type != 'icons') { 1701 if (w2dc_maps_objects.global_map_icons_path != '') { 1702 var re = /(?:\.([^.]+))?$/; 1703 if (location.map_icon_file && typeof re.exec(w2dc_maps_objects.global_map_icons_path+'icons/'+location.map_icon_file)[1] != "undefined") 1704 var icon_file = w2dc_maps_objects.global_map_icons_path+'icons/'+location.map_icon_file; 1705 else 1706 var icon_file = w2dc_maps_objects.global_map_icons_path+"blank.png"; 1707 1708 var el = $("<div>", { 1709 id: 'marker-id-'+location.id, 1710 style: 'background-image: url('+icon_file+'); width: '+parseInt(w2dc_maps_objects.marker_image_width)+'px; height: '+parseInt(w2dc_maps_objects.marker_image_height)+'px', 1711 class: 'w2dc-mapbox-marker' 1712 }); 1713 var marker_div = el[0]; 1714 1715 var marker_options = { 1716 anchor: 'bottom', 1717 element: marker_div 1718 }; 1719 1720 var marker = new mapboxgl.Marker(marker_options) 1721 .setLngLat(location.point) 1722 .addTo(w2dc_maps[map_id]); 1723 } else { 1724 var marker = new mapboxgl.Marker() 1725 .setLngLat(location.point) 1726 .addTo(w2dc_maps[map_id]); 1727 } 1728 } else { 1729 if (location.map_icon_color) 1730 var map_marker_color = location.map_icon_color; 1731 else 1732 var map_marker_color = w2dc_maps_objects.default_marker_color; 1733 1734 if (typeof location.map_icon_file == 'string' && location.map_icon_file.indexOf("w2dc-fa-") != -1) { 1735 var map_marker_icon = '<span class="w2dc-map-marker-icon w2dc-fa '+location.map_icon_file+'" style="color: '+map_marker_color+';"></span>'; 1736 var map_marker_class = 'w2dc-map-marker'; 1737 } else { 1738 if (w2dc_maps_objects.default_marker_icon) { 1739 var map_marker_icon = '<span class="w2dc-map-marker-icon w2dc-fa '+w2dc_maps_objects.default_marker_icon+'" style="color: '+map_marker_color+';"></span>'; 1740 var map_marker_class = 'w2dc-map-marker'; 1741 } else { 1742 var map_marker_icon = ''; 1743 var map_marker_class = 'w2dc-map-marker-empty'; 1744 } 1745 } 1746 1747 var el = $("<div>", { 1748 id: 'marker-id-'+location.id, 1749 class: 'w2dc-mapbox-marker', 1750 html: '<div class="'+map_marker_class+'" style="background: '+map_marker_color+' none repeat scroll 0 0;">'+map_marker_icon+'</div>' 1751 }); 1752 var marker_div = el[0]; 1753 1754 var marker_options = { 1755 anchor: 'bottom', 1756 offset: [0, -20], 1757 element: marker_div 1758 }; 1759 1760 var marker = new mapboxgl.Marker(marker_options) 1761 .setLngLat(location.point) 1762 .addTo(w2dc_maps[map_id]); 1763 } 1764 1765 w2dc_global_markers_array[map_id].push(marker); 1766 1767 marker_div.addEventListener('click', function() { 1768 var attrs_array = w2dc_get_map_markers_attrs_array(map_id); 1769 if (attrs_array.center_map_onclick) { 1770 var map_attrs = attrs_array.map_attrs; 1771 if (typeof map_attrs.ajax_map_loading == 'undefined' || map_attrs.ajax_map_loading == 0) { 1772 w2dc_maps[map_id].panToWithOffset(marker.getLngLat(), 0, -100); 1773 w2dc_setInfoWindow(location, marker, map_id, 'bottom', 'onmarkerclick'); 1774 } 1775 } else { 1776 w2dc_setInfoWindow(location, marker, map_id, '', 'onmarkerclick'); 1777 } 1778 1779 if ($('#w2dc-map-listings-panel-'+map_id).length) { 1780 if ($('#w2dc-map-listings-panel-'+map_id+' #post-'+location.id).length) { 1781 $('#w2dc-map-listings-panel-'+map_id).animate({scrollTop: $('#w2dc-map-listings-panel-'+map_id).scrollTop() + $('#w2dc-map-listings-panel-'+map_id+' #post-'+location.id).position().top}, 'fast'); 1782 } 1783 } 1784
1785 if (attrs_array.show_directions) { 1786 w2dc_directions_display[map_id].directions.setDestination(location.point); 1787 1788 if (w2dc_directions_display[map_id].geolocation_field) { 1789 var geocoded_address = w2dc_directions_display[map_id].geolocation_field.val(); 1790 w2dc_directions_display[map_id].directions.setOrigin(geocoded_address); 1791 } 1792 } 1793 }); 1794 1795 return marker; 1796 } 1797 1798 window.w2dc_setInfoWindow = function(locations, marker, map_id, anchor, event) { 1799 1800 if (Array.isArray(locations)) { 1801 var first_location = locations[0]; 1802 } else { 1803 var first_location = locations; 1804 locations = [locations]; 1805 } 1806 1807 if (!first_location.is_ajax_markers) { 1808 w2dc_showInfoWindow(locations, marker, map_id, anchor, event); 1809 } else { 1810 // show empty infoWindow 1811 w2dc_showInfoWindow(locations, marker, map_id); 1812 1813 var post_data = { 1814 'locations_ids': locations.map(function(location) { return location.id }), 1815 'action': 'w2dc_get_map_marker_info', 1816 'map_id': map_id, 1817 'show_summary_button': first_location.show_summary_button, 1818 'show_readmore_button': first_location.show_readmore_button 1819 }; 1820 $.ajax({ 1821 type: "POST", 1822 url: w2dc_js_objects.ajaxurl, 1823 data: eval(post_data), 1824 dataType: 'json', 1825 success: function(response_from_the_action_function) { 1826 1827 var new_location_objs = []; 1828 1829 for (var i in response_from_the_action_function) { 1830 1831 var marker_array = response_from_the_action_function[i]; 1832 var map_coords_1 = marker_array[1]; 1833 var map_coords_2 = marker_array[2]; 1834 if ($.isNumeric(map_coords_1) && $.isNumeric(map_coords_2)) { 1835 var point = w2dc_buildPoint(map_coords_1, map_coords_2); 1836 1837 new_location_objs.push(new w2dc_glocation(marker_array[0], point, 1838 marker_array[3], 1839 marker_array[4], 1840 marker_array[6], 1841 marker_array[7], 1842 marker_array[8], 1843 marker_array[9], 1844 marker_array[10], 1845 marker_array[11], 1846 location.show_summary_button, 1847 location.show_readmore_button, 1848 map_id, 1849 true 1850 )); 1851 1852 } 1853 } 1854 1855 w2dc_showInfoWindow(new_location_objs, marker, map_id, anchor, 'onbuttonclick'); 1856 }, 1857 complete: function() { 1858 1859 } 1860 }); 1861 } 1862 } 1863 1864 // This function builds info Window and shows it hiding another 1865 function w2dc_showInfoWindow(locations, marker, map_id, anchor, event) { 1866 1867 for (var i=0; i<w2dc_map_markers_attrs_array.length; i++) { 1868 if (w2dc_map_markers_attrs_array[i].map_id == map_id) { 1869 var map_attrs = w2dc_map_markers_attrs_array[i]; 1870 } 1871 } 1872 1873 if (typeof map_attrs.enable_infowindow == 'undefined' || !map_attrs.enable_infowindow) { 1874 return; 1875 } 1876 1877 w2dc_closeInfoWindow(map_id); 1878 1879 if (Array.isArray(locations)) { 1880 var windowHtml = locations[0].content_fields; 1881 1882 var _windowHtml = $(windowHtml); 1883 1884 _windowHtml.find(".w2dc-map-info-window-inner").addClass("w2dc-map-info-window-inner-limit-height"); 1885 1886 for (var i=1; i < locations.length; i++) { 1887 var windowInnerHtml = locations[i].content_fields; 1888 1889 windowInnerHtml = $(windowInnerHtml)[0].outerHTML; 1890 1891 var inner = $(windowInnerHtml).find(".w2dc-map-info-window-inner-item"); 1892 1893 _windowHtml.find(".w2dc-map-info-window-inner-item").last().after(inner); 1894 1895 // remove summary button when no listing excerpt veisible 1896 var listing_id = _windowHtml.find(".w2dc-info-window-summary-button").data("listing-id"); 1897 if (!$("#post-"+listing_id).length) { 1898 var summary_btn = _windowHtml.find(".w2dc-info-window-summary-button"); 1899 1900 summary_btn.parent() 1901 .removeClass("w2dc-map-info-window-buttons") 1902 .addClass("w2dc-map-info-window-buttons-single"); 1903 1904 summary_btn.remove(); 1905 } 1906 windowHtml = _windowHtml[0].outerHTML; 1907 } 1908 } else { 1909 1910 var windowHtml = locations.content_fields; 1911 1912 // remove summary button when no listing excerpt veisible 1913 windowHtml = $($.parseHTML(windowHtml)); 1914 var listing_id = windowHtml.find(".w2dc-info-window-summary-button").data("listing-id"); 1915 if (!$("#post-"+listing_id).length) { 1916 var summary_btn = windowHtml.find(".w2dc-info-window-summary-button"); 1917 1918 summary_btn.parent() 1919 .removeClass("w2dc-map-info-window-buttons") 1920 .addClass("w2dc-map-info-window-buttons-single"); 1921 1922 summary_btn.remove(); 1923 } 1924 windowHtml = $(windowHtml)[0].outerHTML; 1925 } 1926 1927 var infowindow_width; 1928 var map_width = $('#w2dc-map-canvas-'+map_id).width(); 1929 if (map_width < w2dc_maps_objects.infowindow_width) { 1930 infowindow_width = map_width; 1931 } else { 1932 infowindow_width = w2dc_maps_objects.infowindow_width; 1933 } 1934 1935 var options = { 1936 offset: {'bottom': [0,-30]}, 1937 closeOnClick: false, 1938 anchor: anchor, 1939 className: 'w2dc-mapboxgl-popup-container', 1940 maxWidth: infowindow_width+'px' 1941 }; 1942
1943 if (typeof map_attrs.close_infowindow_out_click != 'undefined' && map_attrs.close_infowindow_out_click) { 1944 options.closeOnClick = true; 1945 } 1946 1947 var popup = new mapboxgl.Popup(options) 1948 .addTo(w2dc_maps[map_id]) 1949 .setHTML(windowHtml); 1950 1951 marker.setPopup(popup); 1952 1953 w2dc_infoWindows[map_id] = popup; 1954 w2dc_infoWindows[map_id].marker = marker; 1955 w2dc_infoWindows[map_id].location = locations; 1956 } 1957 1958 window.w2dc_scrollToListing = function(anchor, map_id) { 1959 var scroll_to_anchor = $("#"+anchor); 1960 var sticky_scroll_toppadding = 0; 1961 if (typeof window["w2dc_sticky_scroll_toppadding_"+map_id] != 'undefined') { 1962 sticky_scroll_toppadding = window["w2dc_sticky_scroll_toppadding_"+map_id]; 1963 } 1964 1965 if (scroll_to_anchor.length) { 1966 $('html,body').animate({scrollTop: scroll_to_anchor.position().top - sticky_scroll_toppadding}, 'fast'); 1967 } 1968 } 1969 1970 // global object to set and remove updateClusters event 1971 var w2dc_updateClusters; 1972 window.w2dc_setClusters = function(enable_clusters, map_id, markers) { 1973 if (enable_clusters) { 1974 var map = w2dc_maps[map_id], 1975 clusters = {}, 1976 clustersGeojson = {}; 1977 1978 var displayFeatures = function (features) { 1979 if (w2dc_global_locations_array[map_id].length) { 1980 $.each(w2dc_global_locations_array[map_id], function (i, marker) { 1981 // Do not remove markers, only hide. Otherwise on each move it will remove opened popup as well. 1982 $("#marker-id-"+w2dc_global_locations_array[map_id][i].id).hide(); 1983 }); 1984 } 1985 1986 $.each(features, function (i, feature) { 1987 var isCluster = (!!feature.properties.cluster) ? true : false, 1988 $feature; 1989 1990 if (isCluster) { 1991 var count = feature.properties.point_count, 1992 className; 1993 if (count > 50) { 1994 className = 'w2dc-mapbox-cluster-extralarge'; 1995 } else if (count > 25) { 1996 className = 'w2dc-mapbox-cluster-large'; 1997 } else if (count > 15) { 1998 className = 'w2dc-mapbox-cluster-medium'; 1999 } else if (count > 10) { 2000 className = 'w2dc-mapbox-cluster-small'; 2001 } else { 2002 className = 'w2dc-mapbox-cluster-extrasmall'; 2003 } 2004 2005 $feature = $('<div class="w2dc-mapbox-cluster ' + className + '" tabindex="0">' + feature.properties.point_count_abbreviated + '</div>'); 2006 clusters[feature.properties.cluster_id] = new mapboxgl.Marker($feature[0]).setLngLat(feature.geometry.coordinates).addTo(map); 2007 2008 $feature.on("click", function() { 2009 2010 var locations = []; 2011 var markers = clusterIndex.getLeaves(feature.properties.cluster_id); 2012 2013 for (var y in markers) { 2014 var location_id = markers[y].location_id; 2015 2016 if (w2dc_global_locations_array[map_id].length) { 2017 for (var i=0; i<w2dc_global_locations_array[map_id].length; i++) { 2018 if (typeof w2dc_global_locations_array[map_id][i] == 'object') { 2019 if (location_id == w2dc_global_locations_array[map_id][i].id) { 2020 locations.push(w2dc_global_locations_array[map_id][i]); 2021 } 2022 } 2023 } 2024 } 2025 } 2026 2027 var is_equalCoordinates = true; 2028 if (locations.length != 0) { 2029 for (var i=0; i < locations.length; i++) { 2030 var existingMarker = locations[i]; 2031 var pos = locations[i].point; 2032 2033 for (var j=0; j < locations.length; j++) { 2034 var markerToCompare = locations[j]; 2035 var markerToComparePos = locations[j].point; 2036 2037 var lat1= Math.round(pos[1] * 10000) / 10000; 2038 var lon1= Math.round(pos[0] * 10000) / 10000; 2039 var lat2= Math.round(markerToComparePos[1] * 10000) / 10000; 2040 var lon2= Math.round(markerToComparePos[0] * 10000) / 10000; 2041 2042 if (lat1 != lat2 && lon1 != lon2) { 2043 is_equalCoordinates = false; 2044 } 2045 } 2046 } 2047 } 2048 2049 if (!is_equalCoordinates) { 2050 var cluster_coords = feature.geometry.coordinates; 2051 var cluster_zoom = clusterIndex.getClusterExpansionZoom(feature.properties.cluster_id); 2052 map.flyTo({ 2053 center: cluster_coords, 2054 zoom: cluster_zoom 2055 }); 2056 } else { 2057 w2dc_setInfoWindow(locations, locations[0].marker, map_id, 'bottom', 'onclusterclick'); 2058 } 2059 2060 2061 }); 2062 } else { 2063 $("#marker-id-"+feature.location_id).show(); 2064 } 2065 }); 2066 }; 2067
2068 w2dc_updateClusters = function () { 2069 var bounds = map.getBounds(), 2070 zoom = map.getZoom(); 2071 2072 clustersGeojson = clusterIndex.getClusters([ 2073 bounds.getWest(), 2074 bounds.getSouth(), 2075 bounds.getEast(), 2076 bounds.getNorth() 2077 ], Math.floor(zoom)); 2078 2079 if (Object.keys(clusters).length) { 2080 $.each(clusters, function (i, cluster) { 2081 cluster.remove(); 2082 }); 2083 } 2084 2085 displayFeatures(clustersGeojson); 2086 }; 2087 2088 var feature_collection = []; 2089 for (var j=0; j<w2dc_global_locations_array[map_id].length; j++) { 2090 feature_collection.push({ 2091 "type": "Feature", 2092 "properties": {}, 2093 "geometry": { 2094 "type": "Point", 2095 "coordinates": w2dc_global_locations_array[map_id][j].point 2096 }, 2097 "location_id": w2dc_global_locations_array[map_id][j].id 2098 }); 2099 } 2100 2101 var clusterIndex = supercluster({ 2102 maxZoom: 20 2103 }); 2104 clusterIndex.load(feature_collection); 2105 map.on('moveend', w2dc_updateClusters); 2106 w2dc_updateClusters(); 2107 2108 w2dc_markerClusters[map_id] = clusters; 2109 } 2110 } 2111 window.w2dc_clearMarkers = function(map_id) { 2112 if (typeof w2dc_markerClusters[map_id] != 'undefined') { 2113 $.each(w2dc_markerClusters[map_id], function (i, clusters) { 2114 w2dc_markerClusters[map_id][i].remove(); 2115 }); 2116 // remove updateClusters event 2117 var map = w2dc_maps[map_id]; 2118 map.off('moveend', w2dc_updateClusters); 2119 2120 w2dc_markerClusters[map_id] = []; 2121 } 2122 2123 if (w2dc_global_markers_array[map_id]) { 2124 $.each(w2dc_global_markers_array[map_id], function (i, marker) { 2125 marker.remove(); 2126 }) 2127 } 2128 w2dc_global_markers_array[map_id] = []; 2129 w2dc_global_locations_array[map_id] = []; 2130 } 2131 window.w2dc_removeCircles = function(map_id) { 2132 if (typeof w2dc_drawCircles[map_id] != 'undefined' && w2dc_drawCircles[map_id]) { 2133 w2dc_maps[map_id].removeLayer('radius-circle-'+map_id); 2134 w2dc_maps[map_id].removeSource('source-circle-'+map_id); 2135 w2dc_drawCircles[map_id] = false; 2136 } 2137 } 2138 window.w2dc_removeShapes = function(map_id) { 2139 if (typeof w2dc_polygons[map_id] != 'undefined' && w2dc_polygons[map_id]) { 2140 w2dc_maps[map_id].removeLayer('geo-poly-'+map_id); 2141 w2dc_maps[map_id].removeSource('geo-poly-'+map_id); 2142 w2dc_polygons[map_id] = false; 2143 } 2144 2145 if (typeof w2dc_draws[map_id] != 'undefined' && w2dc_draws[map_id]) { 2146 w2dc_maps[map_id].removeControl(w2dc_draws[map_id]); 2147 w2dc_draws[map_id] = false; 2148 } 2149 } 2150 window.w2dc_reloadMap = function(map_id) { 2151 var map = w2dc_maps[map_id]; 2152 var zoom = map.getZoom(); 2153 var center = map.getCenter(); 2154 map.resize(); 2155 map.setZoom(zoom); 2156 map.setCenter(center); 2157 } 2158 2159 window.w2dc_geocodeField = function(field, error_message, map_id = false) { 2160 if (navigator.geolocation) { 2161 navigator.geolocation.getCurrentPosition( 2162 function(position) { 2163 $.get("https://api.mapbox.com/geocoding/v5/mapbox.places/"+position.coords.longitude + ',' + position.coords.latitude+".json?access_token="+w2dc_maps_objects.mapbox_api_key, function(data) { 2164 if (data.features.length) { 2165 var address = data.features[0].place_name; 2166 field.val(address); 2167 field.trigger('change'); 2168 } 2169 }); 2170 }, 2171 function(e) { 2172 2173 }, 2174 {enableHighAccuracy: true, timeout: 10000, maximumAge: 0} 2175 ); 2176 } else 2177 alert(error_message); 2178 } 2179})(jQuery); 2180 2181// supercluster.js -------------------------------------------------------------------------------------------------------- 2182//https://unpkg.com/[email protected]/dist/supercluster.min.js 2183!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).supercluster=t()}}(function(){return function t(n,o,e){function r(s,u){if(!o[s]){if(!n[s]){var a="function"==typeof require&&require;if(!u&&a)return a(s,!0);if(i)return i(s,!0);var h=new Error("Cannot find module '"+s+"'");throw h.code="MODULE_NOT_FOUND",h}var p=o[s]={exports:{}};n[s][0].call(p.exports,function(t){var o=n[s][1][t];return r(o||t)},p,p.exports,t,n,o,e)}return o[s].exports}for(var i="function"==typeof require&&require,s=0;s<e.length;s++)r(e[s]);return r}({1:[function(t,n,o){"use strict";function e(t){return new r(t)}function r(t){this.options=h(Object.create(this.options),t),this.trees=new Array(this.options.maxZoom+1)}function i(t){return{type:"Feature",properties:s(t),geometry:{type:"Point",coordinates:[function(t){return 360*(t-.5)}(t.x),function(t){var n=(180-360*t)*Math.PI/180;return 360*Math.atan(Math.exp(n))/Math.PI-90}(t.y)]}}}function s(t){var n=t.numPoints,o=n>=1e4?Math.round(n/1e3)+"k":n>=1e3?Math.round(n/100)/10+"k":n;return h(h({},t.properties),{cluster:!0,cluster_id:t.id,point_count:n,point_count_abbreviated:o})}function u(t){return t/360+.5}function a(t){var n=Math.sin(t*Math.PI/180),o=.5-.25*Math.log((1+n)/(1-n))/Math.PI;return o<0?0:o>1?1:o}function h(t,n){for(var o in n)t[o]=n[o];return t}function p(t){return t.x}function f(t){return t.y}var c=t("kdbush");n.exports=e,n.exports.default=e,r.prototype={options:{minZoom:0,maxZoom:16,radius:40,extent:512,nodeSize:64,log:!1,reduce:null,initial:function(){return{}},map:function(t){return t}},load:function(t){var n=this.options.log;n&&console.time("total time");var o="prepare "+t.length+" points";n&&console.time(o),this.points=t;for(var e=[],r=0;r<t.length;r++)t[r].geometry&&e.push(function(t,n){var o=t.geometry.coordinates;return{x:u(o[0]),y:a(o[1]),zoom:1/0,id:n,parentId:-1}}(t[r],r));this.trees[this.options.maxZoom+1]=c(e,p,f,this.options.nodeSize,Float32Array),n&&console.timeEnd(o);for(var i=this.options.maxZoom;i>=this.options.minZoom;i--){var s=+Date.now();e=this._cluster(e,i),this.trees[i]=c(e,p,f,this.options.nodeSize,Float32Array),n&&console.log("z%d: %d clusters in %dms",i,e.length,+Date.now()-s)}return n&&console.timeEnd("total time"),this},getClusters:function(t,n){if(t[0]>t[2]){var o=this.getClusters([t[0],t[1],180,t[3]],n),e=this.getClusters([-180,t[1],t[2],t[3]],n);return o.concat(e)}for(var r=this.trees[this._limitZoom(n)],s=r.range(u(t[0]),a(t[3]),u(t[2]),a(t[1])),h=[],p=0;p<s.length;p++){var f=r.points[s[p]];h.push(f.numPoints?i(f):this.points[f.id])}return h},getChildren:function(t){var n=t>>5,o=t%32,e="No cluster with the specified id.",r=this.trees[o];if(!r)throw new Error(e);var s=r.points[n];if(!s)throw new Error(e);for(var u=this.options.radius/(this.options.extent*Math.pow(2,o-1)),a=r.within(s.x,s.y,u),h=[],p=0;p<a.length;p++){var f=r.points[a[p]];f.parentId===t&&h.push(f.numPoints?i(f):this.points[f.id])}if(0===h.length)throw new Error(e);return h},getLeaves:function(t,n,o){n=n||10,o=o||0;var e=[];return this._appendLeaves(e,t,n,o,0),e},getTile:function(t,n,o){var e=this.trees[this._limitZoom(t)],r=Math.pow(2,t),i=this.options.extent,s=this.options.radius/i,u=(o-s)/r,a=(o+1+s)/r,h={features:[]};return this._addTileFeatures(e.range((n-s)/r,u,(n+1+s)/r,a),e.points,n,o,r,h),0===n&&this._addTileFeatures(e.range(1-s/r,u,1,a),e.points,r,o,r,h),n===r-1&&this._addTileFeatures(e.range(0,u,s/r,a),e.points,-1,o,r,h),h.features.length?h:null},getClusterExpansionZoom:function(t){for(var n=t%32-1;n<this.options.maxZoom;){var o=this.getChildren(t);if(n++,1!==o.length)break;t=o[0].properties.cluster_id}return n},_appendLeaves:function(t,n,o,e,r){for(var i=this.getChildren(n),s=0;s<i.length;s++){var u=i[s].properties;if(u&&u.cluster?r+u.point_count<=e?r+=u.point_count:r=this._appendLeaves(t,u.cluster_id,o,e,r):r<e?r++:t.push(i[s]),t.length===o)break}return r},_addTileFeatures:function(t,n,o,e,r,i){for(var u=0;u<t.length;u++){var a=n[t[u]];i.features.push({type:1,geometry:[[Math.round(this.options.extent*(a.x*r-o)),Math.round(this.options.extent*(a.y*r-e))]],tags:a.numPoints?s(a):this.points[a.id].properties})}},_limitZoom:function(t){return Math.max(this.options.minZoom,Math.min(t,this.options.maxZoom+1))},_cluster:function(t,n){for(var o=[],e=this.options.radius/(this.options.extent*Math.pow(2,n)),r=0;r<t.length;r++){var i=t[r];
2183if(!(i.zoom<=n)){i.zoom=n;var s=this.trees[n+1],u=s.within(i.x,i.y,e),a=i.numPoints||1,h=i.x*a,p=i.y*a,f=null;this.options.reduce&&(f=this.options.initial(),this._accumulate(f,i));for(var c=(r<<5)+(n+1),l=0;l<u.length;l++){var d=s.points[u[l]];if(!(d.zoom<=n)){d.zoom=n;var m=d.numPoints||1;h+=d.x*m,p+=d.y*m,a+=m,d.parentId=c,this.options.reduce&&this._accumulate(f,d)}}1===a?o.push(i):(i.parentId=c,o.push(function(t,n,o,e,r){return{x:t,y:n,zoom:1/0,id:o,parentId:-1,numPoints:e,properties:r}}(h/a,p/a,c,a,f)))}}return o},_accumulate:function(t,n){var o=n.numPoints?n.properties:this.options.map(this.points[n.id].properties);this.options.reduce(t,o)}}},{kdbush:2}],2:[function(t,n,o){"use strict";function e(t,n,o,e,i){n=n||function(t){return t[0]},o=o||function(t){return t[1]},i=i||Array,this.nodeSize=e||64,this.points=t,this.ids=new i(t.length),this.coords=new i(2*t.length);for(var s=0;s<t.length;s++)this.ids[s]=s,this.coords[2*s]=n(t[s]),this.coords[2*s+1]=o(t[s]);r(this.ids,this.coords,this.nodeSize,0,this.ids.length-1,0)}var r=t("./sort"),i=t("./range"),s=t("./within");n.exports=function(t,n,o,r,i){return new e(t,n,o,r,i)},e.prototype={range:function(t,n,o,e){return i(this.ids,this.coords,t,n,o,e,this.nodeSize)},within:function(t,n,o){return s(this.ids,this.coords,t,n,o,this.nodeSize)}}},{"./range":3,"./sort":4,"./within":5}],3:[function(t,n,o){"use strict";n.exports=function(t,n,o,e,r,i,s){for(var u,a,h=[0,t.length-1,0],p=[];h.length;){var f=h.pop(),c=h.pop(),l=h.pop();if(c-l<=s)for(var d=l;d<=c;d++)u=n[2*d],a=n[2*d+1],u>=o&&u<=r&&a>=e&&a<=i&&p.push(t[d]);else{var m=Math.floor((l+c)/2);u=n[2*m],a=n[2*m+1],u>=o&&u<=r&&a>=e&&a<=i&&p.push(t[m]);var v=(f+1)%2;(0===f?o<=u:e<=a)&&(h.push(l),h.push(m-1),h.push(v)),(0===f?r>=u:i>=a)&&(h.push(m+1),h.push(c),h.push(v))}}return p}},{}],4:[function(t,n,o){"use strict";function e(t,n,o,i,s,u){if(!(s-i<=o)){var a=Math.floor((i+s)/2);r(t,n,a,i,s,u%2),e(t,n,o,i,a-1,u+1),e(t,n,o,a+1,s,u+1)}}function r(t,n,o,e,s,u){for(;s>e;){if(s-e>600){var a=s-e+1,h=o-e+1,p=Math.log(a),f=.5*Math.exp(2*p/3),c=.5*Math.sqrt(p*f*(a-f)/a)*(h-a/2<0?-1:1);r(t,n,o,Math.max(e,Math.floor(o-h*f/a+c)),Math.min(s,Math.floor(o+(a-h)*f/a+c)),u)}var l=n[2*o+u],d=e,m=s;for(i(t,n,e,o),n[2*s+u]>l&&i(t,n,e,s);d<m;){for(i(t,n,d,m),d++,m--;n[2*d+u]<l;)d++;for(;n[2*m+u]>l;)m--}n[2*e+u]===l?i(t,n,e,m):i(t,n,++m,s),m<=o&&(e=m+1),o<=m&&(s=m-1)}}function i(t,n,o,e){s(t,o,e),s(n,2*o,2*e),s(n,2*o+1,2*e+1)}function s(t,n,o){var e=t[n];t[n]=t[o],t[o]=e}n.exports=e},{}],5:[function(t,n,o){"use strict";function e(t,n,o,e){var r=t-o,i=n-e;return r*r+i*i}n.exports=function(t,n,o,r,i,s){for(var u=[0,t.length-1,0],a=[],h=i*i;u.length;){var p=u.pop(),f=u.pop(),c=u.pop();if(f-c<=s)for(var l=c;l<=f;l++)e(n[2*l],n[2*l+1],o,r)<=h&&a.push(t[l]);else{var d=Math.floor((c+f)/2),m=n[2*d],v=n[2*d+1];e(m,v,o,r)<=h&&a.push(t[d]);var g=(p+1)%2;(0===p?o-i<=m:r-i<=v)&&(u.push(c),u.push(d-1),u.push(g)),(0===p?o+i>=m:r+i>=v)&&(u.push(d+1),u.push(f),u.push(g))}}return a}},{}]},{},[1])(1)});
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.