vue-maplibre-gl
Version:
Vue 3 plugin for maplibre-gl
1 lines • 177 kB
Source Map (JSON)
{"version":3,"file":"draw.control-D4sJ2phO.cjs","sources":["../src/lib/debounce.ts","../src/types.ts","../src/components/controls/position.enum.ts","../src/composable/usePositionWatcher.ts","../src/components/controls/custom.control.ts","../src/components/button.component.ts","../node_modules/@turf/helpers/dist/esm/index.js","../node_modules/@turf/meta/dist/esm/index.js","../node_modules/@turf/area/dist/esm/index.js","../node_modules/@turf/invariant/dist/esm/index.js","../node_modules/@turf/destination/dist/esm/index.js","../node_modules/@turf/circle/dist/esm/index.js","../src/plugins/draw/mode.abstract.ts","../node_modules/robust-predicates/esm/util.js","../node_modules/robust-predicates/esm/orient2d.js","../node_modules/point-in-polygon-hao/dist/esm/index.js","../node_modules/@turf/boolean-point-in-polygon/dist/esm/index.js","../node_modules/@turf/distance/dist/esm/index.js","../src/plugins/draw/circle.mode.ts","../src/plugins/draw/html.ts","../src/plugins/draw/circleStatic.mode.ts","../node_modules/@turf/clean-coords/dist/esm/index.js","../node_modules/@turf/clone/dist/esm/index.js","../node_modules/@turf/simplify/dist/esm/index.js","../src/plugins/draw/polygon.mode.ts","../src/plugins/draw/styles.ts","../src/plugins/draw/types.ts","../node_modules/@turf/bbox/dist/esm/index.js","../src/plugins/draw/plugin.ts","../src/plugins/draw/draw.control.ts"],"sourcesContent":["export function debounce(fn: Function, wait = 250, immediate = false) {\n\tlet timeout: number | undefined;\n\n\tfunction debounced(/* ...args */) {\n\t\tconst args = arguments;\n\n\t\tconst later = () => {\n\t\t\ttimeout = undefined;\n\t\t\tif (immediate !== true) {\n\t\t\t\t// @ts-ignore\n\t\t\t\tfn.apply(this, args);\n\t\t\t}\n\t\t};\n\n\t\tclearTimeout(timeout!);\n\t\tif (immediate === true && timeout === undefined) {\n\t\t\t// @ts-ignore\n\t\t\tfn.apply(this, args);\n\t\t}\n\t\ttimeout = window.setTimeout(later, wait);\n\t}\n\n\tdebounced.cancel = () => {\n\t\tclearTimeout(timeout!);\n\t};\n\n\treturn debounced;\n}\n\n\nexport type ThrottledFunction<T extends (...args: any) => any> = (...args: Parameters<T>) => ReturnType<T>;\n\nexport function throttle<T extends (...args: any) => any>(func: T, ms: number): ThrottledFunction<T> {\n\tlet inThrottle: boolean;\n\tlet lastResult: ReturnType<T>;\n\n\treturn function (this: any): ReturnType<T> {\n\t\tconst args = arguments;\n\t\tconst context = this;\n\n\t\tif (!inThrottle) {\n\t\t\tinThrottle = true;\n\n\t\t\tsetTimeout(() => (inThrottle = false), ms);\n\n\t\t\tlastResult = func.apply(context, args as unknown as any[]);\n\t\t}\n\n\t\treturn lastResult;\n\t};\n}\n","import type { MglMap } from '@/components';\nimport type { SourceLayerRegistry } from '@/lib/sourceLayer.registry';\nimport type { Map, MapOptions, SourceSpecification, StyleSpecification } from 'maplibre-gl';\nimport type { Emitter } from 'mitt';\nimport type { InjectionKey, Ref, ShallowRef } from 'vue';\n\nexport const mapSymbol = Symbol('map') as InjectionKey<ShallowRef<Map | undefined>>,\n\t\t\t isLoadedSymbol = Symbol('isLoaded') as InjectionKey<Ref<boolean>>,\n\t\t\t isInitializedSymbol = Symbol('isInitialized') as InjectionKey<Ref<boolean>>,\n\t\t\t componentIdSymbol = Symbol('componentId') as InjectionKey<number>,\n\t\t\t sourceIdSymbol = Symbol('sourceId') as InjectionKey<string>,\n\t\t\t sourceLayerRegistry = Symbol('sourceLayerRegistry') as InjectionKey<SourceLayerRegistry>,\n\t\t\t emitterSymbol = Symbol('emitter') as InjectionKey<Emitter<MglEvents>>,\n\t\t\t fitBoundsOptionsSymbol = Symbol('fitBoundsOptions') as InjectionKey<FitBoundsOptions>;\n\nexport type FitBoundsOptions = MapOptions['fitBoundsOptions'] & { useOnBoundsUpdate?: boolean };\n\nexport interface MglEvent<T = any> {\n\ttype: string;\n\tcomponent: InstanceType<typeof MglMap>;\n\tmap: Map;\n\tevent: T;\n}\n\nexport type MglEvents = {\n\tstyleSwitched: StyleSwitchItem;\n}\n\nexport interface StyleSwitchItem {\n\tname: string;\n\tlabel: string;\n\ticon?: {\n\t\tpath: string;\n\t};\n\tstyle: StyleSpecification | string;\n}\n\nexport type AllProps<T extends object> = { [K in keyof T]: undefined };\n\n// only proper way to ensure all possible option to track option changes by type system\nexport function AllOptions<T extends object>(obj: AllProps<Required<T>>) {\n\treturn Object.keys(obj) as Array<keyof T>;\n}\n\nexport function AllSourceOptions<T = SourceSpecification>(obj: AllProps<Required<Omit<T, 'type'>>>) {\n\treturn Object.keys(obj) as Array<keyof T>;\n}\n\nexport type ValidLanguages =\n\t'sq'\n\t| 'am'\n\t| 'ar'\n\t| 'hy'\n\t| 'az'\n\t| 'eu'\n\t| 'be'\n\t| 'bs'\n\t| 'br'\n\t| 'bg'\n\t| 'ca'\n\t| 'zh'\n\t| 'co'\n\t| 'hr'\n\t| 'cs'\n\t| 'da'\n\t| 'nl'\n\t| 'en'\n\t| 'eo'\n\t| 'et'\n\t| 'fi'\n\t| 'fr'\n\t| 'fy'\n\t| 'ka'\n\t| 'de'\n\t| 'el'\n\t| 'he'\n\t| 'hi'\n\t| 'hu'\n\t| 'is'\n\t| 'id'\n\t| 'ga'\n\t| 'it'\n\t| 'ja'\n\t| 'ja-Hira'\n\t| 'ja_kana'\n\t| 'ja_rm'\n\t| 'ja-Latn'\n\t| 'kn'\n\t| 'kk'\n\t| 'ko'\n\t| 'ko-Latn'\n\t| 'ku'\n\t| 'la'\n\t| 'lv'\n\t| 'lt'\n\t| 'lb'\n\t| 'mk'\n\t| 'ml'\n\t| 'mt'\n\t| 'no'\n\t| 'oc'\n\t| 'pl'\n\t| 'pt'\n\t| 'ro'\n\t| 'rm'\n\t| 'ru'\n\t| 'gd'\n\t| 'sr'\n\t| 'sr-Latn'\n\t| 'sk'\n\t| 'sl'\n\t| 'es'\n\t| 'sv'\n\t| 'ta'\n\t| 'te'\n\t| 'th'\n\t| 'tr'\n\t| 'uk'\n\t| 'cy'\n","export enum Position {\n\tTOP_LEFT = 'top-left',\n\tTOP_RIGHT = 'top-right',\n\tBOTTOM_LEFT = 'bottom-left',\n\tBOTTOM_RIGHT = 'bottom-right'\n}\n\nexport const PositionValues = Object.values(Position);\n\nexport type PositionProp = Position | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';\n","import { type Position, type PositionProp, PositionValues } from '@/components/controls/position.enum';\nimport type { WatchSource } from '@vue/runtime-core';\nimport type { IControl, Map } from 'maplibre-gl';\nimport { type ShallowRef, watch } from 'vue';\n\nexport function usePositionWatcher(source: WatchSource<PositionProp | undefined>, map: ShallowRef<Map | undefined>, control: IControl) {\n\twatch(source, (v) => {\n\t\tif (v && PositionValues.indexOf(v as Position) === -1) {\n\t\t\treturn;\n\t\t}\n\t\tif (map.value?.hasControl(control)) {\n\t\t\tmap.value.removeControl(control);\n\t\t}\n\t\tmap.value?.addControl(control, v);\n\t}, { immediate: true });\n}\n","import { Position, type PositionProp, PositionValues } from '@/components/controls/position.enum';\nimport { usePositionWatcher } from '@/composable/usePositionWatcher';\nimport { isInitializedSymbol, mapSymbol } from '@/types';\nimport type { ControlPosition, IControl } from 'maplibre-gl';\nimport { createCommentVNode, defineComponent, h, inject, nextTick, onBeforeUnmount, type PropType, ref, type Ref, type SlotsType, Teleport, watch } from 'vue';\n\n\nexport class CustomControl implements IControl {\n\n\tpublic static readonly CONTROL_CLASS = 'maplibregl-ctrl';\n\tpublic static readonly CONTROL_GROUP_CLASS = 'maplibregl-ctrl-group';\n\n\tpublic readonly container: HTMLDivElement;\n\n\tconstructor(private isAdded: Ref<boolean>, noClasses: boolean) {\n\t\tthis.container = document.createElement('div');\n\t\tthis.setClasses(noClasses);\n\t}\n\n\tgetDefaultPosition(): ControlPosition {\n\t\treturn Position.TOP_LEFT;\n\t}\n\n\tonAdd(): HTMLElement {\n\t\tnextTick(() => this.isAdded.value = true);\n\t\treturn this.container;\n\t}\n\n\tonRemove(): void {\n\t\tthis.isAdded.value = false;\n\t\tthis.container.remove();\n\t}\n\n\tsetClasses(noClasses: boolean) {\n\t\tif (noClasses) {\n\t\t\tthis.container.classList.remove(CustomControl.CONTROL_CLASS);\n\t\t\tthis.container.classList.remove(CustomControl.CONTROL_GROUP_CLASS);\n\t\t} else {\n\t\t\tthis.container.classList.add(CustomControl.CONTROL_CLASS);\n\t\t\tthis.container.classList.add(CustomControl.CONTROL_GROUP_CLASS);\n\t\t}\n\t}\n\n}\n\nexport default /*#__PURE__*/ defineComponent({\n\tname : 'MglCustomControl',\n\tprops: {\n\t\tposition : {\n\t\t\ttype : String as PropType<PositionProp>,\n\t\t\tvalidator: (v: Position) => {\n\t\t\t\treturn PositionValues.indexOf(v) !== -1;\n\t\t\t}\n\t\t},\n\t\tnoClasses: {\n\t\t\ttype : Boolean as PropType<boolean>,\n\t\t\tdefault: false\n\t\t}\n\t},\n\tslots: Object as SlotsType<{ default: {} }>,\n\tsetup(props, { slots }) {\n\n\t\tconst map = inject(mapSymbol)!,\n\t\t\t isInitialized = inject(isInitializedSymbol)!,\n\t\t\t isAdded = ref(false),\n\t\t\t control = new CustomControl(isAdded, props.noClasses!);\n\n\t\tusePositionWatcher(() => props.position, map, control);\n\t\twatch(() => props.noClasses, v => control.setClasses(v!));\n\t\tonBeforeUnmount(() => isInitialized.value && map.value?.removeControl(control));\n\n\t\treturn () => {\n\t\t\tif (!isAdded.value) {\n\t\t\t\treturn createCommentVNode('custom-component');\n\t\t\t}\n\t\t\treturn h(\n\t\t\t\tTeleport as any,\n\t\t\t\t{ to: control.container },\n\t\t\t\tslots.default?.({})\n\t\t\t);\n\t\t};\n\n\t}\n});\n","import { defineComponent, h, type PropType, ref, type SlotsType, warn, watch } from 'vue';\n\nexport enum ButtonType {\n\tDEFAULT = 'default',\n\tTEXT = 'text',\n\tMDI = 'mdi',\n\tSIMPLE_ICON = 'simple-icons',\n}\n\nexport const ButtonTypeValues = Object.values(ButtonType);\n\ninterface Default {\n\tsize: number;\n\tviewbox: string;\n}\n\nconst types: { [key in ButtonType]?: Default } = {\n\t[ ButtonType.TEXT ] : undefined,\n\t[ ButtonType.MDI ] : {\n\t\tsize : 21,\n\t\tviewbox: '0 0 24 24'\n\t},\n\t[ ButtonType.SIMPLE_ICON ]: {\n\t\tsize : 21,\n\t\tviewbox: '0 0 24 24'\n\t},\n\t[ ButtonType.DEFAULT ] : {\n\t\tsize : 0,\n\t\tviewbox: '0 0 0 0'\n\t}\n};\n\n\nexport default /*#__PURE__*/ defineComponent({\n\tname : 'MglButton',\n\tprops: {\n\t\ttype : {\n\t\t\ttype : String as PropType<ButtonType | 'default' | 'text' | 'mdi' | 'simple-icons'>,\n\t\t\tdefault : ButtonType.DEFAULT,\n\t\t\tvalidator: (v: ButtonType) => {\n\t\t\t\treturn ButtonTypeValues.indexOf(v) !== -1;\n\t\t\t}\n\t\t},\n\t\tpath : {\n\t\t\ttype: String as PropType<string>\n\t\t},\n\t\tsize : Number as PropType<number>,\n\t\tviewbox: String as PropType<string>\n\t},\n\tslots: Object as SlotsType<{ default: {} }>,\n\tsetup(props, { slots }) {\n\n\t\tif (!props.path && props.type !== ButtonType.TEXT) {\n\t\t\twarn('property `path` must be set on MaplibreButton');\n\t\t}\n\n\t\tconst defaults = ref(types[ props.type ] || types.default);\n\t\twatch(() => props.type, v => defaults.value = types[ v ] || types.default);\n\n\t\treturn () => {\n\t\t\tif (props.type === ButtonType.TEXT) {\n\t\t\t\treturn h('button', { type: 'button' }, slots.default?.({}));\n\t\t\t}\n\t\t\treturn h('button', { type: 'button', 'class': 'maplibregl-ctrl-icon' },\n\t\t\t\t[\n\t\t\t\t\th(\n\t\t\t\t\t\t'svg',\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\twidth : props.size || defaults.value!.size,\n\t\t\t\t\t\t\theight : props.size || defaults.value!.size,\n\t\t\t\t\t\t\tviewBox: props.viewbox || defaults.value!.viewbox\n\t\t\t\t\t\t},\n\t\t\t\t\t\th('path', { fill: 'currentColor', d: props.path })\n\t\t\t\t\t),\n\t\t\t\t\tslots.default?.({})\n\t\t\t\t]\n\t\t\t);\n\t\t};\n\n\t}\n});\n","// index.ts\nvar earthRadius = 63710088e-1;\nvar factors = {\n centimeters: earthRadius * 100,\n centimetres: earthRadius * 100,\n degrees: 360 / (2 * Math.PI),\n feet: earthRadius * 3.28084,\n inches: earthRadius * 39.37,\n kilometers: earthRadius / 1e3,\n kilometres: earthRadius / 1e3,\n meters: earthRadius,\n metres: earthRadius,\n miles: earthRadius / 1609.344,\n millimeters: earthRadius * 1e3,\n millimetres: earthRadius * 1e3,\n nauticalmiles: earthRadius / 1852,\n radians: 1,\n yards: earthRadius * 1.0936\n};\nvar areaFactors = {\n acres: 247105e-9,\n centimeters: 1e4,\n centimetres: 1e4,\n feet: 10.763910417,\n hectares: 1e-4,\n inches: 1550.003100006,\n kilometers: 1e-6,\n kilometres: 1e-6,\n meters: 1,\n metres: 1,\n miles: 386e-9,\n nauticalmiles: 29155334959812285e-23,\n millimeters: 1e6,\n millimetres: 1e6,\n yards: 1.195990046\n};\nfunction feature(geom, properties, options = {}) {\n const feat = { type: \"Feature\" };\n if (options.id === 0 || options.id) {\n feat.id = options.id;\n }\n if (options.bbox) {\n feat.bbox = options.bbox;\n }\n feat.properties = properties || {};\n feat.geometry = geom;\n return feat;\n}\nfunction geometry(type, coordinates, _options = {}) {\n switch (type) {\n case \"Point\":\n return point(coordinates).geometry;\n case \"LineString\":\n return lineString(coordinates).geometry;\n case \"Polygon\":\n return polygon(coordinates).geometry;\n case \"MultiPoint\":\n return multiPoint(coordinates).geometry;\n case \"MultiLineString\":\n return multiLineString(coordinates).geometry;\n case \"MultiPolygon\":\n return multiPolygon(coordinates).geometry;\n default:\n throw new Error(type + \" is invalid\");\n }\n}\nfunction point(coordinates, properties, options = {}) {\n if (!coordinates) {\n throw new Error(\"coordinates is required\");\n }\n if (!Array.isArray(coordinates)) {\n throw new Error(\"coordinates must be an Array\");\n }\n if (coordinates.length < 2) {\n throw new Error(\"coordinates must be at least 2 numbers long\");\n }\n if (!isNumber(coordinates[0]) || !isNumber(coordinates[1])) {\n throw new Error(\"coordinates must contain numbers\");\n }\n const geom = {\n type: \"Point\",\n coordinates\n };\n return feature(geom, properties, options);\n}\nfunction points(coordinates, properties, options = {}) {\n return featureCollection(\n coordinates.map((coords) => {\n return point(coords, properties);\n }),\n options\n );\n}\nfunction polygon(coordinates, properties, options = {}) {\n for (const ring of coordinates) {\n if (ring.length < 4) {\n throw new Error(\n \"Each LinearRing of a Polygon must have 4 or more Positions.\"\n );\n }\n if (ring[ring.length - 1].length !== ring[0].length) {\n throw new Error(\"First and last Position are not equivalent.\");\n }\n for (let j = 0; j < ring[ring.length - 1].length; j++) {\n if (ring[ring.length - 1][j] !== ring[0][j]) {\n throw new Error(\"First and last Position are not equivalent.\");\n }\n }\n }\n const geom = {\n type: \"Polygon\",\n coordinates\n };\n return feature(geom, properties, options);\n}\nfunction polygons(coordinates, properties, options = {}) {\n return featureCollection(\n coordinates.map((coords) => {\n return polygon(coords, properties);\n }),\n options\n );\n}\nfunction lineString(coordinates, properties, options = {}) {\n if (coordinates.length < 2) {\n throw new Error(\"coordinates must be an array of two or more positions\");\n }\n const geom = {\n type: \"LineString\",\n coordinates\n };\n return feature(geom, properties, options);\n}\nfunction lineStrings(coordinates, properties, options = {}) {\n return featureCollection(\n coordinates.map((coords) => {\n return lineString(coords, properties);\n }),\n options\n );\n}\nfunction featureCollection(features, options = {}) {\n const fc = { type: \"FeatureCollection\" };\n if (options.id) {\n fc.id = options.id;\n }\n if (options.bbox) {\n fc.bbox = options.bbox;\n }\n fc.features = features;\n return fc;\n}\nfunction multiLineString(coordinates, properties, options = {}) {\n const geom = {\n type: \"MultiLineString\",\n coordinates\n };\n return feature(geom, properties, options);\n}\nfunction multiPoint(coordinates, properties, options = {}) {\n const geom = {\n type: \"MultiPoint\",\n coordinates\n };\n return feature(geom, properties, options);\n}\nfunction multiPolygon(coordinates, properties, options = {}) {\n const geom = {\n type: \"MultiPolygon\",\n coordinates\n };\n return feature(geom, properties, options);\n}\nfunction geometryCollection(geometries, properties, options = {}) {\n const geom = {\n type: \"GeometryCollection\",\n geometries\n };\n return feature(geom, properties, options);\n}\nfunction round(num, precision = 0) {\n if (precision && !(precision >= 0)) {\n throw new Error(\"precision must be a positive number\");\n }\n const multiplier = Math.pow(10, precision || 0);\n return Math.round(num * multiplier) / multiplier;\n}\nfunction radiansToLength(radians, units = \"kilometers\") {\n const factor = factors[units];\n if (!factor) {\n throw new Error(units + \" units is invalid\");\n }\n return radians * factor;\n}\nfunction lengthToRadians(distance, units = \"kilometers\") {\n const factor = factors[units];\n if (!factor) {\n throw new Error(units + \" units is invalid\");\n }\n return distance / factor;\n}\nfunction lengthToDegrees(distance, units) {\n return radiansToDegrees(lengthToRadians(distance, units));\n}\nfunction bearingToAzimuth(bearing) {\n let angle = bearing % 360;\n if (angle < 0) {\n angle += 360;\n }\n return angle;\n}\nfunction azimuthToBearing(angle) {\n angle = angle % 360;\n if (angle > 180) {\n return angle - 360;\n } else if (angle < -180) {\n return angle + 360;\n }\n return angle;\n}\nfunction radiansToDegrees(radians) {\n const normalisedRadians = radians % (2 * Math.PI);\n return normalisedRadians * 180 / Math.PI;\n}\nfunction degreesToRadians(degrees) {\n const normalisedDegrees = degrees % 360;\n return normalisedDegrees * Math.PI / 180;\n}\nfunction convertLength(length, originalUnit = \"kilometers\", finalUnit = \"kilometers\") {\n if (!(length >= 0)) {\n throw new Error(\"length must be a positive number\");\n }\n return radiansToLength(lengthToRadians(length, originalUnit), finalUnit);\n}\nfunction convertArea(area, originalUnit = \"meters\", finalUnit = \"kilometers\") {\n if (!(area >= 0)) {\n throw new Error(\"area must be a positive number\");\n }\n const startFactor = areaFactors[originalUnit];\n if (!startFactor) {\n throw new Error(\"invalid original units\");\n }\n const finalFactor = areaFactors[finalUnit];\n if (!finalFactor) {\n throw new Error(\"invalid final units\");\n }\n return area / startFactor * finalFactor;\n}\nfunction isNumber(num) {\n return !isNaN(num) && num !== null && !Array.isArray(num);\n}\nfunction isObject(input) {\n return input !== null && typeof input === \"object\" && !Array.isArray(input);\n}\nfunction validateBBox(bbox) {\n if (!bbox) {\n throw new Error(\"bbox is required\");\n }\n if (!Array.isArray(bbox)) {\n throw new Error(\"bbox must be an Array\");\n }\n if (bbox.length !== 4 && bbox.length !== 6) {\n throw new Error(\"bbox must be an Array of 4 or 6 numbers\");\n }\n bbox.forEach((num) => {\n if (!isNumber(num)) {\n throw new Error(\"bbox must only contain numbers\");\n }\n });\n}\nfunction validateId(id) {\n if (!id) {\n throw new Error(\"id is required\");\n }\n if ([\"string\", \"number\"].indexOf(typeof id) === -1) {\n throw new Error(\"id must be a number or a string\");\n }\n}\nexport {\n areaFactors,\n azimuthToBearing,\n bearingToAzimuth,\n convertArea,\n convertLength,\n degreesToRadians,\n earthRadius,\n factors,\n feature,\n featureCollection,\n geometry,\n geometryCollection,\n isNumber,\n isObject,\n lengthToDegrees,\n lengthToRadians,\n lineString,\n lineStrings,\n multiLineString,\n multiPoint,\n multiPolygon,\n point,\n points,\n polygon,\n polygons,\n radiansToDegrees,\n radiansToLength,\n round,\n validateBBox,\n validateId\n};\n//# sourceMappingURL=index.js.map","// index.js\nimport { feature, point, lineString, isObject } from \"@turf/helpers\";\nfunction coordEach(geojson, callback, excludeWrapCoord) {\n if (geojson === null) return;\n var j, k, l, geometry, stopG, coords, geometryMaybeCollection, wrapShrink = 0, coordIndex = 0, isGeometryCollection, type = geojson.type, isFeatureCollection = type === \"FeatureCollection\", isFeature = type === \"Feature\", stop = isFeatureCollection ? geojson.features.length : 1;\n for (var featureIndex = 0; featureIndex < stop; featureIndex++) {\n geometryMaybeCollection = isFeatureCollection ? geojson.features[featureIndex].geometry : isFeature ? geojson.geometry : geojson;\n isGeometryCollection = geometryMaybeCollection ? geometryMaybeCollection.type === \"GeometryCollection\" : false;\n stopG = isGeometryCollection ? geometryMaybeCollection.geometries.length : 1;\n for (var geomIndex = 0; geomIndex < stopG; geomIndex++) {\n var multiFeatureIndex = 0;\n var geometryIndex = 0;\n geometry = isGeometryCollection ? geometryMaybeCollection.geometries[geomIndex] : geometryMaybeCollection;\n if (geometry === null) continue;\n coords = geometry.coordinates;\n var geomType = geometry.type;\n wrapShrink = excludeWrapCoord && (geomType === \"Polygon\" || geomType === \"MultiPolygon\") ? 1 : 0;\n switch (geomType) {\n case null:\n break;\n case \"Point\":\n if (callback(\n coords,\n coordIndex,\n featureIndex,\n multiFeatureIndex,\n geometryIndex\n ) === false)\n return false;\n coordIndex++;\n multiFeatureIndex++;\n break;\n case \"LineString\":\n case \"MultiPoint\":\n for (j = 0; j < coords.length; j++) {\n if (callback(\n coords[j],\n coordIndex,\n featureIndex,\n multiFeatureIndex,\n geometryIndex\n ) === false)\n return false;\n coordIndex++;\n if (geomType === \"MultiPoint\") multiFeatureIndex++;\n }\n if (geomType === \"LineString\") multiFeatureIndex++;\n break;\n case \"Polygon\":\n case \"MultiLineString\":\n for (j = 0; j < coords.length; j++) {\n for (k = 0; k < coords[j].length - wrapShrink; k++) {\n if (callback(\n coords[j][k],\n coordIndex,\n featureIndex,\n multiFeatureIndex,\n geometryIndex\n ) === false)\n return false;\n coordIndex++;\n }\n if (geomType === \"MultiLineString\") multiFeatureIndex++;\n if (geomType === \"Polygon\") geometryIndex++;\n }\n if (geomType === \"Polygon\") multiFeatureIndex++;\n break;\n case \"MultiPolygon\":\n for (j = 0; j < coords.length; j++) {\n geometryIndex = 0;\n for (k = 0; k < coords[j].length; k++) {\n for (l = 0; l < coords[j][k].length - wrapShrink; l++) {\n if (callback(\n coords[j][k][l],\n coordIndex,\n featureIndex,\n multiFeatureIndex,\n geometryIndex\n ) === false)\n return false;\n coordIndex++;\n }\n geometryIndex++;\n }\n multiFeatureIndex++;\n }\n break;\n case \"GeometryCollection\":\n for (j = 0; j < geometry.geometries.length; j++)\n if (coordEach(geometry.geometries[j], callback, excludeWrapCoord) === false)\n return false;\n break;\n default:\n throw new Error(\"Unknown Geometry Type\");\n }\n }\n }\n}\nfunction coordReduce(geojson, callback, initialValue, excludeWrapCoord) {\n var previousValue = initialValue;\n coordEach(\n geojson,\n function(currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) {\n if (coordIndex === 0 && initialValue === void 0)\n previousValue = currentCoord;\n else\n previousValue = callback(\n previousValue,\n currentCoord,\n coordIndex,\n featureIndex,\n multiFeatureIndex,\n geometryIndex\n );\n },\n excludeWrapCoord\n );\n return previousValue;\n}\nfunction propEach(geojson, callback) {\n var i;\n switch (geojson.type) {\n case \"FeatureCollection\":\n for (i = 0; i < geojson.features.length; i++) {\n if (callback(geojson.features[i].properties, i) === false) break;\n }\n break;\n case \"Feature\":\n callback(geojson.properties, 0);\n break;\n }\n}\nfunction propReduce(geojson, callback, initialValue) {\n var previousValue = initialValue;\n propEach(geojson, function(currentProperties, featureIndex) {\n if (featureIndex === 0 && initialValue === void 0)\n previousValue = currentProperties;\n else\n previousValue = callback(previousValue, currentProperties, featureIndex);\n });\n return previousValue;\n}\nfunction featureEach(geojson, callback) {\n if (geojson.type === \"Feature\") {\n callback(geojson, 0);\n } else if (geojson.type === \"FeatureCollection\") {\n for (var i = 0; i < geojson.features.length; i++) {\n if (callback(geojson.features[i], i) === false) break;\n }\n }\n}\nfunction featureReduce(geojson, callback, initialValue) {\n var previousValue = initialValue;\n featureEach(geojson, function(currentFeature, featureIndex) {\n if (featureIndex === 0 && initialValue === void 0)\n previousValue = currentFeature;\n else previousValue = callback(previousValue, currentFeature, featureIndex);\n });\n return previousValue;\n}\nfunction coordAll(geojson) {\n var coords = [];\n coordEach(geojson, function(coord) {\n coords.push(coord);\n });\n return coords;\n}\nfunction geomEach(geojson, callback) {\n var i, j, g, geometry, stopG, geometryMaybeCollection, isGeometryCollection, featureProperties, featureBBox, featureId, featureIndex = 0, isFeatureCollection = geojson.type === \"FeatureCollection\", isFeature = geojson.type === \"Feature\", stop = isFeatureCollection ? geojson.features.length : 1;\n for (i = 0; i < stop; i++) {\n geometryMaybeCollection = isFeatureCollection ? geojson.features[i].geometry : isFeature ? geojson.geometry : geojson;\n featureProperties = isFeatureCollection ? geojson.features[i].properties : isFeature ? geojson.properties : {};\n featureBBox = isFeatureCollection ? geojson.features[i].bbox : isFeature ? geojson.bbox : void 0;\n featureId = isFeatureCollection ? geojson.features[i].id : isFeature ? geojson.id : void 0;\n isGeometryCollection = geometryMaybeCollection ? geometryMaybeCollection.type === \"GeometryCollection\" : false;\n stopG = isGeometryCollection ? geometryMaybeCollection.geometries.length : 1;\n for (g = 0; g < stopG; g++) {\n geometry = isGeometryCollection ? geometryMaybeCollection.geometries[g] : geometryMaybeCollection;\n if (geometry === null) {\n if (callback(\n null,\n featureIndex,\n featureProperties,\n featureBBox,\n featureId\n ) === false)\n return false;\n continue;\n }\n switch (geometry.type) {\n case \"Point\":\n case \"LineString\":\n case \"MultiPoint\":\n case \"Polygon\":\n case \"MultiLineString\":\n case \"MultiPolygon\": {\n if (callback(\n geometry,\n featureIndex,\n featureProperties,\n featureBBox,\n featureId\n ) === false)\n return false;\n break;\n }\n case \"GeometryCollection\": {\n for (j = 0; j < geometry.geometries.length; j++) {\n if (callback(\n geometry.geometries[j],\n featureIndex,\n featureProperties,\n featureBBox,\n featureId\n ) === false)\n return false;\n }\n break;\n }\n default:\n throw new Error(\"Unknown Geometry Type\");\n }\n }\n featureIndex++;\n }\n}\nfunction geomReduce(geojson, callback, initialValue) {\n var previousValue = initialValue;\n geomEach(\n geojson,\n function(currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {\n if (featureIndex === 0 && initialValue === void 0)\n previousValue = currentGeometry;\n else\n previousValue = callback(\n previousValue,\n currentGeometry,\n featureIndex,\n featureProperties,\n featureBBox,\n featureId\n );\n }\n );\n return previousValue;\n}\nfunction flattenEach(geojson, callback) {\n geomEach(geojson, function(geometry, featureIndex, properties, bbox, id) {\n var type = geometry === null ? null : geometry.type;\n switch (type) {\n case null:\n case \"Point\":\n case \"LineString\":\n case \"Polygon\":\n if (callback(\n feature(geometry, properties, { bbox, id }),\n featureIndex,\n 0\n ) === false)\n return false;\n return;\n }\n var geomType;\n switch (type) {\n case \"MultiPoint\":\n geomType = \"Point\";\n break;\n case \"MultiLineString\":\n geomType = \"LineString\";\n break;\n case \"MultiPolygon\":\n geomType = \"Polygon\";\n break;\n }\n for (var multiFeatureIndex = 0; multiFeatureIndex < geometry.coordinates.length; multiFeatureIndex++) {\n var coordinate = geometry.coordinates[multiFeatureIndex];\n var geom = {\n type: geomType,\n coordinates: coordinate\n };\n if (callback(feature(geom, properties), featureIndex, multiFeatureIndex) === false)\n return false;\n }\n });\n}\nfunction flattenReduce(geojson, callback, initialValue) {\n var previousValue = initialValue;\n flattenEach(\n geojson,\n function(currentFeature, featureIndex, multiFeatureIndex) {\n if (featureIndex === 0 && multiFeatureIndex === 0 && initialValue === void 0)\n previousValue = currentFeature;\n else\n previousValue = callback(\n previousValue,\n currentFeature,\n featureIndex,\n multiFeatureIndex\n );\n }\n );\n return previousValue;\n}\nfunction segmentEach(geojson, callback) {\n flattenEach(geojson, function(feature2, featureIndex, multiFeatureIndex) {\n var segmentIndex = 0;\n if (!feature2.geometry) return;\n var type = feature2.geometry.type;\n if (type === \"Point\" || type === \"MultiPoint\") return;\n var previousCoords;\n var previousFeatureIndex = 0;\n var previousMultiIndex = 0;\n var prevGeomIndex = 0;\n if (coordEach(\n feature2,\n function(currentCoord, coordIndex, featureIndexCoord, multiPartIndexCoord, geometryIndex) {\n if (previousCoords === void 0 || featureIndex > previousFeatureIndex || multiPartIndexCoord > previousMultiIndex || geometryIndex > prevGeomIndex) {\n previousCoords = currentCoord;\n previousFeatureIndex = featureIndex;\n previousMultiIndex = multiPartIndexCoord;\n prevGeomIndex = geometryIndex;\n segmentIndex = 0;\n return;\n }\n var currentSegment = lineString(\n [previousCoords, currentCoord],\n feature2.properties\n );\n if (callback(\n currentSegment,\n featureIndex,\n multiFeatureIndex,\n geometryIndex,\n segmentIndex\n ) === false)\n return false;\n segmentIndex++;\n previousCoords = currentCoord;\n }\n ) === false)\n return false;\n });\n}\nfunction segmentReduce(geojson, callback, initialValue) {\n var previousValue = initialValue;\n var started = false;\n segmentEach(\n geojson,\n function(currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) {\n if (started === false && initialValue === void 0)\n previousValue = currentSegment;\n else\n previousValue = callback(\n previousValue,\n currentSegment,\n featureIndex,\n multiFeatureIndex,\n geometryIndex,\n segmentIndex\n );\n started = true;\n }\n );\n return previousValue;\n}\nfunction lineEach(geojson, callback) {\n if (!geojson) throw new Error(\"geojson is required\");\n flattenEach(geojson, function(feature2, featureIndex, multiFeatureIndex) {\n if (feature2.geometry === null) return;\n var type = feature2.geometry.type;\n var coords = feature2.geometry.coordinates;\n switch (type) {\n case \"LineString\":\n if (callback(feature2, featureIndex, multiFeatureIndex, 0, 0) === false)\n return false;\n break;\n case \"Polygon\":\n for (var geometryIndex = 0; geometryIndex < coords.length; geometryIndex++) {\n if (callback(\n lineString(coords[geometryIndex], feature2.properties),\n featureIndex,\n multiFeatureIndex,\n geometryIndex\n ) === false)\n return false;\n }\n break;\n }\n });\n}\nfunction lineReduce(geojson, callback, initialValue) {\n var previousValue = initialValue;\n lineEach(\n geojson,\n function(currentLine, featureIndex, multiFeatureIndex, geometryIndex) {\n if (featureIndex === 0 && initialValue === void 0)\n previousValue = currentLine;\n else\n previousValue = callback(\n previousValue,\n currentLine,\n featureIndex,\n multiFeatureIndex,\n geometryIndex\n );\n }\n );\n return previousValue;\n}\nfunction findSegment(geojson, options) {\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n var featureIndex = options.featureIndex || 0;\n var multiFeatureIndex = options.multiFeatureIndex || 0;\n var geometryIndex = options.geometryIndex || 0;\n var segmentIndex = options.segmentIndex || 0;\n var properties = options.properties;\n var geometry;\n switch (geojson.type) {\n case \"FeatureCollection\":\n if (featureIndex < 0)\n featureIndex = geojson.features.length + featureIndex;\n properties = properties || geojson.features[featureIndex].properties;\n geometry = geojson.features[featureIndex].geometry;\n break;\n case \"Feature\":\n properties = properties || geojson.properties;\n geometry = geojson.geometry;\n break;\n case \"Point\":\n case \"MultiPoint\":\n return null;\n case \"LineString\":\n case \"Polygon\":\n case \"MultiLineString\":\n case \"MultiPolygon\":\n geometry = geojson;\n break;\n default:\n throw new Error(\"geojson is invalid\");\n }\n if (geometry === null) return null;\n var coords = geometry.coordinates;\n switch (geometry.type) {\n case \"Point\":\n case \"MultiPoint\":\n return null;\n case \"LineString\":\n if (segmentIndex < 0) segmentIndex = coords.length + segmentIndex - 1;\n return lineString(\n [coords[segmentIndex], coords[segmentIndex + 1]],\n properties,\n options\n );\n case \"Polygon\":\n if (geometryIndex < 0) geometryIndex = coords.length + geometryIndex;\n if (segmentIndex < 0)\n segmentIndex = coords[geometryIndex].length + segmentIndex - 1;\n return lineString(\n [\n coords[geometryIndex][segmentIndex],\n coords[geometryIndex][segmentIndex + 1]\n ],\n properties,\n options\n );\n case \"MultiLineString\":\n if (multiFeatureIndex < 0)\n multiFeatureIndex = coords.length + multiFeatureIndex;\n if (segmentIndex < 0)\n segmentIndex = coords[multiFeatureIndex].length + segmentIndex - 1;\n return lineString(\n [\n coords[multiFeatureIndex][segmentIndex],\n coords[multiFeatureIndex][segmentIndex + 1]\n ],\n properties,\n options\n );\n case \"MultiPolygon\":\n if (multiFeatureIndex < 0)\n multiFeatureIndex = coords.length + multiFeatureIndex;\n if (geometryIndex < 0)\n geometryIndex = coords[multiFeatureIndex].length + geometryIndex;\n if (segmentIndex < 0)\n segmentIndex = coords[multiFeatureIndex][geometryIndex].length - segmentIndex - 1;\n return lineString(\n [\n coords[multiFeatureIndex][geometryIndex][segmentIndex],\n coords[multiFeatureIndex][geometryIndex][segmentIndex + 1]\n ],\n properties,\n options\n );\n }\n throw new Error(\"geojson is invalid\");\n}\nfunction findPoint(geojson, options) {\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n var featureIndex = options.featureIndex || 0;\n var multiFeatureIndex = options.multiFeatureIndex || 0;\n var geometryIndex = options.geometryIndex || 0;\n var coordIndex = options.coordIndex || 0;\n var properties = options.properties;\n var geometry;\n switch (geojson.type) {\n case \"FeatureCollection\":\n if (featureIndex < 0)\n featureIndex = geojson.features.length + featureIndex;\n properties = properties || geojson.features[featureIndex].properties;\n geometry = geojson.features[featureIndex].geometry;\n break;\n case \"Feature\":\n properties = properties || geojson.properties;\n geometry = geojson.geometry;\n break;\n case \"Point\":\n case \"MultiPoint\":\n return null;\n case \"LineString\":\n case \"Polygon\":\n case \"MultiLineString\":\n case \"MultiPolygon\":\n geometry = geojson;\n break;\n default:\n throw new Error(\"geojson is invalid\");\n }\n if (geometry === null) return null;\n var coords = geometry.coordinates;\n switch (geometry.type) {\n case \"Point\":\n return point(coords, properties, options);\n case \"MultiPoint\":\n if (multiFeatureIndex < 0)\n multiFeatureIndex = coords.length + multiFeatureIndex;\n return point(coords[multiFeatureIndex], properties, options);\n case \"LineString\":\n if (coordIndex < 0) coordIndex = coords.length + coordIndex;\n return point(coords[coordIndex], properties, options);\n case \"Polygon\":\n if (geometryIndex < 0) geometryIndex = coords.length + geometryIndex;\n if (coordIndex < 0)\n coordIndex = coords[geometryIndex].length + coordIndex;\n return point(coords[geometryIndex][coordIndex], properties, options);\n case \"MultiLineString\":\n if (multiFeatureIndex < 0)\n multiFeatureIndex = coords.length + multiFeatureIndex;\n if (coordIndex < 0)\n coordIndex = coords[multiFeatureIndex].length + coordIndex;\n return point(coords[multiFeatureIndex][coordIndex], properties, options);\n case \"MultiPolygon\":\n if (multiFeatureIndex < 0)\n multiFeatureIndex = coords.length + multiFeatureIndex;\n if (geometryIndex < 0)\n geometryIndex = coords[multiFeatureIndex].length + geometryIndex;\n if (coordIndex < 0)\n coordIndex = coords[multiFeatureIndex][geometryIndex].length - coordIndex;\n return point(\n coords[multiFeatureIndex][geometryIndex][coordIndex],\n properties,\n options\n );\n }\n throw new Error(\"geojson is invalid\");\n}\nexport {\n coordAll,\n coordEach,\n coordReduce,\n featureEach,\n featureReduce,\n findPoint,\n findSegment,\n flattenEach,\n flattenReduce,\n geomEach,\n geomReduce,\n lineEach,\n lineReduce,\n propEach,\n propReduce,\n segmentEach,\n segmentReduce\n};\n//# sourceMappingURL=index.js.map","// index.ts\nimport { earthRadius } from \"@turf/helpers\";\nimport { geomReduce } from \"@turf/meta\";\nfunction area(geojson) {\n return geomReduce(\n geojson,\n (value, geom) => {\n return value + calculateArea(geom);\n },\n 0\n );\n}\nfunction calculateArea(geom) {\n let total = 0;\n let i;\n switch (geom.type) {\n case \"Polygon\":\n return polygonArea(geom.coordinates);\n case \"MultiPolygon\":\n for (i = 0; i < geom.coordinates.length; i++) {\n total += polygonArea(geom.coordinates[i]);\n }\n return total;\n case \"Point\":\n case \"MultiPoint\":\n case \"LineString\":\n case \"MultiLineString\":\n return 0;\n }\n return 0;\n}\nfunction polygonArea(coords) {\n let total = 0;\n if (coords && coords.length > 0) {\n total += Math.abs(ringArea(coords[0]));\n for (let i = 1; i < coords.length; i++) {\n total -= Math.abs(ringArea(coords[i]));\n }\n }\n return total;\n}\nvar FACTOR = earthRadius * earthRadius / 2;\nvar PI_OVER_180 = Math.PI / 180;\nfunction ringArea(coords) {\n const coordsLength = coords.length - 1;\n if (coordsLength <= 2) return 0;\n let total = 0;\n let i = 0;\n while (i < coordsLength) {\n const lower = coords[i];\n const middle = coords[i + 1 === coordsLength ? 0 : i + 1];\n const upper = coords[i + 2 >= coordsLength ? (i + 2) % coordsLength : i + 2];\n const lowerX = lower[0] * PI_OVER_180;\n const middleY = middle[1] * PI_OVER_180;\n const upperX = upper[0] * PI_OVER_180;\n total += (upperX - lowerX) * Math.sin(middleY);\n i++;\n }\n return total * FACTOR;\n}\nvar turf_area_default = area;\nexport {\n area,\n turf_area_default as default\n};\n//# sourceMappingURL=index.js.map","// index.ts\nimport { isNumber } from \"@turf/helpers\";\nfunction getCoord(coord) {\n if (!coord) {\n throw new Error(\"coord is required\");\n }\n if (!Array.isArray(coord)) {\n if (coord.type === \"Feature\" && coord.geometry !== null && coord.geometry.type === \"Point\") {\n return [...coord.geometry.coordinates];\n }\n if (coord.type === \"Point\") {\n return [...coord.coordinates];\n }\n }\n if (Array.isArray(coord) && coord.length >= 2 && !Array.isArray(coord[0]) && !Array.isArray(coord[1])) {\n return [...coord];\n }\n throw new Error(\"coord must be GeoJSON Point or an Array of numbers\");\n}\nfunction getCoords(coords) {\n if (Array.isArray(coords)) {\n return coords;\n }\n if (coords.type === \"Feature\") {\n if (coords.geometry !== null) {\n return coords.geometry.coordinates;\n }\n } else {\n if (coords.coordinates) {\n return coords.coordinates;\n }\n }\n throw new Error(\n \"coords must be GeoJSON Feature, Geometry Object or an Array\"\n );\n}\nfunction containsNumber(coordinates) {\n if (coordinates.length > 1 && isNumber(coordinates[0]) && isNumber(coordinates[1])) {\n return true;\n }\n if (Array.isArray(coordinates[0]) && coordinates[0].length) {\n return containsNumber(coordinates[0]);\n }\n throw new Error(\"coordinates must only contain numbers\");\n}\nfunction geojsonType(value, type, name) {\n if (!type || !name) {\n throw new Error(\"type and name required\");\n }\n if (!value || value.type !== type) {\n throw new Error(\n \"Invalid input to \" + name + \": must be a \" + type + \", given \" + value.type\n );\n }\n}\nfunction featureOf(feature, type, name) {\n if (!feature) {\n throw new Error(\"No feature passed\");\n }\n if (!name) {\n throw new Error(\".featureOf() requires a name\");\n }\n if (!feature || feature.type !== \"Feature\" || !feature.geometry) {\n throw new Error(\n \"Invalid input to \" + name + \", Feature with geometry required\"\n );\n }\n if (!feature.geometry || feature.geometry.type !== type) {\n throw new Error(\n \"Invalid input to \" + name + \": must be a \" + type + \", given \" + feature.geometry.type\n );\n }\n}\nfunction collectionOf(featureCollection, type, name) {\n if (!featureCollection) {\n throw new Error(\"No featureCollection passed\");\n }\n if (!name) {\n throw new Error(\".collectionOf() requires a name\");\n }\n if (!featureCollection || featureCollection.type !== \"FeatureCollection\") {\n throw new Error(\n \"Invalid input to \" + name + \", FeatureCollection required\"\n );\n }\n for (const feature of featureCollection.features) {\n if (!feature || feature.type !== \"Feature\" || !feature.geometry) {\n throw new Error(\n \"Invalid input to \" + name + \", Feature with geometry required\"\n );\n }\n if (!feature.geometry || feature.geometry.type !== type) {\n throw new Error(\n \"Invalid input to \" + name + \": must be a \" + type + \", given \" + feature.geometry.type\n );\n }\n }\n}\nfunction getGeom(geojson) {\n if (geojson.type === \"Feature\") {\n return geojson.geometry;\n }\n return geojson;\n}\nfunction getType(geojson, _name) {\n if (geojson.type === \"FeatureCollection\") {\n return \"FeatureCollection\";\n }\n if (geojson.type === \"GeometryCollection\") {\n return \"GeometryCollection\";\n }\n if (geojson.type === \"Feature\" && geojson.geometry !== null) {\n return geojson.geometry.type;\n }\n return geojson.type;\n}\nexport {\n collectionOf,\n containsNumber,\n featureOf,\n geojsonType,\n getCoord,\n getCoords,\n getGeom,\n getType\n};\n//# sourceMappingURL=index.js.map","// index.ts\nimport {\n degreesToRadians,\n lengthToRadians,\n point,\n radiansToDegrees\n} from \"@turf/helpers\";\nimport { getCoord } from \"@turf/invariant\";\nfunction destination(origin, distance, bearing, options = {}) {\n const coordinates1 = getCoord(origin);\n const longitude1 = degreesToRadians(coordinates1[0]);\n const latitude1 = degreesToRadians(coordinates1[1]);\n const bearingRad = degreesToRadians(bearing);\n const radians = lengthToRadians(distance, options.units);\n const latitude2 = Math.asin(\n Math.sin(latitude1) * Math.cos(radians) + Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearingRad)\n );\n const longitude2 = longitude1 + Math.atan2(\n Math.sin(bearingRad) * Math.sin(radians) * Math.cos(latitude1),\n Math.cos(radians) - Math.sin(latitude1) * Math.sin(latitude2)\n );\n const lng = radiansToDegrees(longitude2);\n const lat = radiansToDegrees(latitude2);\n return point([lng, lat], options.properties);\n}\nvar turf_destination_default = destination;\nexport {\n turf_destination_default as default,\n destination\n};\n//# sourceMappingURL=index.js.map","// index.ts\nimport { destination } from \"@turf/destination\";\nimport { polygon } from \"@turf/helpers\";\nfunction circle(center, radius, options = {}) {\n const steps = options.steps || 64;\n const properties = options.properties ? options.properties : !Array.isArray(center) && center.type === \"Feature\" && center.properties ? center.properties : {};\n const coordinates = [];\n for (let i = 0; i < steps; i++) {\n coordinates.push(\n destination(center, radius, i * -360 / steps, options).geometry.coordinates\n );\n }\n coordinates.push(coordinates[0]);\n return polygon([coordinates], properties);\n}\nvar turf_circle_default = circle;\nexport {\n circle,\n turf_circle_default as default\n};\n//# sourceMappingURL=index.js.map","import type { DrawPlugin } from '@/plugins/draw/plugin.ts';\nimport type { DrawFeatureProperties, DrawModel } from '@/plugins/draw/types.ts';\nimport area from '@turf/area';\nimport circle from '@turf/circle';\nimport type { Feature, FeatureCollection, MultiPoint, Polygon, Position } from 'geojson';\nimport type { GeoJSONSource, LngLatLike, Map, MapLayerMouseEvent, MapLayerTouchEvent } from 'maplibre-gl';\n\nexport abstract class AbstractDrawMode {\n\n\tisTouchEventSupported: boolean = window !== undefined && !!window.TouchEvent;\n\tplugin: DrawPlugin;\n\tmap: Map;\n\tsource: GeoJSONSource;\n\n\tcollection: FeatureCollection<Polygon | MultiPoint, DrawFeatureProperties> | undefined;\n\n\tprotected constructor(plugin: DrawPlugin, map: Map, source: GeoJSONSource) {\n\t\tthis.plugin = plugin;\n\t\tthis.map = map;\n\t\tthis.source = source;\n\t}\n\n\thasPolygon() {\n\t\treturn !!this.collection?.features[ 0 ];\n\t}\n\n\tgetPolygon(): Feature<Polygon, DrawFeatureProperties> {\n\t\treturn this.collection!.features[ 0 ] as Feature<Polygon, DrawFeatureProperties>;\n\t}\n\n\tclonePolygon(): Position[] {\n\t\treturn this.getPolygon().geometry.coordinates[ 0 ].map((p) => [ p[ 0 ], p[ 1 ] ]) as Position[];\n\t}\n\n\tisNearby(a: Position, b: { x: number, y: number }, isTouch: boolean): boolean {\n\t\tconst tolerance = isTouch ? this.plugin.options.pointerPrecision.touch : this.plugin.options.pointerPrecision.mouse,\n\t\t\t point = this.map.project(a as LngLatLike),\n\t\t\t distance = Math.sqrt((b.x - point.x) ** 2 + (b.y - point.y) ** 2);\n\t\treturn distance <= tolerance;\n\t}\n\n\tgetMidpoint(a: Position, b: Position): Position {\n\t\treturn [ (a[ 0 ] + b[ 0 ]) / 2, (a[ 1 ] + b[ 1 ]) / 2 ];\n\t}\n\n\tclear() {\n\t\tthis.source?.setData({ type: 'FeatureCollection', features: [] });\n\t}\n\n\trender() {\n\t\tif (!this.source) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.plugin.options.minArea.size && this.collection?.features[ 0 ]) {\n\t\t\tconst areaSize = this.getAreaSize(this.collection!.features[ 0 ] as Feature<Polygon, DrawFeatureProperties>);\n\t\t\tthis.collection!.features[ 0 ].properties.area = areaSize;\n\t\t\tthis.collection!.features[ 0 ].properties.tooSmall = areaSize < this.plugin.options.minArea.size && !this.collection!.features[ 0 ].properties.hasHelperVertex;\n\t\t\tthis.collection!.features[ 0 ].properties.minSizeLabel = this.plugin.options.minArea.label;\n\t\t}\n\t\tthis.source.setData(this.collection ?? { type: 'FeatureCollection', features: [] });\n\t}\n\n\temitOnUpdate(feature?: Feature<Polygon, DrawFeatureProperties>) {\n\t\tif (feature) {\n\t\t\tthis.plugin.options.onUpdate?.(feature);\n\t\t} else if (this.collection) {\n\t\t\tthis.plugin.options.onUpdate?.(this.collection!.features[ 0 ] as Feature<Polygon, DrawFeatureProperties>);\n\t\t}\n\t}\n\n\tcreateCircle(center: Position, radi