Skip to content

Commit

Permalink
Delay request for location by providing a button #264 + style improve…
Browse files Browse the repository at this point in the history
…ments for map controls
  • Loading branch information
m-mohr committed Oct 20, 2022
1 parent 66c42b0 commit 79df082
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 33 deletions.
8 changes: 6 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ export default {
// Skip login and automatically load up the "discovery mode"
skipLogin: false,

// Request the user location to default the map view on where the user is
requestUserLocation: true,
// Default location for maps
// Default to the center of the EU in Wuerzburg:
// https://en.wikipedia.org/wiki/Geographical_midpoint_of_Europe#Geographic_centre_of_the_European_Union
// The zoom level should show most of Europe
mapLocation: [49.8, 9.9],
mapZoom: 4,

// A message shown on the login page
loginMessage: '',
Expand Down
3 changes: 1 addition & 2 deletions src/components/IDE.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export default {
}
},
async mounted() {
this.initUserLocation();
this.listen('showDataForm', this.showDataForm);
this.listen('editProcess', this.editProcess);
this.listen('showLogin', this.login);
Expand Down Expand Up @@ -145,7 +144,7 @@ export default {
}
},
methods: {
...Utils.mapActions(['describeAccount', 'initUserLocation']),
...Utils.mapActions(['describeAccount']),
...Utils.mapMutations(['discoveryCompleted']),
...Utils.mapMutations('editor', ['setContext', 'setProcess', 'setCollectionPreview']),
Expand Down
2 changes: 1 addition & 1 deletion src/components/Viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default {
}
},
computed: {
...Utils.mapState(['connection', 'userLocation']),
...Utils.mapState(['connection']),
nextTabId() {
return `viewer~${this.tabIdCounter}`;
}
Expand Down
1 change: 1 addition & 0 deletions src/components/datatypes/MapAreaSelect.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<div :id="id">
<ProgressControl ref="progress" :map="map" />
<UserLocationControl :map="map" />
<TextControl :text="help" :map="map" />
</div>
</template>
Expand Down
1 change: 1 addition & 0 deletions src/components/maps/GeoJsonMapEditor.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<div :id="id" class="geojson-map-editor">
<ProgressControl ref="progress" :map="map" />
<UserLocationControl :map="map" />
</div>
</template>

Expand Down
15 changes: 9 additions & 6 deletions src/components/maps/MapMixin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ import 'ol-ext/control/LayerSwitcher.css';
import LayerSwitcher from 'ol-ext/control/LayerSwitcher';
import ProgressControl from './ProgressControl.vue';
import UserLocationControl from './UserLocationControl.vue';
let idCounter = 1;
export default {
components: {
ProgressControl
ProgressControl,
UserLocationControl
},
mixins: [EventBusMixin],
props: {
Expand Down Expand Up @@ -49,9 +51,6 @@ export default {
await this.showMap();
}
},
computed: {
...Utils.mapState(['userLocation', 'locationZoom']),
},
async mounted() {
await this.showMap();
},
Expand Down Expand Up @@ -83,10 +82,14 @@ export default {
if (!view) {
view = new View(viewOpts);
if (!view.getCenter()) {
view.setCenter(fromLonLat([this.userLocation[1], this.userLocation[0]], view.getProjection()));
let location = this.$config.mapLocation;
if (!Array.isArray(location) || location.length != 2) {
location = [0,0];
}
view.setCenter(fromLonLat([location[1], location[0]], view.getProjection()));
}
if (!view.getZoom()) {
view.setZoom(this.locationZoom);
view.setZoom(this.$config.mapZoom || 0);
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/components/maps/TextControl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ export default {
</script>

<style lang="scss" scoped>
.value {
position: absolute;
top: 0.5em;
left: calc(2.375em + 6px);
max-width: calc(100% - 2*(2.375em + 6px));
box-sizing: border-box;
background-color: rgba(255,255,255,0.6);
}
.pointer {
cursor: pointer;
}
Expand Down
44 changes: 44 additions & 0 deletions src/components/maps/UserLocationControl.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<template>
<div class="ol-location ol-unselectable ol-control" style="pointer-events: auto;">
<button type="button" @click.prevent.stop="request" title="Go to your location">
<i class="fas fa-location-arrow"></i>
</button>
</div>
</template>

<script>
import ControlMixin from './ControlMixin.vue';
import { fromLonLat } from 'ol/proj';
export default {
name: 'UserLocationControl',
mixins: [
ControlMixin
],
methods: {
request() {
if ("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition(
position => {
let view = this.map.getView();
let coords = [position.coords.longitude, position.coords.latitude];
view.setCenter(fromLonLat(coords, view.getProjection()));
},
error => Utils.error(this, error, "Location Error"),
{
maximumAge: Infinity
}
);
}
},
}
}
</script>

<style lang="scss" scoped>
.ol-location {
z-index: 0;
left: 0.5em;
top: calc(3.75em + 6px);
}
</style>
5 changes: 1 addition & 4 deletions src/components/viewer/MapViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<Pane id="map">
<div :id="id" class="map-viewer">
<ProgressControl ref="progress" :map="map" />
<UserLocationControl :map="map" />
<TextControl v-if="isGeoTiff" :text="textControlText" />
<ChannelControl v-if="isGeoTiff && !colorMap" :bands="bands" @update="updateGeoTiffStyle" />
<div v-if="loading" class="map-loading">
Expand Down Expand Up @@ -256,8 +257,4 @@ export default {
}
}
}
.ol-control.value {
top: 0.5em;
left: 3em;
}
</style>
19 changes: 1 addition & 18 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ const getDefaultState = () => {
udfRuntimes: {},
processesUpdated: 0,
collections: [],
processNamespaces: Config.processNamespaces || [],
userLocation: [49.8, 9.9], // Default to the center of the EU in Wuerzburg: https://en.wikipedia.org/wiki/Geographical_midpoint_of_Europe#Geographic_centre_of_the_European_Union
locationZoom: 4 // Should show most of Europe
processNamespaces: Config.processNamespaces || []
};
};

Expand Down Expand Up @@ -130,17 +128,6 @@ export default new Vuex.Store({
}
},
actions: {
async initUserLocation(cx) {
if (Config.requestUserLocation && "geolocation" in navigator) {
navigator.geolocation.getCurrentPosition(
position => cx.commit('userLocation', [position.coords.latitude, position.coords.longitude]),
error => console.warn(error),
{
maximumAge: Infinity
}
);
}
},
async connect(cx, url) {
await cx.dispatch('logout');

Expand Down Expand Up @@ -328,10 +315,6 @@ export default new Vuex.Store({
}
},
mutations: {
userLocation(state, location) {
state.userLocation = location;
state.locationZoom = 6;
},
discoveryCompleted(state, completed = true) {
state.discoveryCompleted = completed;
},
Expand Down

0 comments on commit 79df082

Please sign in to comment.