Skip to content

Commit

Permalink
Add per-map view-settings and optimized flat-view only maps
Browse files Browse the repository at this point in the history
  • Loading branch information
TBlueF committed Nov 17, 2024
1 parent f08c794 commit 4d58cc2
Show file tree
Hide file tree
Showing 21 changed files with 812 additions and 480 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ private static class Settings {

private boolean useCookies = true;

private boolean enableFreeFlight = true;
private boolean defaultToFlatView = false;

private String startLocation = null;
Expand All @@ -150,7 +149,6 @@ private static class Settings {

public void setFrom(WebappConfig config) {
this.useCookies = config.isUseCookies();
this.enableFreeFlight = config.isEnableFreeFlight();
this.defaultToFlatView = config.isDefaultToFlatView();
this.startLocation = config.getStartLocation().orElse(null);
this.resolutionDefault = config.getResolutionDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ public class MapConfig implements MapSettings {

private boolean renderEdges = true;

private boolean saveHiresLayer = true;
private boolean enablePerspectiveView = true;
private boolean enableFlatView = true;
private boolean enableFreeFlightView = true;
private boolean enableHires = true;

private String storage = "file";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public class WebappConfig {

private boolean useCookies = true;

private boolean enableFreeFlight = true;
private boolean defaultToFlatView = false;

private String startLocation = null;
Expand Down Expand Up @@ -82,10 +81,6 @@ public boolean isUseCookies() {
return useCookies;
}

public boolean isEnableFreeFlight() {
return enableFreeFlight;
}

public boolean isDefaultToFlatView() {
return defaultToFlatView;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,28 @@ min-inhabited-time: 0
# Default is true
render-edges: true

# Whether the hires-layer will be saved to the storage.
# Whether the perspective view will be enabled for this map.
# Changing this to true requires a re-render of the map, only if the hires-layer is enabled and free-flight view is disabled.
# Default is true
enable-perspective-view: true

# Whether the flat (isometric, top-down) view will be enabled for this map.
# Having only flat-view enabled while disabling free-flight and perspective will speed up the render and reduce the maps storage-size.
# Default is true
enable-flat-view: true

# Whether the free-flight view will be enabled for this map.
# Changing this to true requires a re-render of the map, only if the hires-layer is enabled and perspective view is disabled.
# Default is true
enable-free-flight-view: true

# Whether the hires-layer will be enabled.
# Disabling this will speed up rendering and reduce the size of the map-files a lot.
# But you will not be able to see the full 3d-models if you zoom in on the map.
# Changing this to false will not remove any existing tiles, existing tiles just won't get updated anymore.
# Changing this to true will require a re-render of the map.
# Default is true
save-hires-layer: true
enable-hires: true

# This defines the storage-config that will be used to save this map.
# You can find your storage configs next to this config file in the 'storages'-folder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ update-settings-file: true
# Default is true
use-cookies: true

# If the free-flight-mode in the web-application is enabled or not.
# Default is true
enable-free-flight: true

# If the webapp will default to flat-view instead of perspective-view.
# Default is false
default-to-flat-view: false
Expand Down
13 changes: 9 additions & 4 deletions common/webapp/src/components/ControlBar/ControlsSwitch.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="controls-switch">
<SvgButton :active="isPerspectiveView" @action="setPerspectiveView" :title="$t('controls.perspective.tooltip')">
<div class="controls-switch" v-if="showViewControls">
<SvgButton v-if="mapViewer.map.perspectiveView" :active="isPerspectiveView" @action="setPerspectiveView" :title="$t('controls.perspective.tooltip')">
<svg viewBox="0 0 30 30">
<path d="M19.475,10.574c-0.166-0.021-0.337-0.036-0.51-0.045c-0.174-0.009-0.35-0.013-0.525-0.011
c-0.176,0.002-0.353,0.01-0.526,0.024c-0.175,0.015-0.347,0.036-0.515,0.063l-13.39,2.189
Expand All @@ -13,12 +13,12 @@
c-0.116-0.051-0.243-0.097-0.381-0.138c-0.137-0.041-0.283-0.078-0.438-0.108C19.803,10.621,19.641,10.595,19.475,10.574"/>
</svg>
</SvgButton>
<SvgButton :active="isFlatView" @action="setFlatView" :title="$t('controls.flatView.tooltip')">
<SvgButton v-if="mapViewer.map.flatView" :active="isFlatView" @action="setFlatView" :title="$t('controls.flatView.tooltip')">
<svg viewBox="0 0 30 30">
<path d="M22.371,4.158c1.65,0,3,1.35,3,3v15.684c0,1.65-1.35,3-3,3H7.629c-1.65,0-3-1.35-3-3V7.158c0-1.65,1.35-3,3-3H22.371z"/>
</svg>
</SvgButton>
<SvgButton v-if="controls.enableFreeFlight" :active="isFreeFlight" @action="setFreeFlight" :title="$t('controls.freeFlight.tooltip')">
<SvgButton v-if="mapViewer.map.freeFlightView" :active="isFreeFlight" @action="setFreeFlight" :title="$t('controls.freeFlight.tooltip')">
<svg viewBox="0 0 30 30">
<path d="M21.927,11.253c-0.256-0.487-0.915-0.885-1.465-0.885h-2.004c-0.55,0-0.726-0.356-0.39-0.792c0,0,0.698-0.905,0.698-2.041
c0-2.08-1.687-3.767-3.767-3.767s-3.767,1.687-3.767,3.767c0,1.136,0.698,2.041,0.698,2.041c0.336,0.436,0.161,0.794-0.389,0.797
Expand All @@ -40,6 +40,7 @@
data() {
return {
controls: this.$bluemap.appState.controls,
mapViewer: this.$bluemap.mapViewer.data
}
},
computed: {
Expand All @@ -51,6 +52,10 @@
},
isFreeFlight() {
return this.controls.state === "free";
},
showViewControls() {
if (!this.mapViewer.map) return 0;
return this.mapViewer.map.views.length > 1;
}
},
methods: {
Expand Down
6 changes: 3 additions & 3 deletions common/webapp/src/components/Menu/SettingsMenu.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<template>
<div>
<Group :title="$t('controls.title')">
<SimpleButton :active="appState.controls.state === 'perspective'" @action="$bluemap.setPerspectiveView(500, appState.controls.state === 'free' ? 100 : 0)">{{$t('controls.perspective.button')}}</SimpleButton>
<SimpleButton :active="appState.controls.state === 'flat'" @action="$bluemap.setFlatView(500, appState.controls.state === 'free' ? 100 : 0)">{{$t('controls.flatView.button')}}</SimpleButton>
<SimpleButton v-if="appState.controls.enableFreeFlight" :active="appState.controls.state === 'free'" @action="$bluemap.setFreeFlight(500)">{{$t('controls.freeFlight.button')}}</SimpleButton>
<SimpleButton v-if="mapViewer.map.perspectiveView" :active="appState.controls.state === 'perspective'" @action="$bluemap.setPerspectiveView(500, appState.controls.state === 'free' ? 100 : 0)">{{$t('controls.perspective.button')}}</SimpleButton>
<SimpleButton v-if="mapViewer.map.flatView" :active="appState.controls.state === 'flat'" @action="$bluemap.setFlatView(500, appState.controls.state === 'free' ? 100 : 0)">{{$t('controls.flatView.button')}}</SimpleButton>
<SimpleButton v-if="mapViewer.map.freeFlightView" :active="appState.controls.state === 'free'" @action="$bluemap.setFreeFlight(500)">{{$t('controls.freeFlight.button')}}</SimpleButton>
</Group>

<Group :title="$t('lighting.title')">
Expand Down
22 changes: 15 additions & 7 deletions common/webapp/src/js/BlueMapApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export class BlueMapApp {
/** @type {{
* version: string,
* useCookies: boolean,
* enableFreeFlight: boolean,
* defaultToFlatView: boolean,
* resolutionDefault: number,
* minZoomDistance: number,
Expand Down Expand Up @@ -96,7 +95,6 @@ export class BlueMapApp {
mouseSensitivity: 1,
showZoomButtons: true,
invertMouse: false,
enableFreeFlight: false,
pauseTileLoading: false
},
menu: this.mainMenu,
Expand Down Expand Up @@ -139,7 +137,6 @@ export class BlueMapApp {
await this.getSettings();
this.mapControls.minDistance = this.settings.minZoomDistance;
this.mapControls.maxDistance = this.settings.maxZoomDistance;
this.appState.controls.enableFreeFlight = this.settings.enableFreeFlight;

// load settings-styles
if (this.settings.styles) for (let styleUrl of this.settings.styles) {
Expand Down Expand Up @@ -259,7 +256,9 @@ export class BlueMapApp {

await this.mapViewer.switchMap(map)

if (resetCamera) this.resetCamera();
if (resetCamera || !this.mapViewer.map.hasView(this.appState.controls.state))
this.resetCamera();

this.updatePageAddress();

await Promise.all([
Expand All @@ -283,10 +282,18 @@ export class BlueMapApp {

controls.controls = this.mapControls;
this.appState.controls.state = "perspective";
if (this.settings.defaultToFlatView) {

if (this.settings.defaultToFlatView && map.hasView("flat")) {
this.setFlatView();
}

else if (!map.hasView("perspective")) {
if (map.hasView("flat"))
this.setFlatView();
else
this.setFreeFlight();
}

this.updatePageAddress();
}

Expand Down Expand Up @@ -328,7 +335,6 @@ export class BlueMapApp {
this.settings = {
version: "?",
useCookies: false,
enableFreeFlight: true,
defaultToFlatView: false,
resolutionDefault: 1.0,
minZoomDistance: 5,
Expand Down Expand Up @@ -451,6 +457,7 @@ export class BlueMapApp {

setPerspectiveView(transition = 0, minDistance = 5) {
if (!this.mapViewer.map) return;
if (!this.mapViewer.map.data.perspectiveView) return;
if (this.viewAnimation) this.viewAnimation.cancel();

let cm = this.mapViewer.controlsManager;
Expand Down Expand Up @@ -488,6 +495,7 @@ export class BlueMapApp {

setFlatView(transition = 0, minDistance = 5) {
if (!this.mapViewer.map) return;
if (!this.mapViewer.map.data.flatView) return;
if (this.viewAnimation) this.viewAnimation.cancel();

let cm = this.mapViewer.controlsManager;
Expand Down Expand Up @@ -521,7 +529,7 @@ export class BlueMapApp {

setFreeFlight(transition = 0, targetY = undefined) {
if (!this.mapViewer.map) return;
if (!this.settings.enableFreeFlight) return this.setPerspectiveView(transition);
if (!this.mapViewer.map.data.freeFlightView) return;
if (this.viewAnimation) this.viewAnimation.cancel();

let cm = this.mapViewer.controlsManager;
Expand Down
19 changes: 18 additions & 1 deletion common/webapp/src/js/map/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ export class Map {
tileSize: {x: 32, z: 32},
lodFactor: 5,
lodCount: 3
}
},
perspectiveView: false,
flatView: false,
freeFlightView: false,
views: ["perspective", "flat", "free"]
});

this.raycaster = new Raycaster();
Expand Down Expand Up @@ -198,6 +202,15 @@ export class Map {
lodCount: worldSettings.lowres.lodCount !== undefined ? worldSettings.lowres.lodCount : this.data.lowres.lodCount
};

this.data.perspectiveView = worldSettings.perspectiveView !== undefined ? worldSettings.perspectiveView : this.data.perspectiveView;
this.data.flatView = worldSettings.flatView !== undefined ? worldSettings.flatView : this.data.flatView;
this.data.freeFlightView = worldSettings.freeFlightView !== undefined ? worldSettings.freeFlightView : this.data.freeFlightView;

this.data.views = [];
if (this.data.perspectiveView) this.data.views.push("perspective");
if (this.data.flatView) this.data.views.push("flat");
if (this.data.freeFlightView) this.data.views.push("free");

alert(this.events, `Settings for map '${this.data.id}' loaded.`, "fine");
});
}
Expand Down Expand Up @@ -472,6 +485,10 @@ export class Map {
return false;
}

hasView(view) {
return this.data.views.some(v => v === view)
}

dispose() {
this.unload();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,22 @@ public interface MapSettings extends RenderSettings {

float getSkyLight();

boolean isEnablePerspectiveView();

boolean isEnableFlatView();

boolean isEnableFreeFlightView();

boolean isEnableHires();

@Override
default boolean isSaveHiresLayer() {
return isEnableHires();
}

@Override
default boolean isRenderTopOnly() {
return !isEnableHires() || (!isEnablePerspectiveView() && !isEnableFreeFlightView());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public JsonElement serialize(BmMap map, Type typeOfSrc, JsonSerializationContext
root.addProperty("ambientLight", map.getMapSettings().getAmbientLight());
root.addProperty("skyLight", map.getMapSettings().getSkyLight());

// view settings
root.addProperty("perspectiveView", map.getMapSettings().isEnablePerspectiveView());
root.addProperty("flatView", map.getMapSettings().isEnableFlatView());
root.addProperty("freeFlightView", map.getMapSettings().isEnableFreeFlightView());

return root;
}

Expand Down
Loading

0 comments on commit 4d58cc2

Please sign in to comment.