Skip to content

Commit 1288f77

Browse files
authored
Merge branch 'main' into fix/documentation-supplement-in-address-search
2 parents 0c4e072 + 81cb8b1 commit 1288f77

File tree

12 files changed

+118
-61
lines changed

12 files changed

+118
-61
lines changed

packages/clients/snowbox/src/mapConfiguration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export const mapConfiguration = {
166166
gfi: {
167167
mode: 'bboxDot',
168168
activeLayerPath: 'plugin/layerChooser/activeMaskIds',
169-
boxSelect: true,
169+
multiSelect: 'circle',
170170
layers: {
171171
[uBahn]: {
172172
geometry: true,

packages/plugins/Draw/src/store/createInteractions/createTextInteractions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export default function (
2525
type: 'Point',
2626
style: textStyle,
2727
})
28+
// @ts-expect-error | internal hack to detect it in @polar/plugin-pins and @polar/plugin-gfi
29+
draw._isDrawPlugin = true
2830
draw.on('drawend', function (e) {
2931
e.feature.setStyle(textStyle)
3032
e.feature.set('text', textInput)

packages/plugins/Draw/src/store/createInteractions/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export default function (
4444
type: drawMode,
4545
style,
4646
})
47+
// @ts-expect-error | internal hack to detect it in @polar/plugin-pins and @polar/plugin-gfi
48+
draw._isDrawPlugin = true
4749
draw.on('drawend', (e) => e.feature.setStyle(style))
4850

4951
return [draw, new Snap({ source: drawSource })]

packages/plugins/Gfi/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## unpublished
44

5+
- Feature: Add new configuration parameter `multiSelect` to enable the possibility to choose between the selecting multiple features through a box or through a circle. The addition of this parameter deprecates the previously used parameter `boxSelect`.
56
- Fix: Correctly disable `directSelect` if the user is currently using functionality of `@polar/plugin-draw`.
67

78
## 2.1.0

packages/plugins/Gfi/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ The GFI plugin can be used to fetch and optionally display GFI (GetFeatureInfo)
1616
| layers | Record<string, gfiLayerConfiguration> | Maps a string (must be a layer ID) to a behaviour configuration for that layer. |
1717
| activeLayerPath | string? | Optional store path to array of active mask layer ids. If used with `LayerChooser`, setting this to `'plugin/layerChooser/activeMaskIds'` will result in an info text in the GFI box, should no layer be active. If used without `LayerChooser`, the active mask layers have to be provided by another plugin or the client. If not set, the GFI plugin may e.g. show an empty list, which may be confusing to some users. |
1818
| afterLoadFunction | function (featuresByLayerId: Record<string, GeoJsonFeature[]>): Record<layerId, GeoJsonFeature[]>? | This method can be used to extend, filter, or otherwise modify a GFI result. |
19-
| boxSelect | boolean? | If set to `true`, multiple features can be selected at once by using the modifier key (CTRL on Windows or Command on macOS) and dragging the mouse. Similar to `gfi.directSelect`, features can be added and removed by selection / unselecting them. The features need to be distinguishable by their properties for the functionality to properly work. Does not work together with `extendedMasterportalapiMarkers` of `@polar/core`. Defaults to `false`. |
19+
| boxSelect | boolean? | **This parameter has been deprecated. Please use `multiSelect` to `'box'` instead.** If set to `true`, multiple features can be selected at once by using the modifier key (CTRL on Windows or Command on macOS) and dragging the mouse. Can only be used in Desktop environments. Similar to `gfi.directSelect`, features can be added and removed by selection / unselecting them. The features need to be distinguishable by their properties for the functionality to properly work. Does not work together with `extendedMasterportalapiMarkers` of `@polar/core`. Defaults to `false`. |
2020
| customHighlightStyle | customHighlighStyle? | If required a user can change the stroke and fill of the highlighted feature. The default style as seen in the example will be used for each part that is not customized. An empty object will return the complete default style while e.g. for an object without a configured fill the default fill will be applied. |
2121
| directSelect | boolean? | If set to `true`, a feature can be selected without defining a value in `gfi.coordinateSources`. It is also possible to add multiple features to the selection by using the modifier key (CTRL on Windows or Command on macOS). To delesect a feature, simply reclick it with the modifier key pressed. To create a new selection, click anywhere else without pressing the modifier key. Be careful when using this parameter together with some values set in `coordinateSources` as it may lead to unexpected results. The features need to be distinguishable by their properties for the functionality to properly work. Does not work together with `extendedMasterportalapiMarkers` of `@polar/core`. Defaults to `false`. |
2222
| featureList | featureList? | If defined, a list of available vector layer features is visible when no feature is selected. Only usable if `renderType` is set to `iconMenu` and `window` is set to `true` for at least one configured layer. |
2323
| gfiContentComponent | VueConstructor? | Allows overriding the GfiContent.vue component for custom design and functionality. Coding knowledge is required to use this feature, as any implementation will have to rely upon the VueX store model. Please refer to the implementation. |
2424
| maxFeatures | number? | Limits the viewable GFIs per layer by this number. The first n elements are chosen arbitrarily. Useful if you e.g. just want one result, or to limit an endless stream of returns to e.g. 10. Infinite by default. |
2525
| mode | enum["bboxDot", "intersects"]? | Method of calculating which feature has been chosen by the user. `bboxDot` utilizes the `bbox`-url parameter using the clicked coordinate while `intersects` uses a `Filter` to calculate the intersected features. Layers can have their own `gfiMode` parameter which would override this global mode. To apply this, add the desired value to the parameter in the `mapConfiguration`. Defaults to `'bboxDot'`. |
26+
| multiSelect | enum["box", "circle"]? | If configured, multiple features can be selected at once by using the modifier key (CTRL on Windows or Command on macOS) and dragging the mouse. Can only be used in Desktop environments. If set to `'box'`, the selection will be done in a box. If set to `'circle'`, the selection will be done in a circle. Similar to `gfi.directSelect`, features can be added and removed by selection / unselecting them. The features need to be distinguishable by their properties for the functionality to properly work. Does not work together with `extendedMasterportalapiMarkers` of `@polar/core`. Is disabled by default. |
2627
| renderType | ('iconMenu' \| 'independent')? | Only relevant if `window` is set to `true` for at least one layer. Whether the gfi plugin is rendered independently or as part of the IconMenu. Defaults to 'independent'. |
2728

2829
For details on the `displayComponent` attribute, refer to the [Global Plugin Parameters](../../core/README.md#global-plugin-parameters) section of `@polar/core`.

packages/plugins/Gfi/src/store/actions/index.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
import debounce from 'lodash.debounce'
22
import { Feature as GeoJsonFeature } from 'geojson'
3-
import { Style, Fill, Stroke } from 'ol/style'
3+
import { Fill, Stroke, Style } from 'ol/style'
44
import { GeoJSON } from 'ol/format'
55
import { Feature } from 'ol'
66
import { PolarActionTree } from '@polar/lib-custom-types'
7-
import { getFeatureDisplayLayer, clear } from '../../utils/displayFeatureLayer'
8-
import { FeaturesByLayerId, GfiGetters, GfiState } from '../../types'
97
import { filterFeatures } from '../../utils/filterFeatures'
108
import { renderFeatures } from '../../utils/renderFeatures'
9+
import { clear, getFeatureDisplayLayer } from '../../utils/displayFeatureLayer'
10+
import { FeaturesByLayerId, GfiGetters, GfiState } from '../../types'
1111
import { debouncedGfiRequest } from './debouncedGfiRequest'
12-
import {
13-
setupCoreListener,
14-
setupMultiSelection,
15-
setupTooltip,
16-
setupZoomListeners,
17-
} from './setup'
12+
import { setupCoreListener, setupTooltip, setupZoomListeners } from './setup'
13+
import { setupMultiSelection } from './setupMultiSelection'
1814

1915
// OK for module action set creation
2016
// eslint-disable-next-line max-lines-per-function

packages/plugins/Gfi/src/store/actions/setup.ts

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import getCluster from '@polar/lib-get-cluster'
44
import { getTooltip, Tooltip } from '@polar/lib-tooltip'
55
import Overlay from 'ol/Overlay'
66
import { Feature } from 'ol'
7-
import { DragBox, Draw, Modify } from 'ol/interaction'
8-
import { platformModifierKeyOnly } from 'ol/events/condition'
97
import { GfiGetters, GfiState } from '../../types'
108
import { getOriginalFeature } from '../../utils/getOriginalFeature'
119

@@ -26,46 +24,6 @@ export function setupCoreListener(
2624
}
2725
}
2826

29-
export function setupMultiSelection({
30-
dispatch,
31-
getters,
32-
rootGetters,
33-
}: PolarActionContext<GfiState, GfiGetters>) {
34-
if (getters.gfiConfiguration.boxSelect) {
35-
const dragBox = new DragBox({ condition: platformModifierKeyOnly })
36-
dragBox.on('boxend', () =>
37-
dispatch('getFeatureInfo', {
38-
coordinateOrExtent: dragBox.getGeometry().getExtent(),
39-
modifierPressed: true,
40-
})
41-
)
42-
rootGetters.map.addInteraction(dragBox)
43-
}
44-
if (getters.gfiConfiguration.directSelect) {
45-
rootGetters.map.on('click', ({ coordinate, originalEvent }) => {
46-
const isDrawing = rootGetters.map
47-
.getInteractions()
48-
.getArray()
49-
.some(
50-
(interaction) =>
51-
// these indicate other interactions are expected now
52-
interaction instanceof Draw ||
53-
interaction instanceof Modify ||
54-
// @ts-expect-error | internal hack to detect it from @polar/plugin-draw
55-
interaction._isDeleteSelect
56-
)
57-
if (!isDrawing) {
58-
dispatch('getFeatureInfo', {
59-
coordinateOrExtent: coordinate,
60-
modifierPressed: navigator.userAgent.includes('Mac')
61-
? originalEvent.metaKey
62-
: originalEvent.ctrlKey,
63-
})
64-
}
65-
})
66-
}
67-
}
68-
6927
export function setupTooltip({
7028
getters: { gfiConfiguration },
7129
rootGetters: { map },
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { Map } from 'ol'
2+
import { Modify } from 'ol/interaction'
3+
import Draw, {
4+
createBox,
5+
type Options as DrawOptions,
6+
} from 'ol/interaction/Draw'
7+
import { platformModifierKeyOnly } from 'ol/events/condition'
8+
import { Fill, Stroke, Style } from 'ol/style'
9+
import { PolarActionContext } from '@polar/lib-custom-types'
10+
import { GfiGetters, GfiState } from '../../types'
11+
12+
const isDrawing = (map: Map) =>
13+
map
14+
.getInteractions()
15+
.getArray()
16+
.some(
17+
(interaction) =>
18+
(interaction instanceof Draw &&
19+
// @ts-expect-error | internal hack to detect it from @polar/plugin-gfi and @polar/plugin-draw
20+
(interaction._isMultiSelect || interaction._isDrawPlugin)) ||
21+
interaction instanceof Modify ||
22+
// @ts-expect-error | internal hack to detect it from @polar/plugin-draw
23+
interaction._isDeleteSelect ||
24+
// @ts-expect-error | internal hack to detect it from @polar/plugin-measure
25+
interaction._isMeasureSelect
26+
)
27+
28+
const drawOptions: DrawOptions = {
29+
stopClick: true,
30+
type: 'Circle',
31+
style: new Style({
32+
stroke: new Stroke({ color: 'white', width: 1.5 }),
33+
fill: new Fill({ color: [255, 255, 255, 0.75] }),
34+
}),
35+
freehandCondition: (event) => {
36+
if (event.type === 'pointermove') {
37+
return false
38+
} else if (event.type === 'pointerup') {
39+
return true
40+
}
41+
return platformModifierKeyOnly(event)
42+
},
43+
condition: () => false,
44+
}
45+
46+
export function setupMultiSelection({
47+
dispatch,
48+
getters: {
49+
gfiConfiguration: { boxSelect, directSelect, multiSelect },
50+
},
51+
rootGetters: { map },
52+
}: PolarActionContext<GfiState, GfiGetters>) {
53+
if (boxSelect || multiSelect === 'box' || multiSelect === 'circle') {
54+
if (boxSelect) {
55+
console.warn(
56+
'@polar/plugin-gfi: Configuration parameter "boxSelect" has been deprecated. Please use the new parameter "multiSelect" set to "box" instead.'
57+
)
58+
}
59+
if (multiSelect !== 'circle') {
60+
drawOptions.geometryFunction = createBox()
61+
} else {
62+
delete drawOptions.geometryFunction
63+
}
64+
const draw = new Draw(drawOptions)
65+
draw.on('drawstart', () => {
66+
// @ts-expect-error | internal hack to detect it in @polar/plugin-pins
67+
draw._isMultiSelect = true
68+
})
69+
draw.on('drawend', (e) =>
70+
dispatch('getFeatureInfo', {
71+
// @ts-expect-error | A feature that is drawn has a geometry.
72+
coordinateOrExtent: e.feature.getGeometry().getExtent(),
73+
modifierPressed: true,
74+
}).finally(
75+
() =>
76+
// @ts-expect-error | internal hack to detect it in @polar/plugin-pins
77+
(draw._isMultiSelect = false)
78+
)
79+
)
80+
map.addInteraction(draw)
81+
}
82+
if (directSelect) {
83+
map.on('click', ({ coordinate, originalEvent }) => {
84+
if (!isDrawing(map)) {
85+
dispatch('getFeatureInfo', {
86+
coordinateOrExtent: coordinate,
87+
modifierPressed:
88+
navigator.userAgent.indexOf('Mac') !== -1
89+
? originalEvent.metaKey
90+
: originalEvent.ctrlKey,
91+
})
92+
}
93+
})
94+
}
95+
}

packages/plugins/Pins/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
# unpublished
4+
5+
- Feature: Recognize the multi-select-`Draw` of `@polar/plugin-gfi`.
6+
37
## 2.0.0
48

59
- Breaking: Upgrade peerDependency `ol` from `^7.1.0` to `^9.2.4`.

packages/plugins/Pins/src/store/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ export const makeStoreModule = () => {
5353
rootGetters.map.on('singleclick', async ({ coordinate }) => {
5454
const isDrawing = interactions.getArray().some(
5555
(interaction) =>
56-
// these indicate other interactions are expected now
57-
interaction instanceof Draw ||
56+
(interaction instanceof Draw &&
57+
// @ts-expect-error | internal hack to detect it from @polar/plugin-gfi and @polar/plugin-draw
58+
(interaction._isMultiSelect || interaction._isDrawPlugin)) ||
5859
interaction instanceof Modify ||
5960
// @ts-expect-error | internal hack to detect it from @polar/plugin-draw
6061
interaction._isDeleteSelect

packages/types/custom/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Feature: Add new type `MeasureOptions`.
77
- Feature: Add new type `MeasureMode`.
88
- Feature: Add optional property `measure` to `DrawStyle`.
9+
- Feature: Add new property `multiSelect` to `GfiConfiguration`.
910
- Fix: Make `selectionStyle`, `hoverStyle`, `defaultStyle` and `unselectableStyle` optional and edit type for `dispatchOnMapSelect` in interface `ExtendedMasterportalapiMarkers`.
1011

1112
## 1.5.0

packages/types/custom/core.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ export interface GfiConfiguration extends PluginOptions {
371371
layers: Record<string, GfiLayerConfiguration>
372372
activeLayerPath?: string
373373
afterLoadFunction?: GfiAfterLoadFunction
374+
boxSelect?: boolean
374375
/**
375376
* If required the stroke and fill of the highlighted feature can be configured.
376377
* Otherwise, a default style is applied.
@@ -390,7 +391,7 @@ export interface GfiConfiguration extends PluginOptions {
390391
*/
391392
maxFeatures?: number
392393
mode?: 'bboxDot' | 'intersects'
393-
boxSelect?: boolean
394+
multiSelect?: 'box' | 'circle'
394395
renderType?: RenderType
395396
}
396397

@@ -407,10 +408,6 @@ export interface IconMenuConfiguration extends PluginOptions {
407408
initiallyOpen?: string
408409
}
409410

410-
export interface MeasureConfiguration extends PluginOptions {
411-
color?: Color | ColorLike
412-
textColor?: Color | ColorLike
413-
}
414411
export interface AppearOnClick {
415412
/** Whether the pin should be set with a click on a map. */
416413
show: boolean
@@ -651,7 +648,6 @@ export interface MapConfig extends MasterportalApiConfig {
651648
geoLocation?: GeoLocationConfiguration
652649
gfi?: GfiConfiguration
653650
iconMenu?: IconMenuConfiguration
654-
measure?: MeasureConfiguration
655651
pins?: PinsConfiguration
656652
reverseGeocoder?: ReverseGeocoderConfiguration
657653
scale?: ScaleConfiguration

0 commit comments

Comments
 (0)