Skip to content

Commit

Permalink
wip: Allow to make layers available offline - improved offline view d…
Browse files Browse the repository at this point in the history
…ialog (#833)
  • Loading branch information
claustres committed Oct 24, 2024
1 parent 165e1e6 commit d423510
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
36 changes: 34 additions & 2 deletions map/client/components/catalog/KCreateOfflineView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,32 @@
<KForm
ref="form"
:schema="schema"
@field-changed="onFieldChanged"
class="q-pa-sm"
/>
{{ $t('KCreateOfflineView.NUMBER_OF_TILES') + n }}

</template>
<script setup>
import SphericalMercator from '@mapbox/sphericalmercator'
import { ref, computed } from 'vue'
import KForm from '../../../../core/client/components/form/KForm.vue'
// Props
const props = defineProps({
zoomLevel: {
type: Number,
default: 8
},
view: {
type: Object,
required: true
}
})
// Data
const form = ref(null)
const n = ref(0)
// Computed
const schema = computed(() => {
Expand All @@ -25,15 +42,15 @@ const schema = computed(() => {
properties: {
minZoom: {
type: 'number',
default: 8,
default: props.zoomLevel,
field: {
component: 'form/KNumberField',
label: 'KCreateOfflineView.MIN_ZOOM_FIELD_LABEL'
}
},
maxZoom: {
type: 'number',
default: 10,
default: props.zoomLevel + 2,
field: {
component: 'form/KNumberField',
label: 'KCreateOfflineView.MAX_ZOOM_FIELD_LABEL'
Expand All @@ -53,6 +70,18 @@ const schema = computed(() => {
})
// Functions
function updateNumberOfTiles (minZoom, maxZoom) {
n.value = 0
for (let z = minZoom; z <= maxZoom; z++) {
let sm = new SphericalMercator()
const tilesBounds = sm.xyz([props.view.west, props.view.south, props.view.east, props.view.north], z)
n.value += (tilesBounds.maxX - tilesBounds.minX + 1) * (tilesBounds.maxY - tilesBounds.minY + 1)
}
}
function onFieldChanged() {
const { minZoom, maxZoom } = form.value.values()
updateNumberOfTiles(minZoom, maxZoom)
}
async function apply () {
const { isValid, values } = form.value.validate()
if (isValid) {
Expand All @@ -61,6 +90,9 @@ async function apply () {
return isValid
}
// Immediate
updateNumberOfTiles(props.zoomLevel, props.zoomLevel + 2)
// Expose
defineExpose({
apply
Expand Down
12 changes: 6 additions & 6 deletions map/client/components/catalog/KViewsPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,24 +127,23 @@ export default {
}
case 'cache-view': {
// Select cache options
const center = this.kActivity.getCenter()
Dialog.create({
title: i18n.t('KViewsPanel.CACHE_VIEW_DIALOG_TITLE'),
message: i18n.t('KViewsPanel.CACHE_VIEW_DIALOG_MESSAGE'),
html: true,
component: 'KDialog',
componentProps: {
component: 'catalog/KCreateOfflineView',
zoomLevel: center.zoomLevel,
view,
okAction: {
id: 'ok-button',
label: 'OK',
handler: 'apply',
flat: true
},
cancelAction: {
id: 'cancel-button',
label: 'CANCEL',
flat: true
}
cancelAction: 'CANCEL'
}
}).onOk(async (values) => {
const dismiss = Notify.create({
Expand All @@ -170,7 +169,8 @@ export default {
icon: 'las la-trash-alt',
message: i18n.t('KViewsPanel.UNCACHING_VIEW'),
color: 'primary',
timeout: 0
timeout: 0,
spinner: true
})
await uncacheView(view, this.getProjectLayers(), {
contextId: this.kActivity.contextId
Expand Down
3 changes: 2 additions & 1 deletion map/client/i18n/map_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,8 @@
"KCreateOfflineView": {
"MIN_ZOOM_FIELD_LABEL": "Zoom level from which data will be downloaded, increase will reduce data size",
"MAX_ZOOM_FIELD_LABEL": "Zoom level until which data will be downloaded, increase will increase data size",
"NB_CONCURRENT_REQUESTS_FIELD_LABEL": "Number of concurrent requests issued to download, increase will speed up download but load the device and the server"
"NB_CONCURRENT_REQUESTS_FIELD_LABEL": "Number of concurrent requests issued to download, increase will speed up download but load the device and the server",
"NUMBER_OF_TILES": "Estimated number of tiles to download per layer: "
},
"KProjectsPanel": {
"SORT_PROJECTS": "Sort projects",
Expand Down
3 changes: 2 additions & 1 deletion map/client/i18n/map_fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,8 @@
"KCreateOfflineView": {
"MIN_ZOOM_FIELD_LABEL": "Niveau de zoom à partir duquel les données vont être téléchargées, l'augmenter réduira la taille des données",
"MAX_ZOOM_FIELD_LABEL": "Niveau de zoom jusqu'auquel les données vont être téléchargées, l'augmenter augmentera la taille des données",
"NB_CONCURRENT_REQUESTS_FIELD_LABEL": "Nombre de requêtes concurrentes utilisées pour le téléchargement, l'augmenter accélèrera le processus mais pourra surcharger la machine et le serveur"
"NB_CONCURRENT_REQUESTS_FIELD_LABEL": "Nombre de requêtes concurrentes utilisées pour le téléchargement, l'augmenter accélèrera le processus mais pourra surcharger la machine et le serveur",
"NUMBER_OF_TILES": "Estimation du nombre de tuiles à télécharger pour chaque couche: "
},
"KProjectsPanel": {
"SORT_PROJECTS": "Trier les projets",
Expand Down

0 comments on commit d423510

Please sign in to comment.