3

Does anyone know how to get the URL for a Mapbox vector tile map (aka a "style")? I can only get a style address that looks like this: mapbox://styles/myusername/r3411y10ngh4sh3tc3tc, but I am using a plugin that requires a URL to integrate Mapbox's Vector Tiles with Leaflet: https://github.com/SpatialServer/Leaflet.MapboxVectorTile/blob/master/docs/configuration.md

I tried substituting the style address provided by Mapbox for the URL

var config = {
  url: "mapbox://styles/myusername/fwaoij32wlfij23slkfj3",
  ...etc
};

var mvtSource = new L.TileLayer.MVTSource(config);
map.addLayer(mvtSource);

but I get an error where it can't read the style address as a URL. Any suggestions? Should I be using a different plugin?


Update

In short, the URL for a Mapbox style is not yet available. Here is a response I received from Mapbox:

Leaflet is not yet compatible with styles made in Mapbox Studio since these styles require a GL-based renderer. We're currently working on a new API to allow you to use your Studio style with Leaflet, we expect it to launch in a few weeks.

At this time, you can use Mapbox GL JS to load your Mapbox Studio style. You can still access raster map IDs (maps made with Mapbox Editor, Mapbox Studio Classic) to load with Leaflet - these are found under the "Classic" tab in the Studio dashboard.

4

1 に答える 1

1

Leaflet.MapboxVectorTile プラグインは、たとえば Mapbox GL JS ライブラリとは異なるスタイルへのアプローチを使用します。

Mapbox Studio で作成したスタイルは JSON としてダウンロードできますが、Leaflet.MapboxVectorTile の場合は、ドキュメントでわかるようにプログラムで作成する必要があります。ベクター タイルの URL は引き続き使用できますhttps://b.tiles.mapbox.com/v4/mapbox.mapbox-streets-v6/{z}/{x}/{y}.vector.pbf?access_token=<public api token>が、スタイルはおそらく最初から書き直すか、最初からやり直す必要があります。

Mapbox Gl Javascriptを使用して、作成したスタイルでマップを作成できますが、現在のプロジェクトがどれほど広範囲に及ぶか、他の (リーフレット) プラグインと競合するかどうかはわかりません。

mapboxgl.accessToken = '<public API token>';
var map = new mapboxgl.Map({
    container: 'map',
    style: 'mapbox://styles/<your name>/<style id>',
    center: [-74.50, 40],
    zoom: 9
});
于 2015-12-21T15:37:25.107 に答える