{"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\nconst markerAnchorCoordinates: Record<string, [number, number]> = {\n\t\"top-left\": [0, 0],\n\ttop: [0.5, 0],\n\t\"top-right\": [1, 0],\n\tleft: [0, 0.5],\n\tcenter: [0.5, 0.5],\n\tright: [1, 0.5],\n\t\"bottom-left\": [0, 1],\n\tbottom: [0.5, 1],\n\t\"bottom-right\": [1, 1],\n};\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\t// Cached so listeners are always removed from the element they were added to\n\tprivate _mapEventElement: HTMLElement | 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\tconst markerWidth = calculatedStyles.markerWidth;\n\t\t\t\t\tconst markerHeight = calculatedStyles.markerHeight;\n\t\t\t\t\t// Backwards compatible read: older Terra Draw versions will not have this field in the interface\n\t\t\t\t\tconst markerAnchor = (calculatedStyles as { markerAnchor?: string })\n\t\t\t\t\t\t.markerAnchor;\n\t\t\t\t\tconst [anchorX, anchorY] =\n\t\t\t\t\t\tmarkerAnchorCoordinates[markerAnchor ?? \"bottom\"];\n\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\tmarkerWidth && markerHeight\n\t\t\t\t\t\t\t\t\t? new this._lib.Size(markerWidth, markerHeight)\n\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t\tanchor:\n\t\t\t\t\t\t\t\tmarkerWidth && markerHeight\n\t\t\t\t\t\t\t\t\t? new this._lib.Point(\n\t\t\t\t\t\t\t\t\t\t\tmarkerWidth * anchorX,\n\t\t\t\t\t\t\t\t\t\t\tmarkerHeight * anchorY,\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\t\tthis._mapEventElement = undefined;\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\tif (!this._mapEventElement) {\n\t\t\t// TODO: This is a bit hacky, maybe there is a better solution here\n\t\t\tconst selector = 'div[style*=\"z-index: 3;\"]';\n\t\t\tthis._mapEventElement = this._map\n\t\t\t\t.getDiv()\n\t\t\t\t.querySelector(selector) as HTMLElement;\n\t\t}\n\n\t\treturn this._mapEventElement;\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":["markerAnchorCoordinates","top","left","center","right","bottom","_TerraDrawExtend$Terr","TerraDrawGoogleMapsAdapter","config","_this","call","this","_forwardMapElementEvents","_isolatedData","_data","_cursor","_cursorStyleSheet","_lib","_map","_overlay","_mapEventElement","_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","markerWidth","markerHeight","markerAnchor","_markerAnchorCoordina","anchorX","anchorY","clickable","icon","url","scaledSize","Size","undefined","anchor","Point","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","clientX","clientY","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","_iterator2","_step2","set","_iterator3","_step3","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","_step6","_iterator6","createdFeature","addGeoJson","_step7","features","_iterator7","clearLayers","_this4","onClear","getCoordinatePrecision","key","get","_this$renderedFeature","Boolean","size","TerraDrawExtend","TerraD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