leaflet - Leaflet.js,标记不呈现
问题描述
回到非常基础。我的传单地图渲染,我什至可以添加比例但我没有看到标记L.marker([45, 1]).addTo(map);
。我想我不需要添加默认图标。有什么线索吗?(非常短的)代码完全遵循快速入门指南:codesandbox
“好”版本:
import "leaflet/dist/leaflet.css";
import L from "leaflet";
const map = L.map("map").setView([45, 1], 4);
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
attribution:
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
L.control.scale().addTo(map);
L.marker([45, 1], {icon:
new L.Icon({iconUrl: 'https://unpkg.com/leaflet@1.6.0/dist/images/marker-icon.png'})
}).addTo(map);
<div id="map" style="height:100vh"></div>
解决方案
在传单包上找不到默认标记图标。
采用:
L.marker([45, 1], {icon:
new L.Icon({iconUrl: 'https://unpkg.com/leaflet@1.6.0/dist/images/marker-icon.png'})
}).addTo(map);
推荐阅读
- apache-kafka - 基于消费者滞后的Kafka节流生产者
- spring - 查询字段最大的文档
- youtube-data-api - youtube pubsubhubbub 通知延迟
- c++ - 如何从文本文件中填充指针数组?
- jsf - f:ajax 渲染引用迭代组件
- angular - 具有可变项目高度的 cdk-virtual-scroll-viewport
- c - mDNS 导致在 esp8266 上重新启动
- if-statement - Google 表格 - 如果多个单元格匹配,则将第三个单元格复制到第四个单元格
- linux - Unix中的csv文件操作并将值附加到每一行
- javascript - 如何使用书签在所有浏览器的新选项卡中打开 URL?