-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #211 from Dataport/feature/gfi-radius-select
Extend multi selection by adding new mode "circle"
- Loading branch information
Showing
12 changed files
with
118 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
packages/plugins/Gfi/src/store/actions/setupMultiSelection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { Map } from 'ol' | ||
import { Modify } from 'ol/interaction' | ||
import Draw, { | ||
createBox, | ||
type Options as DrawOptions, | ||
} from 'ol/interaction/Draw' | ||
import { platformModifierKeyOnly } from 'ol/events/condition' | ||
import { Fill, Stroke, Style } from 'ol/style' | ||
import { PolarActionContext } from '@polar/lib-custom-types' | ||
import { GfiGetters, GfiState } from '../../types' | ||
|
||
const isDrawing = (map: Map) => | ||
map | ||
.getInteractions() | ||
.getArray() | ||
.some( | ||
(interaction) => | ||
(interaction instanceof Draw && | ||
// @ts-expect-error | internal hack to detect it from @polar/plugin-gfi and @polar/plugin-draw | ||
(interaction._isMultiSelect || interaction._isDrawPlugin)) || | ||
interaction instanceof Modify || | ||
// @ts-expect-error | internal hack to detect it from @polar/plugin-draw | ||
interaction._isDeleteSelect || | ||
// @ts-expect-error | internal hack to detect it from @polar/plugin-measure | ||
interaction._isMeasureSelect | ||
) | ||
|
||
const drawOptions: DrawOptions = { | ||
stopClick: true, | ||
type: 'Circle', | ||
style: new Style({ | ||
stroke: new Stroke({ color: 'white', width: 1.5 }), | ||
fill: new Fill({ color: [255, 255, 255, 0.75] }), | ||
}), | ||
freehandCondition: (event) => { | ||
if (event.type === 'pointermove') { | ||
return false | ||
} else if (event.type === 'pointerup') { | ||
return true | ||
} | ||
return platformModifierKeyOnly(event) | ||
}, | ||
condition: () => false, | ||
} | ||
|
||
export function setupMultiSelection({ | ||
dispatch, | ||
getters: { | ||
gfiConfiguration: { boxSelect, directSelect, multiSelect }, | ||
}, | ||
rootGetters: { map }, | ||
}: PolarActionContext<GfiState, GfiGetters>) { | ||
if (boxSelect || multiSelect === 'box' || multiSelect === 'circle') { | ||
if (boxSelect) { | ||
console.warn( | ||
'@polar/plugin-gfi: Configuration parameter "boxSelect" has been deprecated. Please use the new parameter "multiSelect" set to "box" instead.' | ||
) | ||
} | ||
if (multiSelect !== 'circle') { | ||
drawOptions.geometryFunction = createBox() | ||
} else { | ||
delete drawOptions.geometryFunction | ||
} | ||
const draw = new Draw(drawOptions) | ||
draw.on('drawstart', () => { | ||
// @ts-expect-error | internal hack to detect it in @polar/plugin-pins | ||
draw._isMultiSelect = true | ||
}) | ||
draw.on('drawend', (e) => | ||
dispatch('getFeatureInfo', { | ||
// @ts-expect-error | A feature that is drawn has a geometry. | ||
coordinateOrExtent: e.feature.getGeometry().getExtent(), | ||
modifierPressed: true, | ||
}).finally( | ||
() => | ||
// @ts-expect-error | internal hack to detect it in @polar/plugin-pins | ||
(draw._isMultiSelect = false) | ||
) | ||
) | ||
map.addInteraction(draw) | ||
} | ||
if (directSelect) { | ||
map.on('click', ({ coordinate, originalEvent }) => { | ||
if (!isDrawing(map)) { | ||
dispatch('getFeatureInfo', { | ||
coordinateOrExtent: coordinate, | ||
modifierPressed: | ||
navigator.userAgent.indexOf('Mac') !== -1 | ||
? originalEvent.metaKey | ||
: originalEvent.ctrlKey, | ||
}) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters