/*if (w2dc_js_objects.is_maps_used) { var w2dc_3rd_party_maps_plugin = false; var _warn = console.warn, _error = console.error; console.error = function() { if (typeof arguments[0].message != "undefined" && arguments[0].message) { alert(arguments[0].message); } return _error.apply(console, arguments); }; }*/ var w2dc_draws = []; var w2dc_draw_features = []; //mapboxgl_edit.js ------------------------------------------------------------------------------------------------------------------------------------------- (function($) { "use strict"; window.w2dc_load_maps_api_backend = function() { if ($("#w2dc-maps-canvas").length) { mapboxgl.accessToken = w2dc_maps_objects.mapbox_api_key; w2dc_map_backend = new mapboxgl.Map({ container: "w2dc-maps-canvas", style: w2dc_maps_objects.map_style }); if (w2dc_js_objects.is_rtl) { mapboxgl.setRTLTextPlugin('https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.1.0/mapbox-gl-rtl-text.js'); } var options = {}; if (w2dc_js_objects.lang) { options = { defaultLanguage: w2dc_js_objects.lang}; } w2dc_map_backend.addControl(new MapboxLanguage(options)) var navigationControl = new mapboxgl.NavigationControl({ showCompass: false, showZoom: true, }); w2dc_map_backend.addControl(navigationControl); if (w2dc_isAnyLocation_backend()) { w2dc_generateMap_backend(); } else { w2dc_map_backend.setCenter([w2dc_maps_objects.default_longitude, w2dc_maps_objects.default_latitude]); } w2dc_map_backend.on('zoom', function() { if (w2dc_allow_map_zoom_backend) { $(".w2dc-map-zoom").val(Math.round(w2dc_map_backend.getZoom())); } }); } w2dc_setupAutocomplete(); } window.w2dc_setupAutocomplete = function() { $(".w2dc-listing-field-autocomplete").listing_address_autocomplete(); } function w2dc_setMapCenter_backend(w2dc_coords_array_1, w2dc_coords_array_2) { var count = 0; var bounds = new mapboxgl.LngLatBounds(); for (count == 0; count", { id: 'marker-id-'+w2dc_glocation.index, style: 'background-image: url('+icon_file+'); width: '+parseInt(w2dc_maps_objects.marker_image_width)+'px; height: '+parseInt(w2dc_maps_objects.marker_image_height)+'px', class: 'w2dc-mapbox-marker' }); var marker_div = el[0]; var marker_options = { anchor: 'bottom', offset: [0, -20], element: marker_div, draggable: true }; var popup = new mapboxgl.Popup({ offset: 25 }) .setText(w2dc_glocation.compileAddress()); var marker = new mapboxgl.Marker(marker_options) .setLngLat(w2dc_glocation.point) .addTo(w2dc_map_backend) .setPopup(popup); } else { var marker = new mapboxgl.Marker() .setLngLat(location.point) .addTo(w2dc_map_backend); } } else { var map_marker_color = w2dc_maps_objects.default_marker_color; if (typeof w2dc_glocation.map_icon_file == 'string' && w2dc_glocation.map_icon_file.indexOf("w2dc-fa-") != -1) { var map_marker_icon = ''; var map_marker_class = 'w2dc-map-marker'; } else { if (w2dc_maps_objects.default_marker_icon) { var map_marker_icon = ''; var map_marker_class = 'w2dc-map-marker'; } else { var map_marker_icon = ''; var map_marker_class = 'w2dc-map-marker-empty'; } } var el = $("
", { id: 'marker-id-'+w2dc_glocation.index, class: 'w2dc-mapbox-marker', html: '
'+map_marker_icon+'
' }); var marker_div = el[0]; var marker_options = { anchor: 'bottom', offset: [0, -20], element: marker_div, draggable: true }; var popup = new mapboxgl.Popup({ offset: 25 }) .setText(w2dc_glocation.compileAddress()); var marker = new mapboxgl.Marker(marker_options) .setLngLat(w2dc_glocation.point) .addTo(w2dc_map_backend) .setPopup(popup); } w2dc_markersArray_backend.push(marker); marker.on('drag', function() { var point = marker.getLngLat(); if (point !== undefined) { var selected_location_num = w2dc_glocation.index; $(".w2dc-manual-coords:eq("+w2dc_glocation.index+")").prop("checked", true); $(".w2dc-manual-coords:eq("+w2dc_glocation.index+")").parents(".w2dc-manual-coords-wrapper").find(".w2dc-manual-coords-block").show(200); $(".w2dc-map-coords-1:eq("+w2dc_glocation.index+")").val(point.lat); $(".w2dc-map-coords-2:eq("+w2dc_glocation.index+")").val(point.lng); } }); } function w2dc_clearOverlays_backend() { if (w2dc_markersArray_backend) { for(var i = 0; i= w2dc_js_objects.mobile_screen_width) { if (w2dc_js_objects.is_rtl) { right_offset = 415; } else { left_offset = 415; } } w2dc_maps[map_id].fitBounds(bounds, {padding: {top: 50, bottom: 50, left: left_offset, right: right_offset}, duration: 0}); } window.w2dc_getMarkerPosition = function(marker) { return marker.getLngLat(); } window.w2dc_closeInfoWindow = function(map_id) { if (typeof w2dc_infoWindows[map_id] != 'undefined') { w2dc_infoWindows[map_id].remove(); } } class w2dc_point { constructor(lng, lat) { this.coord_1 = lng; this.coord_2 = lat; } lng() { return this.coord_1; } lat() { return this.coord_2; } } window.w2dc_setAjaxMarkersListener = function(map_id) { w2dc_setMapAjaxListener(w2dc_maps[map_id], map_id); } window.w2dc_geocodeAddress = function(address, callback, address_autocomplete_code) { if (typeof address_autocomplete_code != 'undefined' && address_autocomplete_code != '0') var country = '&country='+address_autocomplete_code; else var country = ''; $.get("https://api.mapbox.com/geocoding/v5/mapbox.places/"+encodeURIComponent(address)+".json?access_token="+w2dc_maps_objects.mapbox_api_key+country, function(data) { if (data.features.length) { // data.features[0].geometry.coordinates[0] - longitude // data.features[0].geometry.coordinates[1] - latitude callback(true, data.features[0].geometry.coordinates[1], data.features[0].geometry.coordinates[0]); } else { callback(false, 0, 0); } }).fail(function() { callback(false, 0, 0); }); } window.w2dc_callMapResize = function(map_id) { w2dc_maps[map_id].resize(); } window.w2dc_setMapCenter = function(map_id, center) { w2dc_maps[map_id].setCenter(center); } window.w2dc_setMapZoom = function(map_id, zoom) { w2dc_maps[map_id].setZoom(parseInt(zoom)); } window.w2dc_autocompleteService = function(term, address_autocomplete_code, common_array, response, callback) { if (address_autocomplete_code != '0') var country = '&country='+address_autocomplete_code; else var country = ''; var output_predictions = []; $.get("https://api.mapbox.com/geocoding/v5/mapbox.places/"+encodeURIComponent(term)+".json?access_token="+w2dc_maps_objects.mapbox_api_key+country, function(data) { $.map(data.features, function (prediction, i) { var output_prediction = { label: prediction.text, value: prediction.place_name, name: prediction.place_name, sublabel: prediction.place_name.replace(prediction.text + ", ", ""), }; output_predictions.push(output_prediction); }); callback(output_predictions, common_array, response); }).fail(function() { callback(output_predictions, common_array, response); });; } function w2dc_addPolygon(map_id) { var map = w2dc_maps[map_id]; map.addSource('geo-poly-'+map_id, { 'type': 'geojson', 'data': w2dc_draw_features[map_id] }); map.addLayer({ 'id': 'geo-poly-'+map_id, 'type': 'fill', 'source': 'geo-poly-'+map_id, 'layout': {}, 'paint': { 'fill-color': '#0099FF', 'fill-opacity': 0.3, 'fill-outline-color': '#AA2143' } }); w2dc_polygons[map_id] = true; } function w2dc_drawFreeHandPolygon(map_id) { var geojson = { "type": "FeatureCollection", "features": [] }; var linestring = { "type": "Feature", "geometry": { "type": "LineString", "coordinates": [] } }; var map = w2dc_maps[map_id]; map.addSource('geo-lines', { "type": "geojson", "data": geojson }); map.addLayer({ id: 'geo-lines', type: 'line', source: 'geo-lines', layout: { 'line-cap': 'round', 'line-join': 'round' }, paint: { 'line-color': '#AA2143', 'line-width': 2 }, filter: ['in', '$type', 'LineString'] }); var draw_move_event = function(e) { var features = map.queryRenderedFeatures(e.point, { layers: ['geo-lines'] }); // Remove the linestring from the group // So we can redraw it based on the points collection if (geojson.features.length > 1) geojson.features.pop(); var point = { "type": "Feature", "geometry": { "type": "Point", "coordinates": [ e.lngLat.lng, e.lngLat.lat ] }, "properties": { "id": String(new Date().getTime()) } }; geojson.features.push(point); if (geojson.features.length > 1) { linestring.geometry.coordinates = geojson.features.map(function(point) { return point.geometry.coordinates; }); geojson.features.push(linestring); } map.getSource('geo-lines').setData(geojson); }; map.on('mousemove', draw_move_event); map.on('touchmove', draw_move_event); var draw_up_event = function(e) { map.off('mousemove', draw_move_event); map.off('touchmove', draw_move_event); map.removeLayer('geo-lines'); map.removeSource('geo-lines'); var theArrayofLngLat = []; linestring.geometry.coordinates.map(function(point_feature) { theArrayofLngLat.push(new w2dc_point(point_feature[0], point_feature[1])); }); var ArrayforPolygontoUse = w2dc_GDouglasPeucker(theArrayofLngLat, 1); var geo_poly_json = []; var geo_poly_ajax = []; if (ArrayforPolygontoUse.length) { var lat_lng; for (lat_lng in ArrayforPolygontoUse) { geo_poly_json.push([ArrayforPolygontoUse[lat_lng].lng(), ArrayforPolygontoUse[lat_lng].lat()]); geo_poly_ajax.push({ 'lat': ArrayforPolygontoUse[lat_lng].lat(), 'lng': ArrayforPolygontoUse[lat_lng].lng() }); } geo_poly_json.push([ArrayforPolygontoUse[0].lng(), ArrayforPolygontoUse[0].lat()]); } if (geo_poly_json.length) { w2dc_sendGeoPolyAJAX(map_id, geo_poly_ajax); var geo_poly_feature = { 'id': 'geo-poly-feature-'+map_id, 'type': 'Feature', 'properties': {}, 'geometry': { 'type': 'Polygon', 'coordinates': [geo_poly_json] } }; w2dc_draw_features[map_id] = geo_poly_feature; w2dc_addPolygon(map_id); var editButton = $(map.getContainer()).find('.w2dc-map-edit').get(0); $(editButton).removeAttr('disabled'); } var drawButton = $(map.getContainer()).find('.w2dc-map-draw').get(0); drawButton.drawing_state = 0; window.removeEventListener('touchmove', w2dc_stop_touchmove_listener, { passive: false }); map.getCanvas().style.cursor = ''; $(drawButton).removeClass('w2dc-btn-active'); w2dc_disableDrawingMode(map_id); }; map.once('mouseup', draw_up_event); map.once('touchend', draw_up_event); } function w2dc_enableDrawingMode(map_id) { $(w2dc_maps[map_id].getContainer()).find('.w2dc-map-custom-controls').hide(); // if sidebar was not opened - hide search field if (!w2dc_isSidebarOpen(map_id) && $('#w2dc-map-search-wrapper-'+map_id).length) { $('#w2dc-map-search-wrapper-'+map_id).hide(); } var map = w2dc_maps[map_id]; map.scrollZoom.disable(); map.dragRotate.disable(); map.touchZoomRotate.disable(); map.dragPan.disable(); } function w2dc_disableDrawingMode(map_id) { var map = w2dc_maps[map_id]; $(map.getContainer()).find('.w2dc-map-custom-controls').show(); if ($('#w2dc-map-search-wrapper-'+map_id).length) $('#w2dc-map-search-wrapper-'+map_id).show(); var attrs_array = w2dc_get_map_markers_attrs_array(map_id); var enable_wheel_zoom = attrs_array.enable_wheel_zoom; var enable_dragging_touchscreens = attrs_array.enable_dragging_touchscreens; if (enable_dragging_touchscreens || !('ontouchstart' in document.documentElement)) { map.dragRotate.enable(); map.dragPan.enable(); map.touchZoomRotate.enable(); } if (enable_wheel_zoom) { map.scrollZoom.enable(); } } window.w2dc_setMapZoomCenter = function(map_id, map_attrs, markers_array) { if (typeof map_attrs.start_zoom != 'undefined' && map_attrs.start_zoom > 0) var zoom_level = map_attrs.start_zoom; else if (markers_array.length == 1) var zoom_level = markers_array[0][5]; else if (markers_array.length > 1) // fitbounds does not need zoom var zoom_level = false; else var zoom_level = 2; if (typeof map_attrs.start_latitude != 'undefined' && map_attrs.start_latitude && typeof map_attrs.start_longitude != 'undefined' && map_attrs.start_longitude) { var start_latitude = map_attrs.start_latitude; var start_longitude = map_attrs.start_longitude; if (zoom_level == false) { zoom_level = 12; } // required workaround: first zoom, then setCenter w2dc_setMapZoom(map_id, zoom_level); w2dc_setMapCenter(map_id, [start_longitude, start_latitude]); if (typeof map_attrs.ajax_loading != 'undefined' && map_attrs.ajax_loading == 1) { // use closures here w2dc_setMapAjaxListener(w2dc_maps[map_id], map_id); } } else if (typeof map_attrs.start_address != 'undefined' && map_attrs.start_address) { // use closures here w2dc_geocodeStartAddress(map_attrs, map_id, zoom_level); } else if (markers_array.length == 1) { w2dc_setMapZoom(map_id, zoom_level); } else if (zoom_level && markers_array.length == 0) { // no fitbounds here // required workaround: first zoom, then setCenter for initial load when single marker w2dc_setMapZoom(map_id, zoom_level); w2dc_setMapCenter(map_id, [w2dc_maps_objects.default_longitude, w2dc_maps_objects.default_latitude]); } } window.w2dc_show_on_map_links = function() { $(".w2dc-show-on-map").each(function() { var location_id = $(this).data("location-id"); var passed = false; for (var map_id in w2dc_maps) { if (typeof w2dc_global_locations_array[map_id] != 'undefined') { for (var i=0; i
'+(enable_full_screen ? '' : '')+'
'); this.container = customControls; return this.container; } onRemove() { this.container.parentNode.removeChild(this.container); this.map = undefined; } } var customControls = new w2dc_custom_controls(); if (w2dc_js_objects.is_rtl) { var cposition = 'top-left'; } else { var cposition = 'top-right'; } map.addControl(customControls, cposition); $(customControls.container).find('.w2dc-map-btn-zoom-in').on("click", function() { w2dc_maps[map_id].zoomIn(); }); $(customControls.container).find('.w2dc-map-btn-zoom-out').on("click", function() { w2dc_maps[map_id].zoomOut(); }); var interval; var mapDiv = w2dc_maps[map_id].getContainer(); var mapDivParent = $(mapDiv).parent().parent(); var divStyle = mapDiv.style; if (mapDiv.runtimeStyle) divStyle = mapDiv.runtimeStyle; var originalPos = divStyle.position; var originalWidth = divStyle.width; var originalHeight = divStyle.height; // ie8 hack if (originalWidth === "") originalWidth = mapDiv.style.width; if (originalHeight === "") originalHeight = mapDiv.style.height; var originalTop = divStyle.top; var originalLeft = divStyle.left; var originalZIndex = divStyle.zIndex; var bodyStyle = document.body.style; if (document.body.runtimeStyle) bodyStyle = document.body.runtimeStyle; var originalOverflow = bodyStyle.overflow; var thePanoramaOpened = false; var elements_to_zindex = [ "#w2dc-map-search-wrapper-"+map_id, "#w2dc-map-search-panel-wrapper-"+map_id, "#w2dc-map-sidebar-toggle-container-"+map_id, ]; //w2dc_fullScreens[map_id] = true; //openFullScreen(); function openFullScreen() { mapDivParent.after("
"); mapDivParent.appendTo('body'); var center = w2dc_maps[map_id].getCenter(); mapDiv.style.position = "fixed"; mapDiv.style.width = "100%"; mapDiv.style.height = "100%"; mapDiv.style.top = "0"; mapDiv.style.left = "0"; mapDiv.style.zIndex = "100000"; $(mapDiv).parent(".w2dc-maps-canvas-wrapper").css({ 'overflow': 'initial', 'z-index': 100000}); document.body.style.overflow = "hidden"; $(customControls.container).find('.w2dc-map-btn-fullscreen span').removeClass('w2dc-glyphicon-fullscreen'); $(customControls.container).find('.w2dc-map-btn-fullscreen span').addClass('w2dc-glyphicon-resize-small'); w2dc_callMapResize(map_id); w2dc_setMapCenter(map_id, center); $(elements_to_zindex).each(function() { if ($(this).length) { var zindex = ($(this).css('z-index')) ? $(this).css('z-index') : 0; if (zindex !== false) { if ($(document).width() > 768) { $(this).css('position', 'fixed'); } $(this).css('z-index', parseInt(zindex) + 100000); } } }); $(window).trigger('resize'); if ($(".w2dc-map-listings-panel").length) { $(".w2dc-map-listings-panel").getNiceScroll().resize(); } } function closeFullScreen() { $('#w2dc-map-placeholder-'+map_id).after(mapDivParent); $('#w2dc-map-placeholder-'+map_id).detach(); if (originalPos === "") { mapDiv.style.position = "relative"; } else { mapDiv.style.position = originalPos; } var center = w2dc_maps[map_id].getCenter(); mapDiv.style.width = originalWidth; mapDiv.style.height = originalHeight; mapDiv.style.top = originalTop; mapDiv.style.left = originalLeft; mapDiv.style.zIndex = originalZIndex; $(mapDiv).parent(".w2dc-maps-canvas-wrapper").css({ 'overflow': 'hidden', 'z-index': originalZIndex }); document.body.style.overflow = originalOverflow; $(customControls.container).find('.w2dc-map-btn-fullscreen span').removeClass('w2dc-glyphicon-resize-small'); $(customControls.container).find('.w2dc-map-btn-fullscreen span').addClass('w2dc-glyphicon-fullscreen'); w2dc_callMapResize(map_id); w2dc_setMapCenter(map_id, center); $(elements_to_zindex).each(function() { if ($(this).length) { var zindex = ($(this).css('z-index')) ? $(this).css('z-index') : 100000; if (zindex) { if ($(document).width() > 768) { $(this).css('position', 'absolute'); } $(this).css('z-index', parseInt(zindex) - 100000); } } }); $(window).trigger('resize'); if ($(".w2dc-map-listings-panel").length) { $(".w2dc-map-listings-panel").getNiceScroll().resize(); } } if (enable_full_screen) { $(customControls.container).find('.w2dc-map-btn-fullscreen').on("click", function() { if (typeof w2dc_fullScreens[map_id] == "undefined" || !w2dc_fullScreens[map_id]) { $("#w2dc-maps-canvas-wrapper-"+map_id).addClass("w2dc-map-full-screen"); w2dc_fullScreens[map_id] = true; openFullScreen(); } else { $("#w2dc-maps-canvas-wrapper-"+map_id).removeClass("w2dc-map-full-screen"); w2dc_fullScreens[map_id] = false; closeFullScreen(); } }); $(document).on("keyup", function(e) { if (typeof w2dc_fullScreens[map_id] != "undefined" && w2dc_fullScreens[map_id] && e.keyCode == 27) { $("#w2dc-maps-canvas-wrapper-"+map_id).removeClass("w2dc-map-full-screen"); w2dc_fullScreens[map_id] = false; closeFullScreen(); } }); } if (draw_panel) { var drawPanel = document.createElement('div'); $(drawPanel).addClass('w2dc-map-draw-panel'); class w2dc_dummy_control { constructor(drawPanel) { this.drawPanel = drawPanel; } onAdd(map){ this.map = map; var customControls = document.createElement('div'); $(customControls).addClass('mapboxgl-ctrl w2dc-map-draw-panel'); customControls.appendChild(this.drawPanel); this.container = customControls; return this.container; } onRemove(){ this.container.parentNode.removeChild(this.container); this.map = undefined; } } var dummyDiv = new w2dc_dummy_control(drawPanel); map.addControl(dummyDiv, cposition); var drawButton = document.createElement('button'); $(drawButton) .addClass('w2dc-btn w2dc-btn-primary w2dc-map-draw') .attr("title", w2dc_maps_objects.draw_area_button) .html(''); drawPanel.appendChild(drawButton); drawButton.map_id = map_id; drawButton.drawing_state = 0; $(drawButton).on("click", function(e) { var map_id = drawButton.map_id; if (this.drawing_state == 0) { this.drawing_state = 1; window.addEventListener('touchmove', w2dc_stop_touchmove_listener, { passive: false }); w2dc_clearMarkers(map_id); w2dc_closeInfoWindow(map_id); w2dc_removeShapes(map_id); w2dc_enableDrawingMode(map_id); var editButton = $(w2dc_maps[map_id].getContainer()).find('.w2dc-map-edit').get(0); $(editButton).removeClass('w2dc-btn-active'); $(editButton).attr('disabled', 'disabled'); $(editButton).find('.w2dc-map-edit-label').text(w2dc_maps_objects.edit_area_button); editButton.editing_state = 0; // remove ajax_loading and set drawing_state var map_attrs_array; if (map_attrs_array = w2dc_get_map_markers_attrs_array(map_id)) { map_attrs_array.map_attrs.drawing_state = 1; delete map_attrs_array.map_attrs.ajax_loading; } w2dc_maps[map_id].getCanvas().style.cursor = 'crosshair'; $(this).toggleClass('w2dc-btn-active'); w2dc_maps[map_id].getContainer().map_id = map_id; var draw_down_event = function(e) { var el = e.target; do { if ($(el).hasClass('w2dc-map-draw-panel')) { return; } } while (el = el.parentNode); w2dc_drawFreeHandPolygon(map_id); }; w2dc_maps[map_id].once('mousedown', draw_down_event); w2dc_maps[map_id].once('touchstart', draw_down_event); } else if (this.drawing_state == 1) { this.drawing_state = 0; window.removeEventListener('touchmove', w2dc_stop_touchmove_listener, { passive: false }); map.getCanvas().style.cursor = ''; $(drawButton).removeClass('w2dc-btn-active'); w2dc_disableDrawingMode(map_id); // repair ajax_loading and set drawing_state var map_attrs_array; if (map_attrs_array = w2dc_get_map_markers_attrs_array(map_id)) { map_attrs_array.map_attrs.drawing_state = 0; if (typeof w2dc_get_original_map_markers_attrs_array(map_id).map_attrs.ajax_loading != 'undefined' && w2dc_get_original_map_markers_attrs_array(map_id).map_attrs.ajax_loading == 1) { map_attrs_array.map_attrs.ajax_loading = 1; } } } }); var editButton = document.createElement('button'); $(editButton) .addClass('w2dc-btn w2dc-btn-primary w2dc-map-edit') .attr("title", w2dc_maps_objects.edit_area_button) .html('') .attr('disabled', 'disabled'); drawPanel.appendChild(editButton); editButton.map_id = map_id; editButton.editing_state = 0; $(editButton).on("click", function(e) { var map_id = editButton.map_id; if (this.editing_state == 0) { this.editing_state = 1; $(this).toggleClass('w2dc-btn-active'); $(this).attr("title", w2dc_maps_objects.apply_area_button); w2dc_removeShapes(map_id); var draw = new MapboxDraw({ displayControlsDefault: false, styles: [ // line stroke { "id": "gl-draw-line", "type": "line", "filter": ["all", ["==", "$type", "LineString"], ["!=", "mode", "static"]], "layout": { "line-cap": "round", "line-join": "round" }, "paint": { "line-color": "#AA2143", "line-dasharray": [0.2, 2], "line-width": 1 } }, // polygon fill { "id": "gl-draw-polygon-fill", "type": "fill", "filter": ["all", ["==", "$type", "Polygon"], ["!=", "mode", "static"]], "paint": { "fill-color": "#0099FF", "fill-outline-color": "#AA2143", "fill-opacity": 0.3 } }, // vertex point halos { "id": "gl-draw-polygon-and-line-vertex-halo-active", "type": "circle", "filter": ["all", ["==", "meta", "vertex"], ["==", "$type", "Point"], ["!=", "mode", "static"]], "paint": { "circle-radius": 5, "circle-color": "#FFF" } }, // vertex points { "id": "gl-draw-polygon-and-line-vertex-active", "type": "circle", "filter": ["all", ["==", "meta", "vertex"], ["==", "$type", "Point"], ["!=", "mode", "static"]], "paint": { "circle-radius": 3, "circle-color": "#AA2143", } } ] }); map.addControl(draw); draw.add(w2dc_draw_features[map_id]); draw.changeMode('direct_select', { featureId: w2dc_draw_features[map_id].id }); w2dc_draws[map_id] = draw; } else if (this.editing_state == 1) { this.editing_state = 0; $(this).toggleClass('w2dc-btn-active'); $(this).attr("title", w2dc_maps_objects.edit_area_button); if (typeof w2dc_draws[map_id] != 'undefined' && w2dc_draws[map_id]) { var draw = w2dc_draws[map_id]; draw.changeMode('simple_select', { featureId: w2dc_draw_features[map_id].id }); w2dc_draw_features[map_id] = draw.get(w2dc_draw_features[map_id].id); w2dc_addPolygon(map_id); var geo_poly_ajax = []; w2dc_draw_features[map_id].geometry.coordinates[0].map(function(point_feature) { geo_poly_ajax.push({ 'lat': point_feature[1], 'lng': point_feature[0] }); }); if (geo_poly_ajax.length) { w2dc_sendGeoPolyAJAX(map_id, geo_poly_ajax); } } map.removeControl(w2dc_draws[map_id]); w2dc_draws[map_id] = false; } }); var reloadButton = document.createElement('button'); $(reloadButton) .addClass('w2dc-btn w2dc-btn-primary w2dc-map-reload') .attr("title", w2dc_maps_objects.reload_map_button) .html(''); drawPanel.appendChild(reloadButton); reloadButton.map_id = map_id; $(reloadButton).on("click", function(e) { var map_id = reloadButton.map_id; for (var i=0; i'); drawPanel.appendChild(locationButton); locationButton.map_id = map_id; $(locationButton).on("click", function(e) { var map_id = locationButton.map_id; if (navigator.geolocation) { navigator.geolocation.getCurrentPosition( function(position) { var start_latitude = position.coords.latitude; var start_longitude = position.coords.longitude; w2dc_setMapCenter(map_id, w2dc_buildPoint(start_latitude, start_longitude)); }, function(e) { //alert(e.message); }, {timeout: 10000} ); } }); } } } // end of (!fullScreen) w2dc_global_markers_array[map_id] = []; w2dc_global_locations_array[map_id] = []; if (markers_array.length) { var bounds = w2dc_buildBounds(); if (typeof map_attrs.ajax_markers_loading != 'undefined' && map_attrs.ajax_markers_loading == 1) { var is_ajax_markers = true; } else { var is_ajax_markers = false; } var markers = []; for (var j=0; j 0) { w2dc_setMapZoom(map_id, w2dc_maps_attrs[map_id].start_zoom); } for (var j=0; j= bl.lng || p.lng <= tr.lng) { return true; } } else if (p.lng >= bl.lng && p.lng <= tr.lng) { return true; } } if (p.lat >= bl.lat && p.lat <= tr.lat && isLongInRange(bl, tr, p)) { return true; } else { return false; } } if (typeof map_attrs.swLat != 'undefined' && typeof map_attrs.swLng != 'undefined' && typeof map_attrs.neLat != 'undefined' && typeof map_attrs.neLng != 'undefined') { var sw_point = new mapboxgl.LngLat(map_attrs.swLng, map_attrs.swLat); var ne_point = new mapboxgl.LngLat(map_attrs.neLng, map_attrs.neLat); var worldCoordinate_new = map.project(sw_point); var worldCoordinate_old = map.project(south_west); if ( (inBoundingBox(sw_point, ne_point, south_west) && inBoundingBox(sw_point, ne_point, north_east)) || (140 > Math.abs(Math.floor(worldCoordinate_new.x) - Math.floor(worldCoordinate_old.x)) && 140 > Math.abs(Math.floor(worldCoordinate_new.y) - Math.floor(worldCoordinate_old.y))) ) return false; } map_attrs.swLat = south_west.lat; map_attrs.swLng = south_west.lng; map_attrs.neLat = north_east.lat; map_attrs.neLng = north_east.lng; w2dc_ajax_loader_target_show($('#w2dc-maps-canvas-'+map_id)); var ajax_params = {}; for (var attrname in map_attrs) { if (attrname != 'start_latitude' && attrname != 'start_longitude') { ajax_params[attrname] = map_attrs[attrname]; } } ajax_params.action = 'w2dc_get_map_markers'; ajax_params.hash = map_id; var listings_args_array; if (listings_args_array = w2dc_get_controller_args_array(map_id)) { ajax_params.hide_order = listings_args_array.hide_order; ajax_params.hide_count = listings_args_array.hide_count; ajax_params.hide_paginator = listings_args_array.hide_paginator; ajax_params.show_views_switcher = listings_args_array.show_views_switcher; ajax_params.listings_view_type = listings_args_array.listings_view_type; ajax_params.listings_view_grid_columns = listings_args_array.listings_view_grid_columns; ajax_params.listing_thumb_width = listings_args_array.listing_thumb_width; ajax_params.wrap_logo_list_view = listings_args_array.wrap_logo_list_view; ajax_params.logo_animation_effect = listings_args_array.logo_animation_effect; ajax_params.grid_view_logo_ratio = listings_args_array.grid_view_logo_ratio; ajax_params.scrolling_paginator = listings_args_array.scrolling_paginator; ajax_params.paged = listings_args_array.paged; ajax_params.perpage = listings_args_array.perpage; ajax_params.onepage = listings_args_array.onepage; ajax_params.order = listings_args_array.order; ajax_params.order_by = listings_args_array.order_by; ajax_params.base_url = listings_args_array.base_url; w2dc_ajax_loader_target_show($('#w2dc-controller-'+map_id)); } else ajax_params.without_listings = 1; if ($("#w2dc-map-listings-panel-"+map_id).length) { ajax_params.map_listings = 1; w2dc_ajax_loader_target_show($("#w2dc-map-search-panel-wrapper-"+map_id)); } $.ajax({ type: "POST", url: w2dc_js_objects.ajaxurl, data: ajax_params, dataType: 'json', success: function(response_from_the_action_function) { if (response_from_the_action_function) { var responce_hash = response_from_the_action_function.hash; if (response_from_the_action_function.html) { var listings_block = $('#w2dc-controller-'+responce_hash); listings_block.replaceWith(response_from_the_action_function.html); w2dc_ajax_loader_target_hide('w2dc-controller-'+responce_hash); } var map_listings_block = $('#w2dc-map-listings-panel-'+responce_hash); if (map_listings_block.length) { map_listings_block.html(response_from_the_action_function.map_listings); w2dc_ajax_loader_target_hide('w2dc-map-search-panel-wrapper-'+responce_hash); } w2dc_clearMarkers(map_id); w2dc_removeShapes(map_id); if (typeof map_attrs.ajax_markers_loading != 'undefined' && map_attrs.ajax_markers_loading == 1) var is_ajax_markers = true; else var is_ajax_markers = false; var markers_array = response_from_the_action_function.map_markers; w2dc_global_locations_array[map_id] = []; for (var j=0; j meters / 0.075 / Math.cos(latitude * Math.PI / 180) map.addLayer({ "id": "radius-circle-"+map_id, "type": "circle", "source": "source-circle-"+map_id, "paint": { "circle-radius": { stops: [ [0, 0], [20, metersToPixelsAtMaxZoom(map_radius*1000, map_coords_1)] ], base: 2 }, "circle-color": "#FF0000", "circle-opacity": 0.1, "circle-stroke-width": 1, "circle-stroke-color": "#FF0000", "circle-stroke-opacity": 0.25 } }); w2dc_drawCircles[map_id] = true; } } mapboxgl.Map.prototype.panToWithOffset = function(lnglat, offsetX, offsetY) { var map = this; var aPoint = map.project(lnglat); aPoint.x = aPoint.x+offsetX; aPoint.y = aPoint.y+offsetY; map.panTo(map.unproject(aPoint)); }; window.w2dc_placeMarker = function(location, map_id) { if (w2dc_maps_objects.map_markers_type != 'icons') { if (w2dc_maps_objects.global_map_icons_path != '') { var re = /(?:\.([^.]+))?$/; if (location.map_icon_file && typeof re.exec(w2dc_maps_objects.global_map_icons_path+'icons/'+location.map_icon_file)[1] != "undefined") var icon_file = w2dc_maps_objects.global_map_icons_path+'icons/'+location.map_icon_file; else var icon_file = w2dc_maps_objects.global_map_icons_path+"blank.png"; var el = $("
", { id: 'marker-id-'+location.id, style: 'background-image: url('+icon_file+'); width: '+parseInt(w2dc_maps_objects.marker_image_width)+'px; height: '+parseInt(w2dc_maps_objects.marker_image_height)+'px', class: 'w2dc-mapbox-marker' }); var marker_div = el[0]; var marker_options = { anchor: 'bottom', element: marker_div }; var marker = new mapboxgl.Marker(marker_options) .setLngLat(location.point) .addTo(w2dc_maps[map_id]); } else { var marker = new mapboxgl.Marker() .setLngLat(location.point) .addTo(w2dc_maps[map_id]); } } else { if (location.map_icon_color) var map_marker_color = location.map_icon_color; else var map_marker_color = w2dc_maps_objects.default_marker_color; if (typeof location.map_icon_file == 'string' && location.map_icon_file.indexOf("w2dc-fa-") != -1) { var map_marker_icon = ''; var map_marker_class = 'w2dc-map-marker'; } else { if (w2dc_maps_objects.default_marker_icon) { var map_marker_icon = ''; var map_marker_class = 'w2dc-map-marker'; } else { var map_marker_icon = ''; var map_marker_class = 'w2dc-map-marker-empty'; } } var el = $("
", { id: 'marker-id-'+location.id, class: 'w2dc-mapbox-marker', html: '
'+map_marker_icon+'
' }); var marker_div = el[0]; var marker_options = { anchor: 'bottom', offset: [0, -20], element: marker_div }; var marker = new mapboxgl.Marker(marker_options) .setLngLat(location.point) .addTo(w2dc_maps[map_id]); } w2dc_global_markers_array[map_id].push(marker); marker_div.addEventListener('click', function() { var attrs_array = w2dc_get_map_markers_attrs_array(map_id); if (attrs_array.center_map_onclick) { var map_attrs = attrs_array.map_attrs; if (typeof map_attrs.ajax_loading == 'undefined' || map_attrs.ajax_loading == 0) { //w2dc_maps[map_id].panTo(marker.getLngLat()); w2dc_maps[map_id].panToWithOffset(marker.getLngLat(), 0, -100); w2dc_setInfoWindow(location, marker, map_id, 'bottom', 'onmarkerclick'); } } else { w2dc_setInfoWindow(location, marker, map_id, '', 'onmarkerclick'); } if ($('#w2dc-map-listings-panel-'+map_id).length) { if ($('#w2dc-map-listings-panel-'+map_id+' #post-'+location.id).length) { $('#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'); } } }); return marker; } window.w2dc_setInfoWindow = function(location, marker, map_id, anchor, event) { if (!location.is_ajax_markers) { w2dc_showInfoWindow(location, marker, map_id, anchor, event); } else { w2dc_ajax_loader_target_show($('#w2dc-maps-canvas-'+map_id)); var post_data = {'location_id': location.id, 'action': 'w2dc_get_map_marker_info'}; $.ajax({ type: "POST", url: w2dc_js_objects.ajaxurl, data: eval(post_data), dataType: 'json', success: function(response_from_the_action_function) { var marker_array = response_from_the_action_function; var map_coords_1 = marker_array[1]; var map_coords_2 = marker_array[2]; if ($.isNumeric(map_coords_1) && $.isNumeric(map_coords_2)) { var point = w2dc_buildPoint(map_coords_1, map_coords_2); var new_location_obj = new w2dc_glocation(marker_array[0], point, marker_array[3], marker_array[4], marker_array[6], marker_array[7], marker_array[8], marker_array[9], marker_array[10], marker_array[11], location.show_summary_button, location.show_readmore_button, map_id, true ); w2dc_showInfoWindow(new_location_obj, marker, map_id, anchor, 'onbuttonclick'); } }, complete: function() { w2dc_ajax_loader_target_hide("w2dc-maps-canvas-"+map_id); } }); } } // This function builds info Window and shows it hiding another function w2dc_showInfoWindow(w2dc_glocation, marker, map_id, anchor, event) { // we use global infoWindow, not to close/open it - just to set new content (in order to prevent blinking) if (typeof w2dc_infoWindows[map_id] != 'undefined' && w2dc_infoWindows[map_id]) { w2dc_infoWindows[map_id].remove(); w2dc_infoWindows[map_id] = false; } if (w2dc_glocation.nofollow) var nofollow = 'rel="nofollow"'; else var nofollow = ''; var windowHtml = '
'; windowHtml += '
'; if (w2dc_glocation.listing_url && w2dc_glocation.show_readmore_button) windowHtml += ''; windowHtml += w2dc_glocation.listing_title; if (w2dc_glocation.listing_url && w2dc_glocation.show_readmore_button) windowHtml += ''; windowHtml += ''; windowHtml += '
'; if (w2dc_glocation.listing_logo) { windowHtml += ''; } windowHtml += '
'; if (w2dc_glocation.content_fields) { for (var i=0; i'; windowHtml += w2dc_glocation.content_fields[i]; windowHtml += '
'; } } } windowHtml += '
'; if ((w2dc_glocation.show_summary_button && $("#"+w2dc_glocation.anchor).length) || (w2dc_glocation.listing_url && w2dc_glocation.show_readmore_button)) { if (!(w2dc_glocation.show_summary_button && $("#"+w2dc_glocation.anchor).length) || !(w2dc_glocation.listing_url && w2dc_glocation.show_readmore_button)) var button_class = 'w2dc-map-info-window-buttons-single'; else var button_class = 'w2dc-map-info-window-buttons'; windowHtml += '
'; if (w2dc_glocation.show_summary_button && $("#"+w2dc_glocation.anchor).length) windowHtml += '' + w2dc_maps_objects.w2dc_map_info_window_button_summary + ''; if (w2dc_glocation.listing_url && w2dc_glocation.show_readmore_button) windowHtml += '' + w2dc_maps_objects.w2dc_map_info_window_button_readmore + ''; windowHtml += '
'; } windowHtml += '
'; var options = { offset: {'bottom': [0,-30]}, closeOnClick: false, anchor: anchor, maxWidth: w2dc_maps_objects.infowindow_width }; var popup = new mapboxgl.Popup(options) .setHTML(windowHtml) .addTo(w2dc_maps[map_id]); marker.setPopup(popup); // This is needed workaround, otherwise it will not open infoWindow on "On map" button click due to popup.addTo(w2dc_maps[map_id]) if (event == 'onmarkerclick') { marker.addTo(w2dc_maps[map_id]); } w2dc_infoWindows[map_id] = popup; } window.w2dc_scrollToListing = function(anchor, map_id) { var scroll_to_anchor = $("#"+anchor); var sticky_scroll_toppadding = 0; if (typeof window["w2dc_sticky_scroll_toppadding_"+map_id] != 'undefined') { sticky_scroll_toppadding = window["w2dc_sticky_scroll_toppadding_"+map_id]; } if (scroll_to_anchor.length) { $('html,body').animate({scrollTop: scroll_to_anchor.position().top - sticky_scroll_toppadding}, 'fast'); } } // global object to set and remove updateClusters event var w2dc_updateClusters; window.w2dc_setClusters = function(enable_clusters, map_id) { if (enable_clusters) { var map = w2dc_maps[map_id], clusters = {}, markers = [], clustersGeojson = {}; var displayFeatures = function (features) { if (w2dc_global_locations_array[map_id].length) { $.each(w2dc_global_locations_array[map_id], function (i, marker) { // Do not remove markers, only hide. Otherwise on each move it will remove opened opoup as well. $("#marker-id-"+w2dc_global_locations_array[map_id][i].id).hide(); }); } $.each(features, function (i, feature) { var isCluster = (!!feature.properties.cluster) ? true : false, $feature; if (isCluster) { var count = feature.properties.point_count, className; if (count > 50) { className = 'w2dc-mapbox-cluster-extralarge'; } else if (count > 25) { className = 'w2dc-mapbox-cluster-large'; } else if (count > 15) { className = 'w2dc-mapbox-cluster-medium'; } else if (count > 10) { className = 'w2dc-mapbox-cluster-small'; } else { className = 'w2dc-mapbox-cluster-extrasmall'; } $feature = $('
' + feature.properties.point_count_abbreviated + '
'); clusters[feature.properties.cluster_id] = new mapboxgl.Marker($feature[0]).setLngLat(feature.geometry.coordinates).addTo(map); $feature.on("click", function() { var cluster_coords = feature.geometry.coordinates; var cluster_zoom = clusterIndex.getClusterExpansionZoom(feature.properties.cluster_id); map.flyTo({ center: cluster_coords, zoom: cluster_zoom }); }); } else { $("#marker-id-"+feature.location_id).show(); } }); }; w2dc_updateClusters = function () { var bounds = map.getBounds(), zoom = map.getZoom(); clustersGeojson = clusterIndex.getClusters([ bounds.getWest(), bounds.getSouth(), bounds.getEast(), bounds.getNorth() ], Math.floor(zoom)); if (Object.keys(clusters).length) { $.each(clusters, function (i, cluster) { cluster.remove(); }); } displayFeatures(clustersGeojson); }; var feature_collection = []; for (var j=0; j=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=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>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=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);dl;)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)});