mapbox-gl-shadow-simulator 0.13.12 → 0.13.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright Ted Piotrowski 2022
3
3
  * Package: mapbox-gl-shadow-simulator
4
- * Version: 0.13.12
4
+ * Version: 0.13.13
5
5
  * For licensing visit: https://shademap.app/about/
6
6
  */
7
7
 
package/examples/map.html CHANGED
@@ -44,6 +44,19 @@
44
44
  </div>
45
45
  </div>
46
46
  <script>
47
+ const mapLoaded = (map) => {
48
+ return new Promise((res, rej) => {
49
+ function cb() {
50
+ if (!map.loaded()) {
51
+ return;
52
+ }
53
+ map.off("render", cb);
54
+ res();
55
+ }
56
+ map.on("render", cb);
57
+ cb();
58
+ });
59
+ };
47
60
  /* Mapbox setup */
48
61
  mapboxgl.accessToken = 'pk.eyJ1IjoidHBwaW90cm93c2tpIiwiYSI6ImNsNGVpdzMxYzAzenUzb28zYXZ4MXdlc2EifQ.M4IHx7SY0Wv5Zt6xzvKeBQ';
49
62
  const map = new mapboxgl.Map({
@@ -70,7 +83,8 @@
70
83
  getSourceUrl: ({ x, y, z }) => `https://s3.amazonaws.com/elevation-tiles-prod/terrarium/${z}/${x}/${y}.png`,
71
84
  getElevation: ({ r, g, b, a }) => (r * 256 + g + b / 256) - 32768,
72
85
  },
73
- getFeatures: () => {
86
+ getFeatures: async () => {
87
+ await mapLoaded();
74
88
  const buildingData = map.querySourceFeatures('composite', { sourceLayer: 'building' }).filter((feature) => {
75
89
  return feature.properties && feature.properties.underground !== "true" && (feature.properties.height || feature.properties.render_height)
76
90
  });
package/examples/node.ts CHANGED
@@ -1,6 +1,20 @@
1
1
  import Simulator from 'mapbox-gl-shadow-simulator';
2
2
  import { Map } from 'mapbox-gl';
3
3
 
4
+ const mapLoaded = (map: Map) => {
5
+ return new Promise<void>((res, rej) => {
6
+ function cb() {
7
+ if (!map.loaded()) {
8
+ return;
9
+ }
10
+ map.off("render", cb);
11
+ res();
12
+ }
13
+ map.on("render", cb);
14
+ cb();
15
+ });
16
+ };
17
+
4
18
  /* Mapbox setup */
5
19
  const accessToken = 'pk.eyJ1IjoidHBwaW90cm93c2tpIiwiYSI6ImNsNGVpdzMxYzAzenUzb28zYXZ4MXdlc2EifQ.M4IHx7SY0Wv5Zt6xzvKeBQ';
6
20
  const map = new Map({
@@ -28,7 +42,8 @@ map.on('load', () => {
28
42
  getSourceUrl: ({ x, y, z }) => `https://s3.amazonaws.com/elevation-tiles-prod/terrarium/${z}/${x}/${y}.png`,
29
43
  getElevation: ({ r, g, b, a }) => (r * 256 + g + b / 256) - 32768,
30
44
  },
31
- getFeatures: () => {
45
+ getFeatures: async () => {
46
+ await mapLoaded(map);
32
47
  const buildingData = map.querySourceFeatures('composite', { sourceLayer: 'building' }).filter((feature) => {
33
48
  return feature.properties && feature.properties.underground !== "true" && (feature.properties.height || feature.properties.render_height)
34
49
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mapbox-gl-shadow-simulator",
3
- "version": "0.13.12",
3
+ "version": "0.13.13",
4
4
  "description": "Display terrain and structure shadows cast by the sun in a custom style layer",
5
5
  "main": "dist/mapbox-gl-shadow-simulator.umd.min.js",
6
6
  "types": "dist/mapbox-gl-shadow-simulator.d.ts",