-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does not work with ES6 imports for leaflet #874
Comments
works fine for me if you just import all of it...
|
Yes but then you throw away all the benefits of ES6 modules. Which is to load only what you really need. |
If you find a solution let me know, what modules does this work with so far on leaflet? |
Yeah, I'm interested in this proper solution as well... I've taken from the above and was able to get it working, although, as mentioned without the benefit of ES6 and selectively loading what was needed.
Related PRs and discussions for Leaflet:
I'd love to figure out how to use the correct, minimalistic ES6 way with my custom Leaflet setup. The only plugins I'm using are markercluster, because who wouldn't use it?! and the Google maps layer. If I use: |
Hi @himerus, By curiosity, please what is your build engine, version, and what are the Leaflet and Leaflet.markercluster versions you are using? |
I too have the same problem as @himerus.
but if I use
I got error 'L' is not defined no-undef I'm using maven to build |
Same as above mentioned by @azrin1972 . Only difference in my setup is I'm using Webpack. The |
Hi, Thank you @azrin1972 and @himerus for the details of your setup. Very strange, I have no issue at all with webpack, either with
|
I have the same issue. only happens with leaflet 1.3.1 but not with 1.3.0. |
My mistake, I was using a branch version of leaflet: https://github.com/va2ron1/Leaflet which doesn't have the |
Right under the imports, I have used this to declare L. const L = window['L']; |
I'm using
and
The following worked for me:
|
Make things working on
Solution based on earlier crunch (L<=1.3.1). |
I'm using webpack to bundle my project. When I put |
Hi, I'm still unable to load markercluster in my project. what I'm trying to do is to add markercluster to https://github.com/thingsboard/thingsboard. Really need some help on how to solve this. it uses webpack 1.13.2. and I cannot use webpack 4 - I'm getting error compiling it. I've tried all the solution here and still getting the same issue |
Finally found the solution instead of using I use import L from 'leaflet' some reading http://www.thedreaming.org/2017/04/28/es6-imports-babel/ |
Ran into this issue while trying to use Markercluster in a web component based PWA (no packaging involved yet, just dev server). I can import all the leaflet modules like this:
but |
A guess the way to solve this is to stop depending on |
@danzel What do you say about this? Shall we try to make this package independent on global |
We follow what leaflet recommends for plugins (AFAIK). If we want to change this, probably fire up an issue on the leaflet tracker for discussion. |
I can't see anything in their recommendations against this, we'll still bundle the plugin so it'll work as before for those who're using the UMD version |
Coming back here after 2 years I'd have thought this issue to be resolved. It seems its still not possible to properly import leaflet and this plugin. |
I've made PR #984 that should fix this few days ago, I'd like some backup. Basically in source files And it's ok with guidelines: |
import * as L from "leaflet"; Hope it works for you guys |
this gives me :
|
just in case anybody runs into the same situation I had here: import "leaflet";
import "leaflet.markercluster";
...
let mcluster = L.markerClusterGroup({ chunkedLoading: true }); to: import { Map, Marker, } from "leaflet";
import { MarkerClusterGroup } from "leaflet.markercluster/src";
...
let mcluster = MarkerClusterGroup({ chunkedLoading: true }); I banged my head against a wall until I realized I had to call it with let mcluster = new MarkerClusterGroup({ chunkedLoading: true }); |
I guess this still has not been fixed? |
Might be able to work around this by adding to webpack.config.js under exports.plugins:
|
since we're posting hotfixs. I've got a Vue app in Quasar 2. Before the Vue app is initialized:
in a component then:
|
I was having a similar problem using leaflet in Vite: Using |
It seems this plugin makes the assumption that
L
is still exported globally.However using leaflet the ES6 way with direct imports like
import { map } from "leaflet/src/map/Map"
does not expose a
L
global anymore. So trying to include this pluginsMarkerClusterGroup
fails cause of this definition.export var MarkerClusterGroup = L.MarkerClusterGroup = L.FeatureGroup.extend({
The correct way would be to write this like this:
The text was updated successfully, but these errors were encountered: