1 | goog.require('ol.Map');
|
2 | goog.require('ol.View');
|
3 | goog.require('ol.format.MVT');
|
4 | goog.require('ol.layer.VectorTile');
|
5 | goog.require('ol.proj');
|
6 | goog.require('ol.source.VectorTile');
|
7 | goog.require('ol.style.Fill');
|
8 | goog.require('ol.style.Icon');
|
9 | goog.require('ol.style.Stroke');
|
10 | goog.require('ol.style.Style');
|
11 | goog.require('ol.style.Text');
|
12 | goog.require('ol.tilegrid.TileGrid');
|
13 |
|
14 |
|
15 | var key = 'pk.eyJ1IjoiYWhvY2V2YXIiLCJhIjoiRk1kMWZaSSJ9.E5BkluenyWQMsBLsuByrmg';
|
16 |
|
17 |
|
18 | var resolutions = [];
|
19 | for (var i = 0; i <= 8; ++i) {
|
20 | resolutions.push(156543.03392804097 / Math.pow(2, i * 2));
|
21 | }
|
22 |
|
23 | function tileUrlFunction(tileCoord) {
|
24 | return ('https://{a-d}.tiles.mapbox.com/v4/mapbox.mapbox-streets-v6/' +
|
25 | '{z}/{x}/{y}.vector.pbf?access_token=' + key)
|
26 | .replace('{z}', String(tileCoord[0] * 2 - 1))
|
27 | .replace('{x}', String(tileCoord[1]))
|
28 | .replace('{y}', String(-tileCoord[2] - 1))
|
29 | .replace('{a-d}', 'abcd'.substr(
|
30 | ((tileCoord[1] << tileCoord[0]) + tileCoord[2]) % 4, 1));
|
31 | }
|
32 |
|
33 | var map = new ol.Map({
|
34 | layers: [
|
35 | new ol.layer.VectorTile({
|
36 | source: new ol.source.VectorTile({
|
37 | attributions: '© <a href="https://www.mapbox.com/map-feedback/">Mapbox</a> ' +
|
38 | '© <a href="https://www.openstreetmap.org/copyright">' +
|
39 | 'OpenStreetMap contributors</a>',
|
40 | format: new ol.format.MVT(),
|
41 | tileGrid: new ol.tilegrid.TileGrid({
|
42 | extent: ol.proj.get('EPSG:3857').getExtent(),
|
43 | resolutions: resolutions,
|
44 | tileSize: 512
|
45 | }),
|
46 | tileUrlFunction: tileUrlFunction
|
47 | }),
|
48 | style: createMapboxStreetsV6Style(ol.style.Style, ol.style.Fill, ol.style.Stroke, ol.style.Icon, ol.style.Text)
|
49 | })
|
50 | ],
|
51 | target: 'map',
|
52 | view: new ol.View({
|
53 | center: [0, 0],
|
54 | minZoom: 1,
|
55 | zoom: 2
|
56 | })
|
57 | });
|