forked from MapComplete/MapComplete
Fix: pass properties of snapping feature in newPointInput to render correctly
This commit is contained in:
parent
7ba6bb8bb3
commit
c80085dfda
2 changed files with 29 additions and 7 deletions
|
@ -8,13 +8,17 @@
|
||||||
import ShowDataLayer from "../Map/ShowDataLayer"
|
import ShowDataLayer from "../Map/ShowDataLayer"
|
||||||
import type {
|
import type {
|
||||||
FeatureSource,
|
FeatureSource,
|
||||||
FeatureSourceForLayer,
|
FeatureSourceForLayer
|
||||||
} from "../../Logic/FeatureSource/FeatureSource"
|
} from "../../Logic/FeatureSource/FeatureSource"
|
||||||
import SnappingFeatureSource from "../../Logic/FeatureSource/Sources/SnappingFeatureSource"
|
import SnappingFeatureSource from "../../Logic/FeatureSource/Sources/SnappingFeatureSource"
|
||||||
import FeatureSourceMerger from "../../Logic/FeatureSource/Sources/FeatureSourceMerger"
|
import FeatureSourceMerger from "../../Logic/FeatureSource/Sources/FeatureSourceMerger"
|
||||||
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
|
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
|
||||||
import { Utils } from "../../Utils"
|
import { Utils } from "../../Utils"
|
||||||
import Move_arrows from "../../assets/svg/Move_arrows.svelte"
|
import Move_arrows from "../../assets/svg/Move_arrows.svelte"
|
||||||
|
import StaticFeatureSource from "../../Logic/FeatureSource/Sources/StaticFeatureSource"
|
||||||
|
import { prop_dev } from "svelte/internal"
|
||||||
|
import { Tag } from "../../Logic/Tags/Tag"
|
||||||
|
import { TagUtils } from "../../Logic/Tags/TagUtils"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An advanced location input, which has support to:
|
* An advanced location input, which has support to:
|
||||||
|
@ -43,6 +47,8 @@
|
||||||
export let snapToLayers: string[] | undefined
|
export let snapToLayers: string[] | undefined
|
||||||
export let targetLayer: LayerConfig | undefined
|
export let targetLayer: LayerConfig | undefined
|
||||||
export let maxSnapDistance: number = undefined
|
export let maxSnapDistance: number = undefined
|
||||||
|
export let presetProperties: Tag[] = undefined
|
||||||
|
let presetPropertiesUnpacked = TagUtils.KVtoProperties(presetProperties)
|
||||||
|
|
||||||
export let snappedTo: UIEventSource<string | undefined>
|
export let snappedTo: UIEventSource<string | undefined>
|
||||||
|
|
||||||
|
@ -66,16 +72,17 @@
|
||||||
allowMoving: new UIEventSource<boolean>(true),
|
allowMoving: new UIEventSource<boolean>(true),
|
||||||
allowZooming: new UIEventSource<boolean>(true),
|
allowZooming: new UIEventSource<boolean>(true),
|
||||||
minzoom: new UIEventSource<number>(18),
|
minzoom: new UIEventSource<number>(18),
|
||||||
rasterLayer: UIEventSource.feedFrom(state.mapProperties.rasterLayer),
|
rasterLayer: UIEventSource.feedFrom(state.mapProperties.rasterLayer)
|
||||||
}
|
}
|
||||||
state?.showCurrentLocationOn(map)
|
state?.showCurrentLocationOn(map)
|
||||||
|
|
||||||
if (targetLayer) {
|
if (targetLayer) {
|
||||||
|
// Show already existing items
|
||||||
const featuresForLayer = state.perLayer.get(targetLayer.id)
|
const featuresForLayer = state.perLayer.get(targetLayer.id)
|
||||||
if (featuresForLayer) {
|
if (featuresForLayer) {
|
||||||
new ShowDataLayer(map, {
|
new ShowDataLayer(map, {
|
||||||
layer: targetLayer,
|
layer: targetLayer,
|
||||||
features: featuresForLayer,
|
features: featuresForLayer
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,7 +99,7 @@
|
||||||
new ShowDataLayer(map, {
|
new ShowDataLayer(map, {
|
||||||
layer: layer.layer.layerDef,
|
layer: layer.layer.layerDef,
|
||||||
zoomToFeatures: false,
|
zoomToFeatures: false,
|
||||||
features: layer,
|
features: layer
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
const snappedLocation = new SnappingFeatureSource(
|
const snappedLocation = new SnappingFeatureSource(
|
||||||
|
@ -103,14 +110,28 @@
|
||||||
maxDistance: maxSnapDistance ?? 15,
|
maxDistance: maxSnapDistance ?? 15,
|
||||||
allowUnsnapped: true,
|
allowUnsnapped: true,
|
||||||
snappedTo,
|
snappedTo,
|
||||||
snapLocation: value,
|
snapLocation: value
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
const withCorrectedAttributes = new StaticFeatureSource(
|
||||||
|
snappedLocation.features.mapD(feats => feats.map(f => {
|
||||||
|
const properties = {
|
||||||
|
...f.properties,
|
||||||
|
...presetPropertiesUnpacked
|
||||||
|
}
|
||||||
|
properties["_referencing_ways"] = f.properties["snapped-to"]
|
||||||
|
return ({
|
||||||
|
...f,
|
||||||
|
properties
|
||||||
|
})
|
||||||
|
}))
|
||||||
|
)
|
||||||
|
// The actual point to be created, snapped at the new location
|
||||||
new ShowDataLayer(map, {
|
new ShowDataLayer(map, {
|
||||||
layer: targetLayer,
|
layer: targetLayer,
|
||||||
features: snappedLocation,
|
features: withCorrectedAttributes
|
||||||
})
|
})
|
||||||
|
withCorrectedAttributes.features.addCallbackAndRunD(f => console.log("Snapped point is", f))
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -329,6 +329,7 @@
|
||||||
{state}
|
{state}
|
||||||
{coordinate}
|
{coordinate}
|
||||||
targetLayer={selectedPreset.layer}
|
targetLayer={selectedPreset.layer}
|
||||||
|
presetProperties={selectedPreset.preset.tags}
|
||||||
snapToLayers={selectedPreset.preset.preciseInput.snapToLayers}
|
snapToLayers={selectedPreset.preset.preciseInput.snapToLayers}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue