3liz / lizmap-web-client

Transfer a QGIS project on a server, Lizmap is providing the web interface to browse it
https://www.lizmap.com
Mozilla Public License 2.0
257 stars 143 forks source link

[question] Adding new layer to an open lizmap project in the browser #414

Closed jonnyforestGIS closed 2 months ago

jonnyforestGIS commented 7 years ago

Hi guys, it's possible to add a layer into an open lizmap project in the browser? If yes how can i do it? If no where i can see documentation to try to implement this and share?

Regards, João

rldhont commented 7 years ago

It's a feature not yet implemented.

jonnyforestGIS commented 7 years ago

Can i try to help? This need to be done using jelix or OpenLayers?

nboisteault commented 7 years ago

Hi, João, you mean to add a WMS layer? If yes, it is mostly an OpenLayers feature. You can look at our viewer here and click on this button addwms to use the 'add a WMS layer' feature. You can then look at the javascript/openlayers to get inspiration.

jonnyforestGIS commented 7 years ago

@nboisteault WMS, WFS or a local client geofile (.kml, .shp , gml, or geojson). Imagine this: The user have access to a rep in a Lizmap project and wants to upload temporary and overlay to see their information with the lizmap project. This is all OpenLayers side?

mdouchin commented 7 years ago

To ease the development of this feature, I think we should use the QGIS Server plugin wps4server , which can basically run processing scripts or models server side. Its advantage is to automatically create a QGIS project and server the new layer data in WFS and WMS.

So if we publish a simple script "convert", we would be able to send a KML or GeoJSON and add it in Lizmap. I mean no need to recode the server side part. With this you can imagine other scenarios, such as asking for a buffer, or doing an graph, etc.

jonnyforestGIS commented 7 years ago

Hum... nice @mdouchin. correct me if i'm wrong but the process will be more and less like this:

I will explore the wps4server to test and see how it works.

nboisteault commented 7 years ago

@jonnyforestGIS in the link I gave you above you'll also find an area where GeoJSON data can be drag'n'drop. All is done client side.

image

@mdouchin I'm not sure I understand. If a user wants to add a WMS or WFS layer, OpenLayers could directly handle it, so I don't understand the purpose of wps4server.

mdouchin commented 7 years ago

@nboisteault sure, for a WFS or WMS, not need to use a server script to do so

@jonnyforestGIS we will still need to create the interface in Lizmap and code to

nboisteault commented 7 years ago

OpenLayers 2 can natively read GeoJSON, KML and GML so we need a way to convert shapefile to GeoJSON. This link is interesting, maybe conversion could be made client side or via a webservice. Maybe the limitation is how much data the browser can accept as input. wps4server would be the solution for very big geodata by creating a WMS.

Spitfiire commented 7 years ago

I had not seen this post before, the idea is very interesting. I purpose this :

495

jonnyforestGIS commented 7 years ago

Hi, i've do a little research and i found this two: https://github.com/gipong/shp2geojson.js http://wavded.github.io/js-shapefile-to-geojson/

I think one is a fork of other.

This javascript libraries can load to the map without upload to the server-side. Perhaps put the javascript in the custom themes?

Regards João

nboisteault commented 7 years ago

I also found https://github.com/substack/shp2json and there are many scripts available here to convert many formats in GeoJSON.

jlstanus commented 7 years ago

Yes, in my case, adding wfs (with thousand of features) intersets me. But as seen as Lizmap has some limitations with feature numbers in the table, a filter on attributes input would be welcome

armagaet commented 6 years ago

@nboisteault the solution you post is really useful, thanks! I've tried it on my personal lizmap project, I correctly add the WMS on the map, but then I'm not able to show the layer inside the layer menu: how have you achieved that? I'm trying to hack your code but is really hard ;)

To be more precise, I open a lizmap.dock and inside it I load an iframe with a window to choose the WMS url and the layers. Then from the iframe I call: lizmap.map.addLayer(wms_utente);

As I said the layers is correctly loaded but not shown in the menu layers, so I can't switch-off it, for example...

Thanks in advance! Riccardo

nboisteault commented 6 years ago

@armagaet addLayer() is an OpenLayers method to add a layer but it won't change the switcher at left. You need to find a Lizmap method to do that. Maybe you can add your layers in layerConfig object the same way external WMS layers (look at externalWmsToggle and externalAccess in code) are added by Lizmap plugin and then reload the switcher (createSwitcher() maybe ?).

armagaet commented 6 years ago

@nboisteault thanks for the tip. I'll have a look inside the code of LizMap to find the functions you cited. Anyway I find really "obscure" the code of LizMap, there is no documentation or API guide...

By the way, right now I'm trying to let recognize the legend of my added WMS because it seems OL2 is not able to load it correctly (only for some services I've got this problem), and I'm not able to set the corret wms "getLegend"'s url.

nboisteault commented 6 years ago

I find Lizmap code very clear. Like any other code you need time to dig in it. What are the URL and layer of the WMS you want to add ?

armagaet commented 6 years ago

For the WMS I've solved it right now thanks to this thread (if anyone could be interested): http://www.geoext.org/pipermail/users/2010-January/000462.html (I was using GeoExt to create the legend for another project)

Now I will focus on the problem inside LizMap and I will let you know, in case this problem could interest someone else.

By the way the URL of the WMS I would like to load in LizMap (among others) is: http://webgis.arpa.piemonte.it/ags101free/services/geologia_e_dissesto/SIVA/MapServer/WMSServer?

josemvm commented 6 years ago

hi @nboisteault

in this url case and for e.g. xxx layer, how can we add this layer to the LWC?

thanks

nboisteault commented 6 years ago

Sorry I have not coded anything in LWC but what I would try to do is :

It is just an idea ...

armagaet commented 6 years ago

I'm trying to add my layer to: lizMap.config.layers and lizMap.layers, because the object layerConfig is not accessible from my external js code. I get a call to my code in lizmap/responses/myHtmlMapResponse.class.php as $this->addJSLink($bp.'js/riccardo.js');

I don't know if this is the right way. Then in my code riccardo.js I add the lizMap.addDock() function that add my button on the lizMap left menu. Clicking on this button let call my script to set the WMS url and add it to the map.

Also the function createSwitcher() is not accessible outside the lizmap/www/js/map.js code:

Uncaught TypeError: lizMap.createSwitcher is not a function

Honestly I don't know how to access the menu legend in lizMap and update it with new WMS layer already added on map...

Thanks

mdouchin commented 6 years ago

@armagaet We have not published all functions in Lizmap API.

We are aware of improvements to make to

We have planed to do this work, but have yet no fundings to support this kind of work. If you can provide some help in this area, this could benefit to all users.

For your question, it is indeed not so easy to fully integrate an external layer in Lizmap web client, which has been built first with a strong relationship to the QGIS Project.

We could developp a public function to help the devs to do so, something like lizMap.addWmsLayer(url, minZoom, maxZoom, ....)

rldhont commented 2 months ago

I think this feature https://github.com/3liz/lizmap-web-client/pull/4389 fixes this issue, isn't it ?

jonnyforestGIS commented 2 months ago

@rldhont I confirm. Can be close.