I added the latest nuxt-leaflet dependency (no other leaflet dependency), but I am still having troubles getting it to work...
Using nuxt 2.2.0.
I included the module 'nuxt-leaflet'. This is my component:
<template>
<no-ssr>
<l-map
id="map"
:zoom="zoom"
:min-zoom="3"
:center="center"
>
</l-map>
</no-ssr>
</template>
<script lang="ts">
import Vue from 'vue';
import {icon, latLng, marker} from 'leaflet';
import {ExploreItemType} from '~/components/explore/ExploreItem';
import PopupContent from '~/components/explore/PopupContent.vue';
import {Component, Prop, Watch} from "nuxt-property-decorator";
@Component({
props: {
exploreItems: Array
}
})
export default class ExplorerMap extends Vue {
url = 'https://api.tiles.mapbox.com/v4/mapbox.streets/{z}/{x}/{y}.png?access_token=pk.eyJ1Ijoia2dydWVuZWJlcmciLCJhIjoiY2puajJ3c3dmMGV1YzNxbDdwZ3Y5MXc0bCJ9.kuHo67NUkzqya1NtSjTYtw';
attribution = 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery ยฉ <a href="https://www.mapbox.com/">Mapbox</a>';
zoom = 3;
center = latLng(51.505, -0.09);
drawCluster = true;
@Prop()
exploreItems;
getGeoJson(exploreItem) {
return {
type: 'FeatureCollection',
features: [
{
geometry: {
type: 'Point',
coordinates: [
exploreItem.location.geoPoint.longitude,
exploreItem.location.geoPoint.latitude,
],
},
type: 'Feature',
properties: {
identifier: exploreItem.identifier,
popupContent: exploreItem.title,
},
id: 51,
}],
};
}
onEachFeature(feature, layer) {
const self = this;
const PopupCont = Vue.extend(PopupContent);
const popup = new PopupCont({
propsData: {
type: feature.geometry.type,
text: feature.properties.popupContent
}
});
layer.bindPopup(popup.$mount().$el);
layer.on('click', (e) => {
self.$emit('markerSelected', e.target.feature.properties.identifier);
});
}
getGeoJsonOptions(exploreItem) {
const self = this;
return {
pointToLayer(feature, latlng) {
return marker(latlng, {
icon: icon(
{
iconUrl: self.getIconForExploreItemType(exploreItem.type),
iconSize: [20, 20],
iconAnchor: [10, 15],
popupAnchor: [0, -28],
},
),
});
},
onEachFeature: this.onEachFeature
};
}
getIconForExploreItemType(type) {
switch (type) {
case ExploreItemType.CONFERENCE:
return '/conference.png';
case ExploreItemType.WORKSHOP:
return '/workshop.png';
default:
return null;
}
}
clusterClick(e) {
this.$emit('clusterClick', e);
}
@Watch('exploreItems')
itemsChanged() {
const self = this;
self.drawCluster = false;
Vue.nextTick(() => {
self.drawCluster = true;
});
}
}
</script>
<style lang="scss">
#map {
z-index: 0;
height: 500px;
width: 100%
}
</style>
Help would be greatly appreciated, I've been struggling with leaflet + nuxt for quite a time now...