如何修复Vue 2 FelleT应用中未找到的默认标记-Icon.png?
我有一个简单的示例项目, https:// https:// github.com/ericg-vue-questions/leaflet-test/tree/feature/simple-marker
(请注意功能/simple-marker分支)
相关代码在 flaflettest.vue 文件
<template>
<div id="container">
<div id="mapContainer"></div>
</div>
</template>
<script>
import 'leaflet/dist/leaflet.css';
import L from 'leaflet';
import Vue from 'vue';
export default {
name: 'Map',
methods: {
async setupLeafletMap() {
const center = [37, -122];
const mapDiv = L.map('mapContainer').setView(center, 13);
var tiles = new L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
minZoom: 3,
maxZoom: 8
}).addTo(mapDiv);
L.marker(center).addTo(mapDiv);
}
},
async mounted() {
await Vue.nextTick();
await this.setupLeafletMap();
}
};
</script>
<style scoped>
#mapContainer {
width: 500px;
height: 500px;
}
</style>
在代码运行时,默认标记显示向上as:
IMG标签中的URL l.marker(中心).addto(mapdiv);
添加到地图上,
<img src="marker-icon.png" class="leaflet-marker-icon leaflet-zoom-animated leaflet-interactive" alt="Marker" tabindex="0" role="button" style="margin-left: -12px; margin-top: -41px; width: 25px; height: 41px; transform: translate3d(250px, 250px, 0px); z-index: 250;">
我认为在配置VUE应用程序时需要做一些额外的事情,因此在这种情况下,传单可以一起使用。
我需要更改什么,以便默认情况下显示默认标记-Icon.png?
I have a simple, sample project at https://github.com/ericg-vue-questions/leaflet-test/tree/feature/simple-marker
(note the feature/simple-marker branch)
The relevant code is in the LeafletTest.vue file
<template>
<div id="container">
<div id="mapContainer"></div>
</div>
</template>
<script>
import 'leaflet/dist/leaflet.css';
import L from 'leaflet';
import Vue from 'vue';
export default {
name: 'Map',
methods: {
async setupLeafletMap() {
const center = [37, -122];
const mapDiv = L.map('mapContainer').setView(center, 13);
var tiles = new L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
minZoom: 3,
maxZoom: 8
}).addTo(mapDiv);
L.marker(center).addTo(mapDiv);
}
},
async mounted() {
await Vue.nextTick();
await this.setupLeafletMap();
}
};
</script>
<style scoped>
#mapContainer {
width: 500px;
height: 500px;
}
</style>
When the code run, the default marker shows up as:
The URL in the img tag that L.marker(center).addTo(mapDiv);
adds to the map is
<img src="marker-icon.png" class="leaflet-marker-icon leaflet-zoom-animated leaflet-interactive" alt="Marker" tabindex="0" role="button" style="margin-left: -12px; margin-top: -41px; width: 25px; height: 41px; transform: translate3d(250px, 250px, 0px); z-index: 250;">
I figure there is something extra I need to do in configuring the vue app so it and leaflet can work together in this case.
What do I need to change so the default marker-icon.png will show up by default?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现的一个答案是修改
opted()
方法为:添加的部分是:
如果我正确理解此处发生的事情是WebPack会看到需求并协助确保确保正确的事情发生了。如果有人对为什么有效的原因有更详细的解释,我会很感兴趣。
One answer I found was to modify the
mounted()
method to be:The part that was added was:
If I understand correctly what is going on here is that webpack will see the require's and assist in making sure the right thing happens. If anyone has a more detailed explanation of why this works, I would be interested.