mapbox-gl-shadow-simulator 0.15.0 → 0.16.0
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.
- package/README.md +7 -5
- package/demo.jpg +0 -0
- package/dist/mapbox-gl-shadow-simulator.d.ts +1 -0
- package/examples/map.html +41 -3
- package/package.json +1 -1
- package/demo.gif +0 -0
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# mapbox-gl-shadow-simulator
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shadow simulator for Mapbox GL JS and MapLibre GL JS. Visualize sunlight and shadow on a map for any date and time of year.
|
|
4
4
|
|
|
5
|
-
[](https://ted-piotrowski.github.io/mapbox-gl-shadow-simulator/examples/map.html)
|
|
6
6
|
|
|
7
7
|
[Live Demo](https://ted-piotrowski.github.io/mapbox-gl-shadow-simulator/examples/map.html)
|
|
8
8
|
|
|
@@ -114,7 +114,7 @@ Property name | Type | Default value | Comment
|
|
|
114
114
|
`date` | `Date` | `new Date()` | Sun's position in the sky is based on this date
|
|
115
115
|
`color` | `String` | `#000` | 3 or 6 digit hexadecimal number
|
|
116
116
|
`opacity` | `Number` | `0.3`
|
|
117
|
-
`showExposure` | `Boolean` | `false` |
|
|
117
|
+
`showExposure` | `Boolean` | `false` | If set to true, display full-day sun exposure for `date` (**Note:** requires [suncalc](https://www.npmjs.com/package/suncalc))
|
|
118
118
|
`terrainSource` | `Object` | See [terrainSource](#terrainsource) | Specify DEM or DSM tiles containing terrain elevation data
|
|
119
119
|
`getFeatures` | `Function` | See [getFeatures](#getfeatures) | Returns GeoJSON of objects, such as buildings, to display on the map
|
|
120
120
|
|
|
@@ -199,10 +199,12 @@ getFeatures: () => {
|
|
|
199
199
|
|
|
200
200
|
### Available functions
|
|
201
201
|
|
|
202
|
-
`setDate(date: Date)` - update shade layer to reflect new date
|
|
202
|
+
`setDate(date: Date)` - update shade layer to reflect new `date`
|
|
203
203
|
|
|
204
204
|
`setColor(color: String)` - change shade color
|
|
205
205
|
|
|
206
206
|
`setOpacity(opacity: Number)` - change shade opacity
|
|
207
207
|
|
|
208
|
-
`setShowExposure(show: Boolean)` - toggle between
|
|
208
|
+
`setShowExposure(show: Boolean)` - toggle between shadows and full-day sun exposure for `date` (**Note:** requires [suncalc](https://www.npmjs.com/package/suncalc))
|
|
209
|
+
|
|
210
|
+
`remove()` - remove the layer from the map
|
package/demo.jpg
ADDED
|
Binary file
|
package/examples/map.html
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
<meta charset="UTF-8" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
|
8
|
-
<link href='https://api.mapbox.com/mapbox-gl-js/v2.
|
|
9
|
-
<script src='https://api.mapbox.com/mapbox-gl-js/v2.
|
|
8
|
+
<link href='https://api.mapbox.com/mapbox-gl-js/v2.8.2/mapbox-gl.css' rel='stylesheet' />
|
|
9
|
+
<script src='https://api.mapbox.com/mapbox-gl-js/v2.8.2/mapbox-gl.js'></script>
|
|
10
10
|
<script src='https://www.unpkg.com/suncalc@1.9.0/suncalc.js'></script>
|
|
11
11
|
<script src="../dist/mapbox-gl-shadow-simulator.umd.min.js"></script>
|
|
12
12
|
<style>
|
|
@@ -23,6 +23,25 @@
|
|
|
23
23
|
padding: 20px;
|
|
24
24
|
background-color: white;
|
|
25
25
|
}
|
|
26
|
+
|
|
27
|
+
#exposure-gradient-container {
|
|
28
|
+
display: none;
|
|
29
|
+
background-color: white;
|
|
30
|
+
padding: 0 10px 5px;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
#exposure-gradient {
|
|
34
|
+
height: 20px;
|
|
35
|
+
background-image: linear-gradient(to right, rgb(0 0 255/ 0.5), rgb(0 255 0 / 0.5), rgb(255 0 0 / 0.5));
|
|
36
|
+
display: flex;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
#exposure-gradient>div {
|
|
40
|
+
flex: 1;
|
|
41
|
+
border: 1px solid white;
|
|
42
|
+
text-align: center;
|
|
43
|
+
font-weight: bold;
|
|
44
|
+
}
|
|
26
45
|
</style>
|
|
27
46
|
<title>Shade Map Mapbox example</title>
|
|
28
47
|
</head>
|
|
@@ -36,12 +55,16 @@
|
|
|
36
55
|
<button id="increment">+1 hour</button>
|
|
37
56
|
<button id="play">Play</button>
|
|
38
57
|
<button id="stop">Stop</button>
|
|
39
|
-
<label><input id="exposure" type="checkbox" autocomplete="off" />
|
|
58
|
+
<label><input id="exposure" type="checkbox" autocomplete="off" />Full-day sun exposure</label>
|
|
40
59
|
<button>
|
|
41
60
|
<a href="https://shademap.app/about" target="_blank">Get API key</a>
|
|
42
61
|
</button>
|
|
43
62
|
<span id="loader" style="padding: 3px;"></span>
|
|
44
63
|
</div>
|
|
64
|
+
<div id="exposure-gradient-container">
|
|
65
|
+
<div>Hours of sunlight</div>
|
|
66
|
+
<div id="exposure-gradient"></div>
|
|
67
|
+
</div>
|
|
45
68
|
</div>
|
|
46
69
|
</div>
|
|
47
70
|
</div>
|
|
@@ -109,6 +132,8 @@
|
|
|
109
132
|
const play = document.getElementById('play');
|
|
110
133
|
const stop = document.getElementById('stop');
|
|
111
134
|
const exposure = document.getElementById('exposure');
|
|
135
|
+
const exposureGradientContainer = document.getElementById('exposure-gradient-container');
|
|
136
|
+
const exposureGradient = document.getElementById('exposure-gradient');
|
|
112
137
|
|
|
113
138
|
increment.addEventListener('click', () => {
|
|
114
139
|
now = new Date(now.getTime() + 3600000);
|
|
@@ -140,12 +165,25 @@
|
|
|
140
165
|
decrement.disabled = false;
|
|
141
166
|
play.disabled = false;
|
|
142
167
|
stop.disabled = false;
|
|
168
|
+
exposureGradientContainer.style.display = 'none';
|
|
143
169
|
} else {
|
|
144
170
|
shadeMap && shadeMap.setShowExposure(true);
|
|
145
171
|
increment.disabled = true
|
|
146
172
|
decrement.disabled = true;
|
|
147
173
|
play.disabled = true;
|
|
148
174
|
stop.disabled = true;
|
|
175
|
+
|
|
176
|
+
const { lat, lng } = map.getCenter();
|
|
177
|
+
const { sunrise, sunset } = SunCalc.getTimes(now, lat, lng);
|
|
178
|
+
const hours = (sunset - sunrise) / 1000 / 3600;
|
|
179
|
+
const partial = hours - Math.floor(hours);
|
|
180
|
+
const html = [];
|
|
181
|
+
for (let i = 0; i < hours; i++) {
|
|
182
|
+
html.push(`<div>${i + 1}</div>`)
|
|
183
|
+
}
|
|
184
|
+
html.push(`<div style="flex: ${partial}"></div>`);
|
|
185
|
+
exposureGradientContainer.style.display = 'block';
|
|
186
|
+
exposureGradient.innerHTML = html.join('');
|
|
149
187
|
}
|
|
150
188
|
})
|
|
151
189
|
/* End controls setup */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mapbox-gl-shadow-simulator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
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",
|
package/demo.gif
DELETED
|
Binary file
|