Failed to add leaflet-measure plugin

216 views
Skip to first unread message

Jesús Pinilla

unread,
Sep 6, 2022, 12:49:47 PM9/6/22
to Leaflet
I'm used to include in my projects simple Leaflet plugins, for example "Zoomslider", where the files to use are just " Zoomslider.css" and " Zoomslider.js":

<link rel="stylesheet" href="src/plugins/L.Control.Zoomslider.css">
<script src="src/plugins/L.Control.Zoomslider.js"></script>
<script> var ctlZoomslider;
      ....
     ctlZoomslider = L.control.zoomslider({position:'topright'}).addTo(mymap); </script>

However, I'm having problems in adding leaflet-measure. I have tried the following (just a copy of the above code):

<link rel="stylesheet" href="src/plugins/leaflet-measure.scss">
<script src="src/plugins/leaflet-measure.js"></script>
<script> var ctlMeasure;
   ....
   ctlMeasure = L.control.measure();
   ctlMeasure.addTo(myMap);  </script>

But it doesn't work, and I get the following error messages in the browser console:

http://localhost/src/plugins/leaflet-measure.scss net::ERR_ABORTED 404 (Not Found) Uncaught SyntaxError: Cannot use import statement outside a module (at leaflet-measure.js:1:1)

Any suggestions to overcome this issue would be very much appreciated.

Bodo Minea

unread,
Sep 6, 2022, 3:19:01 PM9/6/22
to leafl...@googlegroups.com
Hi, the files included on GitHub for leaflet-measure are not production-ready builds, they are source files. Browsers cannot directly interpret TypeScript or SCSS (mind the S before CSS, that indicates the file needs to be compiled first).

The easy solution is to include the prebuilts you can download at http://ljagis.github.io/leaflet-measure/leaflet-measure.css and http://ljagis.github.io/leaflet-measure/leaflet-measure.js, include it from an online cdn https://www.jsdelivr.com/package/npm/leaflet-measure or clone the the project in whole to your PC and build the dist files as instructed here - https://github.com/ljagis/leaflet-measure#distribuition-build

--

---
You received this message because you are subscribed to the Google Groups "Leaflet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leaflet-js+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/leaflet-js/b238d46a-cd9e-4bb1-beb0-ea1034bc80c8n%40googlegroups.com.


--
Reply all
Reply to author
Forward
0 new messages