【问题标题】:Custom Mapbox tileset not showing in Leaflet.jsLeaflet.js 中未显示自定义 Mapbox 瓦片集
【发布时间】:2016-09-17 00:04:39
【问题描述】:

我正在为圣经营地制作游戏,并且想使用 Leaflet.js 制作地图。我正在使用 Mapbox 创建样式。我通过 csv 上传将罗马和耶路撒冷的坐标导入 Mapbox,它们在 preview 中渲染得很好。但是,它们在通过 Leaflet 加载时不会显示。见以下代码:

<head>
  <title>Race to Rome</title>
   <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
</head>

<body>
 <div id="mapid" style="height:500px;"></div>
   <script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
<h1>Race to Rome</h1>


</body>

<script>

        var mymap = L.map('mapid').setView(L.latLng(34,30), 5);
        L.tileLayer('https://api.mapbox.com/styles/v1/wheelerj/cioerd0vf001yacm7rff4tj5h/tiles/{z}/{x}/{y}?access_token=pk.eyJ1Ijoid2hlZWxlcmoiLCJhIjoiY2lvZXJheTZrMDByNXVsbTNpZXp0c2VnbCJ9.T_jRdbo0CKUgZ2aiuA3kKA', {
            maxZoom: 18,
            attribution: 
                'Imagery &copy;<a href="http://mapbox.com">Mapbox</a>',
            id: 'mapbox.streets'
        }).addTo(mymap);

</script>

我需要做什么才能在 Leaflet 中包含这些标签?

【问题讨论】:

    标签: javascript leaflet mapbox


    【解决方案1】:

    您可能希望考虑使用Mapbox.js(这是为其用户增强的 Leaflet 分支),并使用他们的预构建功能来处理这样的特征层。 请参阅下面的示例。

    https://www.mapbox.com/mapbox.js/example/v1.0.0/show-marker-as-label/

    L.mapbox.featureLayer('MY_FEATURE_LABEL_SET')
        .on('ready', function(e) {
            gj.addData(this.getGeoJSON());
        });
    

    【讨论】:

    • 赶上了其他事情,但计划有一天会回到它。
    猜你喜欢
    • 1970-01-01
    • 2016-09-07
    • 2019-11-19
    • 1970-01-01
    • 1970-01-01
    • 2016-08-29
    • 1970-01-01
    • 2020-01-20
    • 1970-01-01
    相关资源
    最近更新 更多