-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GSLUX-623 intégration 3D #69
Conversation
88a2618
to
19cfb89
Compare
GitHub Pages links: * Luxembourg-geoportail: https://geoportail-luxembourg.github.io/luxembourg-geoportail/maplibre_legacy_OL/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the work, did not test in v3, yet.
Needs some cleaning (eg. app.store.ts.orig is committed).
A JS code editor would have suggested you to install ol types.
Regarding the bundle, only commit what is produced by npm run build:lib:prod
(after a mandatory rebase). Don't commit what has been built in dev mode.
src/stores/app.store.ts.orig
Outdated
import { Ref, ref } from 'vue' | ||
import { acceptHMRUpdate, defineStore } from 'pinia' | ||
|
||
export const DEFAULT_LANG = 'fr' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be cleaned
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of course , oops.
src/App.vue
Outdated
@@ -44,6 +45,15 @@ watch(layersOpen, () => | |||
onMounted(() => window.addEventListener('resize', resizeMap)) | |||
onUnmounted(() => window.removeEventListener('resize', resizeMap)) | |||
|
|||
function traverseLayer(layer, ancestors, visitor) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This utility function should be moved in another file as it has no link with the App component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll put it into the Mapbox lib since it is just useful while the old OL is used.
@@ -52,10 +62,12 @@ function resizeMap() { | |||
map.updateSize() | |||
|
|||
// And trigger update MapLibre layers' canvas size | |||
map.getAllLayers().forEach(layer => { | |||
// map.getAllLayers().forEach(layer => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean code comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add a comment to restore the newer version when OL is updated.
src/composables/map/ol.composable.ts
Outdated
@@ -228,7 +234,8 @@ export default function useOpenLayers() { | |||
layersCache.set(id, layer) | |||
} | |||
|
|||
function getLayerFromCache(layer: Layer): BaseLayer { | |||
function getOrCreateLayer(layer: Layer | undefined | null): BaseLayer | null { | |||
if (layer === null || layer === undefined) return null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using getLayerFromCache()
here? This code block from l.238 to l.241 is doing the same thing as getLayerFromCache()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they used to have the same function. Now getLayerFromCache does not create a layer if it does not exist.
src/composables/map/ol.composable.ts
Outdated
if (layer === null || layer === undefined) return null | ||
const id = layer.id | ||
|
||
return layersCache.get(id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be simplified
return layersCache.get(id) | |
function getLayerFromCache( | |
layer: Layer | undefined | null | |
): BaseLayer | null { | |
return layer ? layersCache.get(layer.id) : null | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
const newVectorSources: VectorSourceDict = new Map() | ||
styleStore.bgVectorSources.forEach((vectorSource, key) => { | ||
if (key === bgLayer.id) { | ||
const newVectorSource = Object.assign({}, vectorSource, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spread syntax is less verbose and now mostly used.
https://stackoverflow.com/questions/32925460/object-spread-vs-object-assign
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow, that's neat, thanks.
@@ -222,7 +247,7 @@ export default function useMvtStyles() { | |||
method: 'POST', | |||
body: formData, | |||
} | |||
return fetch(uploadvtstyleUrl_, options) | |||
return fetch(registerUrls.get('upload') || '', options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the point in fetching an empty url?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will never be empty, but TypeScript requests a backup value
const appliedStyle: ShallowRef<StyleSpecification | undefined> = | ||
shallowRef() | ||
const registerUrls: ShallowRef<Map<string, string>> = shallowRef( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -293,7 +310,9 @@ export default function useOpenLayers() { | |||
olMap.addLayer(bgBaseLayer) | |||
} | |||
} | |||
statePersistorStyleService.restoreStyle(true) | |||
if (oldBgLayerId !== bgLayer?.id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand how, at this point, bg layer's id cannot be different?
What use case is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the style shall be restored from local storage when changing bg Layers. When only the style is changed, restoreStyle shall not be calles.
6cb46d5
to
bb43d72
Compare
…roduce in OL v6.6
…d, without wanting to create it.
bb43d72
to
35597cb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this complex PR @mki-c2c!
I did not go into all the details of the 3D and vector styles, but will try to give a rather general testing feedback:
To make the PR work within the v3 we must not forget to adapt: https://github.com/Geoportail-Luxembourg/geoportailv3/blob/integration-vue/geoportal/geoportailv3_geoportal/static-ngeo/js/resizemapDirective.js#L23
Then however I still get the error Uncaught (in promise) TypeError: Cannot read properties of null (reading 'get') at BackgroundLayerMgr.set (BackgroundLayerMgr.js:106:70)
when turning off 3D mesh and 3D gets stuck in this mode no matter which of the two buttons I click.
The glitch we saw this morning that the wrong bgLayer is selected is not present anymore. However, I only manage to display the satellite imagery as bgLayer. Also, I do not see the other 3D layers like bridges and trees on the map yet.
src/lib/ol-maplibre-layer.js
Outdated
* @property {string|HTMLElement} container | ||
*/ | ||
|
||
export default class MapBox extends Layer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this class rather be called MapLibreLayer
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well this is the heart of the Issue. Yes, I will rename all this lib to mapbox and import the library with an alias. That will be clearer.
@@ -0,0 +1,10 @@ | |||
import olLayerGroup from 'ol/layer/Group.js' | |||
|
|||
export default function traverseLayer(layer, ancestors, visitor) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that we also have a utils.ts
in services. Could make sense to put this in the same place, woudn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, that's a good idea, I also thought about it. But this function is only needed with OL 6.5, so it will be dropped when transitioning to maplibre and OL>6.15 in v4. I think it's clearer when the function is grouped with the custom Mapbox lib
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, I've retested this branch together with https://github.com/Geoportail-Luxembourg/geoportailv3/tree/GSLUX-623_integrate3D
The overall integration of the 3D mode works on my side, thanks @mki-c2c!
I still get the error Uncaught (in promise) TypeError: Cannot read properties of null (reading 'get') at BackgroundLayerMgr.set (BackgroundLayerMgr.js:106:70)
when turning off 3D mesh and 3D gets stuck in this mode no matter which of the two buttons I click.
Also, I do not see the other 3D layers like bridges and trees on the map yet.
Let's try to fix these problems within the new tickets you have created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be a ts file instead of a js file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both library files are copy pasted from a very old js repo, so they are js and not ts.
src/lib/ol-maplibre-layer.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be a ts file instead of a js file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both library files are copy pasted from a very old js repo, so they are js and not ts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, I forgot to include the d.ts files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are 2 js files in src/lib, maybe switch to ts file as the entire project is in TS?
MKI: I agree with you but let's just consider these files as an external legacy js library which will be removed as soon as OL is upgraded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your good comments, I am taking them into account, then merge the PR
src/composables/map/ol.composable.ts
Outdated
@@ -228,7 +234,8 @@ export default function useOpenLayers() { | |||
layersCache.set(id, layer) | |||
} | |||
|
|||
function getLayerFromCache(layer: Layer): BaseLayer { | |||
function getOrCreateLayer(layer: Layer | undefined | null): BaseLayer | null { | |||
if (layer === null || layer === undefined) return null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they used to have the same function. Now getLayerFromCache does not create a layer if it does not exist.
@@ -293,7 +310,9 @@ export default function useOpenLayers() { | |||
olMap.addLayer(bgBaseLayer) | |||
} | |||
} | |||
statePersistorStyleService.restoreStyle(true) | |||
if (oldBgLayerId !== bgLayer?.id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the style shall be restored from local storage when changing bg Layers. When only the style is changed, restoreStyle shall not be calles.
src/composables/map/ol.composable.ts
Outdated
if (layer === null || layer === undefined) return null | ||
const id = layer.id | ||
|
||
return layersCache.get(id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
@@ -52,10 +62,12 @@ function resizeMap() { | |||
map.updateSize() | |||
|
|||
// And trigger update MapLibre layers' canvas size | |||
map.getAllLayers().forEach(layer => { | |||
// map.getAllLayers().forEach(layer => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add a comment to restore the newer version when OL is updated.
src/App.vue
Outdated
@@ -44,6 +45,15 @@ watch(layersOpen, () => | |||
onMounted(() => window.addEventListener('resize', resizeMap)) | |||
onUnmounted(() => window.removeEventListener('resize', resizeMap)) | |||
|
|||
function traverseLayer(layer, ancestors, visitor) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll put it into the Mapbox lib since it is just useful while the old OL is used.
src/stores/app.store.ts.orig
Outdated
import { Ref, ref } from 'vue' | ||
import { acceptHMRUpdate, defineStore } from 'pinia' | ||
|
||
export const DEFAULT_LANG = 'fr' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of course , oops.
@@ -0,0 +1,10 @@ | |||
import olLayerGroup from 'ol/layer/Group.js' | |||
|
|||
export default function traverseLayer(layer, ancestors, visitor) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, that's a good idea, I also thought about it. But this function is only needed with OL 6.5, so it will be dropped when transitioning to maplibre and OL>6.15 in v4. I think it's clearer when the function is grouped with the custom Mapbox lib
src/lib/ol-maplibre-layer.js
Outdated
* @property {string|HTMLElement} container | ||
*/ | ||
|
||
export default class MapBox extends Layer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well this is the heart of the Issue. Yes, I will rename all this lib to mapbox and import the library with an alias. That will be clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both library files are copy pasted from a very old js repo, so they are js and not ts.
src/lib/ol-maplibre-layer.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both library files are copy pasted from a very old js repo, so they are js and not ts.
JIRA issue
https://jira.camptocamp.com/browse/GSLUX-326
Description
Screenshots
(only if the final render is different)