繁体   English   中英

在 Leaflet.js 中添加标记

[英]Adding Markers in Leaflet.js

如果这很简单,我深表歉意,但我对此不是很有经验,并且已经通读并改编了多个示例以达到我目前所处的地步。

我正在为我正在运行的活动制作地图。 我已经使用传单来做到这一点,经过大量修补后,我终于使用单个图像完成了所有工作(这是我想要的,因为它将被大量更新)。

下一步是将标记添加到感兴趣的位置。 现在我并不特别想要任何花哨的东西,我试图使用标记和弹出窗口(如下所示: http : //leafletjs.com/examples/quick-start/example-popups.html ) - 但是我尝试过的方法查看各种示例和教程似乎不起作用。

我将在下面粘贴我的代码,非常感谢任何能够提供帮助的人。 再次,如果事情真的很简单,我深表歉意,我所有有限的知识都来自阅读和调整示例。

其中大部分是使用本教程构建的: http : //kempe.net/blog/2014/06/14/leaflet-pan-zoom-image.html

<!DOCTYPE html> 

<html> 

<head> 

<meta http-equiv="content-type" content="text/html; charset=utf-8"/> 

<link rel="icon" type="image/png" href="assets/icon.ico">

<title>Whispers of Valentia</title>         



<link rel="stylesheet" href="map.css" type="text/css" />    

<link href='http://fonts.googleapis.com/css?family=Cantora+One|Acme|Meddon|Jim+Nightshade' rel='stylesheet' type='text/css'>

    <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css">

</head> 

<body>

    <div id="navigationBar">


        <div id="navigationLogo">

                    <abbr title="This is a test map.">WHISPERS OF VALENTIA</abbr>

        </div>


    </div>

    <div class="shadeBar"></div>


    <div id="image-map" style="background: #1e2831;">


    <script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>

<script>

// Using leaflet.js to pan and zoom a big image.

// See also: http://kempe.net/blog/2014/06/14/leaflet-pan-zoom-image.html

// create the slippy map

var map = L.map('image-map', {

  minZoom: 2,

  maxZoom: 6,

  center: [5000, 2400],

  zoom: 2,

  crs: L.CRS.Simple

});

// dimensions of the image

var w = 10000,

    h = 4800,

    url = 'valentiatest.jpg';

// calculate the edges of the image, in coordinate space

var southWest = map.unproject([0, h], map.getMaxZoom()-1);

var northEast = map.unproject([w, 0], map.getMaxZoom()-1);

var bounds = new L.LatLngBounds(southWest, northEast);


// add the image overlay, 

// so that it covers the entire map

L.imageOverlay(url, bounds).addTo(map);

// tell leaflet that the map is exactly as big as the image

map.setMaxBounds(bounds);

var marker = L.marker([1000, 1000]).addTo(map);


</script>

    </div>

</body>

你的代码似乎是正确的。 您使用以下代码添加标记:

var marker = L.marker([1000, 1000]).addTo(map);

请注意,这会为 position : latitude : 1000; 添加一个标记。 经度:1000;

这是不正确的,并且不在您的地图中。 根据您的中心添加一个正确的位置来添加它。

查看 Leaflet 示例代码和文档以获取更多信息: http : //leafletjs.com/examples/quick-start/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM