forked from MapComplete/MapComplete
chore: automated housekeeping...
This commit is contained in:
parent
8ef7af613f
commit
00151afdea
114 changed files with 2857 additions and 2135 deletions
|
|
@ -1,5 +1,10 @@
|
|||
import { ImmutableStore, Store, UIEventSource } from "../../Logic/UIEventSource"
|
||||
import maplibregl, { Map as MLMap, Map as MlMap, ScaleControl, SourceSpecification } from "maplibre-gl"
|
||||
import maplibregl, {
|
||||
Map as MLMap,
|
||||
Map as MlMap,
|
||||
ScaleControl,
|
||||
SourceSpecification,
|
||||
} from "maplibre-gl"
|
||||
import { RasterLayerPolygon } from "../../Models/RasterLayers"
|
||||
import { Utils } from "../../Utils"
|
||||
import { BBox } from "../../Logic/BBox"
|
||||
|
|
@ -43,10 +48,16 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap {
|
|||
readonly allowRotating: UIEventSource<true | boolean | undefined>
|
||||
readonly allowZooming: UIEventSource<true | boolean | undefined>
|
||||
readonly lastClickLocation: Store<
|
||||
undefined | { lon: number; lat: number; mode: "left" | "right" | "middle" , /**
|
||||
* The nearest feature from a MapComplete layer
|
||||
*/
|
||||
nearestFeature?: Feature }
|
||||
| undefined
|
||||
| {
|
||||
lon: number
|
||||
lat: number
|
||||
mode: "left" | "right" | "middle"
|
||||
/**
|
||||
* The nearest feature from a MapComplete layer
|
||||
*/
|
||||
nearestFeature?: Feature
|
||||
}
|
||||
>
|
||||
readonly minzoom: UIEventSource<number>
|
||||
readonly maxzoom: UIEventSource<number>
|
||||
|
|
@ -64,9 +75,13 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap {
|
|||
|
||||
private readonly _maplibreMap: Store<MLMap>
|
||||
|
||||
constructor(maplibreMap: Store<MLMap>, state?: Partial<MapProperties>, options?:{
|
||||
correctClick?: number
|
||||
}) {
|
||||
constructor(
|
||||
maplibreMap: Store<MLMap>,
|
||||
state?: Partial<MapProperties>,
|
||||
options?: {
|
||||
correctClick?: number
|
||||
}
|
||||
) {
|
||||
if (!MapLibreAdaptor.pmtilesInited) {
|
||||
maplibregl.addProtocol("pmtiles", new Protocol().tile)
|
||||
MapLibreAdaptor.pmtilesInited = true
|
||||
|
|
@ -106,7 +121,7 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap {
|
|||
const lastClickLocation = new UIEventSource<{
|
||||
lat: number
|
||||
lon: number
|
||||
mode: "left" | "right" | "middle",
|
||||
mode: "left" | "right" | "middle"
|
||||
nearestFeature?: Feature
|
||||
}>(undefined)
|
||||
this.lastClickLocation = lastClickLocation
|
||||
|
|
@ -126,30 +141,32 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap {
|
|||
const mouseEvent: MouseEvent = e.originalEvent
|
||||
mode = mode ?? clickmodes[mouseEvent.button]
|
||||
let nearestFeature: Feature = undefined
|
||||
if(options?.correctClick && maplibreMap.data){
|
||||
if (options?.correctClick && maplibreMap.data) {
|
||||
const map = maplibreMap.data
|
||||
const point = e.point
|
||||
const buffer = options?.correctClick
|
||||
const features = map.queryRenderedFeatures([
|
||||
[point.x - buffer, point.y - buffer],
|
||||
[point.x + buffer, point.y + buffer]
|
||||
]).filter(f => f.source.startsWith("mapcomplete_"))
|
||||
if(features.length === 1){
|
||||
const features = map
|
||||
.queryRenderedFeatures([
|
||||
[point.x - buffer, point.y - buffer],
|
||||
[point.x + buffer, point.y + buffer],
|
||||
])
|
||||
.filter((f) => f.source.startsWith("mapcomplete_"))
|
||||
if (features.length === 1) {
|
||||
nearestFeature = features[0]
|
||||
}else{
|
||||
} else {
|
||||
let nearestD: number = undefined
|
||||
for (const feature of features) {
|
||||
let d: number // in meter
|
||||
if(feature.geometry.type === "LineString"){
|
||||
const way = <Feature<LineString>> feature
|
||||
const lngLat:[number,number] = [e.lngLat.lng, e.lngLat.lat]
|
||||
if (feature.geometry.type === "LineString") {
|
||||
const way = <Feature<LineString>>feature
|
||||
const lngLat: [number, number] = [e.lngLat.lng, e.lngLat.lat]
|
||||
const p = GeoOperations.nearestPoint(way, lngLat)
|
||||
console.log(">>>",p, way, lngLat)
|
||||
if(!p){
|
||||
console.log(">>>", p, way, lngLat)
|
||||
if (!p) {
|
||||
continue
|
||||
}
|
||||
d = p.properties.dist * 1000
|
||||
if(nearestFeature === undefined || d < nearestD){
|
||||
if (nearestFeature === undefined || d < nearestD) {
|
||||
nearestFeature = way
|
||||
nearestD = d
|
||||
}
|
||||
|
|
@ -158,7 +175,6 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap {
|
|||
}
|
||||
}
|
||||
lastClickLocation.setData({ lon, lat, mode, nearestFeature })
|
||||
|
||||
}
|
||||
|
||||
maplibreMap.addCallbackAndRunD((map) => {
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class PointRenderingLayer {
|
|||
visibility?: Store<boolean>,
|
||||
fetchStore?: (id: string) => Store<Record<string, string>>,
|
||||
onClick?: (feature: Feature) => void,
|
||||
selectedElement?: Store<{ properties: { id?: string } }>,
|
||||
selectedElement?: Store<{ properties: { id?: string } }>
|
||||
) {
|
||||
this._visibility = visibility
|
||||
this._config = config
|
||||
|
|
@ -98,7 +98,7 @@ class PointRenderingLayer {
|
|||
" while rendering",
|
||||
location,
|
||||
"of",
|
||||
this._config,
|
||||
this._config
|
||||
)
|
||||
}
|
||||
const id = feature.properties.id + "-" + location
|
||||
|
|
@ -110,7 +110,10 @@ class PointRenderingLayer {
|
|||
this.addPoint(feature, <[number, number]>loc)
|
||||
}
|
||||
}
|
||||
if (feature.geometry.type === "MultiLineString" || feature.geometry.type === "Polygon") {
|
||||
if (
|
||||
feature.geometry.type === "MultiLineString" ||
|
||||
feature.geometry.type === "Polygon"
|
||||
) {
|
||||
for (const coors of feature.geometry.coordinates) {
|
||||
for (const loc of coors) {
|
||||
this.addPoint(feature, <[number, number]>loc)
|
||||
|
|
@ -122,7 +125,7 @@ class PointRenderingLayer {
|
|||
|
||||
const loc = GeoOperations.featureToCoordinateWithRenderingType(
|
||||
<any>feature,
|
||||
location,
|
||||
location
|
||||
)
|
||||
if (loc === undefined) {
|
||||
continue
|
||||
|
|
@ -251,7 +254,7 @@ class LineRenderingLayer {
|
|||
config: LineRenderingConfig,
|
||||
visibility?: Store<boolean>,
|
||||
fetchStore?: (id: string) => Store<Record<string, string>>,
|
||||
onClick?: (feature: Feature) => void,
|
||||
onClick?: (feature: Feature) => void
|
||||
) {
|
||||
this._layername = layername
|
||||
this._map = map
|
||||
|
|
@ -271,7 +274,7 @@ class LineRenderingLayer {
|
|||
|
||||
private async addSymbolLayer(
|
||||
sourceId: string,
|
||||
imageAlongWay: { if?: TagsFilter; then: string }[],
|
||||
imageAlongWay: { if?: TagsFilter; then: string }[]
|
||||
) {
|
||||
const map = this._map
|
||||
await Promise.allSettled(
|
||||
|
|
@ -301,7 +304,7 @@ class LineRenderingLayer {
|
|||
spec.filter = filter
|
||||
}
|
||||
map.addLayer(spec)
|
||||
}),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -311,7 +314,7 @@ class LineRenderingLayer {
|
|||
* @private
|
||||
*/
|
||||
private calculatePropsFor(
|
||||
properties: Record<string, string>,
|
||||
properties: Record<string, string>
|
||||
): Partial<Record<(typeof LineRenderingLayer.lineConfigKeys)[number], string>> {
|
||||
const config = this._config
|
||||
|
||||
|
|
@ -393,7 +396,7 @@ class LineRenderingLayer {
|
|||
} catch (e) {
|
||||
console.error(
|
||||
`Invalid dasharray in layer ${this._layername}:`,
|
||||
this._config.dashArray,
|
||||
this._config.dashArray
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -410,11 +413,11 @@ class LineRenderingLayer {
|
|||
}
|
||||
map.setFeatureState(
|
||||
{ source: this._layername, id: feature.properties.id },
|
||||
this.calculatePropsFor(feature.properties),
|
||||
this.calculatePropsFor(feature.properties)
|
||||
)
|
||||
}
|
||||
|
||||
if(this._onClick){
|
||||
if (this._onClick) {
|
||||
map.on("click", linelayer, (e) => {
|
||||
// line-layer-listener
|
||||
e.originalEvent["consumed"] = true
|
||||
|
|
@ -455,7 +458,7 @@ class LineRenderingLayer {
|
|||
"Error while setting visibility of layers ",
|
||||
linelayer,
|
||||
polylayer,
|
||||
e,
|
||||
e
|
||||
)
|
||||
}
|
||||
})
|
||||
|
|
@ -476,7 +479,7 @@ class LineRenderingLayer {
|
|||
console.trace(
|
||||
"Got a feature without ID; this causes rendering bugs:",
|
||||
feature,
|
||||
"from",
|
||||
"from"
|
||||
)
|
||||
LineRenderingLayer.missingIdTriggered = true
|
||||
}
|
||||
|
|
@ -488,7 +491,7 @@ class LineRenderingLayer {
|
|||
if (this._fetchStore === undefined) {
|
||||
map.setFeatureState(
|
||||
{ source: this._layername, id },
|
||||
this.calculatePropsFor(feature.properties),
|
||||
this.calculatePropsFor(feature.properties)
|
||||
)
|
||||
} else {
|
||||
const tags = this._fetchStore(id)
|
||||
|
|
@ -505,7 +508,7 @@ class LineRenderingLayer {
|
|||
}
|
||||
map.setFeatureState(
|
||||
{ source: this._layername, id },
|
||||
this.calculatePropsFor(properties),
|
||||
this.calculatePropsFor(properties)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
@ -529,7 +532,7 @@ export default class ShowDataLayer {
|
|||
layer: LayerConfig
|
||||
drawMarkers?: true | boolean
|
||||
drawLines?: true | boolean
|
||||
},
|
||||
}
|
||||
) {
|
||||
this._options = options
|
||||
this.onDestroy.push(map.addCallbackAndRunD((map) => this.initDrawFeatures(map)))
|
||||
|
|
@ -539,7 +542,7 @@ export default class ShowDataLayer {
|
|||
mlmap: UIEventSource<MlMap>,
|
||||
features: FeatureSource,
|
||||
layers: LayerConfig[],
|
||||
options?: Partial<ShowDataLayerOptions>,
|
||||
options?: Partial<ShowDataLayerOptions>
|
||||
) {
|
||||
const perLayer: PerLayerFeatureSourceSplitter<FeatureSourceForLayer> =
|
||||
new PerLayerFeatureSourceSplitter(
|
||||
|
|
@ -547,7 +550,7 @@ export default class ShowDataLayer {
|
|||
features,
|
||||
{
|
||||
constructStore: (features, layer) => new SimpleFeatureSource(layer, features),
|
||||
},
|
||||
}
|
||||
)
|
||||
if (options?.zoomToFeatures) {
|
||||
options.zoomToFeatures = false
|
||||
|
|
@ -571,7 +574,7 @@ export default class ShowDataLayer {
|
|||
public static showRange(
|
||||
map: Store<MlMap>,
|
||||
features: FeatureSource,
|
||||
doShowLayer?: Store<boolean>,
|
||||
doShowLayer?: Store<boolean>
|
||||
): ShowDataLayer {
|
||||
return new ShowDataLayer(map, {
|
||||
layer: ShowDataLayer.rangeLayer,
|
||||
|
|
@ -580,8 +583,7 @@ export default class ShowDataLayer {
|
|||
})
|
||||
}
|
||||
|
||||
public destruct() {
|
||||
}
|
||||
public destruct() {}
|
||||
|
||||
private static zoomToCurrentFeatures(map: MlMap, features: Feature[]) {
|
||||
if (!features || !map || features.length == 0) {
|
||||
|
|
@ -605,8 +607,8 @@ export default class ShowDataLayer {
|
|||
this._options.layer.title === undefined
|
||||
? undefined
|
||||
: (feature: Feature) => {
|
||||
selectedElement?.setData(feature)
|
||||
}
|
||||
selectedElement?.setData(feature)
|
||||
}
|
||||
}
|
||||
if (this._options.drawLines !== false) {
|
||||
for (let i = 0; i < this._options.layer.lineRendering.length; i++) {
|
||||
|
|
@ -618,7 +620,7 @@ export default class ShowDataLayer {
|
|||
lineRenderingConfig,
|
||||
doShowLayer,
|
||||
fetchStore,
|
||||
onClick,
|
||||
onClick
|
||||
)
|
||||
this.onDestroy.push(l.destruct)
|
||||
}
|
||||
|
|
@ -634,13 +636,13 @@ export default class ShowDataLayer {
|
|||
doShowLayer,
|
||||
fetchStore,
|
||||
onClick,
|
||||
selectedElement,
|
||||
selectedElement
|
||||
)
|
||||
}
|
||||
}
|
||||
if (this._options.zoomToFeatures) {
|
||||
features.features.addCallbackAndRunD((features) =>
|
||||
ShowDataLayer.zoomToCurrentFeatures(map, features),
|
||||
ShowDataLayer.zoomToCurrentFeatures(map, features)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue