{"version":3,"file":"nextalys-maps-module.mjs","sources":["../../lib/types.ts","../../lib/nextalys-maps-module.ts"],"sourcesContent":["\nimport { NxsLocation } from 'nextalys-js-helpers/dist/geo-helpers';\nexport interface NxsMapMarker<T = any> extends NxsLocation {\n    icon?: string;\n    iconSize?: number;\n    draggable?: boolean;\n    infoWindowContent?: string;\n    description?: string;\n    infoWindowOpen?: boolean;\n    showInfowindowCloseButton?: boolean;\n    infoWindowAlwaysOpen?: boolean;\n    focusAfterOpen?: boolean;\n    infoWindowOver?: boolean;\n    meta?: T;\n    offset?: NxsLocation;\n    markerWidth?: number;\n    markerHeight?: number;\n    anchor?: 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';\n    closeOnClick?: boolean;\n}\nexport interface NxsPolyline<T = any> {\n    points: NxsLocation[];\n    opacity?: number;\n    width?: number;\n    color?: string;\n    meta?: T;\n}\nexport interface NxsPolygon<T = any> extends NxsPolyline<T> {\n    fill?: string;\n    fillHover?: string;\n    opacityHover?: number;\n    fillSelected?: string;\n    opacitySelected?: number;\n}\nexport interface NxsMapsModuleOptions {\n    defaultLat?: number;\n    defaultLng?: number;\n    defaultZoom?: number;\n    defaultMarkerIcon?: string;\n    debugMode?: boolean;\n}\nexport type NxsPlacemark = NxsPolygon | NxsPolyline | NxsMapMarker;\nexport type NxsAnySource = (NxsMapMarker | NxsPolygon | NxsPolyline);\nexport type NxsMapFeatureType = 'LineString' | 'Point' | 'Polygon';\n\nexport interface NxsMapboxFeature {\n    geometry: NxsGeometry;\n    properties: any;\n}\nexport interface MapboxClusterOptions {\n    circleColor: string;\n    textColor: string;\n    textSize?: number;\n    clusterMaxZoom?: number;\n    clusterRadius?: number;\n}\nexport interface NxsGeometry {\n    type: NxsMapFeatureType;\n    coordinates: (number[]) | (number[][]) | (number[][][]);\n}\nexport class NxsMapboxLayerWrapper<X = any, Y = any> {\n    delay?: number;\n    before?: string;\n    layerId: string;\n    sourceName?: string;\n    minZoom?: number;\n    maxZoom?: number;\n\n    private pSource: NxsAnySource[];\n    get source() {\n        return this.pSource;\n    }\n    set source(val: NxsAnySource[]) {\n        this.pSource = val;\n        this.sourceFeatures = NxsMapboxLayerWrapper.convertSourceToSourceFeatures(this.pSource, this.featureType);\n    }\n    sourceFeatures?: NxsMapboxFeature[];\n    clusterOptions?: MapboxClusterOptions;\n    featureType: NxsMapFeatureType;\n    layerType?: 'symbol' | 'line' | 'fill';\n    layout?: X;//FillLayout | LineLayout | SymbolLayout\n    isDefaultLayerFromMarkers?: boolean;\n    isDefaultLayerFromPolylines?: boolean;\n    isDefaultLayerFromPolygons?: boolean;\n    paint?: Y;//FillPaint | LinePaint | SymbolPaint;\n    static createFeaturesProperties(input: NxsMapMarker | NxsPolygon | NxsPolyline, featureType: NxsMapFeatureType, index: number) {\n        if (featureType === 'Point')\n            return {\n                icon: (input as NxsMapMarker).icon, 'icon-size': (input as NxsMapMarker).iconSize,\n                description: (input as NxsMapMarker).description || (input as NxsMapMarker).infoWindowContent, index: index,\n                'icon-offset': (!!(input as NxsMapMarker)?.offset) ? [(input as NxsMapMarker)?.offset.lng, (input as NxsMapMarker)?.offset.lat] : [0, 0],\n                'icon-anchor': (input as NxsMapMarker).anchor,\n            };\n        if (featureType === 'LineString')\n            return { opacity: (input as NxsPolyline).opacity, width: (input as NxsPolyline).width, color: (input as NxsPolyline).color, index: index };\n        if (featureType === 'Polygon') {\n            const properties = { fill: (input as NxsPolygon).fill, opacity: (input as NxsPolygon).opacity, width: (input as NxsPolygon).width, color: (input as NxsPolygon).color, index: index };\n            if ((input as NxsPolygon).fillHover)\n                properties['fill-hover'] = (input as NxsPolygon).fillHover;\n            if ((input as NxsPolygon).opacityHover != null)\n                properties['opacity-hover'] = (input as NxsPolygon).opacityHover;\n\n            if ((input as NxsPolygon).opacitySelected != null)\n                properties['opacity-selected'] = (input as NxsPolygon).opacitySelected;\n            if ((input as NxsPolygon).fillSelected != null)\n                properties['fill-selected'] = (input as NxsPolygon).fillSelected;\n            return properties;\n        }\n        return {};\n    }\n    static convertSourceToSourceFeatures(source: NxsAnySource[], featureType: NxsMapFeatureType): NxsMapboxFeature[] {\n        return source.map<NxsMapboxFeature>((x, index) => ({\n            geometry: this.convertToGeometry(x, featureType),\n            properties: this.createFeaturesProperties(x, featureType, index),\n        }));\n    }\n    static convertToGeometry(input: NxsPlacemark, type: NxsMapFeatureType): NxsGeometry {\n        if (type === 'Point')\n            return { coordinates: [(input as NxsMapMarker).lng, (input as NxsMapMarker).lat], type: 'Point' };\n        else if (type === 'LineString')\n            return { coordinates: (input as NxsPolyline).points.map(x => ([x.lng, x.lat])), type: 'LineString' };\n        else if (type === 'Polygon')\n            return { coordinates: [(input as NxsPolyline).points.map(x => ([x.lng, x.lat]))], type: 'Polygon' };\n    }\n    static fromGeometry<T extends NxsPlacemark>(geometry: (number[]) | (number[][]), properties: any, type: NxsMapFeatureType): T {\n\n        switch (type) {\n            case \"LineString\":\n                //TODO\n                return {\n                    points: [],\n                } as NxsPolyline as any;\n            case \"Point\":\n                //TODO\n                return {\n                    lat: 0,\n                    lng: 0,\n                } as NxsMapMarker as any;\n            case \"Polygon\":\n                return {\n                    points: (geometry[0] as any[]).map<NxsLocation>(x => ({ lat: x[1], lng: x[0] })),\n                    color: properties.color,\n                    fill: properties.fill,\n                    opacity: properties.opacity,\n                    fillHover: properties['fill-hover'],\n                    opacityHover: properties['opacity-hover'],\n                } as NxsPolygon as any;\n            default:\n                return null;\n        }\n    }\n    updateSource(source?: NxsAnySource[]) {\n        if (source != null) {\n            this.source = source;\n        }\n        this.sourceFeatures = NxsMapboxLayerWrapper.convertSourceToSourceFeatures(this.source, this.featureType);\n    }\n}\n\nexport interface MapboxMapOptions {\n    bindPolygonsHover?: 'legacy' | 'new';\n    polygonsSelectable?: boolean;\n    addPolygonsBordersLineLayer?: boolean;\n    polygonsBelowCustomLayers?: boolean;\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings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