makinacorpus / Leaflet.FileLayer

Loads files locally (GeoJSON, KML, GPX) as layers using HTML5 File API
http://makinacorpus.github.io/Leaflet.FileLayer/
MIT License
273 stars 91 forks source link

Leaflet.FileLayer (demo) doesn't work for geojson files #18

Closed kkdd closed 8 years ago

kkdd commented 10 years ago

Hello, I have realized that the demo, http://makinacorpus.github.io/Leaflet.FileLayer/index.html, doesn't work for geojson files, but for kml files. ps. I would appreciate it if you could put some sample files in the Leaflet.FileLayer directory.

leplatrem commented 9 years ago

I tried it and it works as expected :) What kind of errors do you have?

kkdd commented 9 years ago

Thank you for your comment. My failure was cause by a syntax error in parsing json due to the strictness of JSON.parse(). In order to relax the situation, I would like to modify the source as follows:

+            try
+            {
-            content = JSON.parse(content);
+                content = eval("(" + content + ")");
+            }
+            catch(e)
+            {
+                console.log("in parsing json: SyntaxError");
+            }

and additionally

         this._parsers = {
             'geojson': this._loadGeoJSON,
+            'json': this._loadGeoJSON,
             'gpx': this._convertToGeoJSON,
             'kml': this._convertToGeoJSON
         };

.

leplatrem commented 9 years ago

I don't feel entirely at ease with eval()... Can you argue a bit more please ? Would it go here https://github.com/makinacorpus/Leaflet.FileLayer/blob/gh-pages/leaflet.filelayer.js#L64 ?

But I'm ok with considering .json extension as GeoJSON. You can open a pull-request ! (or just edit the file directly on Github if it's easier for you)

Thanks !

enguerran commented 8 years ago

32 was merged, I close this issue.