Add location locking functionality
This commit is contained in:
parent
94c0b8667a
commit
19582853f5
5 changed files with 34 additions and 5 deletions
|
@ -48,6 +48,8 @@ export default class LayerConfig {
|
||||||
}[];
|
}[];
|
||||||
|
|
||||||
tagRenderings: TagRenderingConfig [];
|
tagRenderings: TagRenderingConfig [];
|
||||||
|
|
||||||
|
private readonly configuration_warnings : string[] = []
|
||||||
|
|
||||||
constructor(json: LayerConfigJson,
|
constructor(json: LayerConfigJson,
|
||||||
context?: string) {
|
context?: string) {
|
||||||
|
|
|
@ -31,6 +31,7 @@ export default class LayoutConfig {
|
||||||
};
|
};
|
||||||
|
|
||||||
public readonly hideFromOverview: boolean;
|
public readonly hideFromOverview: boolean;
|
||||||
|
public readonly lockLocation: boolean | [[number,number],[number, number]];
|
||||||
public readonly enableUserBadge: boolean;
|
public readonly enableUserBadge: boolean;
|
||||||
public readonly enableShareScreen: boolean;
|
public readonly enableShareScreen: boolean;
|
||||||
public readonly enableMoreQuests: boolean;
|
public readonly enableMoreQuests: boolean;
|
||||||
|
@ -149,7 +150,7 @@ export default class LayoutConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.hideFromOverview = json.hideFromOverview ?? false;
|
this.hideFromOverview = json.hideFromOverview ?? false;
|
||||||
|
this.lockLocation = json.lockLocation ?? false;
|
||||||
this.enableUserBadge = json.enableUserBadge ?? true;
|
this.enableUserBadge = json.enableUserBadge ?? true;
|
||||||
this.enableShareScreen = json.enableShareScreen ?? true;
|
this.enableShareScreen = json.enableShareScreen ?? true;
|
||||||
this.enableMoreQuests = json.enableMoreQuests ?? true;
|
this.enableMoreQuests = json.enableMoreQuests ?? true;
|
||||||
|
|
|
@ -158,6 +158,13 @@ export interface LayoutConfigJson {
|
||||||
*/
|
*/
|
||||||
hideFromOverview?: boolean;
|
hideFromOverview?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If set to true, the basemap will not scroll outside of the area visible on initial zoom.
|
||||||
|
* If set to [[lat0, lon0], [lat1, lon1]], the map will not scroll outside of those bounds.
|
||||||
|
* Off by default, which will enable panning to the entire world
|
||||||
|
*/
|
||||||
|
lockLocation?: boolean | [[number, number], [number, number]];
|
||||||
|
|
||||||
enableUserBadge?: boolean;
|
enableUserBadge?: boolean;
|
||||||
enableShareScreen?: boolean;
|
enableShareScreen?: boolean;
|
||||||
enableMoreQuests?: boolean;
|
enableMoreQuests?: boolean;
|
||||||
|
|
|
@ -15,6 +15,8 @@ export default class TagRenderingConfig {
|
||||||
readonly render?: Translation;
|
readonly render?: Translation;
|
||||||
readonly question?: Translation;
|
readonly question?: Translation;
|
||||||
readonly condition?: TagsFilter;
|
readonly condition?: TagsFilter;
|
||||||
|
|
||||||
|
readonly configuration_warnings : string[] = []
|
||||||
|
|
||||||
readonly freeform?: {
|
readonly freeform?: {
|
||||||
readonly key: string,
|
readonly key: string,
|
||||||
|
@ -152,7 +154,7 @@ export default class TagRenderingConfig {
|
||||||
for (const expectedKey of keys) {
|
for (const expectedKey of keys) {
|
||||||
if(usedKeys.indexOf(expectedKey) < 0){
|
if(usedKeys.indexOf(expectedKey) < 0){
|
||||||
const msg = `${context}.mappings[${i}]: This mapping only defines values for ${usedKeys.join(', ')}, but it should also give a value for ${expectedKey}`
|
const msg = `${context}.mappings[${i}]: This mapping only defines values for ${usedKeys.join(', ')}, but it should also give a value for ${expectedKey}`
|
||||||
console.warn(msg)
|
this.configuration_warnings.push(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -258,8 +258,8 @@ export class InitUiElements {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
isOpened.setData(Hash.hash.data === undefined)
|
isOpened.setData(Hash.hash.data === undefined)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static InitLayerSelection() {
|
private static InitLayerSelection() {
|
||||||
|
@ -276,7 +276,7 @@ export class InitUiElements {
|
||||||
const copyrightNotice =
|
const copyrightNotice =
|
||||||
new ScrollableFullScreen(
|
new ScrollableFullScreen(
|
||||||
() => Translations.t.general.attribution.attributionTitle.Clone(),
|
() => Translations.t.general.attribution.attributionTitle.Clone(),
|
||||||
() => new Combine([
|
() => new Combine([
|
||||||
Translations.t.general.attribution.attributionContent,
|
Translations.t.general.attribution.attributionContent,
|
||||||
"<br/>",
|
"<br/>",
|
||||||
new Attribution(undefined, undefined, State.state.layoutToUse, undefined)
|
new Attribution(undefined, undefined, State.state.layoutToUse, undefined)
|
||||||
|
@ -335,6 +335,7 @@ export class InitUiElements {
|
||||||
|
|
||||||
const attr = new Attribution(State.state.locationControl, State.state.osmConnection.userDetails, State.state.layoutToUse,
|
const attr = new Attribution(State.state.locationControl, State.state.osmConnection.userDetails, State.state.layoutToUse,
|
||||||
State.state.leafletMap);
|
State.state.leafletMap);
|
||||||
|
|
||||||
const bm = new Basemap("leafletDiv",
|
const bm = new Basemap("leafletDiv",
|
||||||
State.state.locationControl,
|
State.state.locationControl,
|
||||||
State.state.backgroundLayer,
|
State.state.backgroundLayer,
|
||||||
|
@ -342,6 +343,22 @@ export class InitUiElements {
|
||||||
attr
|
attr
|
||||||
);
|
);
|
||||||
State.state.leafletMap.setData(bm.map);
|
State.state.leafletMap.setData(bm.map);
|
||||||
|
const layout = State.state.layoutToUse.data
|
||||||
|
if (layout.lockLocation) {
|
||||||
|
const tile = Utils.embedded_tile(layout.startLat, layout.startLon, layout.startZoom - 1)
|
||||||
|
const bounds = Utils.tile_bounds(tile.z, tile.x, tile.y)
|
||||||
|
// We use the bounds to get a sense of distance for this zoom level
|
||||||
|
const latDiff = bounds[0][0] - bounds[1][0]
|
||||||
|
const lonDiff = bounds[0][1] - bounds[1][1]
|
||||||
|
console.warn("Locking the bounds to ", bounds)
|
||||||
|
bm.map.setMaxBounds(
|
||||||
|
[[ layout.startLat - latDiff, layout.startLon - lonDiff ],
|
||||||
|
[ layout.startLat + latDiff, layout.startLon + lonDiff ],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
bm.map.setMinZoom(layout.startZoom)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static InitLayers() {
|
private static InitLayers() {
|
||||||
|
|
Loading…
Reference in a new issue