@treasuryspatial/map-kit 0.1.1 → 0.1.3

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.
@@ -2,6 +2,7 @@ import type { Feature, Polygon } from 'geojson';
2
2
  export type FootprintLayerController = {
3
3
  setHover: (feature: Feature<Polygon> | null) => void;
4
4
  setSelected: (feature: Feature<Polygon> | null) => void;
5
+ setBuildingsVisible: (visible: boolean) => void;
5
6
  destroy: () => void;
6
7
  };
7
8
  export declare function ensureFootprintLayers(map: mapboxgl.Map): FootprintLayerController;
@@ -1 +1 @@
1
- {"version":3,"file":"mapLayers.d.ts","sourceRoot":"","sources":["../src/mapLayers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAKhD,MAAM,MAAM,wBAAwB,GAAG;IACrC,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC;IACrD,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC;IACxD,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAiBF,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,GAAG,wBAAwB,CAkFjF"}
1
+ {"version":3,"file":"mapLayers.d.ts","sourceRoot":"","sources":["../src/mapLayers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAKhD,MAAM,MAAM,wBAAwB,GAAG;IACrC,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC;IACrD,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC;IACxD,mBAAmB,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IAChD,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAiBF,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,GAAG,wBAAwB,CA6FjF"}
package/dist/mapLayers.js CHANGED
@@ -80,6 +80,19 @@ export function ensureFootprintLayers(map) {
80
80
  return {
81
81
  setHover: (feature) => setSource('footprint-hover', feature),
82
82
  setSelected: (feature) => setSource('footprint-selected', feature),
83
+ setBuildingsVisible: (visible) => {
84
+ const layers = map.getStyle()?.layers ?? [];
85
+ layers.forEach((layer) => {
86
+ if (layer.type !== 'fill-extrusion')
87
+ return;
88
+ try {
89
+ map.setLayoutProperty(layer.id, 'visibility', visible ? 'visible' : 'none');
90
+ }
91
+ catch {
92
+ // ignore
93
+ }
94
+ });
95
+ },
83
96
  destroy: () => {
84
97
  const layers = ['footprint-selected-line', 'footprint-hover-line', 'building-footprints-outline', 'building-footprints-fill'];
85
98
  layers.forEach((id) => {
@@ -1 +1 @@
1
- {"version":3,"file":"mapThreeLayer.d.ts","sourceRoot":"","sources":["../src/mapThreeLayer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,QAAQ,CAAC,oBAAoB,CAAC;IACrC,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,IAAI,KAAK,IAAI,CAAC;IAC9C,SAAS,EAAE,CAAC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,KAAK,IAAI,CAAC;IACjE,gBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,KAAK,IAAI,CAAC;CAC5F,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CA0FhF"}
1
+ {"version":3,"file":"mapThreeLayer.d.ts","sourceRoot":"","sources":["../src/mapThreeLayer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,QAAQ,CAAC,oBAAoB,CAAC;IACrC,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,IAAI,KAAK,IAAI,CAAC;IAC9C,SAAS,EAAE,CAAC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,KAAK,IAAI,CAAC;IACjE,gBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,KAAK,IAAI,CAAC;CAC5F,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAoJhF"}
@@ -6,15 +6,22 @@ export function createMapThreeLayer(options) {
6
6
  let scene = null;
7
7
  let camera = null;
8
8
  let renderer = null;
9
+ let screenScene = null;
10
+ let screenCamera = null;
11
+ let screenMaterial = null;
12
+ let screenQuad = null;
13
+ let renderTarget = null;
9
14
  let rootGroup = null;
10
15
  let meshGroup = null;
11
16
  let mercatorOrigin = null;
12
17
  let meterScale = 1;
13
18
  let zOffset = zOffsetMeters;
19
+ let targetWidth = 0;
20
+ let targetHeight = 0;
14
21
  const layer = {
15
22
  id,
16
23
  type: 'custom',
17
- renderingMode: '3d',
24
+ renderingMode: '2d',
18
25
  onAdd: (map, gl) => {
19
26
  mapRef = map;
20
27
  scene = new THREE.Scene();
@@ -23,11 +30,33 @@ export function createMapThreeLayer(options) {
23
30
  canvas: map.getCanvas(),
24
31
  context: gl,
25
32
  antialias: true,
33
+ logarithmicDepthBuffer: true,
26
34
  });
27
35
  renderer.autoClear = false;
28
36
  renderer.outputColorSpace = THREE.SRGBColorSpace;
29
37
  renderer.toneMapping = THREE.NeutralToneMapping;
30
38
  renderer.toneMappingExposure = 1.05;
39
+ renderer.setClearColor(0x000000, 0);
40
+ const canvas = map.getCanvas();
41
+ targetWidth = canvas.width;
42
+ targetHeight = canvas.height;
43
+ renderTarget = new THREE.WebGLRenderTarget(targetWidth, targetHeight, {
44
+ depthBuffer: true,
45
+ stencilBuffer: false,
46
+ });
47
+ renderTarget.texture.colorSpace = THREE.SRGBColorSpace;
48
+ renderTarget.texture.premultiplyAlpha = true;
49
+ screenScene = new THREE.Scene();
50
+ screenCamera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
51
+ screenMaterial = new THREE.MeshBasicMaterial({
52
+ map: renderTarget.texture,
53
+ transparent: true,
54
+ depthTest: false,
55
+ depthWrite: false,
56
+ });
57
+ screenMaterial.premultipliedAlpha = true;
58
+ screenQuad = new THREE.Mesh(new THREE.PlaneGeometry(2, 2), screenMaterial);
59
+ screenScene.add(screenQuad);
31
60
  rootGroup = new THREE.Group();
32
61
  rootGroup.matrixAutoUpdate = false;
33
62
  scene.add(rootGroup);
@@ -36,8 +65,8 @@ export function createMapThreeLayer(options) {
36
65
  if (onInit && renderer && camera)
37
66
  onInit(scene, renderer, camera);
38
67
  },
39
- render: (_gl, matrix) => {
40
- if (!renderer || !scene || !camera || !rootGroup)
68
+ prerender: (_gl, matrix) => {
69
+ if (!renderer || !scene || !camera || !rootGroup || !renderTarget)
41
70
  return;
42
71
  camera.projectionMatrix = new THREE.Matrix4().fromArray(matrix);
43
72
  if (mercatorOrigin) {
@@ -46,8 +75,25 @@ export function createMapThreeLayer(options) {
46
75
  rootGroup.matrix = new THREE.Matrix4().multiplyMatrices(translate, scale);
47
76
  rootGroup.matrixWorldNeedsUpdate = true;
48
77
  }
49
- renderer.resetState();
78
+ const canvas = mapRef?.getCanvas();
79
+ if (canvas && (canvas.width !== targetWidth || canvas.height !== targetHeight)) {
80
+ targetWidth = canvas.width;
81
+ targetHeight = canvas.height;
82
+ renderTarget.setSize(targetWidth, targetHeight);
83
+ }
84
+ renderer.setRenderTarget(renderTarget);
85
+ renderer.clear(true, true, true);
50
86
  renderer.render(scene, camera);
87
+ renderer.setRenderTarget(null);
88
+ },
89
+ render: (gl) => {
90
+ if (!renderer || !screenScene || !screenCamera)
91
+ return;
92
+ renderer.resetState();
93
+ gl.disable(gl.DEPTH_TEST);
94
+ gl.enable(gl.BLEND);
95
+ gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
96
+ renderer.render(screenScene, screenCamera);
51
97
  mapRef?.triggerRepaint();
52
98
  },
53
99
  };
@@ -76,9 +122,19 @@ export function createMapThreeLayer(options) {
76
122
  if (rootGroup) {
77
123
  rootGroup.clear();
78
124
  }
125
+ if (screenQuad) {
126
+ screenQuad.geometry.dispose();
127
+ }
128
+ screenMaterial?.dispose();
129
+ renderTarget?.dispose();
79
130
  meshGroup = null;
80
131
  scene = null;
81
132
  camera = null;
133
+ screenScene = null;
134
+ screenCamera = null;
135
+ screenMaterial = null;
136
+ screenQuad = null;
137
+ renderTarget = null;
82
138
  renderer = null;
83
139
  mapRef = null;
84
140
  mercatorOrigin = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@treasuryspatial/map-kit",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "license": "UNLICENSED",
6
6
  "main": "./dist/index.js",