forked from MapComplete/MapComplete
Download button: take advantage of MVT server, download button will now attempt to download everything
This commit is contained in:
parent
bccda67e1c
commit
e4eb8d6b52
21 changed files with 453 additions and 353 deletions
|
@ -1,30 +1,31 @@
|
|||
import { FeatureSourceForTile } from "../FeatureSource"
|
||||
import { FeatureSourceForTile, UpdatableFeatureSource } from "../FeatureSource"
|
||||
import { Store } from "../../UIEventSource"
|
||||
import { BBox } from "../../BBox"
|
||||
import { Utils } from "../../../Utils"
|
||||
import { Feature, LineString, MultiLineString, Position } from "geojson"
|
||||
import { Tiles } from "../../../Models/TileRange"
|
||||
import { Feature, MultiLineString, Position } from "geojson"
|
||||
import { GeoOperations } from "../../GeoOperations"
|
||||
import DynamicTileSource from "./DynamicTileSource"
|
||||
import { UpdatableDynamicTileSource } from "./DynamicTileSource"
|
||||
|
||||
/**
|
||||
* The PolygonSourceMerger receives various small pieces of bigger polygons and stitches them together.
|
||||
* This is used to reconstruct polygons of vector tiles
|
||||
*/
|
||||
export class LineSourceMerger extends DynamicTileSource<FeatureSourceForTile> {
|
||||
export class LineSourceMerger extends UpdatableDynamicTileSource<
|
||||
FeatureSourceForTile & UpdatableFeatureSource
|
||||
> {
|
||||
private readonly _zoomlevel: Store<number>
|
||||
|
||||
constructor(
|
||||
zoomlevel: Store<number>,
|
||||
minzoom: number,
|
||||
constructSource: (tileIndex: number) => FeatureSourceForTile,
|
||||
constructSource: (tileIndex: number) => FeatureSourceForTile & UpdatableFeatureSource,
|
||||
mapProperties: {
|
||||
bounds: Store<BBox>
|
||||
zoom: Store<number>
|
||||
},
|
||||
options?: {
|
||||
isActive?: Store<boolean>
|
||||
},
|
||||
}
|
||||
) {
|
||||
super(zoomlevel, minzoom, constructSource, mapProperties, options)
|
||||
this._zoomlevel = zoomlevel
|
||||
|
@ -35,33 +36,30 @@ export class LineSourceMerger extends DynamicTileSource<FeatureSourceForTile> {
|
|||
const all: Map<string, Feature<MultiLineString>> = new Map()
|
||||
const currentZoom = this._zoomlevel?.data ?? 0
|
||||
for (const source of sources) {
|
||||
if(source.z != currentZoom){
|
||||
if (source.z != currentZoom) {
|
||||
continue
|
||||
}
|
||||
const bboxCoors = Tiles.tile_bounds_lon_lat(source.z, source.x, source.y)
|
||||
const bboxGeo = new BBox(bboxCoors).asGeoJson({})
|
||||
for (const f of source.features.data) {
|
||||
const id = f.properties.id
|
||||
const coordinates : Position[][] = []
|
||||
if(f.geometry.type === "LineString"){
|
||||
const coordinates: Position[][] = []
|
||||
if (f.geometry.type === "LineString") {
|
||||
coordinates.push(f.geometry.coordinates)
|
||||
}else if(f.geometry.type === "MultiLineString"){
|
||||
} else if (f.geometry.type === "MultiLineString") {
|
||||
coordinates.push(...f.geometry.coordinates)
|
||||
}else {
|
||||
} else {
|
||||
console.error("Invalid geometry type:", f.geometry.type)
|
||||
continue
|
||||
}
|
||||
const oldV = all.get(id)
|
||||
if(!oldV){
|
||||
|
||||
all.set(id, {
|
||||
type: "Feature",
|
||||
properties: f.properties,
|
||||
geometry:{
|
||||
type:"MultiLineString",
|
||||
coordinates
|
||||
}
|
||||
})
|
||||
if (!oldV) {
|
||||
all.set(id, {
|
||||
type: "Feature",
|
||||
properties: f.properties,
|
||||
geometry: {
|
||||
type: "MultiLineString",
|
||||
coordinates,
|
||||
},
|
||||
})
|
||||
continue
|
||||
}
|
||||
oldV.geometry.coordinates.push(...coordinates)
|
||||
|
@ -70,11 +68,13 @@ export class LineSourceMerger extends DynamicTileSource<FeatureSourceForTile> {
|
|||
|
||||
const keys = Array.from(all.keys())
|
||||
for (const key of keys) {
|
||||
all.set(key, <any> GeoOperations.attemptLinearize(<Feature<MultiLineString>>all.get(key)))
|
||||
all.set(
|
||||
key,
|
||||
<any>GeoOperations.attemptLinearize(<Feature<MultiLineString>>all.get(key))
|
||||
)
|
||||
}
|
||||
const newList = Array.from(all.values())
|
||||
this.features.setData(newList)
|
||||
this._featuresById.setData(all)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue