Skip to content
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

Merged
merged 17 commits into from
Sep 22, 2023
Merged

GSLUX-623 intégration 3D #69

merged 17 commits into from
Sep 22, 2023

Conversation

mki-c2c
Copy link
Contributor

@mki-c2c mki-c2c commented Aug 18, 2023

JIRA issue

https://jira.camptocamp.com/browse/GSLUX-326

Description

Screenshots

(only if the final render is different)

@github-actions
Copy link
Contributor

GitHub Pages links: * Luxembourg-geoportail: https://geoportail-luxembourg.github.io/luxembourg-geoportail/maplibre_legacy_OL/

Copy link
Contributor

@AlitaBernachot AlitaBernachot left a 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.
image

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.

import { Ref, ref } from 'vue'
import { acceptHMRUpdate, defineStore } from 'pinia'

export const DEFAULT_LANG = 'fr'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be cleaned

Copy link
Contributor Author

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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 => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean code comment.

Copy link
Contributor Author

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.

@@ -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
Copy link
Contributor

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().

Copy link
Contributor Author

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.

if (layer === null || layer === undefined) return null
const id = layer.id

return layersCache.get(id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be simplified

Suggested change
return layersCache.get(id)
function getLayerFromCache(
layer: Layer | undefined | null
): BaseLayer | null {
return layer ? layersCache.get(layer.id) : null
}

Copy link
Contributor Author

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, {
Copy link
Contributor

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

Copy link
Contributor Author

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)
Copy link
Contributor

@AlitaBernachot AlitaBernachot Aug 22, 2023

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?

Copy link
Contributor Author

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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use stores to configure env. variables, move this into a configurable service instead if needed. By the way, @tkohr has already handled the case, see: e5d151a

@@ -293,7 +310,9 @@ export default function useOpenLayers() {
olMap.addLayer(bgBaseLayer)
}
}
statePersistorStyleService.restoreStyle(true)
if (oldBgLayerId !== bgLayer?.id) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

https://github.com/Geoportail-Luxembourg/luxembourg-geoportail/blob/maplibre_legacy_OL/src/composables/map/ol.synchronizer.ts#L106

Copy link
Contributor

@tkohr tkohr left a 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.

* @property {string|HTMLElement} container
*/

export default class MapBox extends Layer {
Copy link
Contributor

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?

Copy link
Contributor Author

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

@tkohr tkohr left a 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.

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Contributor

@AlitaBernachot AlitaBernachot left a 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.

Copy link
Contributor Author

@mki-c2c mki-c2c left a 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

@@ -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
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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.

https://github.com/Geoportail-Luxembourg/luxembourg-geoportail/blob/maplibre_legacy_OL/src/composables/map/ol.synchronizer.ts#L106

if (layer === null || layer === undefined) return null
const id = layer.id

return layersCache.get(id)
Copy link
Contributor Author

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 => {
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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.

import { Ref, ref } from 'vue'
import { acceptHMRUpdate, defineStore } from 'pinia'

export const DEFAULT_LANG = 'fr'
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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

* @property {string|HTMLElement} container
*/

export default class MapBox extends Layer {
Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@mki-c2c mki-c2c merged commit bf76f3e into main Sep 22, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants