|
1 | 1 | import debounce from 'lodash.debounce' |
| 2 | +import { Feature as GeoJsonFeature } from 'geojson' |
2 | 3 | import { Style, Fill, Stroke } from 'ol/style' |
3 | 4 | import { GeoJSON } from 'ol/format' |
4 | 5 | import { Feature } from 'ol' |
5 | | -import { Feature as GeoJsonFeature, GeoJsonProperties } from 'geojson' |
6 | 6 | import { PolarActionTree } from '@polar/lib-custom-types' |
7 | | -import getCluster from '@polar/lib-get-cluster' |
8 | | -import { DragBox, Draw, Modify } from 'ol/interaction' |
9 | | -import { platformModifierKeyOnly } from 'ol/events/condition' |
10 | 7 | import { getFeatureDisplayLayer, clear } from '../../utils/displayFeatureLayer' |
11 | | -import { GfiGetters, GfiState } from '../../types' |
12 | | -import { getOriginalFeature } from '../../utils/getOriginalFeature' |
13 | | -import { setupTooltip } from './setupTooltip' |
| 8 | +import { FeaturesByLayerId, GfiGetters, GfiState } from '../../types' |
| 9 | +import { filterFeatures } from '../../utils/filterFeatures' |
| 10 | +import { renderFeatures } from '../../utils/renderFeatures' |
14 | 11 | import { debouncedGfiRequest } from './debouncedGfiRequest' |
| 12 | +import { |
| 13 | + setupCoreListener, |
| 14 | + setupMultiSelection, |
| 15 | + setupTooltip, |
| 16 | + setupZoomListeners, |
| 17 | +} from './setup' |
15 | 18 |
|
16 | 19 | // OK for module action set creation |
17 | 20 | // eslint-disable-next-line max-lines-per-function |
@@ -66,97 +69,10 @@ export const makeActions = () => { |
66 | 69 | dispatch('setupZoomListeners') |
67 | 70 | dispatch('setupMultiSelection') |
68 | 71 | }, |
| 72 | + setupCoreListener, |
| 73 | + setupMultiSelection, |
69 | 74 | setupTooltip, |
70 | | - setupCoreListener({ |
71 | | - getters: { gfiConfiguration }, |
72 | | - rootGetters, |
73 | | - dispatch, |
74 | | - }) { |
75 | | - if (gfiConfiguration.featureList?.bindWithCoreHoverSelect) { |
76 | | - this.watch( |
77 | | - () => rootGetters.selected, |
78 | | - (feature) => dispatch('setOlFeatureInformation', { feature }), |
79 | | - { deep: true } |
80 | | - ) |
81 | | - } |
82 | | - }, |
83 | | - setupMultiSelection({ dispatch, getters, rootGetters }) { |
84 | | - if (getters.gfiConfiguration.boxSelect) { |
85 | | - const dragBox = new DragBox({ condition: platformModifierKeyOnly }) |
86 | | - dragBox.on('boxend', () => |
87 | | - dispatch('getFeatureInfo', { |
88 | | - coordinateOrExtent: dragBox.getGeometry().getExtent(), |
89 | | - modifierPressed: true, |
90 | | - }) |
91 | | - ) |
92 | | - rootGetters.map.addInteraction(dragBox) |
93 | | - } |
94 | | - if (getters.gfiConfiguration.directSelect) { |
95 | | - rootGetters.map.on('click', ({ coordinate, originalEvent }) => { |
96 | | - const isDrawing = rootGetters.map |
97 | | - .getInteractions() |
98 | | - .getArray() |
99 | | - .some( |
100 | | - (interaction) => |
101 | | - // these indicate other interactions are expected now |
102 | | - interaction instanceof Draw || |
103 | | - interaction instanceof Modify || |
104 | | - // @ts-expect-error | internal hack to detect it from @polar/plugin-draw |
105 | | - interaction._isDeleteSelect || |
106 | | - // @ts-expect-error | internal hack to detect it from @polar/plugin-measure |
107 | | - interaction._isMeasureSelect |
108 | | - ) |
109 | | - if (!isDrawing) { |
110 | | - dispatch('getFeatureInfo', { |
111 | | - coordinateOrExtent: coordinate, |
112 | | - modifierPressed: navigator.userAgent.includes('Mac') |
113 | | - ? originalEvent.metaKey |
114 | | - : originalEvent.ctrlKey, |
115 | | - }) |
116 | | - } |
117 | | - }) |
118 | | - } |
119 | | - }, |
120 | | - setupZoomListeners({ dispatch, getters, rootGetters }) { |
121 | | - if (getters.gfiConfiguration.featureList) { |
122 | | - this.watch( |
123 | | - () => rootGetters.zoomLevel, |
124 | | - () => { |
125 | | - const { |
126 | | - featureInformation, |
127 | | - listableLayerSources, |
128 | | - visibleWindowFeatureIndex, |
129 | | - windowFeatures, |
130 | | - } = getters |
131 | | - |
132 | | - if (windowFeatures.length) { |
133 | | - const layerId: string = |
134 | | - // @ts-expect-error | if windowFeatures has features, visibleWindowFeatureIndex is in the range of possible features |
135 | | - windowFeatures[visibleWindowFeatureIndex].polarInternalLayerKey |
136 | | - const selectedFeatureProperties: GeoJsonProperties = { |
137 | | - // eslint-disable-next-line @typescript-eslint/naming-convention |
138 | | - _gfiLayerId: layerId, |
139 | | - ...featureInformation[layerId][visibleWindowFeatureIndex] |
140 | | - .properties, |
141 | | - } |
142 | | - const originalFeature = getOriginalFeature( |
143 | | - listableLayerSources, |
144 | | - selectedFeatureProperties |
145 | | - ) |
146 | | - if (originalFeature) { |
147 | | - dispatch('setOlFeatureInformation', { |
148 | | - feature: getCluster( |
149 | | - rootGetters.map, |
150 | | - originalFeature, |
151 | | - '_gfiLayerId' |
152 | | - ), |
153 | | - }) |
154 | | - } |
155 | | - } |
156 | | - } |
157 | | - ) |
158 | | - } |
159 | | - }, |
| 75 | + setupZoomListeners, |
160 | 76 | setupFeatureVisibilityUpdates({ commit, state, getters, rootGetters }) { |
161 | 77 | // debounce to prevent update spam |
162 | 78 | debouncedVisibilityChangeIndicator = debounce( |
@@ -248,6 +164,34 @@ export const makeActions = () => { |
248 | 164 | dispatch('setCoreSelection', { feature, centerOnFeature }) |
249 | 165 | } |
250 | 166 | }, |
| 167 | + setFeatureInformation( |
| 168 | + { commit, getters }, |
| 169 | + featuresByLayerId: FeaturesByLayerId |
| 170 | + ) { |
| 171 | + commit('clearFeatureInformation') |
| 172 | + commit('setVisibleWindowFeatureIndex', 0) |
| 173 | + clear(featureDisplayLayer) |
| 174 | + |
| 175 | + const filteredFeatures = Object.fromEntries( |
| 176 | + Object.entries(filterFeatures(featuresByLayerId)).map( |
| 177 | + ([layerId, features]) => { |
| 178 | + const { isSelectable } = getters.gfiConfiguration.layers[layerId] |
| 179 | + return [ |
| 180 | + layerId, |
| 181 | + typeof isSelectable === 'function' |
| 182 | + ? features.filter((feature) => isSelectable(feature)) |
| 183 | + : features, |
| 184 | + ] |
| 185 | + } |
| 186 | + ) |
| 187 | + ) |
| 188 | + commit('setFeatureInformation', filteredFeatures) |
| 189 | + renderFeatures( |
| 190 | + featureDisplayLayer, |
| 191 | + getters.geometryLayerKeys, |
| 192 | + filteredFeatures |
| 193 | + ) |
| 194 | + }, |
251 | 195 | hover({ commit, rootGetters }, feature: Feature) { |
252 | 196 | if (rootGetters.configuration.extendedMasterportalapiMarkers) { |
253 | 197 | commit('setHovered', feature, { root: true }) |
|
0 commit comments