Geoportail-Luxembourg / geoportailv3

geoportailv3 is the implementation of the v3 of the map viewer of the luxembourgish geoportal
MIT License
25 stars 16 forks source link

Export au format KML et GPX #791

Closed adonno closed 8 years ago

adonno commented 9 years ago

Link to #782

jaykayone commented 8 years ago

@elemoine could you help on this one? You are certainly the one who knows this best.

It concerns KML and GPX import and export

rmichaelis commented 8 years ago

Maybe does @elemoine need some examples of our KML and GPX ?

elemoine commented 8 years ago

Could you please elaborate on how I could help on KML/GPX import/export?

jaykayone commented 8 years ago

I think implementing a directive to import and export KML/GPX data into or from a map would be welcome ..

We could then try with a maximum of files that we have and have encountered problems with.

That way we could profit from your experience to patch openlayers if necessary

elemoine commented 8 years ago

I've done a bit of research related to the export/import functionality, and see how we can implement it based on today's web technologies.

Export

For "export" we will use ol.format.GPX and ol.format.KML to create text representations of features in the map. So no apparent problem here.

Then we need a way for the user to be able to download/save the GPX or KML file.

One possible way is to use an anchor element (<a>) with a download attribute. This is what the OpenLayers export-map example uses. Unfortunately, the download attribute is not supported on IE and iOS.

Another option is to use the FileSaver.js library. This library is used by the jsPDF library. It is also used in mf-geoadmin3. It is to be noted that FileSaver.js does not work on IE 9, although it seems that a workaround exists for text data (which is our case). Also, experiments revealed that FileSaver.js doesn't work on Safari (8 & 9) either.

How export currently works:

In the current version, the export functionality is based on the Mymaps controller's export action. That action is a basic "echo" service, which sets the Content-Disposition header on the responses. On the client Ext.Ajax.request, with isUpload set to true, is used. So in reality Ext posts the document through a form in a iframe, and no Ajax request is involved.

Import

For "import" we will again use ol.format.GPX and ol.format.KML to create OpenLayers features from GPX and KML documents.

The main question is how to get access to the GPX or KML document from the JavaScript code.

The geoadmin application provides three ways to users for importing a KML file: drag&drop, load local file from disk, load remote file from URL.

For "drag&drop" we can rely on the OpenLayers DragAndDrop interaction, which is based on the "drag&drop" support from the browser. The support for "drag&drop" is partial in IE. I still need to understand what it means for the cases we want to support.

For "load local file from disk" geoadmin uses the FileReader browser API. Again IE 9 does not support the FileReader, and the support in IE 10 is partial (with probably no impact for us).

For "load remote file from URL" geoadmin uses the ogcproxy web service to work around the cross-origin policy. I don't see how we could do without a web service in this case.

How import currently works:

In the current version, the import functionality is based on an upload web service. The KML/GPX document is POSTed to the upload action of the controller, which stores the file on disk, and returns a JSON containing the URL to the download action. The client then uses that URL to download the file through Ajax. See the MyMapsPanel.js file. Note that the file is not POSTed through Ajax, the fileUpload option is used, making Ext post the file through a form in a iframe.

How KML import works in GeoMaFish 1:

In GeoMapFish 1 (with CGXP) the import KML functionality is based on c2cgeoportal's "echo" web service. And here again CGXP uses an Ext form with fileUpload set to true, meaning that the document is posted through a form in a iframe. But in contrast to geoportailv2 just one step is used.


Question for the Luxembourg team: for import do we want to support "drag&drop", "load local from disk" and "load remote file from URL", or just a subset of these?

jaykayone commented 8 years ago

Thanks @elemoine for this analysis. We discussed this. In geoportailv2 we only had "load local from disk" and we think it would be enough for v3 too. drag and drop is a nice to have, so if it can be added easily let's do it. There is not need for "load remote from URL".

FileSaver.js seems like a good way to go. Don't loose too much time on IE9, we have 4% and the percentage is decreasing

