Liferay.Loader.define("dynamic-data-mapping-form-field-type@6.0.108/Geolocation/useGeolocation.es",["module","exports","require","@liferay/map-google-maps/js/MapGoogleMaps.es","@liferay/map-openstreetmap/js/MapOpenStreetMap.es","data-engine-js-components-web","dynamic-data-mapping-form-field-type$leaflet","liferay!frontend-js-react-web$react"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.useGeolocation=function({disabled:t,googleMapsAPIKey:a,instanceId:r,mapProviderKey:i,name:s,onChange:c,value:f,viewMode:u}){const M=(0,p.useRef)(null);(0,p.useEffect)((()=>{if(!t||u){const t=l(l({},d),{},{boundingBox:"#map_".concat(r)});t.position.location=f?g(f):{lat:0,lng:0};const p=(e,t)=>{M.current=new e(t),Liferay.MapBase.register(m(s),M.current,"#map_".concat(r))};switch(i){case e.openStreetMap:y((()=>p(o.default,t)));break;case e.googleMaps:b(a,(()=>p(n.default,t)));break;default:throw new Error("mapProvider is not supported!")}}return()=>{M.current&&M.current.dispose()}}),[]),(0,p.useEffect)((()=>{M.current&&(M.current.removeAllListeners("positionChange"),M.current.on("positionChange",c))}),[c]),(0,p.useEffect)((()=>{if(f&&M.current){let e=f;"string"!=typeof e&&(e=JSON.stringify(f)),document.getElementById("input_value_".concat(r)).setAttribute("value",e),M.current.setCenter(g(f))}}),[r,f])},t.MAP_PROVIDER=void 0;var n=s(a("@liferay/map-google-maps/js/MapGoogleMaps.es")),o=s(a("@liferay/map-openstreetmap/js/MapOpenStreetMap.es")),r=a("data-engine-js-components-web"),i=s(a("dynamic-data-mapping-form-field-type$leaflet")),p=a("liferay!frontend-js-react-web$react");function s(e){return e&&e.__esModule?e:{default:e}}function c(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function l(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?c(Object(a),!0).forEach((function(t){f(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):c(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function f(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}const e={googleMaps:"GoogleMaps",openStreetMap:"OpenStreetMap"};t.MAP_PROVIDER=e;const{CONTROLS:u}=Liferay.MapBase,d={controls:[u.HOME,u.PAN,u.SEARCH,u.TYPE,u.ZOOM],geolocation:!0,position:{location:{}}},m=e=>{const{fieldName:t,instanceId:a,portletNamespace:n,repeatedIndex:o}=(0,r.parseName)(e);return"".concat(n,"map$$").concat(t,"$").concat(a,"$").concat(o)},g=e=>"string"==typeof e?JSON.parse(e):e,y=e=>{i.default.Icon.Default.imagePath="https://npmcdn.com/leaflet@1.7.1/dist/images/",window.L||(window.L=i.default),e()},b=(e,t)=>{if(window.google&&window.google.maps&&Liferay.Maps&&Liferay.Maps.gmapsReady)t();else{Liferay.namespace("Maps").onGMapsReady=function(){Liferay.Maps.gmapsReady=!0,Liferay.fire("gmapsReady")},Liferay.once("gmapsReady",(()=>t()));let a="".concat(location.protocol,"//maps.googleapis.com/maps/api/js?v=3.exp&libraries=places&callback=Liferay.Maps.onGMapsReady");e&&(a+="&key="+e);let n=document.createElement("script");n.setAttribute("src",a),document.head.appendChild(n),n=null}}}}));
//# sourceMappingURL=useGeolocation.es.js.map