leaflet-shadow-simulator 0.56.1 → 0.57.1
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/dist/leaflet-shadow-simulator.esm.js +2 -2
- package/dist/leaflet-shadow-simulator.umd.min.js +2 -2
- package/dist/shademap/leaflet-shademap/dist/ShadeMap.d.ts +4 -20
- package/dist/shademap/leaflet-shademap/dist/ShadeMapLeaflet.d.ts +3 -0
- package/dist/shademap/leaflet-shademap/dist/ShadeMapMapbox.d.ts +3 -0
- package/dist/shademap/leaflet-shademap/dist/buildings/BuildingRasterizer.d.ts +6 -2
- package/dist/shademap/leaflet-shademap/dist/lib/TileMerger.d.ts +10 -4
- package/dist/shademap/leaflet-shademap/dist/lib/TileMergerGPU.d.ts +47 -0
- package/dist/shademap/leaflet-shademap/dist/lib/heightMap.d.ts +3 -2
- package/dist/shademap/leaflet-shademap/dist/lib/helpers.d.ts +4 -21
- package/dist/shademap/leaflet-shademap/dist/lib/shadowMap.d.ts +1 -2
- package/dist/shademap/leaflet-shademap/dist/lib/webgl.d.ts +13 -0
- package/dist/shademap/leaflet-shademap/dist/shader/gpu.d.ts +8 -11
- package/dist/shademap/leaflet-shademap/dist/shader/kernel.d.ts +25 -32
- package/dist/shademap/leaflet-shademap/dist/types/shadeMapOptions.d.ts +0 -6
- package/dist/shademap/leaflet-shademap/dist/types/shadow3DData.d.ts +2 -2
- package/examples/test.html +145 -0
- package/package.json +1 -1
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
import { Color } from "../types/color";
|
|
2
|
-
import { DSMSource } from "../types/shadeMapOptions";
|
|
3
2
|
import { Shadow3DData } from "../types/shadow3DData";
|
|
4
3
|
import { CompiledKernel } from "./kernel";
|
|
5
4
|
export declare const updateHeightMapGPU: (compiledKernel: CompiledKernel, shadow3DData: Shadow3DData) => void;
|
|
6
5
|
export declare const updateDateGPU: (compiledKernel: CompiledKernel, params: {
|
|
7
6
|
date: Date;
|
|
8
7
|
}) => void;
|
|
9
|
-
export declare const calculateArea: (compiledKernel: CompiledKernel, params: {
|
|
10
|
-
dates: Date[];
|
|
11
|
-
dsm: DSMSource;
|
|
12
|
-
geometry: {
|
|
13
|
-
coordinates: [number, number][][];
|
|
14
|
-
};
|
|
15
|
-
}) => import("../types/area").ShadeArea[];
|
|
16
8
|
export declare const generateShadeProfile: (compiledKernel: CompiledKernel, params: {
|
|
17
9
|
texCoords: number[][];
|
|
18
10
|
dates: Date[];
|
|
@@ -20,11 +12,17 @@ export declare const generateShadeProfile: (compiledKernel: CompiledKernel, para
|
|
|
20
12
|
shadeColor: number[];
|
|
21
13
|
}) => Uint8Array;
|
|
22
14
|
export declare const generateLocationShadeProfile: (compiledKernel: CompiledKernel, params: {
|
|
15
|
+
startTime: number;
|
|
16
|
+
endTime: number;
|
|
17
|
+
tzId: string;
|
|
23
18
|
texCoord: number[];
|
|
24
|
-
dates: Date[][];
|
|
25
19
|
sunColor: number[];
|
|
26
20
|
shadeColor: number[];
|
|
27
|
-
}) =>
|
|
21
|
+
}) => {
|
|
22
|
+
output: Uint8Array;
|
|
23
|
+
outputWidth: number;
|
|
24
|
+
outputHeight: number;
|
|
25
|
+
};
|
|
28
26
|
export declare const updateDateRangeGPU: (compiledKernel: CompiledKernel, params: {
|
|
29
27
|
startDate: Date;
|
|
30
28
|
endDate: Date;
|
|
@@ -35,4 +33,3 @@ export declare const updateColorGPU: (compiledKernel: CompiledKernel, params: {
|
|
|
35
33
|
color: Color;
|
|
36
34
|
opacity: number;
|
|
37
35
|
}) => void;
|
|
38
|
-
export declare const updateCowHeightGPU: (compiledKernel: CompiledKernel, cowHeight: number) => void;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { DSMSource } from "../types/shadeMapOptions";
|
|
2
|
-
import { ShadeArea } from "../types/area";
|
|
3
1
|
interface CompileProgramArgs {
|
|
4
2
|
gl: WebGLRenderingContext;
|
|
5
3
|
vSrc: string;
|
|
6
4
|
fSrc: string;
|
|
7
5
|
}
|
|
8
|
-
interface
|
|
6
|
+
interface UpdateHeightMapArgs {
|
|
7
|
+
heightMapTex: WebGLTexture | null;
|
|
9
8
|
width: number;
|
|
10
9
|
height: number;
|
|
11
10
|
maxHeight: number;
|
|
@@ -23,13 +22,7 @@ interface UpdateLocationArgs {
|
|
|
23
22
|
outputWidth: number;
|
|
24
23
|
outputHeight: number;
|
|
25
24
|
belowCanopy: boolean;
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
interface UpdateViewportArgs {
|
|
29
|
-
xStart: number;
|
|
30
|
-
yStart: number;
|
|
31
|
-
xEnd: number;
|
|
32
|
-
yEnd: number;
|
|
25
|
+
skipRender: boolean;
|
|
33
26
|
}
|
|
34
27
|
interface UpdateDateArgs {
|
|
35
28
|
dec: number;
|
|
@@ -44,36 +37,36 @@ interface UpdateDateRangeArgs {
|
|
|
44
37
|
interface UpdateColorArgs {
|
|
45
38
|
colorVec: number[];
|
|
46
39
|
}
|
|
40
|
+
interface ShadeProfileArgs {
|
|
41
|
+
texCoords: number[][];
|
|
42
|
+
dates: Date[];
|
|
43
|
+
sunColor: number[];
|
|
44
|
+
shadeColor: number[];
|
|
45
|
+
}
|
|
46
|
+
interface LocationShadeProfileArgs {
|
|
47
|
+
startTime: number;
|
|
48
|
+
endTime: number;
|
|
49
|
+
tzId: string;
|
|
50
|
+
texCoord: number[];
|
|
51
|
+
sunColor: number[];
|
|
52
|
+
shadeColor: number[];
|
|
53
|
+
}
|
|
47
54
|
export interface CompiledKernel {
|
|
48
|
-
|
|
49
|
-
updateViewport: (args: UpdateViewportArgs) => void;
|
|
55
|
+
updateHeightMap: (args: UpdateHeightMapArgs) => void;
|
|
50
56
|
updateDate: (args: UpdateDateArgs) => void;
|
|
51
57
|
updateDateRange: (args: UpdateDateRangeArgs) => Promise<boolean>;
|
|
52
58
|
updateColor: (args: UpdateColorArgs) => void;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}) => Uint8Array;
|
|
60
|
-
generateLocationShadeProfile: (args: {
|
|
61
|
-
texCoord: number[];
|
|
62
|
-
dates: Date[][];
|
|
63
|
-
sunColor: number[];
|
|
64
|
-
shadeColor: number[];
|
|
65
|
-
}) => Uint8Array;
|
|
66
|
-
calculateArea: (args: {
|
|
67
|
-
dates: Date[];
|
|
68
|
-
dsm: DSMSource;
|
|
69
|
-
geometry: {
|
|
70
|
-
coordinates: [number, number][][];
|
|
71
|
-
};
|
|
72
|
-
}) => ShadeArea[];
|
|
59
|
+
generateShadeProfile: (args: ShadeProfileArgs) => Uint8Array;
|
|
60
|
+
generateLocationShadeProfile: (args: LocationShadeProfileArgs) => {
|
|
61
|
+
output: Uint8Array;
|
|
62
|
+
outputWidth: number;
|
|
63
|
+
outputHeight: number;
|
|
64
|
+
};
|
|
73
65
|
}
|
|
74
66
|
export declare function compileProgram(args: CompileProgramArgs): WebGLProgram;
|
|
75
67
|
interface Settings {
|
|
76
68
|
context: WebGLRenderingContext;
|
|
69
|
+
setRenderBuffer: (gl: WebGLRenderingContext, viewportWidth: number, viewportHeight: number) => void;
|
|
77
70
|
}
|
|
78
71
|
declare function kernel(settings: Settings): CompiledKernel;
|
|
79
72
|
export default kernel;
|
|
@@ -32,11 +32,6 @@ export interface SunExposureOptions {
|
|
|
32
32
|
export interface SunExposure extends SunExposureOptions {
|
|
33
33
|
enabled: boolean;
|
|
34
34
|
}
|
|
35
|
-
export interface Geometry {
|
|
36
|
-
enabled: boolean;
|
|
37
|
-
type: string;
|
|
38
|
-
coordinates: number[][][];
|
|
39
|
-
}
|
|
40
35
|
export interface ShadeMapOptions {
|
|
41
36
|
date?: Date;
|
|
42
37
|
color?: string;
|
|
@@ -45,7 +40,6 @@ export interface ShadeMapOptions {
|
|
|
45
40
|
sunExposure?: SunExposure;
|
|
46
41
|
terrainSource?: TerrainSource;
|
|
47
42
|
dsmSource?: DSMSource;
|
|
48
|
-
geometry?: Geometry;
|
|
49
43
|
getFeatures?: () => Promise<MapboxGeoJSONFeature[]>;
|
|
50
44
|
apiKey: string;
|
|
51
45
|
debug?: (msg: string) => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Color } from "./color";
|
|
2
2
|
export interface Shadow3DData {
|
|
3
|
-
|
|
3
|
+
heightMapTex: WebGLTexture | null;
|
|
4
4
|
maxHeight: number;
|
|
5
5
|
width: number;
|
|
6
6
|
height: number;
|
|
@@ -17,5 +17,5 @@ export interface Shadow3DData {
|
|
|
17
17
|
outputWidth: number;
|
|
18
18
|
outputHeight: number;
|
|
19
19
|
belowCanopy: boolean;
|
|
20
|
-
|
|
20
|
+
skipRender: boolean;
|
|
21
21
|
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>Document</title>
|
|
8
|
+
<link rel="stylesheet" href="styles.css" />
|
|
9
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css"
|
|
10
|
+
integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous" />
|
|
11
|
+
|
|
12
|
+
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
13
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
14
|
+
<link
|
|
15
|
+
href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,300;1,400;1,500;1,600;1,700;1,800&display=swap"
|
|
16
|
+
rel="stylesheet" />
|
|
17
|
+
|
|
18
|
+
<script src="https://unpkg.com/@jsreport/browser-client/dist/jsreport.umd.js"></script>
|
|
19
|
+
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.3/dist/leaflet.css" />
|
|
20
|
+
<script src="https://unpkg.com/leaflet@1.9.3/dist/leaflet.js"></script>
|
|
21
|
+
<script src="https://www.unpkg.com/suncalc@1.9.0/suncalc.js"></script>
|
|
22
|
+
<script src="https://unpkg.com/osmtogeojson/osmtogeojson.js"></script>
|
|
23
|
+
<!-- <script src="https://unpkg.com/leaflet-shadow-simulator@0.50.0/dist/leaflet-shadow-simulator.umd.min.js"></script> -->
|
|
24
|
+
<script src="../dist/leaflet-shadow-simulator.umd.min.js"></script>
|
|
25
|
+
</head>
|
|
26
|
+
|
|
27
|
+
<body>
|
|
28
|
+
<div class="px-4">
|
|
29
|
+
<div id="sunlight-map" style="width:100%;height:780px; margin-bottom: 20px"></div>
|
|
30
|
+
|
|
31
|
+
<script>
|
|
32
|
+
try {
|
|
33
|
+
const map = L.map("sunlight-map", {
|
|
34
|
+
zoomControl: false
|
|
35
|
+
}).setView([46.20111914696285, 6.1484776575582], 18);
|
|
36
|
+
|
|
37
|
+
L.tileLayer("https://api.mapbox.com/styles/v1/mapbox/light-v10/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoicG9wZXR5IiwiYSI6ImNpdDlydDEwYzBsMWYydXAyeXhrMHhoamIifQ.9_sT8uJ8zd_6sU0ispPK3w", {
|
|
38
|
+
attribution: '',
|
|
39
|
+
maxZoom: 18,
|
|
40
|
+
}).addTo(map);
|
|
41
|
+
|
|
42
|
+
let now = new Date(1633358583454);
|
|
43
|
+
|
|
44
|
+
const {
|
|
45
|
+
sunrise,
|
|
46
|
+
sunset
|
|
47
|
+
} = SunCalc.getTimes(now, 46.20111914696285, 6.1484776575582);
|
|
48
|
+
|
|
49
|
+
const shadeMap = new ShadeMap({
|
|
50
|
+
date: new Date(), // display shadows for current date
|
|
51
|
+
color: '#01112f', // shade color
|
|
52
|
+
opacity: 0.7, // opacity of shade color
|
|
53
|
+
apiKey: 'eyJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InRwcGlvdHJvd3NraUBzaGFkZW1hcC5hcHAiLCJjcmVhdGVkIjoxNjYyNDkzMDY2Nzk0LCJpYXQiOjE2NjI0OTMwNjZ9.ovCrLTYsdKFTF6TW3DuODxCaAtGQ3qhcmqj3DWcol5g',
|
|
54
|
+
terrainSource: {
|
|
55
|
+
tileSize: 256, // DEM tile size
|
|
56
|
+
_overzoom: 18,
|
|
57
|
+
maxZoom: 15, // Maximum zoom of DEM tile set
|
|
58
|
+
getSourceUrl: ({
|
|
59
|
+
x,
|
|
60
|
+
y,
|
|
61
|
+
z
|
|
62
|
+
}) => `https://s3.amazonaws.com/elevation-tiles-prod/terrarium/${z}/${x}/${y}.png`,
|
|
63
|
+
getElevation: ({
|
|
64
|
+
r,
|
|
65
|
+
g,
|
|
66
|
+
b,
|
|
67
|
+
a
|
|
68
|
+
}) => (r * 256 + g + b / 256) - 32768,
|
|
69
|
+
},
|
|
70
|
+
sunExposure: {
|
|
71
|
+
enabled: true,
|
|
72
|
+
startDate: sunrise,
|
|
73
|
+
endDate: sunset,
|
|
74
|
+
iterations: 3
|
|
75
|
+
},
|
|
76
|
+
getFeatures: async () => {
|
|
77
|
+
try {
|
|
78
|
+
if (map.getZoom() > 15) {
|
|
79
|
+
const bounds = map.getBounds();
|
|
80
|
+
const north = bounds.getNorth();
|
|
81
|
+
const south = bounds.getSouth();
|
|
82
|
+
const east = bounds.getEast();
|
|
83
|
+
const west = bounds.getWest();
|
|
84
|
+
const query = `https://overpass-api.de/api/interpreter?data=%2F*%0AThis%20has%20been%20generated%20by%20the%20overpass-turbo%20wizard.%0AThe%20original%20search%20was%3A%0A%E2%80%9Cbuilding%E2%80%9D%0A*%2F%0A%5Bout%3Ajson%5D%5Btimeout%3A25%5D%3B%0A%2F%2F%20gather%20results%0A%28%0A%20%20%2F%2F%20query%20part%20for%3A%20%E2%80%9Cbuilding%E2%80%9D%0A%20%20way%5B%22building%22%5D%28${south}%2C${west}%2C${north}%2C${east}%29%3B%0A%29%3B%0A%2F%2F%20print%20results%0Aout%20body%3B%0A%3E%3B%0Aout%20skel%20qt%3B`;
|
|
85
|
+
const response = await fetch(query)
|
|
86
|
+
const json = await response.json();
|
|
87
|
+
const geojson = osmtogeojson(json);
|
|
88
|
+
// If no building height, default to one storey of 3 meters
|
|
89
|
+
geojson.features.forEach(feature => {
|
|
90
|
+
if (!feature.properties) {
|
|
91
|
+
feature.properties = {};
|
|
92
|
+
}
|
|
93
|
+
if (!feature.properties.height) {
|
|
94
|
+
feature.properties.height = 3;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
return geojson.features;
|
|
98
|
+
}
|
|
99
|
+
} catch (e) {
|
|
100
|
+
console.error(e);
|
|
101
|
+
}
|
|
102
|
+
return [];
|
|
103
|
+
},
|
|
104
|
+
debug: (msg) => console.log(msg),
|
|
105
|
+
}).addTo(map);
|
|
106
|
+
|
|
107
|
+
// shadeMap.setTerrainSource({
|
|
108
|
+
// getSourceUrl: (params) => {
|
|
109
|
+
// const { x, y, z } = params
|
|
110
|
+
|
|
111
|
+
// return `https://pub-042f8c71c32b4422a6a445f9ecaf6a55.r2.dev/${z}/${x}/${y}.webp`
|
|
112
|
+
// },
|
|
113
|
+
// getElevation: (params) => {
|
|
114
|
+
// const { r, g } = params
|
|
115
|
+
|
|
116
|
+
// return ((r * 256 + g) / 2 ** 16) * 4808
|
|
117
|
+
// },
|
|
118
|
+
// tileSize: 512,
|
|
119
|
+
// maxZoom: 17,
|
|
120
|
+
// _overzoom: 18,
|
|
121
|
+
// })
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
// shadeMap.setSunExposure(true, {
|
|
125
|
+
// startDate: sunrise,
|
|
126
|
+
// endDate: sunset
|
|
127
|
+
// });
|
|
128
|
+
|
|
129
|
+
shadeMap.once('idle', () => {
|
|
130
|
+
shadeMap._reset();
|
|
131
|
+
setTimeout(() => {
|
|
132
|
+
window.JSREPORT_READY_TO_START = true;
|
|
133
|
+
}, 4000);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
} catch (error) {
|
|
137
|
+
console.error("Error name:", error.name);
|
|
138
|
+
console.error("Error message:", error.message);
|
|
139
|
+
console.error("Error stack:", error.stack);
|
|
140
|
+
}
|
|
141
|
+
</script>
|
|
142
|
+
</div>
|
|
143
|
+
</body>
|
|
144
|
+
|
|
145
|
+
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "leaflet-shadow-simulator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.57.1",
|
|
4
4
|
"description": "Display terrain and structure shadows cast by the sun in a custom Leaflet layer",
|
|
5
5
|
"main": "dist/leaflet-shadow-simulator.umd.min.js",
|
|
6
6
|
"browser": "dist/leaflet-shadow-simulator.umd.min.js",
|