import { createCommentVNode, defineComponent, inject, type PropType, provide, type SlotsType, } from "vue"; import { componentIdSymbol, sourceIdSymbol, sourceLayerRegistry, SourceOptionProps, } from "@/lib/types"; import type { RasterDEMTileSource } from "maplibre-gl"; import { SourceLayerRegistry } from "@/lib/lib/sourceLayer.registry"; import { SourceLib } from "@/lib/lib/source.lib"; import { useSource } from "@/lib/composable/useSource"; /** * See [RasterDEMTileSource](https://maplibre.org/maplibre-gl-js/docs/API/classes/RasterDEMTileSource/) */ export default defineComponent({ name: "MglRasterDemSource", props: { sourceId: { type: String as PropType, required: true, }, url: String as PropType, tiles: Array as PropType, bounds: Array as PropType, minzoom: Number as PropType, maxzoom: Number as PropType, tileSize: Number as PropType, attribution: String as PropType, encoding: String as PropType<"terrarium" | "mapbox" | "custom">, volatile: Boolean as PropType, redFactor: Number as PropType, blueFactor: Number as PropType, greenFactor: Number as PropType, baseShift: Number as PropType, }, slots: Object as SlotsType<{ default: unknown }>, setup(props, { slots }) { const cid = inject(componentIdSymbol)!, source = SourceLib.getSourceRef(cid, props.sourceId), registry = new SourceLayerRegistry(), opts = { ...props, type: "raster-dem" }; provide(sourceIdSymbol, props.sourceId); provide(sourceLayerRegistry, registry); useSource(source, opts as SourceOptionProps, registry); return () => [ createCommentVNode("RasterDem Source"), source.value && slots.default ? slots.default({}) : undefined, ]; }, });