|
1 |
| -/*jslint browser: true*/ |
2 |
| -/*global Tangram, gui */ |
3 | 1 | import L from 'leaflet';
|
4 | 2 | import Tangram from 'tangram';
|
5 | 3 | import leafletHash from './leaflet-hash.js';
|
6 | 4 |
|
7 |
| -var map = (function () { |
8 |
| - 'use strict'; |
9 |
| - |
10 |
| - var map_start_location = [40.70531887544228, -74.00976419448853, 15]; // NYC |
11 |
| - |
12 |
| - /*** URL parsing ***/ |
13 |
| - |
14 |
| - // leaflet-style URL hash pattern: |
15 |
| - // #[zoom],[lat],[lng] |
16 |
| - var url_hash = window.location.hash.slice(1, window.location.hash.length).split('/'); |
17 |
| - |
18 |
| - if (url_hash.length == 3) { |
19 |
| - map_start_location = [url_hash[1],url_hash[2], url_hash[0]]; |
20 |
| - // convert from strings |
21 |
| - map_start_location = map_start_location.map(Number); |
22 |
| - } |
23 |
| - |
24 |
| - /*** Map ***/ |
25 |
| - |
26 |
| - var map = L.map('map'); |
27 |
| - |
28 |
| - var layer = Tangram.leafletLayer({ |
29 |
| - scene: 'scene.yaml', |
| 5 | +const map = L.map('map'); |
| 6 | + |
| 7 | +const layer = Tangram |
| 8 | + .leafletLayer({ |
| 9 | + // scene: 'scene.yaml', |
| 10 | + scene: { |
| 11 | + import: [ |
| 12 | + 'https://www.nextzen.org/carto/bubble-wrap-style/10/bubble-wrap-style.zip', |
| 13 | + 'https://www.nextzen.org/carto/bubble-wrap-style/10/themes/label-10.zip', |
| 14 | + 'https://www.nextzen.org/carto/bubble-wrap-style/10/themes/bubble-wrap-road-shields-usa.zip', |
| 15 | + 'https://www.nextzen.org/carto/bubble-wrap-style/10/themes/bubble-wrap-road-shields-international.zip' |
| 16 | + ], |
| 17 | + global: { |
| 18 | + sdk_api_key: 'NaqqS33fTUmyQcvbuIUCKA' |
| 19 | + } |
| 20 | + }, |
30 | 21 | attribution: '<a href="https://mapzen.com/tangram" target="_blank">Tangram</a> | © OSM contributors | <a href="https://mapzen.com/" target="_blank">Mapzen</a>'
|
31 |
| - }); |
32 |
| - |
33 |
| - window.layer = layer; |
34 |
| - var scene = layer.scene; |
35 |
| - window.scene = scene; |
36 |
| - |
37 |
| - // update hash on navigation - uses leaflet-hash.js |
38 |
| - var hash = new L.Hash(map); |
39 |
| - |
40 |
| - // setView expects format ([lat, long], zoom) |
41 |
| - map.setView(map_start_location.slice(0, 3), map_start_location[2]); |
42 |
| - |
43 |
| - /***** Render loop *****/ |
44 |
| - |
45 |
| - window.addEventListener('load', function () { |
46 |
| - // Scene initialized |
47 |
| - window.layer.on('init', function() { |
48 |
| - // MPZN.bug(); |
49 |
| - }); |
50 |
| - window.layer.addTo(map); |
51 |
| - }); |
52 |
| - |
53 |
| - return map; |
54 |
| - |
55 |
| -}()); |
| 22 | + }) |
| 23 | + .addTo(map); |
| 24 | + |
| 25 | +// Set starting location |
| 26 | +// Try to get location from URL, with leaflet-style hash pattern: #[zoom],[lat],[lng] |
| 27 | +let startLocation = [[40.70531887544228, -74.00976419448853], 15]; // default location, NYC |
| 28 | +const urlHash = window.location.hash.slice(1, window.location.hash.length).split('/').map(Number); |
| 29 | +if (urlHash.length == 3) { |
| 30 | + startLocation = [[urlHash[1], urlHash[2]], urlHash[0]]; |
| 31 | +} |
| 32 | + |
| 33 | +map.setView(startLocation[0], startLocation[1]); // setView expects format ([lat, long], zoom) |
| 34 | +// map.setView([40.70531887544228, -74.00976419448853], 15); |
| 35 | + |
| 36 | +// update hash on navigation - uses leaflet-hash.js |
| 37 | +const hash = new L.Hash(map); |
0 commit comments