-
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 branch 'main' into fix/remove-pan-tooltip-during-drag-interaction
- Loading branch information
Showing
20 changed files
with
210 additions
and
58 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
54 changes: 54 additions & 0 deletions
54
packages/plugins/Draw/src/store/createInteractions/createDrawInteractions.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,54 @@ | ||
import { Draw, Snap } from 'ol/interaction' | ||
import Interaction from 'ol/interaction/Interaction' | ||
import { PolarActionContext } from '@polar/lib-custom-types' | ||
import { CreateInteractionsPayload, DrawGetters, DrawState } from '../../types' | ||
import createDrawStyle from '../../utils/createDrawStyle' | ||
import { getSchnaps } from './getSnaps' | ||
|
||
export default function ( | ||
{ | ||
dispatch, | ||
rootGetters, | ||
getters: { | ||
configuration, | ||
drawMode, | ||
measureMode, | ||
selectedStrokeColor, | ||
textInput, | ||
textSize, | ||
}, | ||
}: PolarActionContext<DrawState, DrawGetters>, | ||
{ drawSource }: CreateInteractionsPayload | ||
): Promise<Interaction[]> | Interaction[] { | ||
if (drawMode === 'Text') { | ||
return dispatch('createTextInteractions', { | ||
textInput, | ||
textSize, | ||
drawSource, | ||
configuration, | ||
}) | ||
} | ||
const style = createDrawStyle( | ||
drawMode, | ||
selectedStrokeColor, | ||
measureMode, | ||
rootGetters.map.getView().getProjection(), | ||
configuration?.style | ||
) | ||
const draw = new Draw({ | ||
source: drawSource, | ||
type: drawMode, | ||
style, | ||
}) | ||
// @ts-expect-error | internal hack to detect it in @polar/plugin-pins and @polar/plugin-gfi | ||
draw._isDrawPlugin = true | ||
draw.on('drawend', (e) => e.feature.setStyle(style)) | ||
return [ | ||
draw, | ||
...getSchnaps( | ||
rootGetters.map, | ||
rootGetters.configuration?.draw?.snapTo || [] | ||
), | ||
new Snap({ source: drawSource }), | ||
] | ||
} |
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
22 changes: 22 additions & 0 deletions
22
packages/plugins/Draw/src/store/createInteractions/getSnaps.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,22 @@ | ||
import { Map } from 'ol' | ||
import { Snap } from 'ol/interaction' | ||
import VectorLayer from 'ol/layer/Vector' | ||
import VectorSource from 'ol/source/Vector' | ||
|
||
export const getSchnaps = (map: Map, snapIds: string[]): Snap[] => | ||
snapIds.reduce((accumulator, layerId) => { | ||
const source = ( | ||
map | ||
.getLayers() | ||
.getArray() | ||
.find((layer) => layer.get('id') === layerId) as VectorLayer | ||
)?.getSource?.() | ||
if (source instanceof VectorSource) { | ||
accumulator.push(new Snap({ source })) | ||
} else { | ||
console.warn( | ||
`@polar/plugin-draw: Layer with ID "${layerId}" configured for 'snapTo', but it has no source to snap to. The layer does probably not hold any vector data.` | ||
) | ||
} | ||
return accumulator | ||
}, [] as Snap[]) |
Oops, something went wrong.