elemoine commented 8 years ago

Sounds good to me.

Another thing: I am not sure about FileSaver.js and Safari. And FWIW mf-geoadmin3 uses their "download web service" on IE 9, or Safari, or when the browser doesn't have Blob (required by FileSaver.js). Note that their "download web service" is quite straightforward, so it shouldn't be a problem to add such a web service to geoportailv3 should we need one.

jaykayone commented 8 years ago

let's try it out

elemoine commented 8 years ago

This is an example using FileSaver.js: http://erilem.net/ngeo/exportfeatures/examples/exportfeatures.html. Seems to work on FF, Chrome, IE 10 & 11. However it does not work on Safari 8 for me (in Browserstack).

jaykayone commented 8 years ago

indeed, it does not work in safari 9 either

elemoine commented 8 years ago

So either we find a way to make it work, or a "download" web service will be required for Safari and IE 9.

jaykayone commented 8 years ago

let me play devil's advocate here: if we have to write a download service, why not use it in every browser?

elemoine commented 8 years ago

let me play devil's advocate here: if we have to write a download service, why not use it in every browser?

It's a fair question. I'm asking the same to myself. What you gain is a round-trip on the wire for capable browsers.

elemoine commented 8 years ago

For everyone's information, I've added more information to the analysis, with explanations on the way the current version (geoportail v2) works.

Also, I've added the "import" functionality to my exportfeatures.html example. It's based on the FileReader browser API (see the analysis for details). See http://erilem.net/ngeo/exportfeatures/examples/exportfeatures.html again. I confirm that it works in Firefox and Chrome. Could you please test in IE 10+ and Safari? This file can be used for testing: http://erilem.net/ngeo/exportfeatures/examples/data/2012-02-10.kml.

jaykayone commented 8 years ago

@petzlux can you do safari? @rmichaelis can you do ie10 please?

elemoine commented 8 years ago

I just tried on IE 10 in a Virtualbox VM and it worked. I also confirm that it won't work on IE 9.

elemoine commented 8 years ago

It would be good to know if "import" works with my example in Safari. If it does then it means we have a server-less solution for "import", if we exclude IE 9 obviously. Although we also need to test on phones and tablets...

For "export", the most difficult part it seems, I agree with @jaykayone that we should use the download/export service for every browser, instead of pulling in FileSaver.js and have browser-specific js code. So the plan would be to have a very simple download/export service, and have the client code post the GPX/KML doc to that service through a form. Using a form is necessary for the browser to open a "save as" window upon receiving the response (with Content-Disposition) from the service. The download/export service should go into c2cgeoportal.

petzlux commented 8 years ago

Okay, seems to work in my Safari fine !

elemoine commented 8 years ago

Okay, seems to work in my Safari fine !

Thanks for testing. So it seems we're in pretty good shape on the "import" part. I mentioned "phones" and "tablets" in my previous comment, but I'm not fully sure "import" really makes sense on mobile devices. Sounds like secondary to me.

jaykayone commented 8 years ago

I agree, it is not prioritary at all

On 28 oct. 2015, at 11:36, Éric Lemoine notifications@github.com wrote:

Okay, seems to work in my Safari fine !

Thanks for testing. So it seems we're in pretty good shape on the "import" part. I mentioned "phones" and "tablets" in my previous comment, but I'm not fully sure "import" really makes sense on mobile devices. Sounds like secondary to me.

— Reply to this email directly or view it on GitHub.

elemoine commented 8 years ago

I found two OpenLayers bugs while working on the "export/import" functionality. One on the GPX format and one on the KML format. I created a PR for the former, see https://github.com/openlayers/ol3/pull/4361. The latter has an unfinished PR: https://github.com/openlayers/ol3/pull/3955. I'll try to finish it.

elemoine commented 8 years ago

I've also created an ngeo PR that adds an ngeo-filereader directive and an example demonstrating how to use that directive to import KML files. See https://github.com/camptocamp/ngeo/pull/378.

