{"version":3,"file":"terra-draw-google-maps-adapter.cjs","sources":["../src/terra-draw-google-maps-adapter.ts"],"sourcesContent":["/**\n * @module terra-draw-google-maps-adapter\n */\nimport {\n\tTerraDrawChanges,\n\tSetCursor,\n\tTerraDrawStylingFunction,\n\tTerraDrawExtend,\n\tGeoJSONStoreFeatures,\n} from \"terra-draw\";\n\nimport { GeoJsonObject } from \"geojson\";\n\nexport class TerraDrawGoogleMapsAdapter\n\textends TerraDrawExtend.TerraDrawBaseAdapter\n{\n\tconstructor(\n\t\tconfig: {\n\t\t\tlib: typeof google.maps;\n\t\t\tmap: google.maps.Map;\n\t\t\tforwardMapElementEvents?: boolean;\n\t\t\tisolatedData?: boolean;\n\t\t} & TerraDrawExtend.BaseAdapterConfig,\n\t) {\n\t\tsuper(config);\n\t\tthis._lib = config.lib;\n\t\tthis._map = config.map;\n\t\tthis._forwardMapElementEvents =\n\t\t\ttypeof config.forwardMapElementEvents === \"boolean\"\n\t\t\t\t? config.forwardMapElementEvents\n\t\t\t\t: false;\n\t\tthis._isolatedData = config.isolatedData || false;\n\n\t\tthis._coordinatePrecision =\n\t\t\ttypeof config.coordinatePrecision === \"number\"\n\t\t\t\t? config.coordinatePrecision\n\t\t\t\t: 9;\n\t}\n\n\tprivate _forwardMapElementEvents: boolean = false;\n\tprivate _isolatedData: boolean = false;\n\tprivate _data: google.maps.Data | undefined;\n\tprivate _cursor: string | undefined;\n\tprivate _cursorStyleSheet: HTMLStyleElement | undefined;\n\tprivate _lib: typeof google.maps;\n\tprivate _map: google.maps.Map;\n\tprivate _overlay: google.maps.OverlayView | undefined;\n\tprivate _markerClickListener: any | undefined;\n\tprivate _markerMouseMoveListener: ((event: MouseEvent) => void) | undefined;\n\tprivate _pointerCaptureDownListener:\n\t\t| ((event: PointerEvent) => void)\n\t\t| undefined;\n\tprivate _pointerCaptureUpListener:\n\t\t| ((event: PointerEvent) => void)\n\t\t| undefined;\n\tprivate _clickEventListener: google.maps.MapsEventListener | undefined;\n\tprivate _mouseMoveEventListener: google.maps.MapsEventListener | undefined;\n\tprivate _readyCalled = false;\n\n\tprivate _interactiveTargetSelector = [\n\t\t'[role=\"dialog\"]',\n\t\t\"a\",\n\t\t\"button\",\n\t\t\"input\",\n\t\t\"select\",\n\t\t\"textarea\",\n\t\t\"summary\",\n\t\t'[role=\"button\"]',\n\t\t'[role=\"link\"]',\n\t\t'[contenteditable=\"\"]',\n\t\t'[contenteditable=\"true\"]',\n\t].join(\", \");\n\n\tprivate _advancedMarkerElementTag = \"gmp-advanced-marker\";\n\n\tprivate get _hasRenderedFeatures(): boolean {\n\t\treturn Boolean(this.renderedFeatureIds?.size > 0);\n\t}\n\n\tprivate getPointerTargetElement(target: EventTarget | null) {\n\t\tif (!target) {\n\t\t\treturn null;\n\t\t}\n\n\t\tif (target instanceof Element) {\n\t\t\treturn target;\n\t\t}\n\n\t\tif (target instanceof Node) {\n\t\t\treturn target.parentElement;\n\t\t}\n\n\t\treturn null;\n\t}\n\n\tprivate shouldCapturePointer(event: PointerEvent) {\n\t\tconst targetElement = this.getPointerTargetElement(event.target);\n\t\tif (!targetElement) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (targetElement.closest(this._advancedMarkerElementTag)) {\n\t\t\treturn true;\n\t\t}\n\n\t\t// Avoid pointer capture on interactive controls so native map UI keeps working.\n\t\treturn !targetElement.closest(this._interactiveTargetSelector);\n\t}\n\n\t/**\n\t * Generates an SVG path string for a circle with the given center coordinates and radius.\n\t * Based off this StackOverflow answer: https://stackoverflow.com/a/27905268/1363484\n\t * @param cx The x-coordinate of the circle's center.\n\t * @param cy The y-coordinate of the circle's center.\n\t * @param r The radius of the circle.\n\t * @returns The SVG path string representing the circle.\n\t */\n\tprivate circlePath(cx: number, cy: number, r: number) {\n\t\tconst d = r * 2;\n\t\treturn `M ${cx} ${cy} m -${r}, 0 a ${r},${r} 0 1,0 ${d},0 a ${r},${r} 0 1,0 -${d},0`;\n\t}\n\n\tpublic register(callbacks: TerraDrawExtend.TerraDrawCallbacks) {\n\t\tsuper.register(callbacks);\n\n\t\t// The overlay is responsible for allow us to\n\t\t// get the projection, which in turn allows us to\n\t\t// go through lng/lat to pixel space and vice versa\n\t\tthis._overlay = new this._lib.OverlayView();\n\t\tthis._overlay.draw = function () {\n\t\t\t// No-op\n\t\t};\n\n\t\t// Unfortunately it is only ready after the onAdd\n\t\t// method is called, which is why we need to use the 'ready'\n\t\t// listener with the Google Maps adapter\n\t\tthis._overlay.onAdd = () => {\n\t\t\tif (this._currentModeCallbacks?.onReady && !this._readyCalled) {\n\t\t\t\tthis._currentModeCallbacks.onReady();\n\t\t\t\tthis._readyCalled = true;\n\t\t\t}\n\t\t};\n\t\tthis._overlay.setMap(this._map);\n\n\t\t// Required to avoid runtime error in Google Maps API\n\t\tthis._overlay.onRemove = () => {\n\t\t\t// No-op\n\t\t};\n\n\t\tif (this._forwardMapElementEvents) {\n\t\t\tconst mapEventElement = this.getMapEventElement();\n\t\t\tthis._pointerCaptureDownListener = (event: PointerEvent) => {\n\t\t\t\tif (!event.isPrimary) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (!this.shouldCapturePointer(event)) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (typeof mapEventElement.setPointerCapture === \"function\") {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tmapEventElement.setPointerCapture(event.pointerId);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Pointer capture can throw if the pointer is not active.\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tthis._pointerCaptureUpListener = (event: PointerEvent) => {\n\t\t\t\tif (\n\t\t\t\t\ttypeof mapEventElement.releasePointerCapture === \"function\" &&\n\t\t\t\t\ttypeof mapEventElement.hasPointerCapture === \"function\" &&\n\t\t\t\t\tmapEventElement.hasPointerCapture(event.pointerId)\n\t\t\t\t) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tmapEventElement.releasePointerCapture(event.pointerId);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Pointer may already be released by browser.\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tmapEventElement.addEventListener(\n\t\t\t\t\"pointerdown\",\n\t\t\t\tthis._pointerCaptureDownListener,\n\t\t\t);\n\t\t\tmapEventElement.addEventListener(\n\t\t\t\t\"pointerup\",\n\t\t\t\tthis._pointerCaptureUpListener,\n\t\t\t);\n\t\t\tmapEventElement.addEventListener(\n\t\t\t\t\"pointercancel\",\n\t\t\t\tthis._pointerCaptureUpListener,\n\t\t\t);\n\n\t\t\tthis._markerClickListener = (event: MouseEvent) => {\n\t\t\t\tconst target = event.target as HTMLElement;\n\n\t\t\t\tif (!target?.closest(this._advancedMarkerElementTag)) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst drawEvent = this.getDrawEventFromEvent(event);\n\t\t\t\tif (drawEvent) {\n\t\t\t\t\tcallbacks.onClick(drawEvent);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tmapEventElement.addEventListener(\n\t\t\t\t\"pointerdown\",\n\t\t\t\tthis._markerClickListener,\n\t\t\t);\n\n\t\t\tthis._markerMouseMoveListener = (event: MouseEvent) => {\n\t\t\t\tconst target = event.target as HTMLElement;\n\n\t\t\t\tif (!target?.closest(this._advancedMarkerElementTag)) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst drawEvent = this.getDrawEventFromEvent(event);\n\t\t\t\tif (drawEvent) {\n\t\t\t\t\tcallbacks.onMouseMove(drawEvent);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tmapEventElement.addEventListener(\n\t\t\t\t\"pointermove\",\n\t\t\t\tthis._markerMouseMoveListener,\n\t\t\t);\n\t\t}\n\n\t\t// Clicking on data geometries triggers\n\t\t// swallows the map onclick event,\n\t\t// so we need to forward it to the click callback handler\n\t\tthis._clickEventListener = this.data().addListener(\n\t\t\t\"click\",\n\t\t\t(\n\t\t\t\tevent: google.maps.MapMouseEvent & {\n\t\t\t\t\tdomEvent: MouseEvent;\n\t\t\t\t},\n\t\t\t) => {\n\t\t\t\tconst clickListener = this._listeners.find(\n\t\t\t\t\t({ name }) => name === \"click\",\n\t\t\t\t);\n\t\t\t\tif (clickListener) {\n\t\t\t\t\tclickListener.callback(event);\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\n\t\tthis._mouseMoveEventListener = this.data().addListener(\n\t\t\t\"mousemove\",\n\t\t\t(\n\t\t\t\tevent: google.maps.MapMouseEvent & {\n\t\t\t\t\tdomEvent: MouseEvent;\n\t\t\t\t},\n\t\t\t) => {\n\t\t\t\tconst mouseMoveListener = this._listeners.find(\n\t\t\t\t\t({ name }) => name === \"mousemove\",\n\t\t\t\t);\n\t\t\t\tif (mouseMoveListener) {\n\t\t\t\t\tmouseMoveListener.callback(event);\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\n\t\tif (this._isolatedData) {\n\t\t\tthis._data = new this._lib.Data();\n\t\t\tthis._data.setMap(this._map);\n\t\t}\n\t}\n\n\tprotected data() {\n\t\tif (this._isolatedData && this._data) {\n\t\t\treturn this._data;\n\t\t}\n\t\treturn this._map.data;\n\t}\n\n\tprivate styling: TerraDrawStylingFunction | undefined;\n\n\tprivate style(feature: google.maps.Data.Feature) {\n\t\tif (!this.styling) {\n\t\t\tthrow new Error(\"Styling function not defined\");\n\t\t}\n\n\t\tconst id = String(feature.getId());\n\n\t\t// Style callback has been called for a feature that is not rendered\n\t\tif (!this.renderedFeatureIds.has(id as string)) {\n\t\t\treturn {};\n\t\t}\n\n\t\tconst mode = feature.getProperty(\"mode\") as string;\n\t\tconst gmGeometry = feature.getGeometry();\n\t\tif (!gmGeometry) {\n\t\t\tthrow new Error(\"Google Maps geometry not found\");\n\t\t}\n\t\tconst type = gmGeometry.getType();\n\t\tconst properties: Record<string, any> = {};\n\n\t\tfeature.forEachProperty((value, property) => {\n\t\t\tproperties[property] = value;\n\t\t});\n\n\t\tconst calculatedStyles = this.styling[mode]({\n\t\t\ttype: \"Feature\",\n\t\t\tid,\n\t\t\tgeometry: {\n\t\t\t\ttype: type as \"Point\" | \"LineString\" | \"Polygon\",\n\t\t\t\tcoordinates: [],\n\t\t\t},\n\t\t\tproperties,\n\t\t});\n\n\t\tswitch (type) {\n\t\t\tcase \"Point\":\n\t\t\t\tif (calculatedStyles.markerUrl) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tclickable: false,\n\t\t\t\t\t\ticon: {\n\t\t\t\t\t\t\turl: calculatedStyles.markerUrl as string,\n\t\t\t\t\t\t\tscaledSize:\n\t\t\t\t\t\t\t\tcalculatedStyles.markerWidth && calculatedStyles.markerHeight\n\t\t\t\t\t\t\t\t\t? new this._lib.Size(\n\t\t\t\t\t\t\t\t\t\t\tcalculatedStyles.markerWidth,\n\t\t\t\t\t\t\t\t\t\t\tcalculatedStyles.markerHeight,\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tzIndex: calculatedStyles.zIndex,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tconst path = this.circlePath(0, 0, calculatedStyles.pointWidth);\n\n\t\t\t\t// Backwards compatible read: pre Terra Draw v1.24.0 will not have this field in the interface\n\t\t\t\tconst strokeOpacity = (\n\t\t\t\t\tcalculatedStyles as { pointOutlineOpacity?: number }\n\t\t\t\t).pointOutlineOpacity;\n\t\t\t\tconst fillOpacity = (calculatedStyles as { pointOpacity?: number })\n\t\t\t\t\t.pointOpacity;\n\n\t\t\t\treturn {\n\t\t\t\t\tclickable: false,\n\t\t\t\t\ticon: {\n\t\t\t\t\t\tpath,\n\t\t\t\t\t\tfillColor: calculatedStyles.pointColor,\n\t\t\t\t\t\tfillOpacity: fillOpacity === undefined ? 1 : fillOpacity,\n\t\t\t\t\t\tstrokeColor: calculatedStyles.pointOutlineColor,\n\t\t\t\t\t\tstrokeWeight: calculatedStyles.pointOutlineWidth,\n\t\t\t\t\t\tstrokeOpacity: strokeOpacity === undefined ? 1 : strokeOpacity,\n\t\t\t\t\t\trotation: 0,\n\t\t\t\t\t\tscale: 1,\n\t\t\t\t\t},\n\t\t\t\t\tzIndex: calculatedStyles.zIndex,\n\t\t\t\t};\n\n\t\t\tcase \"LineString\":\n\t\t\t\t// Backwards compatible read: pre Terra Draw v1.24.0 will not have this field in the interface\n\t\t\t\tconst lineStringOpacity = (\n\t\t\t\t\tcalculatedStyles as { lineStringOpacity?: number }\n\t\t\t\t).lineStringOpacity;\n\t\t\t\t// Backwards compatible read: pre Terra Draw v1.24.0 will not have this field in the interface\n\t\t\t\tconst lineStringDash = (\n\t\t\t\t\tcalculatedStyles as {\n\t\t\t\t\t\tlineStringDash?: [number, number];\n\t\t\t\t\t}\n\t\t\t\t).lineStringDash;\n\n\t\t\t\tconst dashedLineStyles = lineStringDash\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tstrokeOpacity: 0,\n\t\t\t\t\t\t\ticons: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ticon: {\n\t\t\t\t\t\t\t\t\t\tpath: \"M 0,0 0,\" + lineStringDash[0],\n\t\t\t\t\t\t\t\t\t\tstrokeOpacity: 1,\n\t\t\t\t\t\t\t\t\t\tstrokeWeight: calculatedStyles.lineStringWidth,\n\t\t\t\t\t\t\t\t\t\tcolor: calculatedStyles.lineStringColor,\n\t\t\t\t\t\t\t\t\t\tscale: 1,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\toffset: \"0\",\n\t\t\t\t\t\t\t\t\trepeat: `${lineStringDash[0] + lineStringDash[1]}px`,\n\t\t\t\t\t\t\t\t\tfixedRotation: false,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t}\n\t\t\t\t\t: {};\n\n\t\t\t\treturn {\n\t\t\t\t\tstrokeColor: calculatedStyles.lineStringColor,\n\t\t\t\t\tstrokeWeight: calculatedStyles.lineStringWidth,\n\t\t\t\t\tstrokeOpacity:\n\t\t\t\t\t\tlineStringOpacity === undefined ? 1 : lineStringOpacity,\n\t\t\t\t\tzIndex: calculatedStyles.zIndex,\n\t\t\t\t\t...dashedLineStyles,\n\t\t\t\t};\n\t\t\tcase \"Polygon\":\n\t\t\t\tconst polygonOutlineOpacity = (\n\t\t\t\t\tcalculatedStyles as { polygonOutlineOpacity?: number }\n\t\t\t\t).polygonOutlineOpacity;\n\n\t\t\t\treturn {\n\t\t\t\t\tstrokeColor: calculatedStyles.polygonOutlineColor,\n\t\t\t\t\tstrokeWeight: calculatedStyles.polygonOutlineWidth,\n\t\t\t\t\tstrokeOpacity:\n\t\t\t\t\t\tpolygonOutlineOpacity === undefined ? 1 : polygonOutlineOpacity,\n\t\t\t\t\tfillOpacity: calculatedStyles.polygonFillOpacity,\n\t\t\t\t\tfillColor: calculatedStyles.polygonFillColor,\n\t\t\t\t\tzIndex: calculatedStyles.zIndex,\n\t\t\t\t};\n\t\t}\n\n\t\tthrow Error(\"Unknown feature type\");\n\t}\n\n\tpublic unregister(): void {\n\t\tsuper.unregister();\n\t\tthis._clickEventListener?.remove();\n\t\tthis._mouseMoveEventListener?.remove();\n\n\t\tif (this._markerClickListener) {\n\t\t\tthis.getMapEventElement().removeEventListener(\n\t\t\t\t\"pointerdown\",\n\t\t\t\tthis._markerClickListener,\n\t\t\t);\n\t\t}\n\n\t\tif (this._markerMouseMoveListener) {\n\t\t\tthis.getMapEventElement().removeEventListener(\n\t\t\t\t\"pointermove\",\n\t\t\t\tthis._markerMouseMoveListener,\n\t\t\t);\n\t\t}\n\n\t\tif (this._pointerCaptureDownListener) {\n\t\t\tthis.getMapEventElement().removeEventListener(\n\t\t\t\t\"pointerdown\",\n\t\t\t\tthis._pointerCaptureDownListener,\n\t\t\t);\n\t\t}\n\n\t\tif (this._pointerCaptureUpListener) {\n\t\t\tthis.getMapEventElement().removeEventListener(\n\t\t\t\t\"pointerup\",\n\t\t\t\tthis._pointerCaptureUpListener,\n\t\t\t);\n\t\t\tthis.getMapEventElement().removeEventListener(\n\t\t\t\t\"pointercancel\",\n\t\t\t\tthis._pointerCaptureUpListener,\n\t\t\t);\n\t\t}\n\n\t\tif (this._overlay && this._overlay.getMap()) {\n\t\t\tthis._overlay.setMap(null);\n\t\t}\n\t\tthis._overlay = undefined;\n\t\tthis._readyCalled = false;\n\n\t\tif (this._isolatedData && this._data) {\n\t\t\tthis._data.setMap(null);\n\t\t\tthis._data = undefined;\n\t\t}\n\t}\n\n\t/**\n\t * Returns the longitude and latitude coordinates from a given PointerEvent on the map.\n\t * @param event The PointerEvent or MouseEvent containing the screen coordinates of the pointer.\n\t * @returns An object with 'lng' and 'lat' properties representing the longitude and latitude, or null if the conversion is not possible.\n\t */\n\tgetLngLatFromEvent(event: PointerEvent | MouseEvent) {\n\t\tif (!this._overlay) {\n\t\t\tthrow new Error(\"cannot get overlay\");\n\t\t}\n\n\t\tconst bounds = this._map.getBounds();\n\n\t\tif (!bounds) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst ne = bounds.getNorthEast();\n\t\tconst sw = bounds.getSouthWest();\n\t\tconst latLngBounds = new this._lib.LatLngBounds(sw, ne);\n\n\t\t// In fullscreen mode, use coordinates relative to the fullscreen element\n\t\tconst mapElement = document.fullscreenElement ?? this._map.getDiv();\n\t\tconst mapCanvasRect = mapElement.getBoundingClientRect();\n\t\tconst offsetX = event.clientX - mapCanvasRect.left;\n\t\tconst offsetY = event.clientY - mapCanvasRect.top;\n\t\tconst screenCoord = new this._lib.Point(offsetX, offsetY);\n\n\t\tconst projection = this._overlay.getProjection();\n\t\tif (!projection) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst latLng = projection.fromContainerPixelToLatLng(screenCoord);\n\n\t\tif (latLng && latLngBounds.contains(latLng)) {\n\t\t\treturn { lng: latLng.lng(), lat: latLng.lat() };\n\t\t} else {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Retrieves the HTML element of the Google Map element that handles interaction events\n\t * @returns The HTMLElement representing the map container.\n\t */\n\tpublic getMapEventElement(\n\t\teventType?: // TODO: Import TerraDrawHandledEvents - however is a breaking change currently\n\t\t\t| \"pointerdown\"\n\t\t\t| \"pointerup\"\n\t\t\t| \"pointermove\"\n\t\t\t| \"contextmenu\"\n\t\t\t| \"keyup\"\n\t\t\t| \"keydown\",\n\t): HTMLElement {\n\t\tif (eventType && (eventType === \"keyup\" || eventType === \"keydown\")) {\n\t\t\treturn this._map.getDiv();\n\t\t}\n\n\t\t// TODO: This is a bit hacky, maybe there is a better solution here\n\t\tconst selector = 'div[style*=\"z-index: 3;\"]';\n\t\treturn this._map.getDiv().querySelector(selector) as HTMLDivElement;\n\t}\n\n\t/**\n\t * Converts longitude and latitude coordinates to pixel coordinates in the map container.\n\t * @param lng The longitude coordinate to project.\n\t * @param lat The latitude coordinate to project.\n\t * @returns An object with 'x' and 'y' properties representing the pixel coordinates within the map container.\n\t */\n\tproject(lng: number, lat: number) {\n\t\tif (!this._overlay) {\n\t\t\tthrow new Error(\"cannot get overlay\");\n\t\t}\n\n\t\tconst bounds = this._map.getBounds();\n\n\t\tif (bounds === undefined) {\n\t\t\tthrow new Error(\"cannot get bounds\");\n\t\t}\n\n\t\tconst projection = this._overlay.getProjection();\n\t\tif (projection === undefined) {\n\t\t\tthrow new Error(\"cannot get projection\");\n\t\t}\n\n\t\tconst point = projection.fromLatLngToContainerPixel(\n\t\t\tnew this._lib.LatLng(lat, lng),\n\t\t);\n\n\t\tif (point === null) {\n\t\t\tthrow new Error(\"cannot project coordinates\");\n\t\t}\n\n\t\treturn { x: point.x, y: point.y };\n\t}\n\n\t/**\n\t * Converts pixel coordinates in the map container to longitude and latitude coordinates.\n\t * @param x The x-coordinate in the map container to unproject.\n\t * @param y The y-coordinate in the map container to unproject.\n\t * @returns An object with 'lng' and 'lat' properties representing the longitude and latitude coordinates.\n\t */\n\tunproject(x: number, y: number) {\n\t\tif (!this._overlay) {\n\t\t\tthrow new Error(\"cannot get overlay\");\n\t\t}\n\n\t\tconst projection = this._overlay.getProjection();\n\t\tif (projection === undefined) {\n\t\t\tthrow new Error(\"cannot get projection\");\n\t\t}\n\n\t\tconst latLng = projection.fromContainerPixelToLatLng(\n\t\t\tnew this._lib.Point(x, y),\n\t\t);\n\n\t\tif (latLng === null) {\n\t\t\tthrow new Error(\"cannot unproject coordinates\");\n\t\t}\n\n\t\treturn { lng: latLng.lng(), lat: latLng.lat() };\n\t}\n\n\t/**\n\t * Sets the cursor style for the map container.\n\t * @param cursor The CSS cursor style to apply, or 'unset' to remove any previously applied cursor style.\n\t */\n\tsetCursor(cursor: Parameters<SetCursor>[0]) {\n\t\tif (cursor === this._cursor) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this._cursorStyleSheet) {\n\t\t\tthis._cursorStyleSheet.remove();\n\t\t\tthis._cursorStyleSheet = undefined;\n\t\t}\n\n\t\tif (cursor !== \"unset\") {\n\t\t\t// TODO: We could cache these individually per cursor\n\n\t\t\tconst div = this._map.getDiv();\n\t\t\tconst styleDiv = div.querySelector(\".gm-style > div\");\n\n\t\t\tif (styleDiv) {\n\t\t\t\tstyleDiv.classList.add(\"terra-draw-google-maps\");\n\n\t\t\t\tconst style = document.createElement(\"style\");\n\t\t\t\tstyle.innerHTML = `.terra-draw-google-maps { cursor: ${cursor} !important; }`;\n\t\t\t\tdocument.getElementsByTagName(\"head\")[0].appendChild(style);\n\t\t\t\tthis._cursorStyleSheet = style;\n\t\t\t}\n\t\t}\n\n\t\tthis._cursor = cursor;\n\t}\n\n\t/**\n\t * Enables or disables the double-click to zoom functionality on the map.\n\t * @param enabled Set to true to enable double-click to zoom, or false to disable it.\n\t */\n\tsetDoubleClickToZoom(enabled: boolean) {\n\t\tif (enabled) {\n\t\t\tthis._map.setOptions({ disableDoubleClickZoom: false });\n\t\t} else {\n\t\t\tthis._map.setOptions({ disableDoubleClickZoom: true });\n\t\t}\n\t}\n\n\t/**\n\t * Enables or disables the draggable functionality of the map.\n\t * @param enabled Set to true to enable map dragging, or false to disable it.\n\t */\n\tsetDraggability(enabled: boolean) {\n\t\tthis._map.setOptions({ draggable: enabled });\n\t}\n\n\tprivate renderedFeatureIds: Set<TerraDrawExtend.FeatureId> = new Set();\n\n\t/**\n\t * Renders GeoJSON features on the map using the provided styling configuration.\n\t * Schedules actual mutations into requestAnimationFrame, applying:\n\t * deletes -> updates -> creates\n\t */\n\trender(changes: TerraDrawChanges, styling: TerraDrawStylingFunction) {\n\t\tthis.styling = styling;\n\n\t\tif (!this.data().getStyle()) {\n\t\t\tthis.data().setStyle((feature) => this.style(feature));\n\t\t}\n\n\t\t// Ensure scheduler state exists\n\t\tif (!this._rafState) {\n\t\t\tthis._rafState = {\n\t\t\t\trafId: null as number | null,\n\t\t\t\tpending: {\n\t\t\t\t\tdeletedIds: [] as string[],\n\t\t\t\t\tupdated: [] as GeoJSONStoreFeatures[],\n\t\t\t\t\tcreated: [] as GeoJSONStoreFeatures[],\n\t\t\t\t},\n\t\t\t\t// Used to coalesce changes within a frame\n\t\t\t\tdeletedSet: new Set<string>(),\n\t\t\t\tupdatedById: new Map<string, GeoJSONStoreFeatures>(),\n\t\t\t\tcreatedById: new Map<string, GeoJSONStoreFeatures>(),\n\t\t\t};\n\t\t}\n\n\t\t// ---- Queue up changes for the next animation frame ----\n\t\t// Deleted\n\t\tfor (const id of changes.deletedIds) {\n\t\t\t// If something is deleted, it shouldn't also be created/updated in same frame.\n\t\t\tthis._rafState.deletedSet.add(id as string);\n\t\t\tthis._rafState.updatedById.delete(id as string);\n\t\t\tthis._rafState.createdById.delete(id as string);\n\t\t}\n\n\t\t// Updated\n\t\tfor (const feature of changes.updated) {\n\t\t\tif (!feature?.id) throw new Error(\"Feature is not valid\");\n\n\t\t\tconst id = String(feature.id);\n\t\t\tif (this._rafState.deletedSet.has(id)) continue; // delete wins\n\n\t\t\t// If it was created this frame, treat as \"create with latest data\"\n\t\t\tif (this._rafState.createdById.has(id)) {\n\t\t\t\tthis._rafState.createdById.set(id, feature);\n\t\t\t} else {\n\t\t\t\tthis._rafState.updatedById.set(id, feature); // latest update wins\n\t\t\t}\n\t\t}\n\n\t\t// Created\n\t\tfor (const feature of changes.created) {\n\t\t\tif (!feature?.id) throw new Error(\"Feature is not valid\");\n\n\t\t\tconst id = String(feature.id);\n\n\t\t\t// Preserve delete+create cycles for the same id in one frame (e.g. undo/redo).\n\t\t\t// Flush order is delete -> update -> create, so recreation still occurs.\n\n\t\t\tthis._rafState.createdById.set(id, feature); // latest create wins\n\t\t\tthis._rafState.updatedById.delete(id); // creation supersedes update in same frame\n\t\t}\n\n\t\t// Schedule a flush if not already scheduled\n\t\tif (this._rafState.rafId == null) {\n\t\t\tthis._rafState.rafId = requestAnimationFrame(() => {\n\t\t\t\tif (!this._rafState) return;\n\n\t\t\t\tthis._rafState.rafId = null;\n\n\t\t\t\t// Snapshot + clear (so new renders can queue while we flush)\n\t\t\t\tconst deletedIds = Array.from(this._rafState.deletedSet);\n\t\t\t\tconst updated = Array.from(this._rafState.updatedById.values());\n\t\t\t\tconst created = Array.from(this._rafState.createdById.values());\n\n\t\t\t\tthis._rafState!.deletedSet.clear();\n\t\t\t\tthis._rafState!.updatedById.clear();\n\t\t\t\tthis._rafState!.createdById.clear();\n\n\t\t\t\t// ---- Apply chronologically: deletes -> updates -> creates ----\n\t\t\t\tif (this._hasRenderedFeatures) {\n\t\t\t\t\t// Deletes\n\t\t\t\t\tfor (const deletedId of deletedIds) {\n\t\t\t\t\t\tconst featureToDelete = this.data().getFeatureById(deletedId);\n\t\t\t\t\t\tif (featureToDelete) {\n\t\t\t\t\t\t\tthis.data().remove(featureToDelete);\n\t\t\t\t\t\t\tthis.renderedFeatureIds.delete(deletedId);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// Updates\n\t\t\t\t\tfor (const updatedFeature of updated) {\n\t\t\t\t\t\tif (!updatedFeature?.id) throw new Error(\"Feature is not valid\");\n\n\t\t\t\t\t\tconst featureToUpdate = this.data().getFeatureById(\n\t\t\t\t\t\t\tString(updatedFeature.id),\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif (!featureToUpdate) {\n\t\t\t\t\t\t\tthrow new Error(\"Feature could not be found by Google Maps API\");\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Remove all keys\n\t\t\t\t\t\tfeatureToUpdate.forEachProperty((_property, name) => {\n\t\t\t\t\t\t\tfeatureToUpdate.setProperty(name, undefined);\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\t// Update all keys\n\t\t\t\t\t\tObject.keys(updatedFeature.properties).forEach((property) => {\n\t\t\t\t\t\t\tfeatureToUpdate.setProperty(\n\t\t\t\t\t\t\t\tproperty,\n\t\t\t\t\t\t\t\tupdatedFeature.properties[property],\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tswitch (updatedFeature.geometry.type) {\n\t\t\t\t\t\t\tcase \"Point\": {\n\t\t\t\t\t\t\t\tconst coordinates = updatedFeature.geometry.coordinates;\n\t\t\t\t\t\t\t\tfeatureToUpdate.setGeometry(\n\t\t\t\t\t\t\t\t\tnew this._lib.Data.Point(\n\t\t\t\t\t\t\t\t\t\tnew this._lib.LatLng(coordinates[1], coordinates[0]),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"LineString\": {\n\t\t\t\t\t\t\t\tconst coordinates = updatedFeature.geometry.coordinates;\n\t\t\t\t\t\t\t\tconst path: google.maps.LatLng[] = [];\n\t\t\t\t\t\t\t\tfor (let i = 0; i < coordinates.length; i++) {\n\t\t\t\t\t\t\t\t\tconst [lng, lat] = coordinates[i];\n\t\t\t\t\t\t\t\t\tpath.push(new this._lib.LatLng(lat, lng));\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tfeatureToUpdate.setGeometry(\n\t\t\t\t\t\t\t\t\tnew this._lib.Data.LineString(path),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcase \"Polygon\": {\n\t\t\t\t\t\t\t\tconst coordinates = updatedFeature.geometry.coordinates;\n\t\t\t\t\t\t\t\tconst paths: google.maps.LatLng[][] = [];\n\t\t\t\t\t\t\t\tfor (let i = 0; i < coordinates.length; i++) {\n\t\t\t\t\t\t\t\t\tconst ring: google.maps.LatLng[] = [];\n\t\t\t\t\t\t\t\t\tfor (let j = 0; j < coordinates[i].length; j++) {\n\t\t\t\t\t\t\t\t\t\tconst [lng, lat] = coordinates[i][j];\n\t\t\t\t\t\t\t\t\t\tring.push(new this._lib.LatLng(lat, lng));\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tpaths.push(ring);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tfeatureToUpdate.setGeometry(new this._lib.Data.Polygon(paths));\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// Creates\n\t\t\t\t\tfor (const createdFeature of created) {\n\t\t\t\t\t\tthis.renderedFeatureIds.add(String(createdFeature.id));\n\t\t\t\t\t\tthis.data().addGeoJson(createdFeature);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// First render: treat everything as a feature collection create\n\t\t\t\t\tconst features: GeoJSONStoreFeatures[] = [];\n\n\t\t\t\t\t// (If you want deletes/updates to matter before first render, you can filter here,\n\t\t\t\t\t// but usually first render is only creates.)\n\t\t\t\t\tfor (const feature of created) {\n\t\t\t\t\t\tthis.renderedFeatureIds.add(String(feature.id));\n\t\t\t\t\t\tfeatures.push(feature);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (features.length) {\n\t\t\t\t\t\tthis.data().addGeoJson({\n\t\t\t\t\t\t\ttype: \"FeatureCollection\",\n\t\t\t\t\t\t\tfeatures,\n\t\t\t\t\t\t} as GeoJsonObject);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\t// Put this on the class:\n\tprivate _rafState?: {\n\t\trafId: number | null;\n\t\tpending: {\n\t\t\tdeletedIds: string[];\n\t\t\tupdated: GeoJSONStoreFeatures[];\n\t\t\tcreated: GeoJSONStoreFeatures[];\n\t\t};\n\t\tdeletedSet: Set<string>;\n\t\tupdatedById: Map<string, GeoJSONStoreFeatures>;\n\t\tcreatedById: Map<string, GeoJSONStoreFeatures>;\n\t};\n\n\tprivate clearLayers() {\n\t\tif (this._hasRenderedFeatures) {\n\t\t\tthis.data().forEach((feature) => {\n\t\t\t\tconst id = feature.getId() as string;\n\t\t\t\tconst hasFeature = this.renderedFeatureIds.has(id);\n\t\t\t\tif (hasFeature) {\n\t\t\t\t\tthis.data().remove(feature);\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis.renderedFeatureIds = new Set();\n\t\t}\n\t}\n\n\t/**\n\t * Clears the map and store of all rendered data layers\n\t * @returns void\n\t * */\n\tpublic clear() {\n\t\tif (this._currentModeCallbacks) {\n\t\t\t// Clean up state first\n\t\t\tthis._currentModeCallbacks.onClear();\n\n\t\t\t// Then clean up rendering\n\t\t\tthis.clearLayers();\n\t\t}\n\n\t\t// clean up any styles set on the default data layer\n\t\tif (this.data()) {\n\t\t\tthis.data().setStyle(null);\n\t\t}\n\t}\n\n\tpublic getCoordinatePrecision(): number {\n\t\t// TODO: It seems this shouldn't be necessary as extends BaseAdapter which as this method\n\t\treturn super.getCoordinatePrecision();\n\t}\n}\n"],"names":["_TerraDrawExtend$Terr","TerraDrawGoogleMapsAdapter","config","_this","call","this","_forwardMapElementEvents","_isolatedData","_data","_cursor","_cursorStyleSheet","_lib","_map","_overlay","_markerClickListener","_markerMouseMoveListener","_pointerCaptureDownListener","_pointerCaptureUpListener","_clickEventListener","_mouseMoveEventListener","_readyCalled","_interactiveTargetSelector","join","_advancedMarkerElementTag","styling","renderedFeatureIds","Set","_rafState","lib","map","forwardMapElementEvents","isolatedData","_coordinatePrecision","coordinatePrecision","_proto","prototype","getPointerTargetElement","target","Element","Node","parentElement","shouldCapturePointer","event","targetElement","closest","circlePath","cx","cy","r","d","register","callbacks","_this2","OverlayView","draw","onAdd","_this2$_currentModeCa","_currentModeCallbacks","onReady","setMap","onRemove","mapEventElement","getMapEventElement","isPrimary","setPointerCapture","pointerId","_unused","releasePointerCapture","hasPointerCapture","_unused2","addEventListener","drawEvent","getDrawEventFromEvent","onClick","onMouseMove","data","addListener","clickListener","_listeners","find","_ref","name","callback","mouseMoveListener","_ref2","Data","style","feature","Error","id","String","getId","has","mode","getProperty","gmGeometry","getGeometry","type","getType","properties","forEachProperty","value","property","calculatedStyles","geometry","coordinates","markerUrl","clickable","icon","url","scaledSize","markerWidth","markerHeight","Size","undefined","zIndex","path","pointWidth","strokeOpacity","pointOutlineOpacity","fillOpacity","pointOpacity","fillColor","pointColor","strokeColor","pointOutlineColor","strokeWeight","pointOutlineWidth","rotation","scale","lineStringOpacity","lineStringDash","_extends","lineStringColor","lineStringWidth","icons","color","offset","repeat","fixedRotation","polygonOutlineOpacity","polygonOutlineColor","polygonOutlineWidth","polygonFillOpacity","polygonFillColor","unregister","_this$_clickEventList","_this$_mouseMoveEvent","remove","removeEventListener","getMap","getLngLatFromEvent","_document$fullscreenE","bounds","getBounds","ne","getNorthEast","sw","getSouthWest","latLngBounds","LatLngBounds","mapCanvasRect","document","fullscreenElement","getDiv","getBoundingClientRect","screenCoord","Point","clientX","left","clientY","top","projection","getProjection","latLng","fromContainerPixelToLatLng","contains","lng","lat","eventType","querySelector","project","point","fromLatLngToContainerPixel","LatLng","x","y","unproject","setCursor","cursor","styleDiv","classList","add","createElement","innerHTML","getElementsByTagName","appendChild","setDoubleClickToZoom","enabled","setOptions","disableDoubleClickZoom","setDraggability","draggable","render","changes","_this3","getStyle","setStyle","rafId","pending","deletedIds","updated","created","deletedSet","updatedById","Map","createdById","_step","_iterator","_createForOfIteratorHelperLoose","done","_step2","_iterator2","set","_step3","_iterator3","requestAnimationFrame","Array","from","values","clear","_hasRenderedFeatures","_iterator4","_step4","deletedId","featureToDelete","getFeatureById","_step5","_loop","updatedFeature","featureToUpdate","_property","setProperty","Object","keys","forEach","setGeometry","i","length","_coordinates$i","push","LineString","paths","ring","j","_coordinates2$_i$j","Polygon","_iterator5","_iterator6","_step6","createdFeature","addGeoJson","_step7","features","_iterator7","clearLayers","_this4","onClear","getCoordinatePrecision","key","get","_this$renderedFeature","Boolean","size","TerraDrawExtend","TerraDrawBaseAdapter"],"mappings":"g+CAcC,SAAAA,GAEA,SAAAC,EACCC,GAKqC,IAAAC,EAc/B,OAZNA,EAAAH,EAAAI,KAAMF,KAAAA,IAAOG,MAeNC,0BAAoC,EAAKH,EACzCI,eAAyB,EAAKJ,EAC9BK,WAAK,EAAAL,EACLM,aAAON,EAAAA,EACPO,uBAAiBP,EAAAA,EACjBQ,UAAIR,EAAAA,EACJS,YAAIT,EACJU,cAAQ,EAAAV,EACRW,0BAAoBX,EAAAA,EACpBY,8BAAwBZ,EAAAA,EACxBa,iCAA2B,EAAAb,EAG3Bc,+BAAyB,EAAAd,EAGzBe,yBAAmB,EAAAf,EACnBgB,6BAAuB,EAAAhB,EACvBiB,cAAe,EAAKjB,EAEpBkB,2BAA6B,CACpC,kBACA,IACA,SACA,QACA,SACA,WACA,UACA,kBACA,gBACA,uBACA,4BACCC,KAAK,MAAKnB,EAEJoB,0BAA4B,sBAAqBpB,EAgNjDqB,aAAO,EAAArB,EA2WPsB,mBAAqD,IAAIC,IAAKvB,EA0L9DwB,eAAS,EAryBhBxB,EAAKQ,KAAOT,EAAO0B,IACnBzB,EAAKS,KAAOV,EAAO2B,IACnB1B,EAAKG,yBACsC,kBAAnCJ,EAAO4B,yBACX5B,EAAO4B,wBAEX3B,EAAKI,cAAgBL,EAAO6B,eAAgB,EAE5C5B,EAAK6B,qBACkC,iBAA/B9B,EAAO+B,oBACX/B,EAAO+B,o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