首页 > 解决方案 > 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:
    '&copy; <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>

标签: leaflet

解决方案


在传单包上找不到默认标记图标。

采用:

L.marker([45, 1], {icon:
   new L.Icon({iconUrl: 'https://unpkg.com/leaflet@1.6.0/dist/images/marker-icon.png'})
}).addTo(map);

推荐阅读