forked from MapComplete/MapComplete
		
	Fix: attempts to stabilize
This commit is contained in:
		
							parent
							
								
									686ad70511
								
							
						
					
					
						commit
						ae84207555
					
				
					 4 changed files with 31 additions and 24 deletions
				
			
		|  | @ -76,7 +76,7 @@ export default class SaveFeatureSourceToLocalStorage { | ||||||
|         const storage = TileLocalStorage.construct<Feature[]>(backend, layername, maxCacheAge) |         const storage = TileLocalStorage.construct<Feature[]>(backend, layername, maxCacheAge) | ||||||
|         this.storage = storage |         this.storage = storage | ||||||
|         const singleTileSavers: Map<number, SingleTileSaver> = new Map<number, SingleTileSaver>() |         const singleTileSavers: Map<number, SingleTileSaver> = new Map<number, SingleTileSaver>() | ||||||
|         features.features.addCallbackAndRunD((features) => { |         features.features.stabilized(5000).addCallbackAndRunD((features) => { | ||||||
|             if ( |             if ( | ||||||
|                 features.some((f) => { |                 features.some((f) => { | ||||||
|                     let totalPoints = 0 |                     let totalPoints = 0 | ||||||
|  | @ -116,7 +116,7 @@ export default class SaveFeatureSourceToLocalStorage { | ||||||
|                     tileSaver = new SingleTileSaver(src, featureProperties) |                     tileSaver = new SingleTileSaver(src, featureProperties) | ||||||
|                     singleTileSavers.set(tileIndex, tileSaver) |                     singleTileSavers.set(tileIndex, tileSaver) | ||||||
|                 } |                 } | ||||||
|                 // Don't cache not-uploaded features yet - they'll be cached when the receive their id
 |                 // Don't cache not-uploaded features yet - they'll be cached when they receive their id
 | ||||||
|                 features = features.filter((f) => !f.properties.id.match(/(node|way)\/-[0-9]+/)) |                 features = features.filter((f) => !f.properties.id.match(/(node|way)\/-[0-9]+/)) | ||||||
|                 tileSaver.saveFeatures(features) |                 tileSaver.saveFeatures(features) | ||||||
|             }) |             }) | ||||||
|  |  | ||||||
|  | @ -116,7 +116,7 @@ export class AvailableRasterLayers { | ||||||
|             availableLayersBboxes.map( |             availableLayersBboxes.map( | ||||||
|                 (eliPolygons) => { |                 (eliPolygons) => { | ||||||
|                     const loc = location.data |                     const loc = location.data | ||||||
|                     const lonlat: [number, number] = [loc.lon, loc.lat] |                     const lonlat: [number, number] = [loc?.lon ?? 0, loc?.lat ?? 0] | ||||||
|                     const matching: RasterLayerPolygon[] = eliPolygons.filter((eliPolygon) => { |                     const matching: RasterLayerPolygon[] = eliPolygons.filter((eliPolygon) => { | ||||||
|                         if (eliPolygon.geometry === null) { |                         if (eliPolygon.geometry === null) { | ||||||
|                             return true // global ELI-layer
 |                             return true // global ELI-layer
 | ||||||
|  |  | ||||||
|  | @ -24,13 +24,13 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap { | ||||||
|         "dragRotate", |         "dragRotate", | ||||||
|         "dragPan", |         "dragPan", | ||||||
|         "keyboard", |         "keyboard", | ||||||
|         "touchZoomRotate", |         "touchZoomRotate" | ||||||
|     ] |     ] | ||||||
|     private static maplibre_zoom_handlers = [ |     private static maplibre_zoom_handlers = [ | ||||||
|         "scrollZoom", |         "scrollZoom", | ||||||
|         "boxZoom", |         "boxZoom", | ||||||
|         "doubleClickZoom", |         "doubleClickZoom", | ||||||
|         "touchZoomRotate", |         "touchZoomRotate" | ||||||
|     ] |     ] | ||||||
|     readonly location: UIEventSource<{ lon: number; lat: number }> |     readonly location: UIEventSource<{ lon: number; lat: number }> | ||||||
|     private readonly isFlying = new UIEventSource(false) |     private readonly isFlying = new UIEventSource(false) | ||||||
|  | @ -44,14 +44,14 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap { | ||||||
|     readonly lastClickLocation: Store< |     readonly lastClickLocation: Store< | ||||||
|         | undefined |         | undefined | ||||||
|         | { |         | { | ||||||
|               lon: number |         lon: number | ||||||
|               lat: number |         lat: number | ||||||
|               mode: "left" | "right" | "middle" |         mode: "left" | "right" | "middle" | ||||||
|               /** |         /** | ||||||
|                * The nearest feature from a MapComplete layer |          * The nearest feature from a MapComplete layer | ||||||
|                */ |          */ | ||||||
|               nearestFeature?: Feature |         nearestFeature?: Feature | ||||||
|           } |     } | ||||||
|     > |     > | ||||||
|     readonly minzoom: UIEventSource<number> |     readonly minzoom: UIEventSource<number> | ||||||
|     readonly maxzoom: UIEventSource<number> |     readonly maxzoom: UIEventSource<number> | ||||||
|  | @ -141,7 +141,7 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap { | ||||||
|                 const features = map |                 const features = map | ||||||
|                     .queryRenderedFeatures([ |                     .queryRenderedFeatures([ | ||||||
|                         [point.x - buffer, point.y - buffer], |                         [point.x - buffer, point.y - buffer], | ||||||
|                         [point.x + buffer, point.y + buffer], |                         [point.x + buffer, point.y + buffer] | ||||||
|                     ]) |                     ]) | ||||||
|                     .filter((f) => f.source.startsWith("mapcomplete_")) |                     .filter((f) => f.source.startsWith("mapcomplete_")) | ||||||
|                 if (features.length === 1) { |                 if (features.length === 1) { | ||||||
|  | @ -281,9 +281,9 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap { | ||||||
|         return { |         return { | ||||||
|             map: mlmap, |             map: mlmap, | ||||||
|             ui: new SvelteUIElement(MaplibreMap, { |             ui: new SvelteUIElement(MaplibreMap, { | ||||||
|                 map: mlmap, |                 map: mlmap | ||||||
|             }), |             }), | ||||||
|             mapproperties: new MapLibreAdaptor(mlmap), |             mapproperties: new MapLibreAdaptor(mlmap) | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -347,7 +347,7 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap { | ||||||
|     ) { |     ) { | ||||||
|         const event = { |         const event = { | ||||||
|             date: new Date(), |             date: new Date(), | ||||||
|             key: key, |             key: key | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         for (let i = 0; i < this._onKeyNavigation.length; i++) { |         for (let i = 0; i < this._onKeyNavigation.length; i++) { | ||||||
|  | @ -536,7 +536,7 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap { | ||||||
|         const bounds = map.getBounds() |         const bounds = map.getBounds() | ||||||
|         const bbox = new BBox([ |         const bbox = new BBox([ | ||||||
|             [bounds.getEast(), bounds.getNorth()], |             [bounds.getEast(), bounds.getNorth()], | ||||||
|             [bounds.getWest(), bounds.getSouth()], |             [bounds.getWest(), bounds.getSouth()] | ||||||
|         ]) |         ]) | ||||||
|         if (this.bounds.data === undefined || !isSetup) { |         if (this.bounds.data === undefined || !isSetup) { | ||||||
|             this.bounds.setData(bbox) |             this.bounds.setData(bbox) | ||||||
|  | @ -611,8 +611,11 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap { | ||||||
|         if (!map) { |         if (!map) { | ||||||
|             return |             return | ||||||
|         } |         } | ||||||
|  |         console.log("Bounds are", bbox?.asGeometry()) | ||||||
|         if (bbox) { |         if (bbox) { | ||||||
|             map?.setMaxBounds(bbox.toLngLat()) |             if (GeoOperations.surfaceAreaInSqMeters(bbox.asGeojsonCached()) > 1) { | ||||||
|  |                 map?.setMaxBounds(bbox.toLngLat()) | ||||||
|  |             } | ||||||
|         } else { |         } else { | ||||||
|             map?.setMaxBounds(null) |             map?.setMaxBounds(null) | ||||||
|         } |         } | ||||||
|  | @ -730,14 +733,14 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap { | ||||||
|                 type: "raster-dem", |                 type: "raster-dem", | ||||||
|                 url: |                 url: | ||||||
|                     "https://api.maptiler.com/tiles/terrain-rgb/tiles.json?key=" + |                     "https://api.maptiler.com/tiles/terrain-rgb/tiles.json?key=" + | ||||||
|                     Constants.maptilerApiKey, |                     Constants.maptilerApiKey | ||||||
|             }) |             }) | ||||||
|             try { |             try { | ||||||
|                 while (!map?.isStyleLoaded()) { |                 while (!map?.isStyleLoaded()) { | ||||||
|                     await Utils.waitFor(250) |                     await Utils.waitFor(250) | ||||||
|                 } |                 } | ||||||
|                 map.setTerrain({ |                 map.setTerrain({ | ||||||
|                     source: id, |                     source: id | ||||||
|                 }) |                 }) | ||||||
|             } catch (e) { |             } catch (e) { | ||||||
|                 console.error(e) |                 console.error(e) | ||||||
|  | @ -762,7 +765,7 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap { | ||||||
|         if (this.scaleControl === undefined) { |         if (this.scaleControl === undefined) { | ||||||
|             this.scaleControl = new ScaleControl({ |             this.scaleControl = new ScaleControl({ | ||||||
|                 maxWidth: 100, |                 maxWidth: 100, | ||||||
|                 unit: "metric", |                 unit: "metric" | ||||||
|             }) |             }) | ||||||
|         } |         } | ||||||
|         if (!map.hasControl(this.scaleControl)) { |         if (!map.hasControl(this.scaleControl)) { | ||||||
|  | @ -775,7 +778,7 @@ export class MapLibreAdaptor implements MapProperties, ExportableMap { | ||||||
|         window.requestAnimationFrame(() => { |         window.requestAnimationFrame(() => { | ||||||
|             this._maplibreMap.data?.flyTo({ |             this._maplibreMap.data?.flyTo({ | ||||||
|                 zoom, |                 zoom, | ||||||
|                 center: [lon, lat], |                 center: [lon, lat] | ||||||
|             }) |             }) | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -590,7 +590,11 @@ export default class ShowDataLayer { | ||||||
|         } |         } | ||||||
|         const bbox = BBox.bboxAroundAll(features.map(BBox.get)) |         const bbox = BBox.bboxAroundAll(features.map(BBox.get)) | ||||||
|         window.requestAnimationFrame(() => { |         window.requestAnimationFrame(() => { | ||||||
|             map.resize() |             try { | ||||||
|  |                 map.resize() | ||||||
|  |             } catch (e) { | ||||||
|  |                 console.error("Could not resize the map in preparation of zoomToCurrentFeatures; the error is:", e) | ||||||
|  |             } | ||||||
|             map.fitBounds(bbox.toLngLat(), { |             map.fitBounds(bbox.toLngLat(), { | ||||||
|                 padding: { top: 10, bottom: 10, left: 10, right: 10 }, |                 padding: { top: 10, bottom: 10, left: 10, right: 10 }, | ||||||
|                 animate: false, |                 animate: false, | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue