First attempt for a current-view box

This commit is contained in:
pietervdvn 2021-12-10 15:51:08 +01:00
parent ee3a18def1
commit dc5b777713
3 changed files with 45 additions and 3 deletions

View file

@ -20,7 +20,7 @@ export default class AllKnownLayers {
public static sharedLayersJson: Map<string, any> = AllKnownLayers.getSharedLayersJson();
public static added_by_default: string[] = ["gps_location", "gps_location_history", "home_location", "gps_track",]
public static added_by_default: string[] = ["gps_location", "gps_location_history", "home_location", "gps_track","current_view"]
public static no_include: string[] = ["conflation", "left_right_style", "split_point"]
/**
* Layer IDs of layers which have special properties through built-in hooks

View file

@ -17,6 +17,7 @@ import {FeatureSourceForLayer, Tiled} from "../FeatureSource/FeatureSource";
import SimpleFeatureSource from "../FeatureSource/Sources/SimpleFeatureSource";
import {LocalStorageSource} from "../Web/LocalStorageSource";
import {GeoOperations} from "../GeoOperations";
import StaticFeatureSource from "../FeatureSource/Sources/StaticFeatureSource";
/**
* Contains all the leaflet-map related state
@ -44,11 +45,12 @@ export default class MapState extends UserRelatedState {
lon: number;
}> = new UIEventSource<{ lat: number; lon: number }>(undefined);
public currentView: FeatureSourceForLayer
/**
* The location as delivered by the GPS
*/
public currentUserLocation: FeatureSourceForLayer & Tiled;
/**
* All previously visited points
*/
@ -125,6 +127,7 @@ export default class MapState extends UserRelatedState {
this.initHomeLocation()
this.initGpsLocation()
this.initUserLocationTrail()
this.initCurrentView()
}
public AddAllOverlaysToMap(leafletMap: UIEventSource<any>) {
@ -169,6 +172,34 @@ export default class MapState extends UserRelatedState {
})
}
}
private initCurrentView(){
const features : UIEventSource<{ feature: any, freshness: Date }[]>= this.currentBounds.map(bounds => {
const feature = {
freshness: new Date(),
feature: {
type: "Polygon",
properties:{
id:"current_view"
},
geometry:{
type:"Polygon",
coordinates:[
[bounds.maxLon, bounds.maxLat],
[bounds.minLon, bounds.maxLat],
[bounds.minLon, bounds.minLat],
[bounds.maxLon, bounds.minLat],
[bounds.maxLon, bounds.maxLat],
]
}
}
}
return [feature]
})
let currentViewLayer: FilteredLayer = this.filteredLayers.data.filter(l => l.layerDef.id === "current_view")[0]
this.currentView = new SimpleFeatureSource(currentViewLayer,0,features)
}
private initGpsLocation() {
// Initialize the gps layer data. This is emtpy for now, the actual writing happens in the Geolocationhandler

View file

@ -1,3 +1,14 @@
{
"id": "current_view",
"description": "A meta-layer which contains one single feature, namely the BBOX of the current map view. This can be used to trigger special actions. If a popup is defined for this layer, this popup will be accessible via an extra button on screen",
"source": {
"osmTags": "id=currentView"
},
"title": "Current View",
"tagRenderings": [],
"mapRendering": [
{
"color": "#cccc0088"
}
]
}