Pass the layer to add a new point to instead of searching it, fixes layer confusion bug reported by ThibaultMol

This commit is contained in:
Pieter Vander Vennet 2023-01-16 11:58:24 +01:00
parent 3046fbfb56
commit 8fc56f7487
2 changed files with 5 additions and 22 deletions

View file

@ -113,6 +113,7 @@ export default class LocationInput
minZoom?: number minZoom?: number
mapBackground?: UIEventSource<BaseLayer> mapBackground?: UIEventSource<BaseLayer>
snapTo?: UIEventSource<{ feature: Feature }[]> snapTo?: UIEventSource<{ feature: Feature }[]>
renderLayerForSnappedPoint?: LayerConfig
maxSnapDistance?: number maxSnapDistance?: number
snappedPointTags?: any snappedPointTags?: any
requiresSnapping?: boolean requiresSnapping?: boolean
@ -149,24 +150,11 @@ export default class LocationInput
this._bounds = options?.bounds this._bounds = options?.bounds
this._minZoom = options?.minZoom this._minZoom = options?.minZoom
this._state = options?.state this._state = options?.state
const self = this
if (this._snapTo === undefined) { if (this._snapTo === undefined) {
this._value = this._centerLocation this._value = this._centerLocation
} else { } else {
const self = this this._matching_layer = options?.renderLayerForSnappedPoint ?? LocationInput.matchLayer
if (self._snappedPointTags !== undefined) {
const layout = this._state.layoutToUse
let matchingLayer = LocationInput.matchLayer
for (const layer of layout.layers) {
if (layer.source.osmTags.matchesProperties(self._snappedPointTags)) {
matchingLayer = layer
}
}
this._matching_layer = matchingLayer
} else {
this._matching_layer = LocationInput.matchLayer
}
// Calculate the location of the point based by snapping it onto a way // Calculate the location of the point based by snapping it onto a way
// As a side-effect, the actual snapped-onto way (if any) is saved into 'snappedOnto' // As a side-effect, the actual snapped-onto way (if any) is saved into 'snappedOnto'
@ -220,10 +208,6 @@ export default class LocationInput
} }
} }
min.properties = options?.snappedPointTags ?? min.properties min.properties = options?.snappedPointTags ?? min.properties
if (matchedWay.properties.id.startsWith("relation/")) {
// We matched a relation instead of a way
console.log("Snapping onto a relation. The relation is", matchedWay)
}
self.snappedOnto.setData(<any>matchedWay) self.snappedOnto.setData(<any>matchedWay)
return min return min
}, },
@ -277,7 +261,6 @@ export default class LocationInput
const startLocation = { ...this._centerLocation.data } const startLocation = { ...this._centerLocation.data }
this._centerLocation.addCallbackD((newLocation) => { this._centerLocation.addCallbackD((newLocation) => {
const f = 100000 const f = 100000
console.log(newLocation.lon, startLocation.lon)
const diff = const diff =
Math.abs(newLocation.lon * f - startLocation.lon * f) + Math.abs(newLocation.lon * f - startLocation.lon * f) +
Math.abs(newLocation.lat * f - startLocation.lat * f) Math.abs(newLocation.lat * f - startLocation.lat * f)
@ -292,7 +275,6 @@ export default class LocationInput
) )
if (this._snapToRaw !== undefined) { if (this._snapToRaw !== undefined) {
// Show the lines to snap to // Show the lines to snap to
console.log("Constructing the snap-to layer", this._snapToRaw)
new ShowDataMultiLayer({ new ShowDataMultiLayer({
features: StaticFeatureSource.fromDateless(this._snapToRaw), features: StaticFeatureSource.fromDateless(this._snapToRaw),
zoomToFeatures: false, zoomToFeatures: false,
@ -306,8 +288,8 @@ export default class LocationInput
} }
return [{ feature: loc }] return [{ feature: loc }]
}) })
console.log("Constructing the match layer", matchPoint)
// The 'matchlayer' is the layer which shows the target location
new ShowDataLayer({ new ShowDataLayer({
features: StaticFeatureSource.fromDateless(matchPoint), features: StaticFeatureSource.fromDateless(matchPoint),
zoomToFeatures: false, zoomToFeatures: false,

View file

@ -78,6 +78,7 @@ export default class ConfirmLocationOfPoint extends Combine {
mapBackground: backgroundLayer, mapBackground: backgroundLayer,
centerLocation: locationSrc, centerLocation: locationSrc,
snapTo: snapToFeatures, snapTo: snapToFeatures,
renderLayerForSnappedPoint: preset.layerToAddTo.layerDef,
snappedPointTags: tags, snappedPointTags: tags,
maxSnapDistance: preset.preciseInput.maxSnapDistance, maxSnapDistance: preset.preciseInput.maxSnapDistance,
bounds: mapBounds, bounds: mapBounds,