【问题标题】:Leaflet map doesn’t work after adding a new control添加新控件后传单地图不起作用
【发布时间】:2020-08-25 05:38:44
【问题描述】:

添加Leaflet.MousePosition 后我的地图没有显示。

var lmap = new L.map("lmap", {
  zoomControl: false,
  maxZoom: 11,
  minZoom: 3,
}).setView([34.543896, 63.160652], 6);
L.control.zoom({
  position: 'topright'
}).addTo(lmap);
lmap.addControl(new L.Control.Fullscreen({position: 'bottomleft'}));
L.control.mousePosition({position: 'bottomright'}).addTo(lmap);

【问题讨论】:

  • 控制台出现什么错误?
  • 未捕获的类型错误:L.control.mousePosition 不是函数
  • 您是否将库添加到您的项目中?
  • 没有提到怎么做。

标签: javascript leaflet maps controls geodjango


【解决方案1】:

您正在使用map,但您必须使用lmap

L.control.mousePosition({position: 'bottomright'}).addTo(lmap);

您还必须将库 src 添加到您的项目中。

将以下内容添加到您的 html 文件中:

<script src="https://cdn.jsdelivr.net/npm/leaflet-mouse-position@1.2.0/src/L.Control.MousePosition.min.js"></script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-16
    • 2015-09-29
    • 2013-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多