"use strict";(self.webpackChunkelement_web=self.webpackChunkelement_web||[]).push([[3935],{"./src/components/views/location/Map.tsx"(o,t,e){e.r(t),e.d(t,{default:()=>h});var n=e("../../node_modules/.pnpm/react@19.2.8/node_modules/react/index.js"),r=e("../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js"),l=e.n(r),a=e("../../node_modules/.pnpm/maplibre-gl@5.24.0/node_modules/maplibre-gl/dist/maplibre-gl.js"),i=e("../../node_modules/.pnpm/matrix-js-sdk@42.2.0/node_modules/matrix-js-sdk/src/matrix.ts"),s=e("../../node_modules/.pnpm/matrix-js-sdk@42.2.0/node_modules/matrix-js-sdk/src/logger.ts"),c=e("./src/contexts/MatrixClientContext.tsx"),d=e("./src/hooks/useEventEmitter.ts"),u=e("./src/utils/location/index.ts"),m=e("./src/utils/WellKnownUtils.ts"),_=e("./src/utils/location/map.ts");var p=e("./src/Modal.tsx"),g=e("./src/components/views/dialogs/ErrorDialog.tsx"),b=e("./src/languageHandler.ts");const f=({id:o,centerGeoUri:t,onError:e,interactive:r,bounds:l,allowGeolocate:p})=>{const g=`mx_Map_${o}`,b=(0,n.useContext)(c.Ay),f=(0,d.dF)(b,i.AUM.ClientWellKnown,o=>{var t;return null===(t=(0,m.XP)(o))||void 0===t?void 0:t.map_style_url}),h=(({interactive:o,bodyId:t,onError:e})=>{const r=(0,c.nH)(),[l,a]=(0,n.useState)();return(0,n.useEffect)(()=>{let n;try{n=(0,_.p)(r,!!o,t,e),a(n)}catch(o){console.error("Error encountered in useMap",o),o instanceof Error&&(null==e||e(o))}return()=>{n&&(n.remove(),a(void 0))}},[r,o,t,e]),l})({interactive:r,bodyId:g,onError:e});(0,n.useEffect)(()=>{f&&h&&h.setStyle(f)},[f,h]),(0,n.useEffect)(()=>{if(h&&t)try{const o=(0,u.XB)(t);if(!o)throw new Error("Invalid geo URI");h.setCenter({lon:o.longitude,lat:o.latitude})}catch(o){s.vF.error("Could not set map center",o)}},[h,t]),(0,n.useEffect)(()=>{if(h&&l)try{const o=new a.LngLatBounds([l.west,l.south],[l.east,l.north]);h.fitBounds(o,{padding:100,maxZoom:15})}catch(o){s.vF.error("Invalid map bounds",o)}},[h,l]);const[C,x]=(0,n.useState)(null);return(0,n.useEffect)(()=>{if(h){if(p&&!C){const o=new a.GeolocateControl({positionOptions:{enableHighAccuracy:!0},trackUserLocation:!1});x(o),h.addControl(o)}!p&&C&&(h.removeControl(C),x(null))}},[h,C,p]),(0,n.useEffect)(()=>{if(C)return C.on("error",v),()=>{C.off("error",v)}},[C]),{map:h,bodyId:g}},v=o=>{var t;s.vF.error("Could not fetch location",o),p.Ay.createDialog(g.A,{title:(0,b._t)("location_sharing|error_fetch_location"),description:null!==(t=(0,u.Ff)(o.code))&&void 0!==t?t:""})},h=({bounds:o,centerGeoUri:t,children:e,className:r,allowGeolocate:a,id:i,interactive:s,onError:c,onClick:d})=>{const{map:u,bodyId:m}=f({centerGeoUri:t,onError:c,id:i,interactive:s,bounds:o,allowGeolocate:a});return n.createElement("div",{className:l()("mx_Map",r),id:m,onClick:o=>{o.target.classList.contains("maplibregl-ctrl-attrib-button")||null==d||d()}},!!e&&!!u&&e({map:u}))}},"./src/utils/location/map.ts"(o,t,e){var n=e("../../node_modules/.pnpm/maplibre-gl@5.24.0/node_modules/maplibre-gl/dist/maplibre-gl.js"),r=e("../../node_modules/.pnpm/matrix-js-sdk@42.2.0/node_modules/matrix-js-sdk/src/logger.ts"),l=e("./src/languageHandler.ts"),a=e("./src/utils/location/findMapStyleUrl.ts"),i=e("./src/utils/location/LocationShareErrors.ts");e.d(t,["h",0,(o,t)=>new n.Marker({element:t,anchor:"bottom",offset:[0,-1]}).setLngLat({lon:o.longitude,lat:o.latitude}),"p",0,(o,t,e,s)=>{try{const c=(0,a.M)(o),d=new n.Map({container:e,style:c,zoom:15,interactive:t,attributionControl:!1,locale:{"AttributionControl.ToggleAttribution":(0,l._t)("location_sharing|toggle_attribution"),"AttributionControl.MapFeedback":(0,l._t)("location_sharing|map_feedback"),"FullscreenControl.Enter":(0,l._t)("action|enter_fullscreen"),"FullscreenControl.Exit":(0,l._t)("action|exit_fullscreeen"),"GeolocateControl.FindMyLocation":(0,l._t)("location_sharing|find_my_location"),"GeolocateControl.LocationNotAvailable":(0,l._t)("location_sharing|location_not_available"),"LogoControl.Title":(0,l._t)("location_sharing|mapbox_logo"),"NavigationControl.ResetBearing":(0,l._t)("location_sharing|reset_bearing"),"NavigationControl.ZoomIn":(0,l._t)("action|zoom_in"),"NavigationControl.ZoomOut":(0,l._t)("action|zoom_out")}});return d.addControl(new n.AttributionControl,"top-right"),d.on("error",o=>{r.vF.error("Failed to load map: check map_style_url in config.json has a valid URL and API key",o.error),null==s||s(new Error(i.$.MapStyleUrlNotReachable))}),d}catch(o){r.vF.error("Failed to render map",o);if((null==o?void 0:o.message).includes("Failed to initialize WebGL"))throw new Error(i.$.WebGLNotEnabled);throw o}}])}}]);
//# sourceMappingURL=3935.js.map