elemoine commented 8 years ago

The latter has an unfinished PR: openlayers/ol3#3955. I'll try to finish it.

For the record, I've created two ol3 PRs related to the KML format: https://github.com/openlayers/ol3/pull/4376 and https://github.com/openlayers/ol3/pull/4378.

elemoine commented 8 years ago

The OpenLayers 3, ngeo and c2cgeoportal patches I worked on for the GPX/KML export/import are now all closed.

jaykayone commented 8 years ago

@pgiraud can you check when we can merge this ? --> cf c2cgeoportal

petzlux commented 8 years ago

Any progress on this ?

rmichaelis commented 8 years ago

Still not. As discussed last week with @pgiraud , I'll do the job. It seems that a new RC of c2cgeoportal should be available this week. I'll use it.

rmichaelis commented 8 years ago

Link to #962

rmichaelis commented 8 years ago

What are the supported projections of the files we want to import ?

geoportallux commented 8 years ago

AFAIK these files are always in LL84 / 4326

Jeff Konnen


From: "Renaud Michaëlis" Date: vendredi 11 décembre 2015 17:31:21 To: "Geoportail-Luxembourg/geoportailv3" Subject: Re: [geoportailv3] Export au format KML et GPX (#791)

What are the supported projections of the files we want to import ?

Reply to this email directly or view it on GitHubhttps://github.com/Geoportail-Luxembourg/geoportailv3/issues/791#issuecomment-163983259.

rmichaelis commented 8 years ago

It seems that Openlayers allows to export/import in the projection you want. That means, I have to export everything in 4326

Here is an exmample of a mymaps export :

<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 https://developers.google.com/kml/schema/kml22gx.xsd"><Document><Placemark id="1635262"><name>un point</name><description>avec des accents :::%??

" select *</description><Style><LineStyle><color>ff0000ff</color><width>10</width></LineStyle><PolyStyle><color>7f0000ff</color></PolyStyle></Style><Point><coordinates>667201.299280475,6467436.38128167</coordinates></Point></Placemark><Placemark id="1635261"><name>un trait</name><description>test</description><Style><LineStyle><color>ffff99cc</color><width>10</width></LineStyle><PolyStyle><color>7fff99cc</color></PolyStyle></Style><LineString><coordinates>666767.232683719,6467341.703417777 667108.1839549331,6467315.974275423 667179.2315551225,6467554.959894007 667294.6947166746,6467436.598574937 667195.2684744908,6467352.078420372 667154.9100266285,6467303.596540394 667253.132531319,6467235.146847445 667100.426588668,6467305.029876819 666982.4570869074,6467164.2738241805 666871.7513276841,6467245.177129016 666730.2494936596,6467183.966349386 666716.0402123149,6467268.219497265 666633.3525458181,6467347.6266661035 666549.364938923,6467319.328546397 666287.6150717711,6467420.151811348 666637.9365743726,6467383.538331486 666650.43017412,6467366.3984082015</coordinates></LineString></Placemark><Placemark id="1635260"><name>Maison de la retraitée</name><description></description><Style><LabelStyle><color>ff000000</color></LabelStyle></Style><Point><coordinates>667377.3718468049,6466682.123323638</coordinates></Point></Placemark><Placemark id="1635259"><name>terrain de foot</name><description>enfin je crois</description><Style/><Polygon><outerBoundaryIs><LinearRing><coordinates>667835.8139249292,6467000.012550591 667982.0059817753,6467054.189823223 667873.3815466495,6466905.667513486 668016.4505223219,6466963.738596236 667831.1566534559,6466994.539140862 667853.0667011909,6466941.520523654 668002.3483082037,6467005.849418113 667835.8139249292,6467000.012550591</coordinates></LinearRing></outerBoundaryIs></Polygon></Placemark></Document></kml>
rmichaelis commented 8 years ago

better file name

rmichaelis commented 8 years ago

No button. Open directly the file selector