diff --git a/Customizations/AllKnownLayers.ts b/Customizations/AllKnownLayers.ts index d5f1350d2e..a4a9d6c9d9 100644 --- a/Customizations/AllKnownLayers.ts +++ b/Customizations/AllKnownLayers.ts @@ -20,7 +20,7 @@ export default class AllKnownLayers { public static sharedLayersJson: Map = 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 diff --git a/Logic/State/MapState.ts b/Logic/State/MapState.ts index 815ea54d3d..4627dad25b 100644 --- a/Logic/State/MapState.ts +++ b/Logic/State/MapState.ts @@ -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) { @@ -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 diff --git a/assets/layers/current_view/current_view.json b/assets/layers/current_view/current_view.json index 0e0dcd235c..5b4aacd37d 100644 --- a/assets/layers/current_view/current_view.json +++ b/assets/layers/current_view/current_view.json @@ -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" + } + ] } \ No newline at end of file