essais non fructueux de pré-charger les tiles au zoom sur les étapes
This commit is contained in:
parent
d8785d830c
commit
c11b90f235
|
@ -0,0 +1,23 @@
|
||||||
|
export default function (L) {
|
||||||
|
L.EdgeBuffer = {
|
||||||
|
previousMethods: {
|
||||||
|
getTiledPixelBounds: L.GridLayer.prototype._getTiledPixelBounds,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
L.GridLayer.include({
|
||||||
|
_getTiledPixelBounds: function (center, zoom, tileZoom) {
|
||||||
|
var pixelBounds = L.EdgeBuffer.previousMethods.getTiledPixelBounds.call(this, center, zoom, tileZoom);
|
||||||
|
|
||||||
|
var edgeBufferTiles = this.options.edgeBufferTiles ?? 1;
|
||||||
|
if (edgeBufferTiles > 0) {
|
||||||
|
var pixelEdgeBuffer = L.GridLayer.prototype.getTileSize.call(this).multiplyBy(edgeBufferTiles);
|
||||||
|
pixelBounds = new L.Bounds(pixelBounds.min.subtract(pixelEdgeBuffer), pixelBounds.max.add(pixelEdgeBuffer));
|
||||||
|
}
|
||||||
|
return pixelBounds;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return L;
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,9 @@ import { initVueContentModale } from './utils/vue-setup';
|
||||||
import { processClickableElements } from './utils/process-clickable-elements';
|
import { processClickableElements } from './utils/process-clickable-elements';
|
||||||
import { handleReactiveness, setMenuToggle, setHamburgerWhenLogged } from './utils/layout-setup';
|
import { handleReactiveness, setMenuToggle, setHamburgerWhenLogged } from './utils/layout-setup';
|
||||||
import { initFirstLoadRouting, handleClickableElements, handleBrowserNavigation } from './utils/handle-navigation';
|
import { initFirstLoadRouting, handleClickableElements, handleBrowserNavigation } from './utils/handle-navigation';
|
||||||
import { setupMapStore } from './utils/map-setup';
|
import { setupMapStore, preloadEtapesTiles } from './utils/map-setup';
|
||||||
|
|
||||||
|
import initEdgeBuffer from './libs/leaflet.edgebuffer';
|
||||||
|
|
||||||
import '../scss/main.scss'
|
import '../scss/main.scss'
|
||||||
|
|
||||||
|
@ -11,8 +13,8 @@ import '../scss/main.scss'
|
||||||
(function ($, Drupal, drupalSettings) {
|
(function ($, Drupal, drupalSettings) {
|
||||||
const CaravaneTheme = function () {
|
const CaravaneTheme = function () {
|
||||||
function init () {
|
function init () {
|
||||||
console.log('DrupalSettings', drupalSettings);
|
// console.log('DrupalSettings', drupalSettings);
|
||||||
|
|
||||||
const baseUrl = window.location.protocol + "//" + window.location.host;
|
const baseUrl = window.location.protocol + "//" + window.location.host;
|
||||||
const siteName = document.querySelector('#site_name').innerText;
|
const siteName = document.querySelector('#site_name').innerText;
|
||||||
const { store, mapStore, router, route } = initVueContentModale();
|
const { store, mapStore, router, route } = initVueContentModale();
|
||||||
|
@ -25,7 +27,12 @@ import '../scss/main.scss'
|
||||||
|
|
||||||
Drupal.behaviors.customLeafletInteraction = {
|
Drupal.behaviors.customLeafletInteraction = {
|
||||||
attach: function(context, settings) {
|
attach: function(context, settings) {
|
||||||
$(context).on('leafletMapInit', function (e, settings, map, mapid, markers) {
|
|
||||||
|
initEdgeBuffer(L);
|
||||||
|
let mapSettings = settings.leaflet[Object.keys(settings.leaflet)[0]].map;
|
||||||
|
mapSettings.layers.layer.edgeBufferTiles = 8;
|
||||||
|
|
||||||
|
$(context).on('leafletMapInit', function (e, settings, map, mapid, markers) {
|
||||||
const {
|
const {
|
||||||
etapeListLinks,
|
etapeListLinks,
|
||||||
generalListLinks,
|
generalListLinks,
|
||||||
|
@ -36,6 +43,8 @@ import '../scss/main.scss'
|
||||||
|
|
||||||
setupMapStore(mapStore, map, settings);
|
setupMapStore(mapStore, map, settings);
|
||||||
|
|
||||||
|
// preloadEtapesTiles(mapStore, map);
|
||||||
|
|
||||||
initFirstLoadRouting(store, router, baseUrl, siteName);
|
initFirstLoadRouting(store, router, baseUrl, siteName);
|
||||||
|
|
||||||
handleClickableElements(clickableElements, store, router, baseUrl, siteName, mapStore);
|
handleClickableElements(clickableElements, store, router, baseUrl, siteName, mapStore);
|
||||||
|
|
|
@ -254,7 +254,7 @@ export const useContentStore = defineStore('content', {
|
||||||
|
|
||||||
this.content[`${this.contentType}s`] = multiItemPageArray;
|
this.content[`${this.contentType}s`] = multiItemPageArray;
|
||||||
|
|
||||||
console.log(this.content);
|
// console.log(this.content);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.error = 'Failed to fetch data';
|
this.error = 'Failed to fetch data';
|
||||||
|
|
|
@ -17,18 +17,18 @@ export const useMapStore = defineStore('mapState', {
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
zoomToPlace(lat, long) {
|
zoomToPlace(lat, long) {
|
||||||
if (useLayoutStore().isDesktop) long = long - 0.03;
|
if (useLayoutStore().isDesktop) long = long - 0.03;
|
||||||
this.map.flyTo(
|
this.map.flyTo(
|
||||||
[lat, long],
|
[lat, long],
|
||||||
this.maxZoom,
|
this.maxZoom,
|
||||||
{ animate: this.animationsAreEnabled, animationDuration: this.animationDuration });
|
{ animate: this.animationsAreEnabled, duration: this.animationDuration });
|
||||||
this.currentZoom = this.maxZoom;
|
this.currentZoom = this.maxZoom;
|
||||||
},
|
},
|
||||||
resetMap() {
|
resetMap(animate = this.animationsAreEnabled, duration = this.animationDuration) {
|
||||||
this.map.flyTo(
|
this.map.flyTo(
|
||||||
this.defaultMapCenter,
|
this.defaultMapCenter,
|
||||||
useLayoutStore().isDesktop ? this.defaultZoomDesktop : this.defaultZoomMobile,
|
useLayoutStore().isDesktop ? this.defaultZoomDesktop : this.defaultZoomMobile,
|
||||||
{ animate: this.animationsAreEnabled, animationDuration: this.animationDuration });
|
{ animate, duration });
|
||||||
this.currentZoom = useLayoutStore().isDesktop ? this.defaultZoomDesktop : this.defaultZoomMobile;
|
this.currentZoom = useLayoutStore().isDesktop ? this.defaultZoomDesktop : this.defaultZoomMobile;
|
||||||
},
|
},
|
||||||
lockMap() {
|
lockMap() {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { useLayoutStore } from '../stores/layout';
|
import { useLayoutStore } from '../stores/layout';
|
||||||
|
import REST from '../api/rest-axios';
|
||||||
|
|
||||||
export function setupMapStore(mapStore, map, settings) {
|
export function setupMapStore(mapStore, map, settings) {
|
||||||
mapStore.map = map;
|
mapStore.map = map;
|
||||||
|
@ -8,4 +9,58 @@ export function setupMapStore(mapStore, map, settings) {
|
||||||
mapStore.defaultZoomMobile = settings.settings.minZoom - 1;
|
mapStore.defaultZoomMobile = settings.settings.minZoom - 1;
|
||||||
mapStore.map.flyTo([mapStore.defaultMapCenter.lat, mapStore.defaultMapCenter.lng], useLayoutStore().isDesktop ? mapStore.defaultZoomDesktop : mapStore.defaultZoomMobile);
|
mapStore.map.flyTo([mapStore.defaultMapCenter.lat, mapStore.defaultMapCenter.lng], useLayoutStore().isDesktop ? mapStore.defaultZoomDesktop : mapStore.defaultZoomMobile);
|
||||||
mapStore.checkReducedMotion();
|
mapStore.checkReducedMotion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// not working
|
||||||
|
// kept to maybe rework on it later
|
||||||
|
export async function preloadEtapesTiles(mapStore, map) {
|
||||||
|
function waitForEvent(el, eventName) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
el.once(eventName, resolve);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const tilesSource = map._layers.layer._url;
|
||||||
|
|
||||||
|
const response = await REST.get(`/jsonapi/node/etape/`);
|
||||||
|
|
||||||
|
const defaultZoom = useLayoutStore().isDesktop ? mapStore.defaultZoomDesktop : mapStore.defaultZoomMobile;
|
||||||
|
|
||||||
|
let tilesCached = new Set();
|
||||||
|
|
||||||
|
for (const etape of response.data.data) {
|
||||||
|
const etapeCoords = {
|
||||||
|
title: etape.attributes.title,
|
||||||
|
lat: etape.attributes.field_geofield.lat,
|
||||||
|
lng: etape.attributes.field_geofield.lon,
|
||||||
|
};
|
||||||
|
|
||||||
|
for (let zoom = defaultZoom; zoom <= mapStore.maxZoom; zoom++) {
|
||||||
|
map.flyTo([etapeCoords.lat, etapeCoords.lng], zoom, { animate: true, duration: 0.001 });
|
||||||
|
await waitForEvent(map, 'moveend zoomend');
|
||||||
|
|
||||||
|
let allTilesCached = Object.keys(map._layers.layer._tiles).every(tile => tilesCached.has(tile));
|
||||||
|
|
||||||
|
const tileLayer = Object.values(map._layers).find(layer => layer instanceof L.TileLayer);
|
||||||
|
|
||||||
|
if (!allTilesCached && tileLayer._loading) {
|
||||||
|
await waitForEvent(tileLayer, 'load');
|
||||||
|
Object.keys(map._layers.layer._tiles).forEach(tile => {
|
||||||
|
if (!tilesCached.has(tile)) {
|
||||||
|
/* const tileObject = map._layers.layer._tiles[tile];
|
||||||
|
let img = new Image();
|
||||||
|
const url = tilesSource
|
||||||
|
.replace('{z}', tileObject.coords.z)
|
||||||
|
.replace('{x}', tileObject.coords.x)
|
||||||
|
.replace('{y}', tileObject.coords.y);
|
||||||
|
img.src = url; */
|
||||||
|
tilesCached.add(tile)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// console.log(tilesCached);
|
||||||
|
mapStore.resetMap(false, 0);
|
||||||
|
}
|
||||||
|
|
|
@ -301,6 +301,7 @@ body{
|
||||||
top: 0;
|
top: 0;
|
||||||
width: 100vw;
|
width: 100vw;
|
||||||
.leaflet-container {
|
.leaflet-container {
|
||||||
|
background-color: $main-color-light;
|
||||||
.leaflet-popup {
|
.leaflet-popup {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue