forked from MapComplete/MapComplete
refactoring: fix basic flow to add a new point
This commit is contained in:
parent
52a0810ea9
commit
0241f89d3d
109 changed files with 1931 additions and 1446 deletions
|
@ -4,7 +4,7 @@ import Constants from "../../Models/Constants"
|
|||
import { GeoLocationPointProperties, GeoLocationState } from "../State/GeoLocationState"
|
||||
import { UIEventSource } from "../UIEventSource"
|
||||
import { Feature, LineString, Point } from "geojson"
|
||||
import FeatureSource from "../FeatureSource/FeatureSource"
|
||||
import { FeatureSource } from "../FeatureSource/FeatureSource"
|
||||
import { LocalStorageSource } from "../Web/LocalStorageSource"
|
||||
import { GeoOperations } from "../GeoOperations"
|
||||
import { OsmTags } from "../../Models/OsmFeature"
|
||||
|
|
|
@ -9,6 +9,7 @@ import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig"
|
|||
import SimpleMetaTagger from "../SimpleMetaTagger"
|
||||
import FeaturePropertiesStore from "../FeatureSource/Actors/FeaturePropertiesStore"
|
||||
import { Feature } from "geojson"
|
||||
import { OsmTags } from "../../Models/OsmFeature"
|
||||
|
||||
export default class SelectedElementTagsUpdater {
|
||||
private static readonly metatags = new Set([
|
||||
|
@ -87,7 +88,7 @@ export default class SelectedElementTagsUpdater {
|
|||
}
|
||||
})
|
||||
}
|
||||
private applyUpdate(latestTags: any, id: string) {
|
||||
private applyUpdate(latestTags: OsmTags, id: string) {
|
||||
const state = this.state
|
||||
try {
|
||||
const leftRightSensitive = state.layoutToUse.isLeftRightSensitive()
|
||||
|
|
|
@ -26,11 +26,15 @@ export default class TitleHandler {
|
|||
|
||||
const tags = selected.properties
|
||||
const layer = selectedLayer.data
|
||||
if (layer.title === undefined) {
|
||||
return defaultTitle
|
||||
}
|
||||
const tagsSource =
|
||||
allElements.getStore(tags.id) ?? new UIEventSource<Record<string, string>>(tags)
|
||||
const title = new SvelteUIElement(TagRenderingAnswer, {
|
||||
tags: tagsSource,
|
||||
state,
|
||||
config: layer.title,
|
||||
selectedElement: selectedElement.data,
|
||||
layer,
|
||||
})
|
||||
|
|
|
@ -138,6 +138,45 @@ export class BBox {
|
|||
return true
|
||||
}
|
||||
|
||||
squarify(): BBox {
|
||||
const w = this.maxLon - this.minLon
|
||||
const h = this.maxLat - this.minLat
|
||||
const s = Math.sqrt(w * h)
|
||||
const lon = (this.maxLon + this.minLon) / 2
|
||||
const lat = (this.maxLat + this.minLat) / 2
|
||||
// we want to have a more-or-less equal surface, so the new side 's' should be
|
||||
// w * h = s * s
|
||||
// The ratio for w is:
|
||||
|
||||
return new BBox([
|
||||
[lon - s / 2, lat - s / 2],
|
||||
[lon + s / 2, lat + s / 2],
|
||||
])
|
||||
}
|
||||
|
||||
isNearby(location: [number, number], maxRange: number): boolean {
|
||||
if (this.contains(location)) {
|
||||
return true
|
||||
}
|
||||
const [lon, lat] = location
|
||||
// We 'project' the point onto the near edges. If they are close to a horizontal _and_ vertical edge, it is nearby
|
||||
// Vertically nearby: either wihtin minLat range or at most maxRange away
|
||||
const nearbyVertical =
|
||||
(this.minLat <= lat &&
|
||||
this.maxLat >= lat &&
|
||||
GeoOperations.distanceBetween(location, [lon, this.minLat]) <= maxRange) ||
|
||||
GeoOperations.distanceBetween(location, [lon, this.maxLat]) <= maxRange
|
||||
if (!nearbyVertical) {
|
||||
return false
|
||||
}
|
||||
const nearbyHorizontal =
|
||||
(this.minLon <= lon &&
|
||||
this.maxLon >= lon &&
|
||||
GeoOperations.distanceBetween(location, [this.minLon, lat]) <= maxRange) ||
|
||||
GeoOperations.distanceBetween(location, [this.maxLon, lat]) <= maxRange
|
||||
return nearbyHorizontal
|
||||
}
|
||||
|
||||
getEast() {
|
||||
return this.maxLon
|
||||
}
|
||||
|
@ -214,7 +253,7 @@ export class BBox {
|
|||
* @param zoomlevel
|
||||
*/
|
||||
expandToTileBounds(zoomlevel: number): BBox {
|
||||
if(zoomlevel === undefined){
|
||||
if (zoomlevel === undefined) {
|
||||
return this
|
||||
}
|
||||
const ul = Tiles.embedded_tile(this.minLat, this.minLon, zoomlevel)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import FeatureSource, { IndexedFeatureSource } from "../FeatureSource"
|
||||
import { FeatureSource, IndexedFeatureSource } from "../FeatureSource"
|
||||
import { UIEventSource } from "../../UIEventSource"
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import FeatureSource, { FeatureSourceForLayer } from "../FeatureSource"
|
||||
import { FeatureSource , FeatureSourceForLayer } from "../FeatureSource"
|
||||
import { Feature } from "geojson"
|
||||
import { BBox } from "../../BBox"
|
||||
import { GeoOperations } from "../../GeoOperations"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import FeatureSource from "../FeatureSource"
|
||||
import { FeatureSource } from "../FeatureSource"
|
||||
import { Feature } from "geojson"
|
||||
import TileLocalStorage from "./TileLocalStorage"
|
||||
import { GeoOperations } from "../../GeoOperations"
|
||||
|
|
|
@ -3,7 +3,7 @@ import FilteredLayer from "../../Models/FilteredLayer"
|
|||
import { BBox } from "../BBox"
|
||||
import { Feature } from "geojson"
|
||||
|
||||
export default interface FeatureSource {
|
||||
export interface FeatureSource {
|
||||
features: Store<Feature[]>
|
||||
}
|
||||
export interface WritableFeatureSource extends FeatureSource {
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
import FeatureSource, { FeatureSourceForLayer } from "./FeatureSource"
|
||||
import { FeatureSource, FeatureSourceForLayer } from "./FeatureSource"
|
||||
import FilteredLayer from "../../Models/FilteredLayer"
|
||||
import SimpleFeatureSource from "./Sources/SimpleFeatureSource"
|
||||
import { Feature } from "geojson"
|
||||
import { Utils } from "../../Utils"
|
||||
import { UIEventSource } from "../UIEventSource"
|
||||
import { feature } from "@turf/turf"
|
||||
|
||||
/**
|
||||
* In some rare cases, some elements are shown on multiple layers (when 'passthrough' is enabled)
|
||||
|
@ -26,7 +25,7 @@ export default class PerLayerFeatureSourceSplitter<
|
|||
const knownLayers = new Map<string, T>()
|
||||
this.perLayer = knownLayers
|
||||
const layerSources = new Map<string, UIEventSource<Feature[]>>()
|
||||
|
||||
console.log("PerLayerFeatureSourceSplitter got layers", layers)
|
||||
const constructStore =
|
||||
options?.constructStore ?? ((store, layer) => new SimpleFeatureSource(layer, store))
|
||||
for (const layer of layers) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import FeatureSource from "../FeatureSource"
|
||||
import { FeatureSource } from "../FeatureSource"
|
||||
import { Feature, Polygon } from "geojson"
|
||||
import StaticFeatureSource from "./StaticFeatureSource"
|
||||
import { GeoOperations } from "../../GeoOperations"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Store, UIEventSource } from "../../UIEventSource"
|
||||
import FeatureSource, { IndexedFeatureSource } from "../FeatureSource"
|
||||
import { FeatureSource , IndexedFeatureSource } from "../FeatureSource"
|
||||
import { Feature } from "geojson"
|
||||
import { Utils } from "../../../Utils"
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Store, UIEventSource } from "../../UIEventSource"
|
||||
import FilteredLayer from "../../../Models/FilteredLayer"
|
||||
import FeatureSource from "../FeatureSource"
|
||||
import { FeatureSource } from "../FeatureSource"
|
||||
import { TagsFilter } from "../../Tags/TagsFilter"
|
||||
import { Feature } from "geojson"
|
||||
import { GlobalFilter } from "../../../Models/GlobalFilter"
|
||||
|
@ -73,21 +73,9 @@ export default class FilteringFeatureSource implements FeatureSource {
|
|||
return false
|
||||
}
|
||||
|
||||
for (const filter of layer.layerDef.filters) {
|
||||
const state = layer.appliedFilters.get(filter.id).data
|
||||
if (state === undefined) {
|
||||
continue
|
||||
}
|
||||
let neededTags: TagsFilter
|
||||
if (typeof state === "string") {
|
||||
// This filter uses fields
|
||||
} else {
|
||||
neededTags = filter.options[state].osmTags
|
||||
}
|
||||
if (neededTags !== undefined && !neededTags.matchesProperties(f.properties)) {
|
||||
// Hidden by the filter on the layer itself - we want to hide it no matter what
|
||||
return false
|
||||
}
|
||||
let neededTags: TagsFilter = layer.currentFilter.data
|
||||
if (neededTags !== undefined && !neededTags.matchesProperties(f.properties)) {
|
||||
return false
|
||||
}
|
||||
|
||||
for (const globalFilter of globalFilters ?? []) {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
import { Store, UIEventSource } from "../../UIEventSource"
|
||||
import { Utils } from "../../../Utils"
|
||||
import FeatureSource from "../FeatureSource"
|
||||
import { FeatureSource } from "../FeatureSource"
|
||||
import { BBox } from "../../BBox"
|
||||
import { GeoOperations } from "../../GeoOperations"
|
||||
import { Feature } from "geojson"
|
||||
|
|
|
@ -1,21 +1,23 @@
|
|||
import LayoutConfig from "../../../Models/ThemeConfig/LayoutConfig"
|
||||
import FeatureSource from "../FeatureSource"
|
||||
import { ImmutableStore, Store } from "../../UIEventSource"
|
||||
import { WritableFeatureSource } from "../FeatureSource"
|
||||
import { ImmutableStore, Store, UIEventSource } from "../../UIEventSource"
|
||||
import { Feature, Point } from "geojson"
|
||||
import { TagUtils } from "../../Tags/TagUtils"
|
||||
import BaseUIElement from "../../../UI/BaseUIElement"
|
||||
import { Utils } from "../../../Utils"
|
||||
import { regex_not_newline_characters } from "svelte/types/compiler/utils/patterns"
|
||||
import { render } from "sass"
|
||||
|
||||
/**
|
||||
* Highly specialized feature source.
|
||||
* Based on a lon/lat UIEVentSource, will generate the corresponding feature with the correct properties
|
||||
*/
|
||||
export class LastClickFeatureSource implements FeatureSource {
|
||||
features: Store<Feature[]>
|
||||
export class LastClickFeatureSource implements WritableFeatureSource {
|
||||
public readonly features: UIEventSource<Feature[]> = new UIEventSource<Feature[]>([])
|
||||
|
||||
/**
|
||||
* Must be public: passed as tags into the selected view
|
||||
*/
|
||||
public properties: Record<string, string>
|
||||
|
||||
constructor(location: Store<{ lon: number; lat: number }>, layout: LayoutConfig) {
|
||||
const allPresets: BaseUIElement[] = []
|
||||
for (const layer of layout.layers)
|
||||
|
@ -43,15 +45,16 @@ export class LastClickFeatureSource implements FeatureSource {
|
|||
first_preset: renderings[0],
|
||||
}
|
||||
this.properties = properties
|
||||
this.features = location.mapD(({ lon, lat }) => [
|
||||
<Feature<Point>>{
|
||||
location.addCallbackAndRunD(({ lon, lat }) => {
|
||||
const point = <Feature<Point>>{
|
||||
type: "Feature",
|
||||
properties,
|
||||
geometry: {
|
||||
type: "Point",
|
||||
coordinates: [lon, lat],
|
||||
},
|
||||
},
|
||||
])
|
||||
}
|
||||
this.features.setData([point])
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
import GeoJsonSource from "./GeoJsonSource"
|
||||
import LayerConfig from "../../../Models/ThemeConfig/LayerConfig"
|
||||
import FeatureSource from "../FeatureSource"
|
||||
import { FeatureSource } from "../FeatureSource"
|
||||
import { Or } from "../../Tags/Or"
|
||||
import FeatureSwitchState from "../../State/FeatureSwitchState"
|
||||
import OverpassFeatureSource from "./OverpassFeatureSource"
|
||||
import { Store } from "../../UIEventSource"
|
||||
import { ImmutableStore, Store } from "../../UIEventSource"
|
||||
import OsmFeatureSource from "./OsmFeatureSource"
|
||||
import FeatureSourceMerger from "./FeatureSourceMerger"
|
||||
import DynamicGeoJsonTileSource from "../TiledFeatureSource/DynamicGeoJsonTileSource"
|
||||
import { BBox } from "../../BBox"
|
||||
import LocalStorageFeatureSource from "../TiledFeatureSource/LocalStorageFeatureSource"
|
||||
import StaticFeatureSource from "./StaticFeatureSource"
|
||||
|
||||
/**
|
||||
* This source will fetch the needed data from various sources for the given layout.
|
||||
|
@ -78,6 +79,9 @@ export default class LayoutSource extends FeatureSourceMerger {
|
|||
backend: string,
|
||||
featureSwitches: FeatureSwitchState
|
||||
): FeatureSource {
|
||||
if (osmLayers.length == 0) {
|
||||
return new StaticFeatureSource(new ImmutableStore([]))
|
||||
}
|
||||
const minzoom = Math.min(...osmLayers.map((layer) => layer.minzoom))
|
||||
const isActive = zoom.mapD((z) => {
|
||||
if (z < minzoom) {
|
||||
|
@ -107,6 +111,9 @@ export default class LayoutSource extends FeatureSourceMerger {
|
|||
zoom: Store<number>,
|
||||
featureSwitches: FeatureSwitchState
|
||||
): FeatureSource {
|
||||
if (osmLayers.length == 0) {
|
||||
return new StaticFeatureSource(new ImmutableStore([]))
|
||||
}
|
||||
const minzoom = Math.min(...osmLayers.map((layer) => layer.minzoom))
|
||||
const isActive = zoom.mapD((z) => {
|
||||
if (z < minzoom) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Changes } from "../../Osm/Changes"
|
||||
import { OsmNode, OsmObject, OsmRelation, OsmWay } from "../../Osm/OsmObject"
|
||||
import FeatureSource from "../FeatureSource"
|
||||
import { FeatureSource } from "../FeatureSource"
|
||||
import { UIEventSource } from "../../UIEventSource"
|
||||
import { ChangeDescription } from "../../Osm/Actions/ChangeDescription"
|
||||
import { ElementStorage } from "../../ElementStorage"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Feature } from "geojson"
|
||||
import FeatureSource from "../FeatureSource"
|
||||
import { FeatureSource } from "../FeatureSource"
|
||||
import { ImmutableStore, Store, UIEventSource } from "../../UIEventSource"
|
||||
import LayerConfig from "../../../Models/ThemeConfig/LayerConfig"
|
||||
import { Or } from "../../Tags/Or"
|
||||
|
|
|
@ -1,37 +1,69 @@
|
|||
import FeatureSource from "../FeatureSource"
|
||||
import { Store } from "../../UIEventSource"
|
||||
import { FeatureSource } from "../FeatureSource"
|
||||
import { Store, UIEventSource } from "../../UIEventSource"
|
||||
import { Feature, Point } from "geojson"
|
||||
import { GeoOperations } from "../../GeoOperations"
|
||||
import { BBox } from "../../BBox"
|
||||
|
||||
export interface SnappingOptions {
|
||||
/**
|
||||
* If the distance is bigger then this amount, don't snap.
|
||||
* In meter
|
||||
*/
|
||||
maxDistance?: number
|
||||
maxDistance: number
|
||||
|
||||
allowUnsnapped?: false | boolean
|
||||
|
||||
/**
|
||||
* The snapped-to way will be written into this
|
||||
*/
|
||||
snappedTo?: UIEventSource<string>
|
||||
|
||||
/**
|
||||
* The resulting snap coordinates will be written into this UIEventSource
|
||||
*/
|
||||
snapLocation?: UIEventSource<{ lon: number; lat: number }>
|
||||
}
|
||||
|
||||
export default class SnappingFeatureSource implements FeatureSource {
|
||||
public readonly features: Store<Feature<Point>[]>
|
||||
|
||||
private readonly _snappedTo: UIEventSource<string>
|
||||
public readonly snappedTo: Store<string>
|
||||
|
||||
constructor(
|
||||
snapTo: FeatureSource,
|
||||
location: Store<{ lon: number; lat: number }>,
|
||||
options?: SnappingOptions
|
||||
options: SnappingOptions
|
||||
) {
|
||||
const simplifiedFeatures = snapTo.features.mapD((features) =>
|
||||
features
|
||||
.filter((feature) => feature.geometry.type !== "Point")
|
||||
.map((f) => GeoOperations.forceLineString(<any>f))
|
||||
)
|
||||
const maxDistance = options?.maxDistance
|
||||
this._snappedTo = options.snappedTo ?? new UIEventSource<string>(undefined)
|
||||
this.snappedTo = this._snappedTo
|
||||
const simplifiedFeatures = snapTo.features
|
||||
.mapD((features) =>
|
||||
features
|
||||
.filter((feature) => feature.geometry.type !== "Point")
|
||||
.map((f) => GeoOperations.forceLineString(<any>f))
|
||||
)
|
||||
.map(
|
||||
(features) => {
|
||||
const { lon, lat } = location.data
|
||||
const loc: [number, number] = [lon, lat]
|
||||
return features.filter((f) => BBox.get(f).isNearby(loc, maxDistance))
|
||||
},
|
||||
[location]
|
||||
)
|
||||
|
||||
location.mapD(
|
||||
this.features = location.mapD(
|
||||
({ lon, lat }) => {
|
||||
const features = snapTo.features.data
|
||||
const features = simplifiedFeatures.data
|
||||
const loc: [number, number] = [lon, lat]
|
||||
const maxDistance = (options?.maxDistance ?? 1000) * 1000
|
||||
const maxDistance = (options?.maxDistance ?? 1000) / 1000
|
||||
let bestSnap: Feature<Point, { "snapped-to": string; dist: number }> = undefined
|
||||
for (const feature of features) {
|
||||
if (feature.geometry.type !== "LineString") {
|
||||
// TODO handle Polygons with holes
|
||||
continue
|
||||
}
|
||||
const snapped = GeoOperations.nearestPoint(<any>feature, loc)
|
||||
if (snapped.properties.dist > maxDistance) {
|
||||
continue
|
||||
|
@ -44,7 +76,23 @@ export default class SnappingFeatureSource implements FeatureSource {
|
|||
bestSnap = <any>snapped
|
||||
}
|
||||
}
|
||||
return bestSnap
|
||||
this._snappedTo.setData(bestSnap?.properties?.["snapped-to"])
|
||||
if (bestSnap === undefined && options?.allowUnsnapped) {
|
||||
bestSnap = {
|
||||
type: "Feature",
|
||||
geometry: {
|
||||
type: "Point",
|
||||
coordinates: [lon, lat],
|
||||
},
|
||||
properties: {
|
||||
"snapped-to": undefined,
|
||||
dist: -1,
|
||||
},
|
||||
}
|
||||
}
|
||||
const c = bestSnap.geometry.coordinates
|
||||
options?.snapLocation?.setData({ lon: c[0], lat: c[1] })
|
||||
return [bestSnap]
|
||||
},
|
||||
[snapTo.features]
|
||||
)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import FeatureSource, { FeatureSourceForLayer, Tiled } from "../FeatureSource"
|
||||
import { FeatureSource , FeatureSourceForLayer, Tiled } from "../FeatureSource"
|
||||
import { ImmutableStore, Store } from "../../UIEventSource"
|
||||
import FilteredLayer from "../../../Models/FilteredLayer"
|
||||
import { BBox } from "../../BBox"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import FeatureSource, { FeatureSourceForLayer } from "../FeatureSource"
|
||||
import {FeatureSource, FeatureSourceForLayer } from "../FeatureSource"
|
||||
import StaticFeatureSource from "./StaticFeatureSource"
|
||||
import { GeoOperations } from "../../GeoOperations"
|
||||
import { BBox } from "../../BBox"
|
||||
|
|
|
@ -81,6 +81,7 @@ export default class DynamicGeoJsonTileSource extends DynamicTileSource {
|
|||
return new GeoJsonSource(layer, {
|
||||
zxy,
|
||||
featureIdBlacklist: blackList,
|
||||
isActive: options?.isActive,
|
||||
})
|
||||
},
|
||||
mapProperties,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Store, Stores } from "../../UIEventSource"
|
||||
import { Tiles } from "../../../Models/TileRange"
|
||||
import { BBox } from "../../BBox"
|
||||
import FeatureSource from "../FeatureSource"
|
||||
import { FeatureSource } from "../FeatureSource"
|
||||
import FeatureSourceMerger from "../Sources/FeatureSourceMerger"
|
||||
|
||||
/***
|
||||
|
@ -26,10 +26,6 @@ export default class DynamicTileSource extends FeatureSourceMerger {
|
|||
mapProperties.bounds
|
||||
.mapD(
|
||||
(bounds) => {
|
||||
if (options?.isActive?.data === false) {
|
||||
// No need to download! - the layer is disabled
|
||||
return undefined
|
||||
}
|
||||
const tileRange = Tiles.TileRangeBetween(
|
||||
zoomlevel,
|
||||
bounds.getNorth(),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import FeatureSource, { FeatureSourceForLayer, Tiled } from "../FeatureSource"
|
||||
import {FeatureSource, FeatureSourceForLayer, Tiled } from "../FeatureSource"
|
||||
import { OsmNode, OsmObject, OsmWay } from "../../Osm/OsmObject"
|
||||
import SimpleFeatureSource from "../Sources/SimpleFeatureSource"
|
||||
import FilteredLayer from "../../../Models/FilteredLayer"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BBox } from "./BBox"
|
||||
import LayerConfig from "../Models/ThemeConfig/LayerConfig"
|
||||
import * as turf from "@turf/turf"
|
||||
import { AllGeoJSON, booleanWithin, Coord } from "@turf/turf"
|
||||
import { AllGeoJSON, booleanWithin, Coord, Lines } from "@turf/turf"
|
||||
import {
|
||||
Feature,
|
||||
GeoJSON,
|
||||
|
@ -273,7 +273,7 @@ export class GeoOperations {
|
|||
* @param point Point defined as [lon, lat]
|
||||
*/
|
||||
public static nearestPoint(
|
||||
way: Feature<LineString | MultiLineString | Polygon | MultiPolygon>,
|
||||
way: Feature<LineString>,
|
||||
point: [number, number]
|
||||
): Feature<
|
||||
Point,
|
||||
|
@ -951,4 +951,24 @@ export class GeoOperations {
|
|||
}
|
||||
throw "CalculateIntersection fallthrough: can not calculate an intersection between features"
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a linestring object based on the outer ring of the given polygon
|
||||
*
|
||||
* Returns the argument if not a polygon
|
||||
* @param p
|
||||
*/
|
||||
public static outerRing<P>(p: Feature<Polygon | LineString, P>): Feature<LineString, P> {
|
||||
if (p.geometry.type !== "Polygon") {
|
||||
return <Feature<LineString, P>>p
|
||||
}
|
||||
return {
|
||||
type: "Feature",
|
||||
properties: p.properties,
|
||||
geometry: {
|
||||
type: "LineString",
|
||||
coordinates: p.geometry.coordinates[0],
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import CreateWayWithPointReuseAction, { MergePointConfig } from "./CreateWayWith
|
|||
import { And } from "../../Tags/And"
|
||||
import { TagUtils } from "../../Tags/TagUtils"
|
||||
import { SpecialVisualizationState } from "../../../UI/SpecialVisualization"
|
||||
import FeatureSource from "../../FeatureSource/FeatureSource"
|
||||
import { FeatureSource } from "../../FeatureSource/FeatureSource"
|
||||
|
||||
/**
|
||||
* More or less the same as 'CreateNewWay', except that it'll try to reuse already existing points
|
||||
|
|
|
@ -104,9 +104,13 @@ export default class CreateNewNodeAction extends OsmCreateAction {
|
|||
// Project the point onto the way
|
||||
console.log("Snapping a node onto an existing way...")
|
||||
const geojson = this._snapOnto.asGeoJson()
|
||||
const projected = GeoOperations.nearestPoint(geojson, [this._lon, this._lat])
|
||||
const projected = GeoOperations.nearestPoint(GeoOperations.outerRing(geojson), [
|
||||
this._lon,
|
||||
this._lat,
|
||||
])
|
||||
const projectedCoor = <[number, number]>projected.geometry.coordinates
|
||||
const index = projected.properties.index
|
||||
console.log("Attempting to snap:", { geojson, projected, projectedCoor, index })
|
||||
// We check that it isn't close to an already existing point
|
||||
let reusedPointId = undefined
|
||||
let outerring: [number, number][]
|
||||
|
|
|
@ -5,7 +5,7 @@ import { ChangeDescription } from "./ChangeDescription"
|
|||
import { BBox } from "../../BBox"
|
||||
import { TagsFilter } from "../../Tags/TagsFilter"
|
||||
import { GeoOperations } from "../../GeoOperations"
|
||||
import FeatureSource from "../../FeatureSource/FeatureSource"
|
||||
import { FeatureSource } from "../../FeatureSource/FeatureSource"
|
||||
import StaticFeatureSource from "../../FeatureSource/Sources/StaticFeatureSource"
|
||||
import CreateNewNodeAction from "./CreateNewNodeAction"
|
||||
import CreateNewWayAction from "./CreateNewWayAction"
|
||||
|
|
|
@ -2,7 +2,7 @@ import OsmChangeAction from "./OsmChangeAction"
|
|||
import { Changes } from "../Changes"
|
||||
import { ChangeDescription } from "./ChangeDescription"
|
||||
import { Tag } from "../../Tags/Tag"
|
||||
import FeatureSource from "../../FeatureSource/FeatureSource"
|
||||
import { FeatureSource } from "../../FeatureSource/FeatureSource"
|
||||
import { OsmNode, OsmObject, OsmWay } from "../OsmObject"
|
||||
import { GeoOperations } from "../../GeoOperations"
|
||||
import StaticFeatureSource from "../../FeatureSource/Sources/StaticFeatureSource"
|
||||
|
|
|
@ -6,7 +6,7 @@ import { ChangeDescription, ChangeDescriptionTools } from "./Actions/ChangeDescr
|
|||
import { Utils } from "../../Utils"
|
||||
import { LocalStorageSource } from "../Web/LocalStorageSource"
|
||||
import SimpleMetaTagger from "../SimpleMetaTagger"
|
||||
import FeatureSource, { IndexedFeatureSource } from "../FeatureSource/FeatureSource"
|
||||
import {FeatureSource, IndexedFeatureSource } from "../FeatureSource/FeatureSource"
|
||||
import { GeoLocationPointProperties } from "../State/GeoLocationState"
|
||||
import { GeoOperations } from "../GeoOperations"
|
||||
import { ChangesetHandler, ChangesetTag } from "./ChangesetHandler"
|
||||
|
|
|
@ -368,7 +368,7 @@ export class OsmConnection {
|
|||
"Content-Type": "application/json",
|
||||
})
|
||||
const parsed = JSON.parse(response)
|
||||
const id = parsed.properties.id
|
||||
const id = parsed.properties
|
||||
console.log("OPENED NOTE", id)
|
||||
return id
|
||||
}
|
||||
|
|
|
@ -73,7 +73,8 @@ export abstract class OsmObject {
|
|||
if (rawData["error"] !== undefined && rawData["statuscode"] === 410) {
|
||||
return "deleted"
|
||||
}
|
||||
return rawData["content"].elements[0].tags
|
||||
// Tags is undefined if the element does not have any tags
|
||||
return rawData["content"].elements[0].tags ?? {}
|
||||
}
|
||||
|
||||
static async DownloadObjectAsync(
|
||||
|
|
|
@ -21,7 +21,7 @@ export default class LayerState {
|
|||
/**
|
||||
* Which layers are enabled in the current theme and what filters are applied onto them
|
||||
*/
|
||||
public readonly filteredLayers: Map<string, FilteredLayer>
|
||||
public readonly filteredLayers: ReadonlyMap<string, FilteredLayer>
|
||||
private readonly osmConnection: OsmConnection
|
||||
|
||||
/**
|
||||
|
@ -32,14 +32,15 @@ export default class LayerState {
|
|||
*/
|
||||
constructor(osmConnection: OsmConnection, layers: LayerConfig[], context: string) {
|
||||
this.osmConnection = osmConnection
|
||||
this.filteredLayers = new Map()
|
||||
const filteredLayers = new Map()
|
||||
for (const layer of layers) {
|
||||
this.filteredLayers.set(
|
||||
filteredLayers.set(
|
||||
layer.id,
|
||||
FilteredLayer.initLinkedState(layer, context, this.osmConnection)
|
||||
)
|
||||
}
|
||||
layers.forEach((l) => this.linkFilterStates(l))
|
||||
this.filteredLayers = filteredLayers
|
||||
layers.forEach((l) => LayerState.linkFilterStates(l, filteredLayers))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,11 +49,14 @@ export default class LayerState {
|
|||
*
|
||||
* This methods links those states for the given layer
|
||||
*/
|
||||
private linkFilterStates(layer: LayerConfig) {
|
||||
private static linkFilterStates(
|
||||
layer: LayerConfig,
|
||||
filteredLayers: Map<string, FilteredLayer>
|
||||
) {
|
||||
if (layer.filterIsSameAs === undefined) {
|
||||
return
|
||||
}
|
||||
const toReuse = this.filteredLayers.get(layer.filterIsSameAs)
|
||||
const toReuse = filteredLayers.get(layer.filterIsSameAs)
|
||||
if (toReuse === undefined) {
|
||||
throw (
|
||||
"Error in layer " +
|
||||
|
@ -65,6 +69,6 @@ export default class LayerState {
|
|||
console.warn(
|
||||
"Linking filter and isDisplayed-states of " + layer.id + " and " + layer.filterIsSameAs
|
||||
)
|
||||
this.filteredLayers.set(layer.id, toReuse)
|
||||
filteredLayers.set(layer.id, toReuse)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import FilteredLayer from "../../Models/FilteredLayer"
|
|||
import TilesourceConfig from "../../Models/ThemeConfig/TilesourceConfig"
|
||||
import { QueryParameters } from "../Web/QueryParameters"
|
||||
import ShowOverlayLayer from "../../UI/ShowDataLayer/ShowOverlayLayer"
|
||||
import FeatureSource, { FeatureSourceForLayer, Tiled } from "../FeatureSource/FeatureSource"
|
||||
import { FeatureSource, FeatureSourceForLayer, Tiled } from "../FeatureSource/FeatureSource"
|
||||
import StaticFeatureSource, {
|
||||
TiledStaticFeatureSource,
|
||||
} from "../FeatureSource/Sources/StaticFeatureSource"
|
||||
|
|
|
@ -4,7 +4,7 @@ import { MangroveIdentity } from "../Web/MangroveReviews"
|
|||
import { Store, Stores, UIEventSource } from "../UIEventSource"
|
||||
import Locale from "../../UI/i18n/Locale"
|
||||
import StaticFeatureSource from "../FeatureSource/Sources/StaticFeatureSource"
|
||||
import FeatureSource from "../FeatureSource/FeatureSource"
|
||||
import { FeatureSource } from "../FeatureSource/FeatureSource"
|
||||
import { Feature } from "geojson"
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,7 +4,6 @@ import { TagsFilter } from "./TagsFilter"
|
|||
export class Tag extends TagsFilter {
|
||||
public key: string
|
||||
public value: string
|
||||
public static newlyCreated = new Tag("_newly_created", "yes")
|
||||
constructor(key: string, value: string) {
|
||||
super()
|
||||
this.key = key
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue