@ohuoy/easymap 1.0.21 → 1.0.22

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.
@@ -3,12 +3,13 @@ import {hasProperty,transform,downloadFileByBase64, sleep} from '../../utils/uti
3
3
  import mapboxgl from '../../../lib/mapbox-gl/dist/mapbox-gl.js';
4
4
  import * as THREE from 'three'
5
5
  import {Threebox} from '../../../lib/threebox-plugin';
6
- var tb = {};
7
- let markerGroup = new THREE.Group();
6
+ // let this.markerGroup = new THREE.Group();
8
7
  export default class MarkerAreaLayer{
8
+ tb = {};
9
9
  markerArr = []
10
10
  opacity = 0.8
11
11
  textClass = ''
12
+ markerGroup = new THREE.Group();
12
13
  constructor(id,config) {
13
14
  this.id = id;
14
15
  this.opacity = config?.opacity ? Number(config.opacity):0.8
@@ -24,7 +25,7 @@ export default class MarkerAreaLayer{
24
25
  transparent: true
25
26
  });
26
27
  let mesh = new THREE.Mesh( geometry, material) ;
27
- mesh = tb.Object3D({ obj: mesh, units: 'meters' ,anchor:'center'});
28
+ mesh = this.tb.Object3D({ obj: mesh, units: 'meters' ,anchor:'center'});
28
29
  mesh.setCoords(transform(item.coords))
29
30
  let geometryB = new THREE.CylinderGeometry( 5000 * item.size,7000 * item.size, 4000 * item.size,32)
30
31
  let materialB = new THREE.MeshBasicMaterial({
@@ -38,11 +39,11 @@ export default class MarkerAreaLayer{
38
39
  meshB.position.z -= 600000
39
40
  meshB.rotation.set(-Math.PI / 2, 0, 0);
40
41
 
41
- meshB = tb.Object3D({ obj: meshB, units: 'meters' ,anchor:'center',rotation: { x: 90, y: 0, z: 0 } });
42
+ meshB = this.tb.Object3D({ obj: meshB, units: 'meters' ,anchor:'center',rotation: { x: 90, y: 0, z: 0 } });
42
43
  meshB.setCoords(transform(item.coords))
43
44
  //meshB.setRotation({x:0,y:Math.PI / 4,z:0})
44
- markerGroup.add(mesh)
45
- markerGroup.add(meshB)
45
+ this.markerGroup.add(mesh)
46
+ this.markerGroup.add(meshB)
46
47
  }
47
48
 
48
49
 
@@ -60,15 +61,15 @@ export default class MarkerAreaLayer{
60
61
 
61
62
  onAdd(map, gl) {
62
63
  this.map = map;
63
- tb = new Threebox(
64
+ this.tb = new Threebox(
64
65
  map,
65
66
  gl, //get the context from Mapbox
66
67
  { defaultLights: true ,passiveRendering:false}
67
68
  );
68
- tb.add(markerGroup)
69
+ this.tb.add(this.markerGroup)
69
70
  }
70
71
  render(gl, matrix) {
71
- tb.update();
72
+ this.tb.update();
72
73
  this.map.triggerRepaint();
73
74
  }
74
75
 
@@ -4,8 +4,9 @@ import { getBBox } from '../../utils/util.js';
4
4
  import { sleep } from '../../utils/util.js';
5
5
  import {hasProperty,transform} from '../../utils/util.js'
6
6
  import mapboxgl from '../../../lib/mapbox-gl/dist/mapbox-gl.js';
7
- var tb = {};
7
+
8
8
  export default class PathLineLayer{
9
+ tb={}
9
10
  lines = []
10
11
  constructor(id,config) {
11
12
  this.id = id;
@@ -14,7 +15,7 @@ export default class PathLineLayer{
14
15
  }
15
16
 
16
17
  remove(){
17
- this.lines.forEach(a=>tb.remove(a))
18
+ this.lines.forEach(a=>this.tb.remove(a))
18
19
  }
19
20
 
20
21
  drawLine(list){
@@ -57,8 +58,8 @@ export default class PathLineLayer{
57
58
  // width: Math.random() + 1 // random width between 1 and 2
58
59
  // }
59
60
 
60
- let lineMesh = tb.line(line);
61
- tb.add(lineMesh)
61
+ let lineMesh = this.tb.line(line);
62
+ this.tb.add(lineMesh)
62
63
  this.lines.push(lineMesh)
63
64
  })
64
65
  this.map.fitBounds(getBBox(list.map(a=>a.point)), {
@@ -70,14 +71,14 @@ export default class PathLineLayer{
70
71
 
71
72
  onAdd(map, gl) {
72
73
  this.map = map;
73
- tb = new Threebox(
74
+ this.tb = new Threebox(
74
75
  map,
75
76
  gl, //get the context from Mapbox
76
77
  { defaultLights: true ,passiveRendering:false}
77
78
  );
78
79
  }
79
80
  render(gl, matrix) {
80
- tb.update();
81
+ this.tb.update();
81
82
  this.map.triggerRepaint();
82
83
  }
83
84
  }
@@ -7,8 +7,8 @@ import { Line2 } from 'three/addons/lines/Line2.js';
7
7
  import {LineMaterial} from 'three/examples/jsm/lines/LineMaterial.js'
8
8
  import * as THREE from 'three'
9
9
  import {Threebox} from '../../../lib/threebox-plugin';
10
- var tb = {};
11
10
  export default class ThreeScanLayer{
11
+ tb = {};
12
12
  drawArray = []
13
13
  opacity = 0.8
14
14
  textClass = ''
@@ -23,11 +23,11 @@ export default class ThreeScanLayer{
23
23
  }
24
24
 
25
25
  //同时渲染多个地点图片文本
26
- async drawImageList(list,delay = 300){
26
+ async drawImageList(list,delay = 300){
27
27
  for(let i in list){
28
28
  await this.update(list[i])
29
29
  //this.drawArray.push(list[i])
30
- }
30
+ }
31
31
  for(let i in this.drawArray){
32
32
  let _point = list.find(a=>a.center[0] == this.drawArray[i].center[0] && a.center[1] == this.drawArray[i].center[1])
33
33
  if(!_point){
@@ -36,7 +36,7 @@ export default class ThreeScanLayer{
36
36
  }
37
37
  }
38
38
  this.drawArray = this.drawArray.filter(a=>a)
39
- tb.update();
39
+ this.tb.update();
40
40
  this.map.triggerRepaint();
41
41
  await sleep(delay)
42
42
  let canvas = this.map.getCanvas()
@@ -50,7 +50,7 @@ export default class ThreeScanLayer{
50
50
 
51
51
  remove(point){
52
52
  point.mesh.label.element.remove()
53
- tb.remove(point.mesh)
53
+ this.tb.remove(point.mesh)
54
54
  }
55
55
 
56
56
  removeAll(){
@@ -59,7 +59,7 @@ export default class ThreeScanLayer{
59
59
  this.drawArray[i] = null
60
60
  }
61
61
  this.drawArray = this.drawArray.filter(a=>a)
62
- tb.update();
62
+ this.tb.update();
63
63
  this.map.triggerRepaint();
64
64
  }
65
65
 
@@ -82,7 +82,7 @@ export default class ThreeScanLayer{
82
82
  let w = point.rect.width ? point.rect.width: this.rectMesh.w
83
83
  if(!this.rectMesh.mesh || w!= this.rectMesh.w || point.rect.position[0]!=this.rectMesh.lng || point.rect.position[1] !=this.rectMesh.lat){
84
84
  if(this.rectMesh.mesh){
85
- tb.remove(this.rectMesh.mesh)
85
+ this.tb.remove(this.rectMesh.mesh)
86
86
  }
87
87
  let bounds = getLayerMapPosition(w,transform(point.rect.position))
88
88
  bounds.push(bounds[0])
@@ -92,11 +92,11 @@ export default class ThreeScanLayer{
92
92
  width: 20 // random width between 1 and 2
93
93
  }
94
94
 
95
- let lineMesh = tb.line(lineOptions);
95
+ let lineMesh = this.tb.line(lineOptions);
96
96
  this.rectMesh.mesh = lineMesh;
97
- tb.add(lineMesh)
97
+ this.tb.add(lineMesh)
98
98
  // if(this.rectMesh.mesh){
99
- // tb.remove(this.rectMesh.mesh)
99
+ // this.tb.remove(this.rectMesh.mesh)
100
100
  // }
101
101
  // let plane = new THREE.PlaneGeometry( w*20,w*20);
102
102
  // let material = new THREE.MeshLambertMaterial({
@@ -113,14 +113,14 @@ export default class ThreeScanLayer{
113
113
 
114
114
  // let line = new THREE.LineSegments(edges, edgesMaterial);
115
115
  // mesh.add(line);
116
- // mesh = tb.Object3D({ obj: mesh, units: 'meters',fixedZoom :15 ,anchor:'center'});
116
+ // mesh = this.tb.Object3D({ obj: mesh, units: 'meters',fixedZoom :15 ,anchor:'center'});
117
117
  // this.rectMesh.mesh = mesh;
118
118
  // this.rectMesh.w = w;
119
119
 
120
120
  }
121
121
  // if(this.rectMesh.mesh){
122
122
  // this.rectMesh.mesh.setCoords(transform(point.rect.position))
123
- // tb.add(this.rectMesh.mesh);
123
+ // this.tb.add(this.rectMesh.mesh);
124
124
  // }
125
125
  }
126
126
 
@@ -153,11 +153,18 @@ export default class ThreeScanLayer{
153
153
  point.url += `?tempid=${Math.random()}`
154
154
  }
155
155
  let p = ()=>new Promise(function(resolve,reject){
156
- new THREE.TextureLoader().load(point.url,(_texture)=>{
157
- resolve(_texture)
158
- })
156
+ try{
157
+ new THREE.TextureLoader().load(point.url,(_texture)=>{
158
+ resolve(_texture)
159
+ },()=>{},()=>{
160
+ resolve(null)
161
+ })
162
+ }catch{
163
+ reject(null)
164
+ }
159
165
  })
160
- texture = await p()
166
+ texture = await p()
167
+ if(!texture) return;
161
168
  texture.center.set(0.5,0.5);
162
169
  texture.rotation = -Math.PI;
163
170
  }
@@ -182,10 +189,10 @@ export default class ThreeScanLayer{
182
189
  material.color.convertSRGBToLinear();
183
190
  let mesh = new THREE.Mesh(geometry, material);
184
191
  mesh.name = 'scanimg'
185
- mesh = tb.Object3D({ obj: mesh, units: 'meters',fixedZoom :15 ,anchor:'center'});
192
+ mesh = this.tb.Object3D({ obj: mesh, units: 'meters',fixedZoom :15 ,anchor:'center'});
186
193
  mesh.setCoords( transform(point.center));
187
- tb.renderer.outputEncoding = THREE.sRGBEncoding;
188
- tb.add(mesh);
194
+ this.tb.renderer.outputEncoding = THREE.sRGBEncoding;
195
+ this.tb.add(mesh);
189
196
  let dom =document.createElement('div')
190
197
  mesh.addLabel(dom,true,{x:mesh.anchor.x,y:mesh.anchor.y+point.distance *1200,z:mesh.anchor.z},0)
191
198
  mesh.label.element.className += ('' +this.textClass)
@@ -217,10 +224,10 @@ export default class ThreeScanLayer{
217
224
  material.color.convertSRGBToLinear();
218
225
  let mesh = new THREE.Mesh(geometry, material);
219
226
  mesh.name = 'scanimg'
220
- mesh = tb.Object3D({ obj: mesh, units: 'meters',fixedZoom :15 ,anchor:'center'});
227
+ mesh = this.tb.Object3D({ obj: mesh, units: 'meters',fixedZoom :15 ,anchor:'center'});
221
228
  mesh.setCoords( transform(point.center));
222
- tb.renderer.outputEncoding = THREE.sRGBEncoding;
223
- tb.add(mesh);
229
+ this.tb.renderer.outputEncoding = THREE.sRGBEncoding;
230
+ this.tb.add(mesh);
224
231
  let dom =document.createElement('div')
225
232
  mesh.addLabel(dom,true,{x:mesh.anchor.x,y:mesh.anchor.y+point.distance *1200,z:mesh.anchor.z},0)
226
233
  mesh.label.element.className += ('' +this.textClass)
@@ -254,10 +261,10 @@ export default class ThreeScanLayer{
254
261
  material.color.convertSRGBToLinear();
255
262
  let mesh = new THREE.Mesh(geometry, material);
256
263
  mesh.name = 'scanimg'
257
- mesh = tb.Object3D({ obj: mesh, units: 'meters',fixedZoom :15 ,anchor:'center'});
264
+ mesh = this.tb.Object3D({ obj: mesh, units: 'meters',fixedZoom :15 ,anchor:'center'});
258
265
  mesh.setCoords( transform(point.center));
259
- tb.renderer.outputEncoding = THREE.sRGBEncoding;
260
- tb.add(mesh);
266
+ this.tb.renderer.outputEncoding = THREE.sRGBEncoding;
267
+ this.tb.add(mesh);
261
268
  let dom =document.createElement('div')
262
269
  mesh.addLabel(dom,true,{x:mesh.anchor.x,y:mesh.anchor.y+point.distance *1200,z:mesh.anchor.z},0)
263
270
  mesh.label.element.className += ('' +this.textClass)
@@ -266,15 +273,15 @@ export default class ThreeScanLayer{
266
273
  }
267
274
 
268
275
  onAdd(map, gl) {
269
- this.map = map;
270
- tb = new Threebox(
276
+ this.map = map;
277
+ this.tb = new Threebox(
271
278
  map,
272
279
  gl, //get the context from Mapbox
273
280
  { defaultLights: true ,passiveRendering:false}
274
281
  );
275
282
  }
276
- render(gl, matrix) {
277
- tb.update();
283
+ render(gl, matrix) {
284
+ this.tb.update();
278
285
  this.map.triggerRepaint();
279
286
  }
280
287
 
@@ -4,11 +4,14 @@ import {Threebox} from '../../../lib/threebox-plugin';
4
4
  import { lnglatsToWorld ,normalizeVertices,flattenVectors,projectToWorld} from '../../utils/mapUtil';
5
5
  import CameraSync from '../../utils/CameraSync';
6
6
  const WORLD_SIZE = 1024000;
7
- var tb = {};
8
- let scene;
7
+ // var this.
8
+ // let this.scene;
9
9
  let cameraTransform;
10
- var group = new THREE.Group();
10
+ // var this.group = new THREE.Group();
11
11
  export default class ThreeWallLayer{
12
+ tb = {};
13
+ group = new THREE.Group();
14
+ scene;
12
15
  opacity = 0.8
13
16
  scale = 2
14
17
  limit = 6
@@ -152,9 +155,9 @@ export default class ThreeWallLayer{
152
155
  } );
153
156
  //material.color.convertSRGBToLinear();
154
157
  let mesh = new THREE.Mesh( geometry, material );
155
- // mesh = tb.Object3D({ obj: mesh, units: 'meters',anchor:'center'});
156
- // tb.add(mesh);
157
- group.add( mesh );
158
+ // mesh = this.tb.Object3D({ obj: mesh, units: 'meters',anchor:'center'});
159
+ // this.tb.add(mesh);
160
+ this.group.add( mesh );
158
161
  this.map.fitBounds(getBBox(dataList.map(a=>[a.lng,a.lat])), {
159
162
  padding: {top: 45, bottom:45, left: 35, right: 35},
160
163
  maxZoom:11,
@@ -234,22 +237,22 @@ export default class ThreeWallLayer{
234
237
  } );
235
238
 
236
239
  let mesh = new THREE.Mesh( geometry, material );
237
- scene.add( mesh );
238
- // mesh = tb.Object3D({ obj: mesh, units: 'meters',anchor:'center'});
239
- // tb.add(mesh);
240
+ this.scene.add( mesh );
241
+ // mesh = this.tb.Object3D({ obj: mesh, units: 'meters',anchor:'center'});
242
+ // this.tb.add(mesh);
240
243
  // for(let line of lines){
241
244
  // this.createLine(line.coords,`rgba(${line.color.join(',')})`)
242
245
  // }
243
246
  }
244
247
 
245
248
  createLine(path,color){
246
- let line = tb.line({
249
+ let line = this.tb.line({
247
250
  width:this.width,
248
251
  opacity:this.opacity,
249
252
  color:color,
250
253
  geometry:path
251
254
  })
252
- tb.add(line)
255
+ this.tb.add(line)
253
256
  }
254
257
 
255
258
  onAdd(map, gl) {
@@ -258,9 +261,9 @@ export default class ThreeWallLayer{
258
261
  const w = container.clientWidth;
259
262
  const h = container.clientHeight;
260
263
  this.camera = new THREE.PerspectiveCamera(map.transform.fov, w / h, 0.1, 1e21);
261
- scene = new THREE.Scene();
262
- scene.add(group)
263
- new CameraSync(this.map, this.camera, group);
264
+ this.scene = new THREE.Scene();
265
+ this.scene.add(this.group)
266
+ new CameraSync(this.map, this.camera, this.group);
264
267
  // let centerlngLat = map.getCenter()
265
268
  // let center = mapboxgl.MercatorCoordinate.fromLngLat(centerlngLat)
266
269
  // const scale = center.meterInMercatorCoordinateUnits();
@@ -297,17 +300,17 @@ export default class ThreeWallLayer{
297
300
  // create two three.js lights to illuminate the model
298
301
  // let directionalLight = new THREE.DirectionalLight(0xffffff);
299
302
  // directionalLight.position.set(0, -70, 100).normalize();
300
- // scene.add(directionalLight);
303
+ // this.scene.add(directionalLight);
301
304
 
302
305
  // let directionalLight2 = new THREE.DirectionalLight(0xffffff);
303
306
  // directionalLight2.position.set(0, 70, 100).normalize();
304
- // scene.add(directionalLight2);
305
- // tb = new Threebox(
307
+ // this.scene.add(directionalLight2);
308
+ // this.tb = new Threebox(
306
309
  // map,
307
310
  // gl, //get the context from Mapbox
308
311
  // { defaultLights: true ,passiveRendering:false}
309
312
  // );
310
- //scene.add(new THREE.AxesHelper(1000));
313
+ //this.scene.add(new THREE.AxesHelper(1000));
311
314
  this.renderer = new THREE.WebGLRenderer({
312
315
  canvas: map.getCanvas(),
313
316
  context: gl,
@@ -321,7 +324,7 @@ export default class ThreeWallLayer{
321
324
  }
322
325
 
323
326
  render(gl, matrix) {
324
- //tb.update();
327
+ //this.tb.update();
325
328
  // const rotationX = new THREE.Matrix4().makeRotationAxis(
326
329
  // new THREE.Vector3(1, 0, 0),
327
330
  // modelTransform.rotateX
@@ -357,7 +360,8 @@ export default class ThreeWallLayer{
357
360
  // var m = new THREE.Matrix4().fromArray(matrix);
358
361
  // this.camera.projectionMatrix = m.multiply(cameraTransform);;
359
362
  // this.renderer.resetState();
360
- this.renderer.render(scene, this.camera);
363
+
364
+ this.renderer.render(this.scene, this.camera);
361
365
  this.map.triggerRepaint();
362
366
  }
363
367