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
bounds are not of type LatLngBounds. #48
Comments
Thanks for the detailed report, @Saltibarsciai ! Before I get too far into it, I just want to confirm something with you. In your sample code, you have
—should that either have |
@mikeu sorry, I tried to write it from my head as sketch, mine code is a bit more complicated, if you need reproduction repo I can create it. this sketch is more correct, but still to actually reproduce you would need 2 nextTicks on 0.1.2
|
another thing: now use the same bounds via map ref |
Thanks for the clarifications, @Saltibarsciai . This error reminds me very strongly of one I saw ages ago in Vue2Leaflet, long before I started working on its code, I've literally stepped through that same function, seeing Leaflet look at what should be a LatLngBounds object, then move on to create new bounds with an undefined second parameter :) I think I've managed to reproduce the issue, but one more question to confirm—somewhere in there you end up calling |
@mikeu yes, good catch, I forgot to mention that! |
@Saltibarsciai Are you using webpack and vue-cli? Could you try adding an alias for leaflet on the vue-cli webpack config? // vue.config.js
const path = require('path');
module.exports = {
configureWebpack: config => {
config.resolve.alias['leaflet'] = path.join(__dirname, 'node_modules/leaflet');
},
}
} |
@DonNicoJs I'm using laravel mix. I added:
but issue still occurs |
reproduction demo: https://github.com/Saltibarsciai/leaflet-laravel |
@Saltibarsciai Thank you so much! |
@Saltibarsciai I've took a look at the reproduction demo and I've seen a 'pattern', can you try to remove
And see if ti works? I am quite sure that this is the 'old' issue where leaflet is imported multiple times |
@DonNicoJs Just did, pushed changes to repo, same error.
|
tested map bounds, they are valid for fitbounds
other bounds are not
|
I temporary fixed this issue in production by renaming |
So this happens because leaflet inside compare with |
As I expected, if one tries: <template>
<div style="height: 75vh; width: 50vw;">
<l-map ref="map" v-model:zoom="zoom" :center="center" @ready="readyHandler">
<l-tile-layer
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
></l-tile-layer>
<l-marker :lat-lng="[0, 0]" draggable @moveend="log('moveend')">
<l-tooltip>
lol
</l-tooltip>
</l-marker>
</l-map>
<button @click="changeIcon">New kitten icon</button>
</div>
</template>
<script>
import "leaflet";
import { LMap, LTileLayer, LMarker, LTooltip } from "@vue-leaflet/vue-leaflet";
import "leaflet/dist/leaflet.css";
export default {
components: {
LMap,
LTileLayer,
LMarker,
LTooltip,
},
data() {
return {
center: [47.41322, -1.219482],
zoom: 2,
iconWidth: 25,
iconHeight: 40,
};
},
methods: {
log(a) {
console.log(a);
},
async readyHandler() {
const bounds = this.$refs.map.leafletObject.getBounds();
const lBounds = window.L.latLngBounds(
bounds._northEast,
bounds._southWest
);
console.log(bounds instanceof window.L.LatLngBounds);
console.log(lBounds instanceof window.L.LatLngBounds);
},
},
};
</script>
This is a tell that we have 2 different leaflet instances going on. |
@Saltibarsciai Okay I found a workaround for you! A decent one! Instead of doing
If you use dynamic imports it works perfectly, here is how I modified the above function: async readyHandler() {
const { latLngBounds, LatLngBounds } = await import(
"leaflet/dist/leaflet-src.esm"
);
const bounds = this.$refs.map.leafletObject.getBounds();
const lBounds = latLngBounds(bounds._northEast, bounds._southWest);
console.log(bounds instanceof LatLngBounds); // true
console.log(lBounds instanceof LatLngBounds); // true
}, |
So what I am thinking is that when using dynamic imports and normal imports somehow we end up importing two different instances of leaflet @mikeu This will pose a problem, I am thinking to add an utility function that will allow the user to specify what modules do they want from leaflet, it will import them and return them, otherwise this is going to become a nightmare |
@Saltibarsciai @mikeu I finally found the culprit and the fix! Inside vue-leaflet we are always importing from @Saltibarsciai if you smply start importing directly from You can check this codesanbox for how I came to the solution: https://codesandbox.io/s/awesome-hofstadter-48s8s?file=/src/index.js We need to document this ASAP :) Or maybe even experiment if we can import directly from |
@DonNicoJs Awesome, you solved it!
fixes the error! This probably should be put in README.md as warning. Moving from vue2leaflet people will need to know. Maybe an upgrade guide should be created |
Wow, thanks for tracking that down @DonNicoJs ! I agree it poses quite the potential issue going forward. I see a few possible approaches, including your initial suggestion, but no obvious winner yet... What are your thoughts on these and/or other options? Utility dynamic importerGive to the user some function that they pass names of Leaflet exports, and it returns the imported results. But using it will barely look different from just doing the import yourself anyway, I don't think, will it? If you have to say Still, if you think there's a good approach that might simplify the whole process, or make it easier for us to enforce some kind of consistency, then I'd be happy to see it for sure! Imports specified in
|
@mikeu I believe that for now, we best simply document this, I am afraid that anything we may end up implementing on our side will be rather hacky and not sturdy. Maybe we should rather create a |
@DonNicoJs I agree. We have a simple, effective solution that is easy enough to document and point people toward, so let's stick with that at the moment. I like the idea of a wrapper at some point. Are you envisioning a vue-leaflet component that any user of the library could use, or a separate library that anyone could use to reasonably quickly publish a wrapped plugin? |
@mikeu I was thinking of a wrapper component yes :) something that could facilitate using custom code in the In the meantime let's close this since we documented the fix! |
Met this issue myself Can confirm that doing |
Appreciate this is old but anyone struggling with this, a simple idea (and incomplete as doesn't solve the cause, just addresses the specific symptom) is to replace bounds with an array e.g. [bounds.getSouthWest(), bounds.getNorthEast()] i.e. |
Is anyone has a solution for how to use [elmarquis] leaflet gesture handling library with vue-leaflet |
fitBounds() does not work because bounds are not of type LatLngBounds.
Reproduce:
This issue happens when accessing
toLatLngBounds()
throughfitBounds()
accessed from map refBut this issue is not happening when accessing
toLatLngBounds()
through imported 'leaflet' packageP.S.
Mainly tested on 0.1.2 because 0.2.0/0.3.0 has this issue #47 but also tried 0.3.0 (same)
The text was updated successfully, but these errors were encountered: