2026-02-05 17:08:59 +03:00

1 line
3.3 KiB
JavaScript

!function(t){"use strict";function e(t){if(!(0<t.length))return awbOpenStreetMap.default_coords;const e=t.length;let o,a,n,i,r,s,p,d,u;for(o=0,a=0,n=0,u=0;u<t.length;u++)i=t[u][0]*Math.PI/180,r=t[u][1]*Math.PI/180,s=Math.cos(i)*Math.cos(r),p=Math.cos(i)*Math.sin(r),d=Math.sin(i),o+=s,a+=p,n+=d;o/=e,a/=e,n/=e,r=Math.atan2(a,o);const c=Math.sqrt(o*o+a*a);i=Math.atan2(n,c);return[180*i/Math.PI,180*r/Math.PI]}function o(e){return t(e).find(".awb-openstreet-map-marker").map((function(){const t=this.getAttribute("data-latitude"),e=this.getAttribute("data-longitude");return t&&e?[[t,e]]:null})).get()}window.fusion_open_street_map=[],t(window).on("load fusion-element-render-fusion_openstreetmap",(function(a,n){var i=void 0!==n;(i?t('div[data-cid="'+n+'"]').find(".awb-openstreet-map"):t(".awb-openstreet-map")).each((function(){this.dataset.isRendered||function(a,n,i){const r=a.getAttribute("data-map-style"),s=a.getAttribute("data-zoom"),p=a.getAttribute("data-zoomsnap"),d=a.getAttribute("data-zoomcontrol"),u=a.getAttribute("data-dragging"),c=a.getAttribute("data-touchzoom"),l=a.getAttribute("data-dbclickzoom"),h=a.getAttribute("data-scrollwheelzoom"),b=a.getAttribute("data-map-type"),m=a.getAttribute("data-shape-color"),g=a.getAttribute("data-shape-weight"),f=a.getAttribute("data-fitbounds"),w={color:m,weight:g};let _=o(a);const A=[],M=[],k={zoomControl:d,zoomSnap:parseFloat(p)};n&&(window.fusion_open_street_map[i]=[]);const y=L.map(a,k).setView(e(_),parseFloat(s));L.tileLayer(awbOpenStreetMap.tiles[r].url,{attribution:awbOpenStreetMap.tiles[r].attribute}).addTo(y),u||y.dragging.disable(),h||y.scrollWheelZoom.disable(),c||y.touchZoom.disable(),l||y.doubleClickZoom.disable(),t(a).on("awb_openstreetmap/updateCoords",(function(){const t=e(o(a));y.flyTo(t)})).on("awb_openstreetmap/updateMarker",(function(){if(A.forEach((function(t,e){y.removeLayer(A[e])})),n&&(window.fusion_open_street_map[i]=[]),M.forEach((function(t,e){y.removeLayer(M[e])})),_=o(a),t(a).find(".awb-openstreet-map-marker").each((function(){const e=this.getAttribute("data-latitude"),o=this.getAttribute("data-longitude"),a=t(this).find(".awb-openstreet-map-content-wrapper").html(),r=this.getAttribute("data-action"),s=t(this).find(".awb-openstreet-map-marker-icon-wrapper"),p=s.width(),d=s.height();if(!e||!o)return!0;const u=L.marker([e,o],{icon:L.divIcon({iconSize:[p,d],html:s[0].outerHTML,className:"awb-openstreet-map-marker-icon"})});switch(u.addTo(y),r){case"popup":u.bindPopup(a);break;case"static_close_on":u.bindPopup(a,{closeOnClick:!1,autoClose:!1,closeOnEscapeKey:!1}).openPopup();break;case"static_close_off":u.bindPopup(a,{closeOnClick:!1,autoClose:!1,closeButton:!1,closeOnEscapeKey:!1}).openPopup();break;case"tooltip":u.bindTooltip(a,{direction:"top",opacity:1})}A.push(u),n&&(window.fusion_open_street_map[i][this.getAttribute("data-cid")]||(window.fusion_open_street_map[i][this.getAttribute("data-cid")]=[]),window.fusion_open_street_map[i][this.getAttribute("data-cid")].push(u))})),"polygon"===b){const t=L.polygon(_,w).addTo(y);f&&y.fitBounds(t.getBounds()),M.push(t)}if("polyline"===b){const t=L.polyline(_,w).addTo(y);f&&y.fitBounds(t.getBounds()),M.push(t)}if(A.length&&"marker"===b&&f){const t=L.featureGroup(A),e=1===A.length?{animate:!0}:{};y.fitBounds(t.getBounds(),e)}})).trigger("awb_openstreetmap/updateMarker"),a.dataset.isRendered=1}(this,i,n)}))}))}(jQuery);