lizmap-javascript-scripts icon indicating copy to clipboard operation
lizmap-javascript-scripts copied to clipboard

Selection from a popup feature geometry not working

Open gioman opened this issue 1 year ago • 11 comments

I believe that my test project is ok, configured as explaine in the script readme. Using QGIS Server/Desktop 3.28.15 and LMWC 3.6.10

When clicking on the icon/star in the feature popup (to trigger the selection on the other layers) the dev console shows this:

Uncaught TypeError: lizMap.mainLizmap.digitizing.drawLayer.getSource is not a function
    popupSelectionButtonClickHandler getMedia:86
    addSelectionButton getMedia:32
    lizmappopupdisplayed getMedia:178
    lizmappopupdisplayed getMedia:154
    triggerEvent OpenLayers.js:255
    Z map.js:2679
    getfeatureinfo map.js:3440
    triggerEvent OpenLayers.js:255
    triggerGetFeatureInfo OpenLayers.js:1692
    handleResponse OpenLayers.js:1693
    callback OpenLayers.js:1689
    bind OpenLayers.js:77
    runCallbacks OpenLayers.js:1563
    onreadystatechange OpenLayers.js:1559
    dispatchEvent OpenLayers.js:1593
    fReadyStateChange OpenLayers.js:1596
    onreadystatechange OpenLayers.js:1579
    open OpenLayers.js:1574
    issue OpenLayers.js:1558
    GET OpenLayers.js:1564
    request OpenLayers.js:1691
    getInfoForClick OpenLayers.js:1683
    callback OpenLayers.js:718
    delayedCall OpenLayers.js:1384
    bind OpenLayers.js:77
    setTimeout handler*queuePotentialClick OpenLayers.js:1380
    handleSingle OpenLayers.js:1380
    click OpenLayers.js:1377
    triggerEvent OpenLayers.js:255
    handleBrowserEvent OpenLayers.js:261
    bindAsEventListener OpenLayers.js:77
    observe OpenLayers.js:238
    attachToElement OpenLayers.js:247
    initialize OpenLayers.js:244
    initialize OpenLayers.js:300
    init map.js:1362
    init map.js:6282
[getMedia:86:44](https:/***/lizmap/www/index.php/view/media/getMedia?repository=qgisserverdemos&project=teste&mtime=1709052737&path=media%2Fjs%2Fdefault%2FselectionFromPopupGeometry.js)

​

gioman avatar Feb 27 '24 17:02 gioman

Hi gioman, Your error indicates that getSource does not exist for your object. This method doesn't work with LMWC 3.6 but works with LMWC 3.7. I believe this is because version 3.7 removed code from OpenLayers 2. You can test lizMap.mainLizmap.digitizing.drawLayer.getSource().clear() in the JS console for both of these projects to see the difference:

LMWC 3.6 Projects LMWC 3.7 Project

altheaFeu avatar Mar 01 '24 10:03 altheaFeu

Your error indicates that getSource does not exist for your object. This method doesn't work with LMWC 3.6 but works with LMWC 3.7. I believe this is because version 3.7 removed code from OpenLayers 2.

@altheaFeu thanks for the reply. The script is 2 years old, with no recent changes, so does not seems to be the case(?).

You can test lizMap.mainLizmap.digitizing.drawLayer.getSource().clear() in the JS console for both of these projects to see the difference:

LMWC 3.6 Projects LMWC 3.7 Project

unclear to me what I should test. The first link does not point to a specific project, the second one points to a project that has no selection tool available.

gioman avatar Mar 01 '24 12:03 gioman

The first link does not point to a specific project

You can choose any project you want for the first one. They are all using LMWC 3.6.

unclear to me what I should test.

I expressed myself poorly. If you type lizMap.mainLizmap.digitizing.drawLayer.getSource().clear() in the JS console of this project (LMWC 3.6), you will encounter an error,

Uncaught TypeError: lizMap.mainLizmap.digitizing.drawLayer.getSource is not a function

You won't face an error if you do the same thing with LMWC 3.7 project.

I suspect that the issue originates from the version of your LMWC.

altheaFeu avatar Mar 01 '24 13:03 altheaFeu

I expressed myself poorly. If you type lizMap.mainLizmap.digitizing.drawLayer.getSource().clear() in the JS console of this project (LMWC 3.6), you will encounter an error,

@altheaFeu but the js code is 2 years old with no changes in the meantime, this means that it has been created as it is long before LM 3.7.

gioman avatar Mar 01 '24 14:03 gioman

@gioman Indeed, in this case, I wouldn't be able to tell where the error comes from.

altheaFeu avatar Mar 01 '24 15:03 altheaFeu

@altheaFeu thanks anyway!

gioman avatar Mar 01 '24 15:03 gioman

Hi @gioman I needed this tool for my own project, so I rectified the script. I also translated the native JavaScript functions into jQuery. You can find the correction here, and it successfully operated on my project with LMWC 3.5.10.

altheaFeu avatar Mar 28 '24 16:03 altheaFeu

@altheaFeu thanks!

gioman avatar Mar 30 '24 11:03 gioman

You can find the correction https://github.com/3liz/lizmap-javascript-scripts/pull/78, and it successfully operated on my project with LMWC 3.5.10.

Thanks @altheaFeu for all contributions ! Very appreciated. I didn't get time last week to review (I was in Grenoble for the QGIS user conf where I met some of your company :) )

Sorry, but did you have a instance with LWC 3.7 running ? For now, Javascript files do not have metadata about which LWC versions they are targeting. I'm bit reluctant to merge files if it's targeting LWC 3.5, as this version is already not maintained by us.

Of course, if your files are on API that didn't change in LWC 3.7, there is no issue, but I will need to ask my colleagues for the review (@nboisteault mainly)

Gustry avatar Apr 04 '24 13:04 Gustry

Thanks @altheaFeu for all contributions !

@Gustry You're welcome ! I'm currently working on Lizmap projectsat the place where I'm doing my apprenticeship. We're developing JS tools, and since we're using an open-source solutions, it seems only natural to share my work as open source (It's afterall one of the primary objective of open-source).

Sorry, but did you have a instance with LWC 3.7 running ?

Unfortunately, I'm using an LWC 3.5 instance. But I'll try to install a 3.7 version on my personal computer if I find the time outside of my classes and my apprenticeship hours (so it's not guaranteed).

altheaFeu avatar Apr 04 '24 14:04 altheaFeu

If the PR makes the script work on LM 3.6 is well worth the merge, many are holding on the move to LMWC 3,7.

gioman avatar Apr 05 '24 12:04 gioman