@ohuoy/easymap 1.0.21 → 1.0.23

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.
@@ -21,30 +21,35 @@ const params = {
21
21
  radius: 2.5,
22
22
  exposure: 0,
23
23
  };
24
- var tb = {};
25
- let scene;
26
24
  let sceneTarget;
27
25
  let cameraMap;
28
- let target;
29
26
  let cameraTarget;
30
- let materialTarget;
31
27
  let cameraTransform;
32
28
 
33
- var camera
34
- let outlineComposer;
29
+ // let this.outlineComposer;
35
30
  let bloomComposer;
36
31
  let renderScene;
37
32
  let bloomPass;
38
33
  let composer;
39
- let outlinePass;
34
+ // let this.outlinePass;
40
35
  let composer2;
41
- var group = new THREE.Group();
42
- let group2 = new THREE.Group();
43
- let group3 = new THREE.Group();
36
+ // var this.group = new THREE.Group();
37
+ // let this.group2 = new THREE.Group();
38
+ // let this.group3 = new THREE.Group();
44
39
  let sceneMap;
45
40
  var darkMaterial = new THREE.MeshBasicMaterial({ color: 'black' ,transparent:true,opacity:1});
46
41
  var bloomLayer = new THREE.Layers();
47
42
  export default class ExtrusionLayer{
43
+ tb = {};
44
+ scene;
45
+ camera;
46
+ outlineComposer;
47
+ outlinePass;
48
+ group = new THREE.Group();
49
+ group2 = new THREE.Group();
50
+ group3 = new THREE.Group();
51
+ materialTarget;
52
+ target;
48
53
  opacity = 0.8
49
54
  previewCanvas = null;
50
55
  w = 0;
@@ -72,7 +77,7 @@ export default class ExtrusionLayer{
72
77
  }
73
78
  const material1 = new THREE.MeshLambertMaterial({ color: 0xb00000, wireframe: false });
74
79
  const material2 = new THREE.MeshLambertMaterial({ color: 0xff8000, wireframe: false });
75
- let star = tb.extrusion({
80
+ let star = this.tb.extrusion({
76
81
  coordinates: [points],
77
82
  geometryOptions: { depth: 20, steps: 1, bevelEnabled: true, bevelThickness: 2, bevelSize: 4, bevelSegments: 1 },
78
83
  anchor: 'center',
@@ -83,7 +88,7 @@ export default class ExtrusionLayer{
83
88
  star.addTooltip("A animated extruded star over Columbus Park", true);
84
89
  star.setCoords([-74.0001269, 40.7151698, 50]);
85
90
  star.set({ rotation: {x: 0, y: 0, z: 720}, duration: 20000 })
86
- tb.add(star);
91
+ this.tb.add(star);
87
92
  }
88
93
 
89
94
  addExtrusionsThreeBox(coordinates,center, height = 1000) {
@@ -96,11 +101,11 @@ export default class ExtrusionLayer{
96
101
  // let coords = []
97
102
  // data.forEach((b) => {
98
103
  // // let center = b.properties.center;
99
- // // let s = tb.projectedUnitsPerMeter(center[1]);
104
+ // // let s = this.tb.projectedUnitsPerMeter(center[1]);
100
105
  // coords.push(b.geometry.coordinates)
101
106
 
102
107
  // });
103
- let extrusion = tb.extrusion({
108
+ let extrusion = this.tb.extrusion({
104
109
  coordinates: coordinates,
105
110
  anchor:'center',
106
111
  geometryOptions: { curveSegments: 1, depth: height },
@@ -108,7 +113,7 @@ export default class ExtrusionLayer{
108
113
  },this.map);
109
114
  // extrusion.addTooltip(b.properties.tooltip, true);
110
115
  extrusion.setCoords([...transform(center), 0]);
111
- tb.add(extrusion);
116
+ this.tb.add(extrusion);
112
117
  this.outlineObj(extrusion)
113
118
  }
114
119
 
@@ -144,43 +149,43 @@ export default class ExtrusionLayer{
144
149
  const geometry = new THREE.ExtrudeGeometry( shape, { curveSegments: 1, depth: height } );
145
150
  const mesh = new THREE.Mesh( geometry, material ) ;
146
151
  mesh.layers.enable(BLOOM_SCENE)
147
- group.add(mesh)
148
- // /group2.add()
152
+ this.group.add(mesh)
153
+ // /this.group2.add()
149
154
  })
150
155
  }
151
156
 
152
157
  outlineObj(selectedObjects) {
153
- if (outlinePass) {
154
- outlineComposer.removePass(outlinePass)
155
- outlinePass = null
158
+ if (this.outlinePass) {
159
+ this.outlineComposer.removePass(this.outlinePass)
160
+ this.outlinePass = null
156
161
  }
157
162
  // 物体边缘发光通道
158
- outlinePass = new OutlinePass(
163
+ this.outlinePass = new OutlinePass(
159
164
  new THREE.Vector2(window.innerWidth, window.innerHeight),
160
- scene,
161
- camera
165
+ this.scene,
166
+ this.camera
162
167
  )
163
- outlinePass.edgeStrength = 5 // 边框的亮度
164
- outlinePass.edgeGlow = 0.1 // 光晕[0,1]
165
- outlinePass.edgeThickness = 0.1 // 边框宽度
166
- outlinePass.pulsePeriod = 2 // 呼吸闪烁的速度
167
- outlinePass.visibleEdgeColor.set(0xff4ecfff)
168
- outlinePass.hiddenEdgeColor.set(0x00ffff)
169
- outlinePass.selectedObjects = selectedObjects
170
- outlineComposer.addPass(outlinePass)
168
+ this.outlinePass.edgeStrength = 5 // 边框的亮度
169
+ this.outlinePass.edgeGlow = 0.1 // 光晕[0,1]
170
+ this.outlinePass.edgeThickness = 0.1 // 边框宽度
171
+ this.outlinePass.pulsePeriod = 2 // 呼吸闪烁的速度
172
+ this.outlinePass.visibleEdgeColor.set(0xff4ecfff)
173
+ this.outlinePass.hiddenEdgeColor.set(0x00ffff)
174
+ this.outlinePass.selectedObjects = selectedObjects
175
+ this.outlineComposer.addPass(this.outlinePass)
171
176
  // 自定义的着色器通道 作为参数
172
177
  }
173
178
 
174
179
 
175
180
  addLineThreeBox(coordinates,center, height = 1000){
176
181
  coordinates.forEach(coords => {
177
- let line = tb.line({
182
+ let line = this.tb.line({
178
183
  geometry:coords,
179
184
  color:0xe6f2ff,
180
185
  width:2
181
186
  });
182
187
  //line.setCoords([...transform(center), 0]);
183
- tb.add(line);
188
+ this.tb.add(line);
184
189
  });
185
190
 
186
191
  }
@@ -239,7 +244,7 @@ export default class ExtrusionLayer{
239
244
  let line = new Line2(geometry, matLine);
240
245
  line.position.copy(normalized.position);
241
246
  line.computeLineDistances();
242
- group.add(line)
247
+ this.group.add(line)
243
248
  }
244
249
 
245
250
  addLine(coordinates, height = 1000,opacity = 0.5,width = 2,color = 0xb6d1fc){
@@ -263,10 +268,10 @@ export default class ExtrusionLayer{
263
268
  // let line = new Line2( geometry, matLine );
264
269
  let line = this.createLine(coords,height,opacity,width,color)
265
270
  line.layers.enable(BLOOM_SCENE)
266
- group.add(line)
271
+ this.group.add(line)
267
272
  lines.push(line)
268
273
  })
269
- //this.outlineObj([group])
274
+ //this.outlineObj([this.group])
270
275
  }
271
276
 
272
277
 
@@ -289,7 +294,7 @@ export default class ExtrusionLayer{
289
294
  // composePlaneGeometry.setAttribute( 'uv', new THREE.Float32BufferAttribute( [ 0, 2, 0, 0, 2, 0 ], 2 ) );
290
295
  let composePlaneGeometry = new THREE.PlaneGeometry(w * 10000 ,h * 10000);
291
296
  //debugger
292
- // materialTarget = new THREE.ShaderMaterial( {
297
+ // this.materialTarget = new THREE.ShaderMaterial( {
293
298
  // uniforms: {
294
299
  // 'tDiffuse': { value: null },
295
300
  // 'opacity': { value: 1 }
@@ -315,23 +320,23 @@ export default class ExtrusionLayer{
315
320
  // depthTest: false,
316
321
  // depthWrite: false
317
322
  // } );
318
- materialTarget = new THREE.MeshPhongMaterial({
319
- map:target.texture,
323
+ this.materialTarget = new THREE.MeshPhongMaterial({
324
+ map:this.target.texture,
320
325
  opacity:1,
321
326
  transparent: true,
322
327
  });
323
- let mesh = new THREE.Mesh(composePlaneGeometry, materialTarget);
324
- mesh = tb.Object3D({ obj: mesh, units: 'meters',fixedZoom :15 ,anchor:'center'});
328
+ let mesh = new THREE.Mesh(composePlaneGeometry, this.materialTarget);
329
+ mesh = this.tb.Object3D({ obj: mesh, units: 'meters',fixedZoom :15 ,anchor:'center'});
325
330
  mesh.setCoords( [0,0]);
326
- tb.add(mesh);
331
+ this.tb.add(mesh);
327
332
 
328
- group2.add(mesh)
333
+ this.group2.add(mesh)
329
334
  }
330
335
 
331
336
 
332
337
  onAdd(map, gl) {
333
338
  this.map = map;
334
- tb = new Threebox(
339
+ this.tb = new Threebox(
335
340
  map,
336
341
  gl, //get the context from Mapbox
337
342
  { defaultLights: true ,passiveRendering:false}
@@ -342,16 +347,16 @@ export default class ExtrusionLayer{
342
347
  this.w = w;
343
348
  this.h = h;
344
349
 
345
- scene = new THREE.Scene();
350
+ this.scene = new THREE.this.scene();
346
351
  //sceneTarget.background = new THREE.Color('rgba(0,0,0,0)')
347
- camera = new THREE.PerspectiveCamera(map.transform.fov, w / h, 0.1, 1e21);
348
- scene.add(group)
349
- scene.add(new THREE.AmbientLight(0xffffff));
350
- //scene.add(group2)
352
+ this.camera = new THREE.PerspectiveCamera(map.transform.fov, w / h, 0.1, 1e21);
353
+ this.scene.add(this.group)
354
+ this.scene.add(new THREE.AmbientLight(0xffffff));
355
+ //this.scene.add(this.group2)
351
356
 
352
- new CameraSync(this.map, camera, group);
357
+ new CameraSync(this.map, this.camera, this.group);
353
358
 
354
- //new CameraSync(this.map, camera, group2);
359
+ //new CameraSync(this.map, this.camera, this.group2);
355
360
  this.renderer = new THREE.WebGLRenderer({
356
361
  canvas: map.getCanvas(),
357
362
  context: gl,
@@ -360,13 +365,13 @@ export default class ExtrusionLayer{
360
365
  });
361
366
  this.renderer.outputEncoding = THREE.sRGBEncoding;
362
367
  this.renderer.autoClear = false;
363
- scene.add(new THREE.AxesHelper(0))
364
- //scene.background =null;
365
- //scene.background = new THREE.Color(0x000000);
368
+ this.scene.add(new THREE.AxesHelper(0))
369
+ //this.scene.background =null;
370
+ //this.scene.background = new THREE.Color(0x000000);
366
371
  //this.renderer.setClearAlpha(0.0);
367
- // target = new THREE.WebGLRenderTarget(w,h,{encoding: THREE.sRGBEncoding });
372
+ // this.target = new THREE.WebGLRenderTarget(w,h,{encoding: THREE.sRGBEncoding });
368
373
  // this.setTargetTexture(w,h)
369
- //renderScene = new RenderPass(scene, camera);
374
+ //renderScene = new RenderPass(this.scene, this.camera);
370
375
  //composer2 = new EffectComposer(this.renderer);
371
376
  //bloomPass = new UnrealBloomPass(new THREE.Vector2(w/2, h/2), params.strength, params.radius, params.threshold);
372
377
  //composer2.addPass(renderScene);
@@ -379,14 +384,14 @@ export default class ExtrusionLayer{
379
384
  // bloomComposer.renderToScreen = true;
380
385
  // bloomComposer.addPass(renderScene);
381
386
  // bloomComposer.addPass(bloomPass);
382
- //outlineComposer = new EffectComposer(this.renderer)
387
+ //this.outlineComposer = new EffectComposer(this.renderer)
383
388
  // bloomLayer.set(BLOOM_SCENE);
384
389
 
385
390
 
386
391
  // const bloomPass = new OutlinePass(
387
392
  // new THREE.Vector2(window.innerWidth, window.innerHeight),
388
- // scene,
389
- // camera
393
+ // this.scene,
394
+ // this.camera
390
395
  // )
391
396
  // bloomPass.edgeStrength = 5 // 边框的亮度
392
397
  // bloomPass.edgeGlow = 1 // 光晕[0,1]
@@ -394,7 +399,7 @@ export default class ExtrusionLayer{
394
399
  // bloomPass.pulsePeriod = 3 // 呼吸闪烁的速度
395
400
  // bloomPass.visibleEdgeColor.set(0xff4ecfff)
396
401
  // bloomPass.hiddenEdgeColor.set(0x00ffff)
397
- //bloomPass.selectedObjects = [group]
402
+ //bloomPass.selectedObjects = [this.group]
398
403
 
399
404
 
400
405
 
@@ -422,8 +427,8 @@ export default class ExtrusionLayer{
422
427
  // composer.addPass(outputPass);
423
428
 
424
429
 
425
- //let renderPass = new RenderPass(scene, camera)
426
- //outlineComposer.addPass(renderPass)
430
+ //let renderPass = new RenderPass(this.scene, this.camera)
431
+ //this.outlineComposer.addPass(renderPass)
427
432
  }
428
433
 
429
434
 
@@ -449,17 +454,17 @@ export default class ExtrusionLayer{
449
454
  render(gl, matrix) {
450
455
 
451
456
  //composer.render()
452
- // scene.traverse(this.darkenNonBloomed);
457
+ // this.scene.traverse(this.darkenNonBloomed);
453
458
  // bloomComposer.render();
454
- //outlineComposer.render()
459
+ //this.outlineComposer.render()
455
460
  //composer2.render();
456
461
  this.renderer.resetState();
457
- this.renderer.render(scene,camera)
462
+ this.renderer.render(this.scene,this.camera)
458
463
  this.map.triggerRepaint();
459
464
  }
460
465
 
461
466
  darkenNonBloomed(obj) {
462
- // if (obj instanceof THREE.Scene) {
467
+ // if (obj instanceof THREE.this.scene) {
463
468
  // obj.background = new THREE.Color(0x000fff)
464
469
  // debugger
465
470
  // }
@@ -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
 
@@ -1,11 +1,12 @@
1
- import {Threebox} from '../../../lib/threebox-plugin';
1
+ import {Threebox} from 'threebox-plugin';
2
2
  import * as THREE from 'three'
3
3
  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){
@@ -27,24 +28,39 @@ export default class PathLineLayer{
27
28
  }
28
29
  for(let i in list){
29
30
  let item = list[i]
30
-
31
31
  if(i>0){
32
32
  let pre = list[i-1]
33
33
  if(item.color == pre.color){
34
- _line.geometry.push(item.point)
34
+ _line.geometry.push(item.point)
35
+ if(i == list.length -1){
36
+ if(_line.geometry.length > 0){
37
+ _lines.push(_line)
38
+ }
39
+ }
35
40
  }else{
36
- let c = new THREE.Color(item.color)
37
- _lines.push(_line)
41
+ _line.geometry.push(item.point)
42
+ let c = new THREE.Color()
43
+
44
+ c.set(item.color)
45
+ if(_line.geometry.length > 0){
46
+ _lines.push(_line)
47
+ }
38
48
  _line = {
39
49
  geometry:[],
40
50
  color:c,
41
51
  width:20
42
52
  }
53
+ _line.geometry.push(item.point)
43
54
  }
44
-
45
- if(i == list.length-1){
46
- _lines.push(_line)
55
+ }else{
56
+ let c = new THREE.Color()
57
+ c.set(item.color)
58
+ _line = {
59
+ geometry:[],
60
+ color:c,
61
+ width:20
47
62
  }
63
+ _line.geometry.push(item.point)
48
64
  }
49
65
  // lineMesh.addEventListener('ObjectMouseOver', ()=>{
50
66
  // console.log(999)
@@ -57,8 +73,8 @@ export default class PathLineLayer{
57
73
  // width: Math.random() + 1 // random width between 1 and 2
58
74
  // }
59
75
 
60
- let lineMesh = tb.line(line);
61
- tb.add(lineMesh)
76
+ let lineMesh = this.tb.line(line);
77
+ this.tb.add(lineMesh)
62
78
  this.lines.push(lineMesh)
63
79
  })
64
80
  this.map.fitBounds(getBBox(list.map(a=>a.point)), {
@@ -70,14 +86,14 @@ export default class PathLineLayer{
70
86
 
71
87
  onAdd(map, gl) {
72
88
  this.map = map;
73
- tb = new Threebox(
89
+ this.tb = new Threebox(
74
90
  map,
75
91
  gl, //get the context from Mapbox
76
92
  { defaultLights: true ,passiveRendering:false}
77
93
  );
78
94
  }
79
95
  render(gl, matrix) {
80
- tb.update();
96
+ this.tb.update();
81
97
  this.map.triggerRepaint();
82
98
  }
83
99
  }