@bpd-library/components 1.2.8-beta.7 → 1.2.9-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/atoms/button/button.js +33 -0
- package/dist/esm/atoms/button/button.js.map +1 -0
- package/dist/esm/atoms/col/col.js +22 -0
- package/dist/esm/atoms/col/col.js.map +1 -0
- package/dist/esm/atoms/container/container.js +6 -0
- package/dist/esm/atoms/container/container.js.map +1 -0
- package/dist/esm/atoms/form-elements/range-slider/range-slider.js +21 -0
- package/dist/esm/atoms/form-elements/range-slider/range-slider.js.map +1 -0
- package/dist/esm/atoms/form-elements/utilities/range-slider.js +100 -0
- package/dist/esm/atoms/form-elements/utilities/range-slider.js.map +1 -0
- package/dist/esm/atoms/image/image.js +18 -0
- package/dist/esm/atoms/image/image.js.map +1 -0
- package/dist/esm/atoms/image/utilities/create-image-url.js +15 -0
- package/dist/esm/atoms/image/utilities/create-image-url.js.map +1 -0
- package/dist/esm/atoms/row/row.js +6 -0
- package/dist/esm/atoms/row/row.js.map +1 -0
- package/dist/esm/atoms/svg/svg.js +25 -0
- package/dist/esm/atoms/svg/svg.js.map +1 -0
- package/dist/esm/index.js +14 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/molecules/infobox/infobox.js +20 -0
- package/dist/esm/molecules/infobox/infobox.js.map +1 -0
- package/dist/esm/molecules/map/map.js +256 -0
- package/dist/esm/molecules/map/map.js.map +1 -0
- package/dist/esm/molecules/map/store/map/store.js +150 -0
- package/dist/esm/molecules/map/store/map/store.js.map +1 -0
- package/dist/esm/molecules/map/utilities/fit-bounds.js +4 -0
- package/dist/esm/molecules/map/utilities/fit-bounds.js.map +1 -0
- package/dist/esm/molecules/map/utilities/mapbox/add-data.js +54 -0
- package/dist/esm/molecules/map/utilities/mapbox/add-data.js.map +1 -0
- package/dist/esm/molecules/map/utilities/mapbox/center.js +15 -0
- package/dist/esm/molecules/map/utilities/mapbox/center.js.map +1 -0
- package/dist/esm/molecules/map/utilities/mapbox/constants.js +5 -0
- package/dist/esm/molecules/map/utilities/mapbox/constants.js.map +1 -0
- package/dist/esm/molecules/map/utilities/mapbox/index.js +3 -0
- package/dist/esm/molecules/map/utilities/mapbox/index.js.map +1 -0
- package/dist/esm/molecules/map/utilities/mapbox/mapbox.js +27 -0
- package/dist/esm/molecules/map/utilities/mapbox/mapbox.js.map +1 -0
- package/dist/esm/molecules/map/utilities/mapbox/parse-feature-properties.js +18 -0
- package/dist/esm/molecules/map/utilities/mapbox/parse-feature-properties.js.map +1 -0
- package/dist/esm/molecules/map/utilities/mapbox/pointers/setup-pointers.js +151 -0
- package/dist/esm/molecules/map/utilities/mapbox/pointers/setup-pointers.js.map +1 -0
- package/dist/esm/molecules/map/utilities/mapbox/polygons/feature-state.js +11 -0
- package/dist/esm/molecules/map/utilities/mapbox/polygons/feature-state.js.map +1 -0
- package/dist/esm/molecules/map/utilities/mapbox/polygons/geojson.js +10 -0
- package/dist/esm/molecules/map/utilities/mapbox/polygons/geojson.js.map +1 -0
- package/dist/esm/molecules/map/utilities/mapbox/polygons/interaction.js +34 -0
- package/dist/esm/molecules/map/utilities/mapbox/polygons/interaction.js.map +1 -0
- package/dist/esm/molecules/map/utilities/mapbox/polygons/layer.js +110 -0
- package/dist/esm/molecules/map/utilities/mapbox/polygons/layer.js.map +1 -0
- package/dist/esm/molecules/map/utilities/mapbox/raster.js +43 -0
- package/dist/esm/molecules/map/utilities/mapbox/raster.js.map +1 -0
- package/dist/esm/molecules/map/utilities/mapbox/search/alternative-city-suggestions.js +27 -0
- package/dist/esm/molecules/map/utilities/mapbox/search/alternative-city-suggestions.js.map +1 -0
- package/dist/esm/molecules/map/utilities/mapbox/search/search.js +174 -0
- package/dist/esm/molecules/map/utilities/mapbox/search/search.js.map +1 -0
- package/dist/esm/molecules/map/utilities/mapbox/tooltip.js +26 -0
- package/dist/esm/molecules/map/utilities/mapbox/tooltip.js.map +1 -0
- package/dist/esm/molecules/tooltip/tooltip.js +14 -0
- package/dist/esm/molecules/tooltip/tooltip.js.map +1 -0
- package/dist/esm/node_modules/tslib/tslib.es6.js +24 -0
- package/dist/esm/node_modules/tslib/tslib.es6.js.map +1 -0
- package/dist/lib/atoms/button/button.js +31 -0
- package/dist/lib/atoms/button/button.js.map +1 -0
- package/dist/lib/atoms/button/index.js +2 -0
- package/dist/lib/atoms/button/index.js.map +1 -0
- package/dist/lib/atoms/col/col.js +19 -0
- package/dist/lib/atoms/col/col.js.map +1 -0
- package/dist/lib/atoms/container/container.js +3 -0
- package/dist/lib/atoms/container/container.js.map +1 -0
- package/dist/lib/atoms/form-elements/range-slider/range-slider.js +18 -0
- package/dist/lib/atoms/form-elements/range-slider/range-slider.js.map +1 -0
- package/dist/lib/atoms/form-elements/utilities/range-slider.js +97 -0
- package/dist/lib/atoms/form-elements/utilities/range-slider.js.map +1 -0
- package/dist/lib/atoms/image/image.js +15 -0
- package/dist/lib/atoms/image/image.js.map +1 -0
- package/dist/lib/atoms/image/index.js +2 -0
- package/dist/lib/atoms/image/index.js.map +1 -0
- package/dist/lib/atoms/image/utilities/create-image-url.js +14 -0
- package/dist/lib/atoms/image/utilities/create-image-url.js.map +1 -0
- package/dist/lib/atoms/image/utilities/detect-responsive-images.js +24 -0
- package/dist/lib/atoms/image/utilities/detect-responsive-images.js.map +1 -0
- package/dist/lib/atoms/image/utilities/image.js +86 -0
- package/dist/lib/atoms/image/utilities/image.js.map +1 -0
- package/dist/lib/atoms/image/utilities/object-fit.js +35 -0
- package/dist/lib/atoms/image/utilities/object-fit.js.map +1 -0
- package/dist/lib/atoms/row/row.js +3 -0
- package/dist/lib/atoms/row/row.js.map +1 -0
- package/dist/lib/atoms/svg/svg.js +23 -0
- package/dist/lib/atoms/svg/svg.js.map +1 -0
- package/dist/lib/index.js +12 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/molecules/infobox/index.js +2 -0
- package/dist/lib/molecules/infobox/index.js.map +1 -0
- package/dist/lib/molecules/infobox/infobox.js +17 -0
- package/dist/lib/molecules/infobox/infobox.js.map +1 -0
- package/dist/lib/molecules/map/hooks/use-style-loaded.js +14 -0
- package/dist/lib/molecules/map/hooks/use-style-loaded.js.map +1 -0
- package/dist/lib/molecules/map/index.js +4 -0
- package/dist/lib/molecules/map/index.js.map +1 -0
- package/dist/lib/molecules/map/map.js +256 -0
- package/dist/lib/molecules/map/map.js.map +1 -0
- package/dist/lib/molecules/map/store/map/index.js +2 -0
- package/dist/lib/molecules/map/store/map/index.js.map +1 -0
- package/dist/lib/molecules/map/store/map/store.js +147 -0
- package/dist/lib/molecules/map/store/map/store.js.map +1 -0
- package/dist/lib/molecules/map/storybook/themes.js +54 -0
- package/dist/lib/molecules/map/storybook/themes.js.map +1 -0
- package/dist/lib/molecules/map/utilities/fit-bounds.js +2 -0
- package/dist/lib/molecules/map/utilities/fit-bounds.js.map +1 -0
- package/dist/lib/molecules/map/utilities/mapbox/add-data.js +52 -0
- package/dist/lib/molecules/map/utilities/mapbox/add-data.js.map +1 -0
- package/dist/lib/molecules/map/utilities/mapbox/center.js +13 -0
- package/dist/lib/molecules/map/utilities/mapbox/center.js.map +1 -0
- package/dist/lib/molecules/map/utilities/mapbox/constants.js +3 -0
- package/dist/lib/molecules/map/utilities/mapbox/constants.js.map +1 -0
- package/dist/lib/molecules/map/utilities/mapbox/index.js +3 -0
- package/dist/lib/molecules/map/utilities/mapbox/index.js.map +1 -0
- package/dist/lib/molecules/map/utilities/mapbox/mapbox.js +25 -0
- package/dist/lib/molecules/map/utilities/mapbox/mapbox.js.map +1 -0
- package/dist/lib/molecules/map/utilities/mapbox/parse-feature-properties.js +16 -0
- package/dist/lib/molecules/map/utilities/mapbox/parse-feature-properties.js.map +1 -0
- package/dist/lib/molecules/map/utilities/mapbox/pointers/setup-pointers.js +151 -0
- package/dist/lib/molecules/map/utilities/mapbox/pointers/setup-pointers.js.map +1 -0
- package/dist/lib/molecules/map/utilities/mapbox/polygons/feature-state.js +10 -0
- package/dist/lib/molecules/map/utilities/mapbox/polygons/feature-state.js.map +1 -0
- package/dist/lib/molecules/map/utilities/mapbox/polygons/geojson.js +9 -0
- package/dist/lib/molecules/map/utilities/mapbox/polygons/geojson.js.map +1 -0
- package/dist/lib/molecules/map/utilities/mapbox/polygons/interaction.js +32 -0
- package/dist/lib/molecules/map/utilities/mapbox/polygons/interaction.js.map +1 -0
- package/dist/lib/molecules/map/utilities/mapbox/polygons/layer.js +109 -0
- package/dist/lib/molecules/map/utilities/mapbox/polygons/layer.js.map +1 -0
- package/dist/lib/molecules/map/utilities/mapbox/raster.js +42 -0
- package/dist/lib/molecules/map/utilities/mapbox/raster.js.map +1 -0
- package/dist/lib/molecules/map/utilities/mapbox/search/alternative-city-suggestions.js +26 -0
- package/dist/lib/molecules/map/utilities/mapbox/search/alternative-city-suggestions.js.map +1 -0
- package/dist/lib/molecules/map/utilities/mapbox/search/search.js +172 -0
- package/dist/lib/molecules/map/utilities/mapbox/search/search.js.map +1 -0
- package/dist/lib/molecules/map/utilities/mapbox/tooltip.js +24 -0
- package/dist/lib/molecules/map/utilities/mapbox/tooltip.js.map +1 -0
- package/dist/lib/molecules/tooltip/index.js +2 -0
- package/dist/lib/molecules/tooltip/index.js.map +1 -0
- package/dist/lib/molecules/tooltip/tooltip.js +11 -0
- package/dist/lib/molecules/tooltip/tooltip.js.map +1 -0
- package/dist/molecules/map/map.js +11 -11
- package/dist/molecules/map/map.js.map +1 -1
- package/dist/molecules/map/store/map/store.d.ts +3 -4
- package/dist/molecules/map/store/map/store.js.map +1 -1
- package/dist/molecules/map/utilities/mapbox/directions/directions.js +3 -3
- package/dist/molecules/map/utilities/mapbox/directions/directions.js.map +1 -1
- package/dist/molecules/map/utilities/mapbox/isochrone.js +3 -3
- package/dist/molecules/map/utilities/mapbox/isochrone.js.map +1 -1
- package/dist/molecules/map/utilities/mapbox/pointers/setup-pointers.js +0 -7
- package/dist/molecules/map/utilities/mapbox/pointers/setup-pointers.js.map +1 -1
- package/dist/molecules/map/utilities/mapbox/raster.js +2 -1
- package/dist/molecules/map/utilities/mapbox/raster.js.map +1 -1
- package/dist/molecules/map/utilities/mapbox/search/search.js +2 -2
- package/dist/molecules/map/utilities/mapbox/search/search.js.map +1 -1
- package/dist/types/atoms/button/button.d.ts +17 -0
- package/dist/types/atoms/button/index.d.ts +1 -0
- package/dist/types/atoms/col/col.d.ts +11 -0
- package/dist/types/atoms/container/container.d.ts +6 -0
- package/dist/types/atoms/form-elements/range-slider/range-slider.d.ts +11 -0
- package/dist/types/atoms/form-elements/utilities/range-slider.d.ts +7 -0
- package/dist/types/atoms/image/image.d.ts +14 -0
- package/dist/types/atoms/image/index.d.ts +1 -0
- package/dist/types/atoms/image/utilities/create-image-url.d.ts +6 -0
- package/dist/types/atoms/image/utilities/detect-responsive-images.d.ts +7 -0
- package/dist/types/atoms/image/utilities/image.d.ts +18 -0
- package/dist/types/atoms/image/utilities/object-fit.d.ts +7 -0
- package/dist/types/atoms/row/row.d.ts +6 -0
- package/dist/types/atoms/svg/svg.d.ts +4 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/molecules/infobox/index.d.ts +1 -0
- package/dist/types/molecules/infobox/infobox.d.ts +7 -0
- package/dist/types/molecules/map/hooks/use-style-loaded.d.ts +2 -0
- package/dist/types/molecules/map/index.d.ts +3 -0
- package/dist/types/molecules/map/map.d.ts +2 -0
- package/dist/types/molecules/map/store/map/index.d.ts +1 -0
- package/dist/types/molecules/map/store/map/store.d.ts +60 -0
- package/dist/types/molecules/map/storybook/themes.d.ts +3 -0
- package/dist/types/molecules/map/utilities/fit-bounds.d.ts +3 -0
- package/dist/types/molecules/map/utilities/mapbox/add-data.d.ts +3 -0
- package/dist/types/molecules/map/utilities/mapbox/center.d.ts +3 -0
- package/dist/types/molecules/map/utilities/mapbox/constants.d.ts +2 -0
- package/dist/types/molecules/map/utilities/mapbox/index.d.ts +2 -0
- package/dist/types/molecules/map/utilities/mapbox/mapbox.d.ts +16 -0
- package/dist/types/molecules/map/utilities/mapbox/parse-feature-properties.d.ts +6 -0
- package/dist/types/molecules/map/utilities/mapbox/pointers/setup-pointers.d.ts +3 -0
- package/dist/types/molecules/map/utilities/mapbox/polygons/feature-state.d.ts +2 -0
- package/dist/types/molecules/map/utilities/mapbox/polygons/geojson.d.ts +3 -0
- package/dist/types/molecules/map/utilities/mapbox/polygons/interaction.d.ts +3 -0
- package/dist/types/molecules/map/utilities/mapbox/polygons/layer.d.ts +3 -0
- package/dist/types/molecules/map/utilities/mapbox/raster.d.ts +3 -0
- package/dist/types/molecules/map/utilities/mapbox/search/alternative-city-suggestions.d.ts +3 -0
- package/dist/types/molecules/map/utilities/mapbox/search/search.d.ts +4 -0
- package/dist/types/molecules/map/utilities/mapbox/tooltip.d.ts +4 -0
- package/dist/types/molecules/tooltip/index.d.ts +1 -0
- package/dist/types/molecules/tooltip/tooltip.d.ts +7 -0
- package/package.json +4 -4
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -79
- package/coverage/index.html +0 -95
- package/coverage/lcov.info +0 -0
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -170
- package/dist/molecules/map/store/map/hooks/index.d.ts +0 -1
- package/dist/molecules/map/store/map/hooks/index.js +0 -2
- package/dist/molecules/map/store/map/hooks/index.js.map +0 -1
- package/dist/molecules/map/store/map/hooks/use-map-instance.d.ts +0 -2
- package/dist/molecules/map/store/map/hooks/use-map-instance.js +0 -15
- package/dist/molecules/map/store/map/hooks/use-map-instance.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.js","sources":["../../../../src/molecules/map/map.tsx"],"sourcesContent":["import { defineElement, FC, onDidLoad, useElement, useProp } from '@atomify/hooks';\nimport { Fragment, h } from '@atomify/jsx';\nimport { MapInfobox, MapOptions, MapSearchOptions, MapTheme } from '@bpd-library/types';\nimport {\n calculateMapDataBoundingBox,\n calculateMapDataCenter,\n detectTouch,\n expandBoundingBox,\n functionIsTrue,\n getCountryBoundingBox,\n} from '@bpd-library/utilities';\nimport MapboxLanguage from '@mapbox/mapbox-gl-language';\nimport mapboxgl from 'mapbox-gl';\n\nimport { Button } from '../../atoms/button';\nimport { Infobox } from '../infobox';\nimport { clearHover, MapState, mapStore, setMapInstance } from './store/map';\nimport mapbox from './utilities/mapbox';\n\nconst DEFAULT_OPTIONS: MapOptions = {\n zoomButtons: true,\n mobileToggle: false,\n tooltipMode: 'hover',\n openInTab: false,\n autoOpenUrl: true,\n language: window.__ENVIRONMENT_DETAILS__.language || 'nl',\n searchCountryIsoCodes: ['nl', 'de'],\n};\n\nconst CONTAINER_VISIBLE = 'map--is-visible';\nconst MOBILE_TOGGLE_CLASS = 'map--mobile-toggle';\nconst MAP_HOVERING_CLASS = 'map--hovering';\nconst POINTER_FOCUS_CLASS = 'map__pointer--focus';\n\nexport const Map: FC = () => {\n let [options] = useProp<MapOptions>('options', {});\n const [theme] = useProp<MapTheme>('theme');\n const container = useElement<HTMLDivElement>('[js-hook-map-container]');\n const infoboxWrapper = useElement<HTMLDivElement>('[js-hook-infobox-wrapper]');\n const element = useElement<HTMLDivElement>('[js-hook-map]');\n\n let map: mapboxgl.Map;\n let mapboxHelpers: ReturnType<typeof mapbox>;\n let focusTimeout: ReturnType<typeof setTimeout> | undefined;\n\n onDidLoad(async () => {\n if (options.mobileToggle) element.current!.classList.add(MOBILE_TOGGLE_CLASS);\n options = { ...DEFAULT_OPTIONS, ...options };\n\n map = createMapboxInstance();\n mapboxHelpers = mapbox(map, options, theme);\n setMapInstance(map);\n\n await setupMapbox();\n\n subscribe();\n\n if (options.search)\n options.search.forEach((e: MapSearchOptions) => mapboxHelpers.search(e));\n });\n\n function subscribe() {\n const { filter, data } = mapStore.getState();\n const { addData } = mapboxHelpers;\n\n addData(filter ? filter : data);\n\n mapStore.subscribe(({ data }) => addData(data), ['data']);\n mapStore.subscribe(handleHover, ['hover']);\n mapStore.subscribe(handleClick, ['click']);\n mapStore.subscribe(handleFocus, ['focus']);\n mapStore.subscribe(({ filter, data }) => addData(filter ? filter : data), ['filter']);\n mapStore.subscribe(\n ({ layerRasterSettings }) =>\n layerRasterSettings && mapboxHelpers.raster(layerRasterSettings),\n ['layerRasterSettings'],\n );\n }\n\n function handleHover({ hover }: MapState) {\n const { current, previous } = hover;\n const canvasStyle = map.getCanvas().style;\n const { setFeatureState, addTooltip, removeTooltip } = mapboxHelpers;\n\n /*\n Add / Remove tooltip\n */\n if (options.tooltipMode === 'hover') {\n if (current?.tooltip && !detectTouch.touch) addTooltip(current.coordinates, current);\n if (!current && !detectTouch.touch) removeTooltip();\n }\n\n /*\n Set hover state\n */\n if (hasHoverTheme()) {\n if (current) setFeatureState(current.variant, current.id, 'hover', true);\n if (previous) setFeatureState(previous.variant, previous.id, 'hover', false);\n }\n\n canvasStyle.cursor = current ? 'pointer' : '';\n }\n\n function handleClick({ click }: MapState) {\n if (!click) return;\n\n const { addTooltip } = mapboxHelpers;\n const { infobox, coordinates, tooltip, url } = click;\n\n clearHover();\n\n if (options.tooltipMode === 'click' && tooltip) {\n addTooltip(coordinates, click);\n }\n\n if (options.tooltipMode === 'hover') {\n if (url && !detectTouch.touch && options.autoOpenUrl) {\n window.open(url, options.openInTab ? '_blank' : '_self');\n } else if ((url && tooltip) || (detectTouch.touch && !url && tooltip)) {\n addTooltip(coordinates, click);\n }\n }\n\n if (infobox) {\n showInfobox(infobox);\n } else {\n clearInfobox();\n }\n }\n\n function handleFocus({ focus }: MapState) {\n const { current, previous, options } = focus;\n const { setFeatureState, center, addTooltip, removeTooltip } = mapboxHelpers;\n\n if (focusTimeout) clearTimeout(focusTimeout);\n\n if (previous) {\n previous.forEach(({ id, variant }) => {\n if (hasHoverTheme()) setFeatureState(variant, id, 'focus', false);\n pointerFocusToggle(id, 'remove');\n });\n }\n\n if (current) {\n current.forEach((item) => {\n const { variant, id, coordinates, tooltip } = item;\n\n function handleTooltip() {\n const showTooltip = options?.toggleTooltip && tooltip;\n\n if (theme.polygon || pointerExists(id)) {\n if (showTooltip) addTooltip(coordinates, item);\n\n pointerFocusToggle(id, 'add');\n }\n }\n\n if (theme.polygon) {\n if (hasHoverTheme()) setFeatureState(variant, id, 'focus', true);\n }\n\n if (pointerExists(id)) {\n handleTooltip();\n } else {\n /*\n If a pointer doesn't exist, it means it's inside a cluster or outside of the view.\n When the map is idle, all newly centered pointers are drawn and the tooltip can be shown. (if not in a cluster)\n */\n map.once('idle', handleTooltip);\n }\n });\n\n if (options?.zoom) {\n let bounds = calculateMapDataBoundingBox(current);\n bounds = expandBoundingBox(bounds, 0.05);\n\n map.fitBounds(bounds);\n } else if (!options?.static) {\n center([[calculateMapDataCenter(current)]]);\n }\n } else {\n removeTooltip();\n }\n }\n\n function pointerFocusToggle(id: string, action: 'add' | 'remove') {\n const pointer = getPointerElementById(id);\n\n if (pointer) {\n pointer.classList[action](POINTER_FOCUS_CLASS);\n element.current!.classList[action](MAP_HOVERING_CLASS);\n }\n }\n\n function showInfobox(infobox: MapInfobox) {\n clearInfobox();\n infoboxWrapper.current!.appendChild(\n <Infobox {...infobox} onClose={clearInfobox} openInTab={options.openInTab} />,\n );\n }\n\n function clearInfobox() {\n infoboxWrapper.current!.innerHTML = '';\n }\n\n function toggleMap() {\n element.current!.classList.toggle(CONTAINER_VISIBLE);\n map.resize();\n }\n\n function hasHoverTheme() {\n return theme.polygon && theme.polygon.settings[0].hover;\n }\n\n function createMapboxInstance() {\n mapboxgl.accessToken = window.__ENVIRONMENT_DETAILS__.mapbox.accessToken;\n\n const mapboxOptions: mapboxgl.MapboxOptions = {\n container: container.current!,\n style: `mapbox://styles/${window.__ENVIRONMENT_DETAILS__.mapbox.style}`,\n minZoom: 4,\n maxZoom: 30,\n dragPan: true,\n scrollZoom: false,\n };\n\n if (options.center) mapboxOptions.center = options.center;\n if (options.zoom) mapboxOptions.zoom = options.zoom;\n if (options.boundingBox) mapboxOptions.bounds = options.boundingBox;\n\n if (!options.zoom && !options.center && !options.boundingBox) {\n mapboxOptions.bounds = getCountryBoundingBox(['nl']);\n }\n\n return new mapboxgl.Map(mapboxOptions);\n }\n\n function getMapboxLanguageString(): string {\n let language: string | undefined;\n\n // If language could be nl-NL etc., make sure to strip first two characters\n if (options.language) {\n language = options.language.substr(0, 2);\n }\n\n // nl is not supported, use multilanguage instead\n language = !language || language === 'nl' ? 'mul' : language;\n\n return language;\n }\n\n async function setupMapbox() {\n const { raster, geojson, layer, interaction, setupPointers } = mapboxHelpers;\n\n await functionIsTrue(() => map.isStyleLoaded());\n\n // Setup Mapbox Language\n const languageControl = new MapboxLanguage({\n defaultLanguage: getMapboxLanguageString(),\n });\n map.addControl(languageControl);\n\n // Setup Layer Raster\n // Layer raster can be set via the store and options attribute\n const optionsLayerRaster = options.layerRaster\n ? { layerRaster: options.layerRaster }\n : undefined;\n const storeLayerRaster = mapStore.getState().layerRasterSettings;\n\n if (optionsLayerRaster) {\n raster(optionsLayerRaster);\n } else if (storeLayerRaster) {\n raster(storeLayerRaster);\n }\n\n // Setup in case of polygons\n if (theme.polygon) {\n theme.polygon.settings.forEach((setting) => {\n geojson(setting);\n layer(setting);\n interaction(setting);\n });\n }\n\n // Setup in case of pointers\n if (theme.pointer) {\n setupPointers(element.current!);\n }\n\n map.resize();\n }\n\n function getPointerElementById(id: string) {\n return element.current!.querySelector(`#pointer-${id}`);\n }\n\n function pointerExists(id: string) {\n return !!getPointerElementById(id);\n }\n\n return (\n <Fragment>\n <div class=\"c-map\" js-hook-map>\n <div className=\"map__container\" js-hook-map-container>\n {options.zoomButtons && (\n <div class=\"map__navigation\">\n <button class=\"map__button\" onClick={() => map.zoomIn()}>\n <bpd-svg name=\"icons-plus\"></bpd-svg>\n </button>\n <button class=\"map__button\" onClick={() => map.zoomOut()}>\n <span class=\"map__minus\"></span>\n </button>\n </div>\n )}\n\n {options.mobileToggle && (\n <button type=\"button\" class=\"map__close\" onClick={toggleMap}>\n <bpd-svg name=\"icons-close\" />\n </button>\n )}\n\n <div class=\"map__infobox-wrapper\" js-hook-infobox-wrapper></div>\n </div>\n </div>\n\n {options.mobileToggle && (\n <Fragment>\n <Button\n variant=\"bg\"\n label={options.mobileToggleLabel || 'Toon kaart'}\n classes=\"map__open\"\n onClick={toggleMap}></Button>\n </Fragment>\n )}\n </Fragment>\n );\n};\n\nMap.props = {\n options: {\n type: Object,\n },\n theme: {\n type: Object,\n required: true,\n },\n zoomButtons: {\n type: Boolean,\n },\n};\n\ndefineElement('bpd-map', Map);\n"],"names":[],"mappings":";;;;;;;;;;AAmBA,MAAM,eAAe,GAAe;IAChC,WAAW,EAAE,IAAI;IACjB,YAAY,EAAE,KAAK;IACnB,WAAW,EAAE,OAAO;IACpB,SAAS,EAAE,KAAK;IAChB,WAAW,EAAE,IAAI;IACjB,QAAQ,EAAE,MAAM,CAAC,uBAAuB,CAAC,QAAQ,IAAI,IAAI;IACzD,qBAAqB,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;CACtC,CAAC;AAEF,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAC5C,MAAM,mBAAmB,GAAG,oBAAoB,CAAC;AACjD,MAAM,kBAAkB,GAAG,eAAe,CAAC;AAC3C,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;MAErC,GAAG,GAAO;IACnB,IAAI,CAAC,OAAO,CAAC,GAAG,OAAO,CAAa,SAAS,EAAE,EAAE,CAAC,CAAC;IACnD,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAW,OAAO,CAAC,CAAC;IAC3C,MAAM,SAAS,GAAG,UAAU,CAAiB,yBAAyB,CAAC,CAAC;IACxE,MAAM,cAAc,GAAG,UAAU,CAAiB,2BAA2B,CAAC,CAAC;IAC/E,MAAM,OAAO,GAAG,UAAU,CAAiB,eAAe,CAAC,CAAC;IAE5D,IAAI,GAAiB,CAAC;IACtB,IAAI,aAAwC,CAAC;IAG7C,SAAS,CAAC;QACN,IAAI,OAAO,CAAC,YAAY;YAAE,OAAO,CAAC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B,EAAC,QAAQ;YACL,EAAC,MAAM,IACH,OAAO,EAAC,IAAI,EACZ,KAAK,EAAE,OAAO,CAAC,iBAAiB,IAAI,YAAY,EAChD,OAAO,EAAC,WAAW,EACnB,OAAO,EAAE,SAAS,GAAW,CAC1B,CACd,CACM,EACb;AACN,EAAE;AAEF,GAAG,CAAC,KAAK,GAAG;IACR,OAAO,EAAE;QACL,IAAI,EAAE,MAAM;KACf;IACD,KAAK,EAAE;QACH,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACjB;IACD,WAAW,EAAE;QACT,IAAI,EAAE,OAAO;KAChB;CACJ,CAAC;AAEF,aAAa,CAAC,SAAS,EAAE,GAAG,CAAC;;;;"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { createStore } from '@atomify/kit';
|
|
2
|
+
|
|
3
|
+
const initialState = {
|
|
4
|
+
data: [],
|
|
5
|
+
hover: {},
|
|
6
|
+
focus: {},
|
|
7
|
+
searchIsMoving: false,
|
|
8
|
+
};
|
|
9
|
+
const UPDATE_MAP_DATA = 'updateMapData';
|
|
10
|
+
const UPDATE_HOVER = 'updateHover';
|
|
11
|
+
const CLEAR_HOVER = 'clearHover';
|
|
12
|
+
const UPDATE_CLICK = 'updateClick';
|
|
13
|
+
const SET_FOCUS = 'setFocus';
|
|
14
|
+
const CLEAR_FOCUS = 'clearFocus';
|
|
15
|
+
const UPDATE_SEARCH_RESULT = 'updateSearchResult';
|
|
16
|
+
const CLEAR_SEARCH_RESULT = 'clearSearchResult';
|
|
17
|
+
const UPDATE_SEARCH_IS_MOVING = 'updateSearchIsMoving';
|
|
18
|
+
const SET_FILTER = 'setFilter';
|
|
19
|
+
const CLEAR_FILTER = 'clearFilter';
|
|
20
|
+
const SET_MAP_INSTANCE = 'setMapInstance';
|
|
21
|
+
const SET_LAYER_RASTER = 'SET_LAYER_RASTER';
|
|
22
|
+
const MANUAL_SEARCH = 'manualSearch';
|
|
23
|
+
const actions = {
|
|
24
|
+
[UPDATE_MAP_DATA]: (state, data) => {
|
|
25
|
+
state.data = data;
|
|
26
|
+
return state;
|
|
27
|
+
},
|
|
28
|
+
[UPDATE_HOVER]: (state, hover) => {
|
|
29
|
+
state.hover = {
|
|
30
|
+
current: hover,
|
|
31
|
+
previous: state.hover.current,
|
|
32
|
+
};
|
|
33
|
+
return state;
|
|
34
|
+
},
|
|
35
|
+
[CLEAR_HOVER]: (state) => {
|
|
36
|
+
state.hover = {
|
|
37
|
+
current: undefined,
|
|
38
|
+
previous: state.hover.current,
|
|
39
|
+
};
|
|
40
|
+
return state;
|
|
41
|
+
},
|
|
42
|
+
[UPDATE_CLICK]: (state, click) => {
|
|
43
|
+
state.click = Object.assign({}, click);
|
|
44
|
+
return state;
|
|
45
|
+
},
|
|
46
|
+
[SET_FOCUS]: (state, { ids, options }) => {
|
|
47
|
+
var _a;
|
|
48
|
+
const dataItems = state.data.filter(({ id }) => ids.indexOf(id) > -1);
|
|
49
|
+
if (dataItems.length) {
|
|
50
|
+
state.focus = {
|
|
51
|
+
current: dataItems,
|
|
52
|
+
previous: (_a = state.focus) === null || _a === void 0 ? void 0 : _a.current,
|
|
53
|
+
options,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return state;
|
|
57
|
+
},
|
|
58
|
+
[CLEAR_FOCUS]: (state) => {
|
|
59
|
+
state.focus = {
|
|
60
|
+
current: undefined,
|
|
61
|
+
previous: state.focus.current,
|
|
62
|
+
};
|
|
63
|
+
return state;
|
|
64
|
+
},
|
|
65
|
+
[UPDATE_SEARCH_RESULT]: (state, searchResult) => {
|
|
66
|
+
state.searchResult = searchResult;
|
|
67
|
+
return state;
|
|
68
|
+
},
|
|
69
|
+
[CLEAR_SEARCH_RESULT]: (state) => {
|
|
70
|
+
state.searchResult = undefined;
|
|
71
|
+
return state;
|
|
72
|
+
},
|
|
73
|
+
[SET_FILTER]: (state, data) => {
|
|
74
|
+
state.filter = data;
|
|
75
|
+
return state;
|
|
76
|
+
},
|
|
77
|
+
[CLEAR_FILTER]: (state) => {
|
|
78
|
+
state.filter = undefined;
|
|
79
|
+
return state;
|
|
80
|
+
},
|
|
81
|
+
[SET_MAP_INSTANCE]: (state, mapInstance) => {
|
|
82
|
+
state.mapInstance = mapInstance;
|
|
83
|
+
return state;
|
|
84
|
+
},
|
|
85
|
+
[MANUAL_SEARCH]: (state, query) => {
|
|
86
|
+
state.manualSearch = query;
|
|
87
|
+
return state;
|
|
88
|
+
},
|
|
89
|
+
[UPDATE_SEARCH_IS_MOVING]: (state, searchIsMoving) => {
|
|
90
|
+
state.searchIsMoving = searchIsMoving;
|
|
91
|
+
return state;
|
|
92
|
+
},
|
|
93
|
+
[SET_LAYER_RASTER]: (state, layerRasterSettings) => {
|
|
94
|
+
state.layerRasterSettings = layerRasterSettings;
|
|
95
|
+
return state;
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
const mapStore = createStore({
|
|
99
|
+
initialState,
|
|
100
|
+
actions: actions,
|
|
101
|
+
});
|
|
102
|
+
const updateMapData = (data) => {
|
|
103
|
+
mapStore.dispatch(UPDATE_MAP_DATA, data);
|
|
104
|
+
};
|
|
105
|
+
const clearHover = () => {
|
|
106
|
+
mapStore.dispatch(CLEAR_HOVER);
|
|
107
|
+
};
|
|
108
|
+
const updateHover = (hover) => {
|
|
109
|
+
mapStore.dispatch(UPDATE_HOVER, hover);
|
|
110
|
+
};
|
|
111
|
+
const updateClick = (click) => {
|
|
112
|
+
mapStore.dispatch(UPDATE_CLICK, click);
|
|
113
|
+
};
|
|
114
|
+
const setFocus = (ids, options = {}) => {
|
|
115
|
+
mapStore.dispatch(SET_FOCUS, { ids, options });
|
|
116
|
+
};
|
|
117
|
+
const clearFocus = () => {
|
|
118
|
+
mapStore.dispatch(CLEAR_FOCUS);
|
|
119
|
+
};
|
|
120
|
+
const updateSearchResult = (searchResult) => {
|
|
121
|
+
mapStore.dispatch(UPDATE_SEARCH_RESULT, searchResult);
|
|
122
|
+
};
|
|
123
|
+
const clearSearchResult = () => {
|
|
124
|
+
mapStore.dispatch(CLEAR_SEARCH_RESULT);
|
|
125
|
+
};
|
|
126
|
+
const setFilter = (data) => {
|
|
127
|
+
mapStore.dispatch(SET_FILTER, data);
|
|
128
|
+
};
|
|
129
|
+
const clearFilter = () => {
|
|
130
|
+
mapStore.dispatch(CLEAR_FILTER);
|
|
131
|
+
};
|
|
132
|
+
const setMapInstance = (mapInstance) => {
|
|
133
|
+
mapStore.dispatch(SET_MAP_INSTANCE, mapInstance);
|
|
134
|
+
};
|
|
135
|
+
const manualSearch = (query) => {
|
|
136
|
+
mapStore.dispatch(MANUAL_SEARCH, query);
|
|
137
|
+
};
|
|
138
|
+
const updateSearchIsMoving = (isMoving) => {
|
|
139
|
+
mapStore.dispatch(UPDATE_SEARCH_IS_MOVING, isMoving);
|
|
140
|
+
};
|
|
141
|
+
const setLayerRaster = (layerRasterSettings) => {
|
|
142
|
+
mapStore.dispatch(SET_LAYER_RASTER, layerRasterSettings);
|
|
143
|
+
};
|
|
144
|
+
const getMapboxData = () => mapStore.getState().data;
|
|
145
|
+
const getHover = () => mapStore.getState().hover;
|
|
146
|
+
const getMapInstance = () => mapStore.getState().mapInstance;
|
|
147
|
+
const getSearchIsMoving = () => mapStore.getState().searchIsMoving;
|
|
148
|
+
|
|
149
|
+
export { clearFilter, clearFocus, clearHover, clearSearchResult, getHover, getMapInstance, getMapboxData, getSearchIsMoving, manualSearch, mapStore, setFilter, setFocus, setLayerRaster, setMapInstance, updateClick, updateHover, updateMapData, updateSearchIsMoving, updateSearchResult };
|
|
150
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sources":["../../../../../../src/molecules/map/store/map/store.ts"],"sourcesContent":["import { createStore } from '@atomify/kit';\nimport { BoundingBox, MapDataItem } from '@bpd-library/types';\n\nexport type SearchResult = {\n items: MapDataItem[];\n result: any;\n originalBoundingBox?: BoundingBox;\n expandedBoundingBox?: BoundingBox;\n};\n\ninterface MapFocusOptions {\n zoom?: boolean;\n toggleTooltip?: boolean;\n static?: boolean;\n}\n\nexport interface MapLayerRasterSettings {\n layerRaster: string;\n minzoom?: number;\n maxzoom?: number;\n}\n\nexport interface MapState {\n data: MapDataItem[];\n mapInstance?: mapboxgl.Map;\n hover: {\n current?: MapDataItem;\n previous?: MapDataItem;\n };\n filter?: MapDataItem[];\n click?: MapDataItem;\n focus: {\n current?: MapDataItem[];\n previous?: MapDataItem[];\n options?: MapFocusOptions;\n };\n searchResult?: SearchResult;\n searchIsMoving: boolean;\n manualSearch?: string;\n layerRasterSettings?: MapLayerRasterSettings;\n}\n\nconst initialState: MapState = {\n data: [],\n hover: {},\n focus: {},\n searchIsMoving: false,\n};\n\nconst UPDATE_MAP_DATA = 'updateMapData';\nconst UPDATE_HOVER = 'updateHover';\nconst CLEAR_HOVER = 'clearHover';\nconst UPDATE_CLICK = 'updateClick';\nconst SET_FOCUS = 'setFocus';\nconst CLEAR_FOCUS = 'clearFocus';\nconst UPDATE_SEARCH_RESULT = 'updateSearchResult';\nconst CLEAR_SEARCH_RESULT = 'clearSearchResult';\nconst UPDATE_SEARCH_IS_MOVING = 'updateSearchIsMoving';\nconst SET_FILTER = 'setFilter';\nconst CLEAR_FILTER = 'clearFilter';\nconst SET_MAP_INSTANCE = 'setMapInstance';\nconst SET_LAYER_RASTER = 'SET_LAYER_RASTER';\nconst MANUAL_SEARCH = 'manualSearch';\n\nconst actions = {\n [UPDATE_MAP_DATA]: (state: MapState, data: MapDataItem[]) => {\n state.data = data;\n return state;\n },\n [UPDATE_HOVER]: (state: MapState, hover: MapDataItem) => {\n state.hover = {\n current: hover,\n previous: state.hover.current,\n };\n\n return state;\n },\n [CLEAR_HOVER]: (state: MapState) => {\n state.hover = {\n current: undefined,\n previous: state.hover.current,\n };\n\n return state;\n },\n [UPDATE_CLICK]: (state: MapState, click: MapDataItem) => {\n state.click = { ...click };\n return state;\n },\n [SET_FOCUS]: (\n state: MapState,\n { ids, options }: { ids: string[]; options: MapFocusOptions },\n ) => {\n const dataItems = state.data.filter(({ id }) => ids.indexOf(id) > -1);\n\n if (dataItems.length) {\n state.focus = {\n current: dataItems,\n previous: state.focus?.current,\n options,\n };\n }\n\n return state;\n },\n [CLEAR_FOCUS]: (state: MapState) => {\n state.focus = {\n current: undefined,\n previous: state.focus.current,\n };\n\n return state;\n },\n [UPDATE_SEARCH_RESULT]: (state: MapState, searchResult: SearchResult) => {\n state.searchResult = searchResult;\n return state;\n },\n [CLEAR_SEARCH_RESULT]: (state: MapState) => {\n state.searchResult = undefined;\n return state;\n },\n [SET_FILTER]: (state: MapState, data: MapDataItem[]) => {\n state.filter = data;\n return state;\n },\n [CLEAR_FILTER]: (state: MapState) => {\n state.filter = undefined;\n return state;\n },\n [SET_MAP_INSTANCE]: (state: MapState, mapInstance: mapboxgl.Map) => {\n state.mapInstance = mapInstance;\n return state;\n },\n [MANUAL_SEARCH]: (state: MapState, query: string) => {\n state.manualSearch = query;\n return state;\n },\n [UPDATE_SEARCH_IS_MOVING]: (state: MapState, searchIsMoving: boolean) => {\n state.searchIsMoving = searchIsMoving;\n return state;\n },\n [SET_LAYER_RASTER]: (state: MapState, layerRasterSettings: MapLayerRasterSettings) => {\n state.layerRasterSettings = layerRasterSettings;\n return state;\n },\n};\n\nexport const mapStore = createStore<MapState>({\n initialState,\n actions: actions as any,\n});\n\n/*\n Setters\n*/\nexport const updateMapData = (data: MapDataItem[]) => {\n mapStore.dispatch(UPDATE_MAP_DATA, data);\n};\n\nexport const clearHover = () => {\n mapStore.dispatch(CLEAR_HOVER);\n};\n\nexport const updateHover = (hover: MapDataItem) => {\n mapStore.dispatch(UPDATE_HOVER, hover);\n};\n\nexport const updateClick = (click: MapDataItem) => {\n mapStore.dispatch(UPDATE_CLICK, click);\n};\n\nexport const setFocus = (ids: string[], options: MapFocusOptions = {}) => {\n mapStore.dispatch(SET_FOCUS, { ids, options });\n};\n\nexport const clearFocus = () => {\n mapStore.dispatch(CLEAR_FOCUS);\n};\n\nexport const updateSearchResult = (searchResult: SearchResult) => {\n mapStore.dispatch(UPDATE_SEARCH_RESULT, searchResult);\n};\n\nexport const clearSearchResult = () => {\n mapStore.dispatch(CLEAR_SEARCH_RESULT);\n};\n\nexport const setFilter = (data: MapDataItem[]) => {\n mapStore.dispatch(SET_FILTER, data);\n};\n\nexport const clearFilter = () => {\n mapStore.dispatch(CLEAR_FILTER);\n};\n\nexport const setMapInstance = (mapInstance: mapboxgl.Map) => {\n mapStore.dispatch(SET_MAP_INSTANCE, mapInstance);\n};\n\nexport const manualSearch = (query: string) => {\n mapStore.dispatch(MANUAL_SEARCH, query);\n};\n\nexport const updateSearchIsMoving = (isMoving: boolean) => {\n mapStore.dispatch(UPDATE_SEARCH_IS_MOVING, isMoving);\n};\n\nexport const setLayerRaster = (layerRasterSettings: MapLayerRasterSettings) => {\n mapStore.dispatch(SET_LAYER_RASTER, layerRasterSettings);\n};\n\n/*\n Getters\n*/\nexport const getMapboxData = () => mapStore.getState().data;\nexport const getHover = () => mapStore.getState().hover;\nexport const getMapInstance = () => mapStore.getState().mapInstance;\nexport const getSearchIsMoving = () => mapStore.getState().searchIsMoving;\n"],"names":[],"mappings":";;AA0CA,MAAM,YAAY,GAAa;IAC3B,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,EAAE;IACT,KAAK,EAAE,EAAE;IACT,cAAc,EAAE,KAAK;CACxB,CAAC;AAEF,MAAM,eAAe,GAAG,eAAe,CAAC;AACxC,MAAM,YAAY,GAAG,aAAa,CAAC;AACnC,MAAM,WAAW,GAAG,YAAY,CAAC;AACjC,MAAM,YAAY,GAAG,aAAa,CAAC;AACnC,MAAM,SAAS,GAAG,UAAU,CAAC;AAC7B,MAAM,WAAW,GAAG,YAAY,CAAC;AACjC,MAAM,oBAAoB,GAAG,oBAAoB,CAAC;AAClD,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AAChD,MAAM,uBAAuB,GAAG,sBAAsB,CAAC;AACvD,MAAM,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AE,KAAK,CAAC,CAAC;AAC5C,EAAE;MAEW,oBAAoB,GAAG,CAAC,QAAiB;IAClD,QAAQ,CAAC,QAAQ,CAAC,uBAAuB,EAAE,QAAQ,CAAC,CAAC;AACzD,EAAE;MAEW,cAAc,GAAG,CAAC,mBAA2C;IACtE,QAAQ,CAAC,QAAQ,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,CAAC;AAC7D,EAAE;MAKW,aAAa,GAAG,MAAM,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK;MAC/C,QAAQ,GAAG,MAAM,QAAQ,CAAC,QAAQ,EAAE,CAAC,MAAM;MAC3C,cAAc,GAAG,MAAM,QAAQ,CAAC,QAAQ,EAAE,CAAC,YAAY;MACvD,iBAAiB,GAAG,MAAM,QAAQ,CAAC,QAAQ,EAAE,CAAC;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fit-bounds.js","sources":["../../../../../src/molecules/map/utilities/fit-bounds.ts"],"sourcesContent":["import { BoundingBox } from '@bpd-library/types';\n\nexport const fitBounds = (map: mapboxgl.Map, boundingBox: BoundingBox) =>\n map.fitBounds(boundingBox);\n"],"names":[],"mappings":"MAEa,SAAS,GAAG,CAAC,GAAiB,EAAE,WAAwB,KACjE,GAAG,CAAC,SAAS,CAAC,WAAW;;;;"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { calculateCenter, functionIsTrue } from '@bpd-library/utilities';
|
|
2
|
+
|
|
3
|
+
const variants = [];
|
|
4
|
+
const isPointerVariant = (variant, theme) => {
|
|
5
|
+
var _a;
|
|
6
|
+
return !!((_a = theme.pointer) === null || _a === void 0 ? void 0 : _a.settings.find((pointerTheme) => pointerTheme.variant === variant));
|
|
7
|
+
};
|
|
8
|
+
const addData = async (map, data, theme) => {
|
|
9
|
+
const features = {};
|
|
10
|
+
variants.forEach((variant) => (features[variant] = []));
|
|
11
|
+
data.forEach((item) => {
|
|
12
|
+
const { variant } = item;
|
|
13
|
+
if (variants.indexOf(variant) < 0) {
|
|
14
|
+
variants.push(variant);
|
|
15
|
+
features[variant] = [];
|
|
16
|
+
}
|
|
17
|
+
if (isPointerVariant(variant, theme)) {
|
|
18
|
+
features[variant].push({
|
|
19
|
+
type: 'Feature',
|
|
20
|
+
geometry: {
|
|
21
|
+
coordinates: calculateCenter(item.coordinates),
|
|
22
|
+
type: 'Point',
|
|
23
|
+
},
|
|
24
|
+
properties: Object.assign({}, item),
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
item.coordinates.forEach((coordinate) => {
|
|
29
|
+
features[variant].push({
|
|
30
|
+
type: 'Feature',
|
|
31
|
+
geometry: {
|
|
32
|
+
coordinates: [coordinate],
|
|
33
|
+
type: 'Polygon',
|
|
34
|
+
},
|
|
35
|
+
properties: Object.assign({}, item),
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
await functionIsTrue(() => map.isStyleLoaded() && map.isSourceLoaded);
|
|
41
|
+
Object.keys(features).forEach((variant) => {
|
|
42
|
+
const variantFeatures = features[variant];
|
|
43
|
+
const source = map.getSource(variant);
|
|
44
|
+
if (source) {
|
|
45
|
+
source.setData({
|
|
46
|
+
type: 'FeatureCollection',
|
|
47
|
+
features: variantFeatures,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { addData as default };
|
|
54
|
+
//# sourceMappingURL=add-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-data.js","sources":["../../../../../../src/molecules/map/utilities/mapbox/add-data.ts"],"sourcesContent":["import { MapData, MapTheme } from '@bpd-library/types';\nimport { calculateCenter, functionIsTrue } from '@bpd-library/utilities';\n\nconst variants: string[] = [];\n\nconst isPointerVariant = (variant: string, theme: MapTheme) => {\n return !!theme.pointer?.settings.find((pointerTheme) => pointerTheme.variant === variant);\n};\n\nconst addData = async (map: mapboxgl.Map, data: MapData, theme: MapTheme) => {\n const features: { [variant: string]: GeoJSON.Feature[] } = {};\n\n /*\n Create empty arrays for previously set variants,\n this will make sure old variants will be removed.\n */\n variants.forEach((variant) => (features[variant] = []));\n\n /*\n Construct GeoJSON Features\n */\n data.forEach((item) => {\n const { variant } = item;\n\n if (variants.indexOf(variant) < 0) {\n variants.push(variant);\n features[variant] = [];\n }\n\n if (isPointerVariant(variant, theme)) {\n features[variant].push({\n type: 'Feature',\n geometry: {\n coordinates: calculateCenter(item.coordinates),\n type: 'Point',\n },\n properties: {\n ...item,\n },\n });\n } else {\n item.coordinates.forEach((coordinate) => {\n features[variant].push({\n type: 'Feature',\n geometry: {\n coordinates: [coordinate],\n type: 'Polygon',\n },\n properties: {\n ...item,\n },\n });\n });\n }\n });\n\n /*\n Update layer with features\n */\n await functionIsTrue(() => map.isStyleLoaded() && map.isSourceLoaded);\n\n Object.keys(features).forEach((variant) => {\n const variantFeatures = features[variant];\n\n const source = map.getSource(variant) as mapboxgl.GeoJSONSource | undefined;\n\n if (source) {\n source.setData({\n type: 'FeatureCollection',\n features: variantFeatures,\n });\n }\n });\n};\n\nexport default addData;\n"],"names":[],"mappings":";;AAGA,MAAM,QAAQ,GAAa,EAAE,CAAC;AAE9B,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAE,KAAe;;IACtD,OAAO,CAAC,QAAC,KAAK,CAAC,OAAO,0CAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,YAAY,KAAK,YAAY,CAAC,OAAO,KAAK,OAAO,EAAC,CAAC;AAC9F,CAAC,CAAC;MAEI,OAAO,GAAG,OAAO,GAAiB,EAAE,IAAa,EAAE,KAAe;IACpE,MAAM,QAAQ,GAA6C,EAAE,CAAC;IAM9D,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,MAAM,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IAKxD,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI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CAAC;SACN;KACJ,CAAC,CAAC;AACP;;;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { calculateCenter } from '@bpd-library/utilities';
|
|
2
|
+
import { MAP_FLY_EASING_FUNCTION, MAP_FLY_DURATION } from './constants.js';
|
|
3
|
+
|
|
4
|
+
const center = (map, coordinates) => {
|
|
5
|
+
const center = calculateCenter(coordinates);
|
|
6
|
+
map.flyTo({
|
|
7
|
+
center,
|
|
8
|
+
curve: 0,
|
|
9
|
+
easing: MAP_FLY_EASING_FUNCTION,
|
|
10
|
+
duration: MAP_FLY_DURATION,
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { center as default };
|
|
15
|
+
//# sourceMappingURL=center.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"center.js","sources":["../../../../../../src/molecules/map/utilities/mapbox/center.ts"],"sourcesContent":["import { Coordinates } from '@bpd-library/types';\nimport { calculateCenter } from '@bpd-library/utilities';\n\nimport { MAP_FLY_DURATION, MAP_FLY_EASING_FUNCTION } from './constants';\n\nconst center = (map: mapboxgl.Map, coordinates: Coordinates) => {\n const center = calculateCenter(coordinates);\n\n map.flyTo({\n center,\n curve: 0,\n easing: MAP_FLY_EASING_FUNCTION,\n duration: MAP_FLY_DURATION,\n });\n};\n\nexport default center;\n"],"names":[],"mappings":";;;MAKM,MAAM,GAAG,CAAC,GAAiB,EAAE,WAAwB;IACvD,MAAM,MAAM,GAAG,eAAe,CAAC,WAAW,CAAC,CAAC;IAE5C,GAAG,CAAC,KAAK,CAAC;QACN,MAAM;QACN,KAAK,EAAE,CAAC;QACR,MAAM,EAAE,uBAAuB;QAC/B,QAAQ,EAAE,gBAAgB;KAC7B,CAAC,CAAC;AACP;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../../../../../src/molecules/map/utilities/mapbox/constants.ts"],"sourcesContent":["export const MAP_FLY_DURATION = 1000;\nexport const MAP_FLY_EASING_FUNCTION = (t: number) =>\n t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;\n"],"names":[],"mappings":"MAAa,gBAAgB,GAAG,KAAK;MACxB,uBAAuB,GAAG,CAAC,CAAS,KAC7C,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import addData from './add-data.js';
|
|
2
|
+
import center from './center.js';
|
|
3
|
+
import setupPointers from './pointers/setup-pointers.js';
|
|
4
|
+
import setFeatureState from './polygons/feature-state.js';
|
|
5
|
+
import geojson from './polygons/geojson.js';
|
|
6
|
+
import interaction from './polygons/interaction.js';
|
|
7
|
+
import layer from './polygons/layer.js';
|
|
8
|
+
import raster from './raster.js';
|
|
9
|
+
import search from './search/search.js';
|
|
10
|
+
import { addTooltip, removeTooltip } from './tooltip.js';
|
|
11
|
+
|
|
12
|
+
const mapbox = (map, options, theme) => ({
|
|
13
|
+
raster: (settings) => raster(map, settings),
|
|
14
|
+
geojson: (setting) => geojson(map, setting),
|
|
15
|
+
layer: (setting) => layer(map, setting),
|
|
16
|
+
interaction: (setting) => interaction(map, setting),
|
|
17
|
+
center: (coordinates) => center(map, coordinates),
|
|
18
|
+
setupPointers: (element) => setupPointers(map, theme, element),
|
|
19
|
+
addData: (data) => addData(map, data, theme),
|
|
20
|
+
addTooltip: (coordinates, mapDataItem) => addTooltip(map, coordinates, mapDataItem, options.openInTab),
|
|
21
|
+
removeTooltip,
|
|
22
|
+
setFeatureState: (variant, id, type, hover) => setFeatureState(map, variant, id, type, hover),
|
|
23
|
+
search: (searchOptions) => search(map, searchOptions, options),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export { mapbox as default };
|
|
27
|
+
//# sourceMappingURL=mapbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapbox.js","sources":["../../../../../../src/molecules/map/utilities/mapbox/mapbox.ts"],"sourcesContent":["import {\n Coordinates,\n MapData,\n MapDataItem,\n MapOptions,\n MapSearchOptions,\n MapTheme,\n PolygonThemeSetting,\n} from '@bpd-library/types';\n\nimport { MapLayerRasterSettings } from '../../store/map';\nimport addData from './add-data';\nimport center from './center';\nimport setupPointers from './pointers/setup-pointers';\nimport setFeatureState from './polygons/feature-state';\nimport geojson from './polygons/geojson';\nimport interaction from './polygons/interaction';\nimport layer from './polygons/layer';\nimport raster from './raster';\nimport search from './search/search';\nimport { addTooltip, removeTooltip } from './tooltip';\n\nconst mapbox = (map: mapboxgl.Map, options: MapOptions, theme: MapTheme) => ({\n raster: (settings: MapLayerRasterSettings) => raster(map, settings),\n geojson: (setting: PolygonThemeSetting) => geojson(map, setting),\n layer: (setting: PolygonThemeSetting) => layer(map, setting),\n interaction: (setting: PolygonThemeSetting) => interaction(map, setting),\n center: (coordinates: Coordinates) => center(map, coordinates),\n setupPointers: (element: HTMLElement) => setupPointers(map, theme, element),\n addData: (data: MapData) => addData(map, data, theme),\n addTooltip: (coordinates: Coordinates, mapDataItem: MapDataItem) =>\n addTooltip(map, coordinates, mapDataItem, options.openInTab),\n removeTooltip,\n setFeatureState: (variant: string, id: string, type: 'hover' | 'focus', hover: boolean) =>\n setFeatureState(map, variant, id, type, hover),\n search: (searchOptions: MapSearchOptions) => search(map, searchOptions, options),\n});\n\nexport default mapbox;\n"],"names":[],"mappings":";;;;;;;;;;;MAsBM,MAAM,GAAG,CAAC,GAAiB,EAAE,OAAmB,EAAE,KAAe,MAAM;IACzE,MAAM,EAAE,CAAC,QAAgC,KAAK,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC;IACnE,OAAO,EAAE,CAAC,OAA4B,KAAK,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC;IAChE,KAAK,EAAE,CAAC,OAA4B,KAAK,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC;IAC5D,WAAW,EAAE,CAAC,OAA4B,KAAK,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC;IACxE,MAAM,EAAE,CAAC,WAAwB,KAAK,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC;IAC9D,aAAa,EAAE,CAAC,OAAoB,KAAK,aAAa,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC;IAC3E,OAAO,EAAE,CAAC,IAAa,KAAK,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC;IACrD,UAAU,EAAE,CAAC,WAAwB,EAAE,WAAwB,KAC3D,UAAU,CAAC,GAAG,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,SAAS,CAAC;IAChE,aAAa;IACb,eAAe,EAAE,CAAC,OAAe,EAAE,EAAU,EAAE,IAAuB,EAAE,KAAc,KAClF,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC;IAClD,MAAM,EAAE,CAAC,aAA+B,KAAK,MAAM,CAAC,GAAG,EAAE,aAAa,EAAE,OAAO,CAAC;CACnF;;;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const parseFeatureProperties = (obj) => {
|
|
2
|
+
const safeJSONParse = (str) => {
|
|
3
|
+
try {
|
|
4
|
+
return JSON.parse(str);
|
|
5
|
+
}
|
|
6
|
+
catch (e) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
Object.keys(obj).forEach(key => {
|
|
11
|
+
const parsedJSON = safeJSONParse(obj[key]);
|
|
12
|
+
obj[key] = parsedJSON || obj[key];
|
|
13
|
+
});
|
|
14
|
+
return obj;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { parseFeatureProperties };
|
|
18
|
+
//# sourceMappingURL=parse-feature-properties.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-feature-properties.js","sources":["../../../../../../src/molecules/map/utilities/mapbox/parse-feature-properties.ts"],"sourcesContent":["export type FeatureProperties = { [key: string]: string };\n\nexport const parseFeatureProperties = (obj: FeatureProperties): { [key: string]: any } => {\n const safeJSONParse = (str: string) => {\n try {\n return JSON.parse(str);\n } catch (e) {\n return false;\n }\n };\n\n Object.keys(obj).forEach(key => {\n const parsedJSON = safeJSONParse(obj[key]);\n\n obj[key] = parsedJSON || obj[key];\n });\n\n return obj;\n};\n"],"names":[],"mappings":"MAEa,sBAAsB,GAAG,CAAC,GAAsB;IACzD,MAAM,aAAa,GAAG,CAAC,GAAW;QAC9B,IAAI;YACA,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;SAC1B;QAAC,OAAO,CAAC,EAAE;YACR,OAAO,KAAK,CAAC;SAChB;KACJ,CAAC;IAEF,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG;QACxB,MAAM,UAAU,GAAG,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QAE3C,GAAG,CAAC,GAAG,CAAC,GAAG,UAAU,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;KACrC,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACf;;;;"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { h } from '@atomify/jsx';
|
|
2
|
+
import { throttle, calculateCenter } from '@bpd-library/utilities';
|
|
3
|
+
import { Marker } from 'mapbox-gl';
|
|
4
|
+
import { updateHover, clearHover, updateClick } from '../../../store/map/store.js';
|
|
5
|
+
import { MAP_FLY_DURATION, MAP_FLY_EASING_FUNCTION } from '../constants.js';
|
|
6
|
+
import { parseFeatureProperties } from '../parse-feature-properties.js';
|
|
7
|
+
|
|
8
|
+
const MAP_HOVER_CLASS = 'map--hovering';
|
|
9
|
+
const POINTER_FADEOUT_DURATION = 300;
|
|
10
|
+
const setupPointers = (map, theme, element) => {
|
|
11
|
+
const { pointer: pointerTheme } = theme;
|
|
12
|
+
const clusters = { cache: {}, onScreen: {} };
|
|
13
|
+
const pointers = { cache: {}, onScreen: {} };
|
|
14
|
+
init();
|
|
15
|
+
function init() {
|
|
16
|
+
var _a;
|
|
17
|
+
(_a = theme.pointer) === null || _a === void 0 ? void 0 : _a.settings.forEach(({ variant, minzoom, maxzoom }) => {
|
|
18
|
+
map.addSource(variant, {
|
|
19
|
+
type: 'geojson',
|
|
20
|
+
data: { type: 'FeatureCollection', features: [] },
|
|
21
|
+
cluster: true,
|
|
22
|
+
clusterRadius: 50,
|
|
23
|
+
clusterMaxZoom: 8,
|
|
24
|
+
promoteId: 'id',
|
|
25
|
+
});
|
|
26
|
+
const layerSettings = {
|
|
27
|
+
id: variant,
|
|
28
|
+
type: 'circle',
|
|
29
|
+
source: variant,
|
|
30
|
+
filter: ['!=', 'cluster', true],
|
|
31
|
+
paint: {
|
|
32
|
+
'circle-opacity': 0,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
if (minzoom)
|
|
36
|
+
layerSettings.minzoom = minzoom;
|
|
37
|
+
if (maxzoom)
|
|
38
|
+
layerSettings.maxzoom = maxzoom;
|
|
39
|
+
map.addLayer(layerSettings);
|
|
40
|
+
});
|
|
41
|
+
bindEvents();
|
|
42
|
+
}
|
|
43
|
+
function bindEvents() {
|
|
44
|
+
map.on('render', throttle(updateMarkers, 200));
|
|
45
|
+
}
|
|
46
|
+
function addCluster(clus, variant) {
|
|
47
|
+
const { properties, geometry } = clus;
|
|
48
|
+
const { coordinates } = geometry;
|
|
49
|
+
const { cluster_id: id, point_count: count } = properties;
|
|
50
|
+
let cluster;
|
|
51
|
+
if (id && count) {
|
|
52
|
+
cluster = clusters.cache[id];
|
|
53
|
+
if (!cluster) {
|
|
54
|
+
cluster = new Marker({
|
|
55
|
+
element: (h("button", { class: "map__cluster", onMouseenter: () => {
|
|
56
|
+
element.classList.add(MAP_HOVER_CLASS);
|
|
57
|
+
}, onMouseleave: () => {
|
|
58
|
+
element.classList.remove(MAP_HOVER_CLASS);
|
|
59
|
+
}, onClick: () => {
|
|
60
|
+
element.classList.remove(MAP_HOVER_CLASS);
|
|
61
|
+
map.getSource(variant).getClusterExpansionZoom(id, (err, zoom) => {
|
|
62
|
+
if (err)
|
|
63
|
+
return;
|
|
64
|
+
map.easeTo({
|
|
65
|
+
center: coordinates,
|
|
66
|
+
zoom,
|
|
67
|
+
duration: MAP_FLY_DURATION,
|
|
68
|
+
easing: MAP_FLY_EASING_FUNCTION,
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
} }, pointerTheme.cluster(count))),
|
|
72
|
+
}).setLngLat(coordinates);
|
|
73
|
+
clusters.cache[id] = cluster;
|
|
74
|
+
}
|
|
75
|
+
if (!clusters.onScreen[id])
|
|
76
|
+
cluster.addTo(map);
|
|
77
|
+
}
|
|
78
|
+
return [cluster, id];
|
|
79
|
+
}
|
|
80
|
+
function addPointer({ properties, }) {
|
|
81
|
+
const mapDataItem = parseFeatureProperties(properties);
|
|
82
|
+
const { id, variant, coordinates } = mapDataItem;
|
|
83
|
+
const setting = pointerTheme.settings.find((setting) => setting.variant === variant);
|
|
84
|
+
if (!setting)
|
|
85
|
+
return [undefined, undefined];
|
|
86
|
+
let pointer = pointers.cache[id];
|
|
87
|
+
const center = calculateCenter(coordinates);
|
|
88
|
+
if (!pointer) {
|
|
89
|
+
pointer = new Marker({
|
|
90
|
+
anchor: 'center',
|
|
91
|
+
element: (h("button", { id: `pointer-${id}`, onMouseenter: () => {
|
|
92
|
+
element.classList.add(MAP_HOVER_CLASS);
|
|
93
|
+
updateHover(mapDataItem);
|
|
94
|
+
}, onMouseleave: () => {
|
|
95
|
+
element.classList.remove(MAP_HOVER_CLASS);
|
|
96
|
+
clearHover();
|
|
97
|
+
}, onClick: (e) => {
|
|
98
|
+
e.stopPropagation();
|
|
99
|
+
updateClick(mapDataItem);
|
|
100
|
+
}, class: `map__pointer${setting.disablePointerEvents ? ' map__pointer--disabled' : ''}` }, setting.createElement(mapDataItem))),
|
|
101
|
+
}).setLngLat(center);
|
|
102
|
+
pointers.cache[id] = pointer;
|
|
103
|
+
}
|
|
104
|
+
if (!pointers.onScreen[id])
|
|
105
|
+
pointer.addTo(map);
|
|
106
|
+
return [pointer, id];
|
|
107
|
+
}
|
|
108
|
+
function updateMarkers() {
|
|
109
|
+
var _a;
|
|
110
|
+
const newClusters = {};
|
|
111
|
+
const newPointers = {};
|
|
112
|
+
(_a = theme.pointer) === null || _a === void 0 ? void 0 : _a.settings.forEach(({ variant }) => {
|
|
113
|
+
const features = map.querySourceFeatures(variant);
|
|
114
|
+
features.forEach((feature) => {
|
|
115
|
+
const { properties } = feature;
|
|
116
|
+
if (properties === null || properties === void 0 ? void 0 : properties.cluster) {
|
|
117
|
+
const [cluster, id] = addCluster(feature, variant);
|
|
118
|
+
if (cluster && id)
|
|
119
|
+
newClusters[id] = cluster;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
const [pointer, id] = addPointer(feature);
|
|
123
|
+
if (pointer && id)
|
|
124
|
+
newPointers[id] = pointer;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
Object.keys(clusters.onScreen).forEach((id) => {
|
|
129
|
+
if (!newClusters[id])
|
|
130
|
+
clusters.onScreen[id].remove();
|
|
131
|
+
});
|
|
132
|
+
Object.keys(pointers.onScreen).forEach((id) => {
|
|
133
|
+
if (!newPointers[id]) {
|
|
134
|
+
fadeoutPointer(pointers.onScreen[id]);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
clusters.onScreen = newClusters;
|
|
138
|
+
pointers.onScreen = newPointers;
|
|
139
|
+
}
|
|
140
|
+
function fadeoutPointer(pointer) {
|
|
141
|
+
const pointerElement = pointer.getElement();
|
|
142
|
+
pointerElement.classList.add('map__pointer--fadeout');
|
|
143
|
+
setTimeout(() => {
|
|
144
|
+
pointer.remove();
|
|
145
|
+
pointerElement.classList.remove('map__pointer--fadeout');
|
|
146
|
+
}, POINTER_FADEOUT_DURATION);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export { setupPointers as default };
|
|
151
|
+
//# sourceMappingURL=setup-pointers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup-pointers.js","sources":["../../../../../../../src/molecules/map/utilities/mapbox/pointers/setup-pointers.tsx"],"sourcesContent":["import { h } from '@atomify/jsx';\nimport { MapDataItem, MapTheme } from '@bpd-library/types';\nimport { calculateCenter, throttle } from '@bpd-library/utilities';\nimport { GeoJSONSource, LngLatLike, Marker } from 'mapbox-gl';\n\nimport { clearHover, updateClick, updateHover } from '../../../store/map';\nimport { MAP_FLY_DURATION, MAP_FLY_EASING_FUNCTION } from '../constants';\nimport { FeatureProperties, parseFeatureProperties } from '../parse-feature-properties';\n\ntype MapMarkers = { [key: string]: mapboxgl.Marker };\n\ntype MarkerObject = {\n cache: MapMarkers;\n onScreen: MapMarkers;\n};\n\nconst MAP_HOVER_CLASS = 'map--hovering';\nconst POINTER_FADEOUT_DURATION = 300;\n\nconst setupPointers = (map: mapboxgl.Map, theme: MapTheme, element: HTMLElement) => {\n const { pointer: pointerTheme } = theme;\n const clusters: MarkerObject = { cache: {}, onScreen: {} };\n const pointers: MarkerObject = { cache: {}, onScreen: {} };\n const sourceNames: string[] = [];\n\n init();\n\n function init() {\n theme.pointer?.settings.forEach(({ variant, minzoom, maxzoom }) => {\n sourceNames.push(variant);\n\n map.addSource(variant, {\n type: 'geojson',\n data: { type: 'FeatureCollection', features: [] },\n cluster: true,\n clusterRadius: 50,\n clusterMaxZoom: 8,\n promoteId: 'id',\n });\n\n const layerSettings: mapboxgl.AnyLayer | mapboxgl.CustomLayerInterface = {\n id: variant,\n type: 'circle',\n source: variant,\n filter: ['!=', 'cluster', true],\n paint: {\n 'circle-opacity': 0,\n },\n };\n\n if (minzoom) layerSettings.minzoom = minzoom;\n if (maxzoom) layerSettings.maxzoom = maxzoom;\n\n map.addLayer(layerSettings);\n });\n\n bindEvents();\n }\n\n function bindEvents() {\n map.on('render', throttle(updateMarkers, 200));\n }\n\n function addCluster(\n clus: GeoJSON.Feature,\n variant: string,\n ): [mapboxgl.Marker | undefined, number | undefined] {\n const { properties, geometry } = clus;\n const { coordinates } = geometry as GeoJSON.Point;\n const { cluster_id: id, point_count: count } = properties as {\n cluster_id?: number;\n point_count?: number;\n };\n\n let cluster: mapboxgl.Marker | undefined;\n\n if (id && count) {\n cluster = clusters.cache[id];\n\n if (!cluster) {\n cluster = new Marker({\n element: (\n <button\n class=\"map__cluster\"\n onMouseenter={() => {\n element.classList.add(MAP_HOVER_CLASS);\n }}\n onMouseleave={() => {\n element.classList.remove(MAP_HOVER_CLASS);\n }}\n onClick={() => {\n element.classList.remove(MAP_HOVER_CLASS);\n\n (map.getSource(variant) as GeoJSONSource).getClusterExpansionZoom(\n id,\n (err, zoom) => {\n if (err) return;\n\n map.easeTo({\n center: coordinates as LngLatLike,\n zoom,\n duration: MAP_FLY_DURATION,\n easing: MAP_FLY_EASING_FUNCTION,\n });\n },\n );\n }}>\n {pointerTheme!.cluster(count)}\n </button>\n ),\n }).setLngLat(coordinates as LngLatLike);\n\n clusters.cache[id] = cluster;\n }\n\n if (!clusters.onScreen[id]) cluster.addTo(map);\n }\n\n return [cluster, id];\n }\n\n function addPointer({\n properties,\n }: GeoJSON.Feature): [mapboxgl.Marker | undefined, string | undefined] {\n const mapDataItem = parseFeatureProperties(properties as FeatureProperties) as MapDataItem;\n const { id, variant, coordinates } = mapDataItem;\n const setting = pointerTheme!.settings.find((setting) => setting.variant === variant);\n\n if (!setting) return [undefined, undefined];\n\n let pointer: mapboxgl.Marker | undefined = pointers.cache[id];\n const center = calculateCenter(coordinates);\n\n if (!pointer) {\n pointer = new Marker({\n anchor: 'center',\n element: (\n <button\n id={`pointer-${id}`}\n onMouseenter={() => {\n element.classList.add(MAP_HOVER_CLASS);\n updateHover(mapDataItem);\n }}\n onMouseleave={() => {\n element.classList.remove(MAP_HOVER_CLASS);\n clearHover();\n }}\n onClick={(e: Event) => {\n e.stopPropagation();\n updateClick(mapDataItem);\n }}\n class={`map__pointer${\n setting.disablePointerEvents ? ' map__pointer--disabled' : ''\n }`}>\n {setting.createElement(mapDataItem)}\n </button>\n ),\n }).setLngLat(center);\n\n pointers.cache[id] = pointer;\n }\n\n if (!pointers.onScreen[id]) pointer.addTo(map);\n\n return [pointer, id];\n }\n\n function updateMarkers() {\n const newClusters: MapMarkers = {};\n const newPointers: MapMarkers = {};\n\n theme.pointer?.settings.forEach(({ variant }) => {\n const features = map.querySourceFeatures(variant);\n\n features.forEach((feature) => {\n const { properties } = feature;\n\n if (properties?.cluster) {\n const [cluster, id] = addCluster(feature, variant);\n\n if (cluster && id) newClusters[id] = cluster;\n } else {\n const [pointer, id] = addPointer(feature);\n\n if (pointer && id) newPointers[id] = pointer;\n }\n });\n });\n\n Object.keys(clusters.onScreen).forEach((id) => {\n if (!newClusters[id]) clusters.onScreen[id].remove();\n });\n\n Object.keys(pointers.onScreen).forEach((id) => {\n if (!newPointers[id]) {\n fadeoutPointer(pointers.onScreen[id]);\n }\n });\n\n clusters.onScreen = newClusters;\n pointers.onScreen = newPointers;\n }\n\n function fadeoutPointer(pointer: mapboxgl.Marker) {\n const pointerElement = pointer.getElement();\n\n pointerElement.classList.add('map__pointer--fadeout');\n\n setTimeout(() => {\n pointer.remove();\n\n pointerElement.classList.remove('map__pointer--fadeout');\n }, POINTER_FADEOUT_DURATION);\n }\n};\n\nexport default setupPointers;\n"],"names":[],"mappings":";;;;;;;AAgBA,MAAM,eAAe,GAAG,eAAe,CAAC;AACxC,MAAM,wBAAwB,GAAG,GAAG,CAAC;MAE/B,aAAa,GAAG,CAAC,GAAiB,EAAE,KAAe,E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AAC,CAAC,MAAM,EAAE,CAAC;SACxD,CAAC,CAAC;QAEH,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE;YACtC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,EAAE;gBAClB,cAAc,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;aACzC;SACJ,CAAC,CAAC;QAEH,QAAQ,CAAC,QAAQ,GAAG,WAAW,CAAC;QAChC,QAAQ,CAAC,QAAQ,GAAG,WAAW,CAAC;KACnC;IAED,SAAS,cAAc,CAAC,OAAwB;QAC5C,MAAM,cAAc,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;QAE5C,cAAc,CAAC,SAAS,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;QAEtD,UAAU,CAAC;YACP,OAAO,CAAC,MAAM,EAAE,CAAC;YAEjB,cAAc,CAAC,SAAS,CAAC,MAAM,CAAC,uBAAuB,CAAC,CAAC;SAC5D,EAAE,wBAAwB,CAAC,CAAC;KAChC;AACL;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature-state.js","sources":["../../../../../../../src/molecules/map/utilities/mapbox/polygons/feature-state.ts"],"sourcesContent":["const setFeatureState = (\n map: mapboxgl.Map,\n variant: string,\n id: string,\n type: 'hover' | 'focus',\n value: boolean,\n) => {\n map.setFeatureState(\n {\n source: variant,\n id,\n },\n {\n [type]: value,\n },\n );\n};\n\nexport default setFeatureState;\n"],"names":[],"mappings":"MAAM,eAAe,GAAG,CACpB,GAAiB,EACjB,OAAe,EACf,EAAU,EACV,IAAuB,EACvB,KAAc;IAEd,GAAG,CAAC,eAAe,CACf;QACI,MAAM,EAAE,OAAO;QACf,EAAE;KACL,EACD;QACI,CAAC,IAAI,GAAG,KAAK;KAChB,CACJ,CAAC;AACN;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geojson.js","sources":["../../../../../../../src/molecules/map/utilities/mapbox/polygons/geojson.ts"],"sourcesContent":["import { PolygonThemeSetting } from '@bpd-library/types';\n\nconst geojson = (map: mapboxgl.Map, setting: PolygonThemeSetting) => {\n map.addSource(setting.variant, {\n type: 'geojson',\n data: { type: 'FeatureCollection', features: [] },\n promoteId: 'id',\n });\n};\n\nexport default geojson;\n"],"names":[],"mappings":"MAEM,OAAO,GAAG,CAAC,GAAiB,EAAE,OAA4B;IAC5D,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE;QAC3B,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,EAAE,IAAI,EAAE,mBAAmB,EAAE,QAAQ,EAAE,EAAE,EAAE;QACjD,SAAS,EAAE,IAAI;KAClB,CAAC,CAAC;AACP;;;;"}
|