Liferay.Loader.define("dynamic-data-mapping-form-field-type@6.0.128/Geolocation/useGeolocation.es",["module","exports","require","@liferay/map-google-maps/js/MapGoogleMaps","@liferay/map-openstreetmap/js/MapOpenStreetMap","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 useGeolocation({disabled:t,googleMapsAPIKey:a,instanceId:r,mapProviderKey:i,name:c,onChange:l,value:f,viewMode:u}){const d=(0,p.useRef)(null);(0,p.useEffect)((()=>{if(!t||u){const t=_objectSpread(_objectSpread({},s),{},{boundingBox:"#map_".concat(r)});t.position.location=f?parseJSONValue(f):{lat:0,lng:0};const registerMapBase=(e,t)=>{d.current=new e(t),Liferay.MapBase.register(getMapName(c),d.current,"#map_".concat(r))};switch(i){case e.openStreetMap:setupMapOpenStreetMaps((()=>registerMapBase(n.default,t)));break;case e.googleMaps:setupGoogleMaps(a,(()=>registerMapBase(o.default,t)));break;default:throw new Error("mapProvider is not supported!")}}return()=>{d.current&&d.current.dispose()}}),[]),(0,p.useEffect)((()=>{d.current&&(d.current.removeAllListeners("positionChange"),d.current.on("positionChange",l))}),[l]),(0,p.useEffect)((()=>{if(f&&d.current){let e=f;"string"!=typeof e&&(e=JSON.stringify(f)),document.getElementById("input_value_".concat(r)).setAttribute("value",e),d.current.setCenter(parseJSONValue(f))}}),[r,f])},t.MAP_PROVIDER=void 0;var o=_interopRequireDefault(a("@liferay/map-google-maps/js/MapGoogleMaps")),n=_interopRequireDefault(a("@liferay/map-openstreetmap/js/MapOpenStreetMap")),r=a("data-engine-js-components-web"),i=_interopRequireDefault(a("dynamic-data-mapping-form-field-type$leaflet")),p=a("liferay!frontend-js-react-web$react");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function ownKeys(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,o)}return a}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(a),!0).forEach((function(t){_defineProperty(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):ownKeys(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function _defineProperty(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:c}=Liferay.MapBase,s={controls:[c.HOME,c.PAN,c.SEARCH,c.TYPE,c.ZOOM],geolocation:!0,position:{location:{}}},getMapName=e=>{const{fieldName:t,instanceId:a,portletNamespace:o,repeatedIndex:n}=(0,r.parseName)(e);return"".concat(o,"map$$").concat(t,"$").concat(a,"$").concat(n)},parseJSONValue=e=>"string"==typeof e?JSON.parse(e):e,setupMapOpenStreetMaps=e=>{i.default.Icon.Default.imagePath="https://npmcdn.com/leaflet@1.7.1/dist/images/",window.L||(window.L=i.default),e()},setupGoogleMaps=(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 o=document.createElement("script");o.setAttribute("src",a),document.head.appendChild(o),o=null}}}}));
//# sourceMappingURL=useGeolocation.es.js.map