如何使用mapbox麻点

如何使用mapbox麻点

1.注册账号获得access_token.

https://www.mapbox.com
也可使用mapbox网页上的access_token

2.在网页中嵌入地图

页面结构如下:

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>A simple map</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.mapbox.com/mapbox.js/v3.0.1/mapbox.js'></script>
<link href='https://api.mapbox.com/mapbox.js/v3.0.1/mapbox.css' rel='stylesheet' />
<style>
  body { margin:0; padding:0; }
  #map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<!--地图容器-->
<div id='map'></div>
<script>
    L.mapbox.accessToken = '<your access token here>';
    var map = L.mapbox.map('map', 'mapbox.streets')
        .setView([40, -74.50], 9);
</script>
</body>
</html>

3.实例化maker并添加至地图

如有多个marker请用foreach添加(数据源一般来源于服务器)

<script>
// L.marker is a low-level marker constructor in Leaflet.
L.marker([37.9, -77], {
    icon: L.mapbox.marker.icon({
        'marker-size': 'large',
        'marker-symbol': 'bus',
        'marker-color': '#fa0'
    })
}).addTo(map);
</script>

4、点击marker出现弹层

需要用到marker的bindPopup()方法
例子中的popupContent为html

<script>
    marker.bindPopup(popupContent).openPopup();
</script>

最后修订:星期四, 02. 三月 2017 05:14下午

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容