@ohuoy/easymap 1.0.11 → 1.0.13

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/index.js CHANGED
@@ -6,13 +6,15 @@ import * as mdi from '@mdi/js'
6
6
  import './lib/mapbox-gl/dist/mapbox-gl.css';
7
7
  import '@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css'
8
8
  import * as turf from '@turf/turf'
9
- import {getLayerMapPosition, transform,downloadFileByBase64,guid,downloadFile,downloadFileByBlob} from './src/utils/util.js';
9
+ import {getLayerMapPosition, transform,downloadFileByBase64,downloadFileBlobByBase64,guid,downloadFile,downloadFileByBlob, sleep} from './src/utils/util.js';
10
10
  import Toobars from './src/components/control/Toobars.js'
11
11
  import TilesBar from './src/components/control/TilesBar.js'
12
12
  import DrawBar from './src/components/control/DrawBar.js'
13
13
  import { ScanLayer } from './src/components/index.js';
14
14
  import JSZip from 'jszip';
15
15
  import gif from './src/components/gif/gif.js'
16
+ import * as EmComponents from './src/components/index'
17
+
16
18
  import { getGifWorker } from './src/components/gif/gif.worker.js'
17
19
 
18
20
  //导出组件
@@ -49,7 +51,7 @@ export class EasyMap {
49
51
  }
50
52
  config.center = config?.center? transform(config.center): transform([108.7198975,35.0446]);
51
53
  this.config = Object.assign(this.config,config)
52
- let scene = new Scene({
54
+ let scene = new Scene({
53
55
  id: target,
54
56
  logoVisible:false,
55
57
  // map: new Mapbox({
@@ -491,13 +493,38 @@ export class EasyMap {
491
493
  }
492
494
 
493
495
  //获取指定位置指定距离截图
494
- getMapImageByDistance(center,distance,_target){
496
+ getMapImageByDistance(center,distance,imageList=[],config = {
497
+ target:null,
498
+ style: 'http://192.168.11.93:1234/api/styles/osm',
499
+ type:'blob',
500
+ pix:{
501
+ w:1024,
502
+ h:1024
503
+ },
504
+ callback:()=>{}
505
+ }){
495
506
  let target;
507
+ config = Object.assign({},{
508
+ target:null,
509
+ type:'blob',
510
+ delay:300,
511
+ pix:{
512
+ w:1024,
513
+ h:1024
514
+ },
515
+ opacity:0.7,
516
+ style: 'http://192.168.11.93:1234/api/styles/osm',
517
+ callback:()=>{}
518
+ },config)
496
519
  let bounds = getLayerMapPosition(distance,transform(center))
497
- if(!_target) target = document.createElement('div');
498
- else target = _target;
499
- let pix = 1024;
500
- target.style = `width:${pix}px;height:${pix}px;`
520
+ if(!config.target) {
521
+ target = document.createElement('div');
522
+ }
523
+ else{
524
+ target = config.target;
525
+ }
526
+ let pix = config.pix;
527
+ target.style = `width:${pix.w}px;height:${pix.h}px;z-index:-1;`
501
528
  document.body.appendChild(target)
502
529
  let scene = new Scene({
503
530
  id: target,
@@ -505,11 +532,12 @@ export class EasyMap {
505
532
  // mapInstance: map,
506
533
  // }),
507
534
  map: new Mapbox({
508
- style:'http://192.168.11.93:1234/api/styles/osm',
535
+ style:config.style,
509
536
  preserveDrawingBuffer:true,
510
- center:transform([114.7198975,23.0446]),
537
+ //center:transform([114.7198975,23.0446]),
511
538
  bounds:[bounds[0],bounds[2]],
512
- container:target,
539
+ container:target,
540
+ opacity:0.7,
513
541
  pitch: 0,
514
542
  zoom: 0,
515
543
  rotation: 0,
@@ -517,10 +545,33 @@ export class EasyMap {
517
545
  })
518
546
  })
519
547
  let map = scene.map;
520
- map.on('load',()=>{
521
- let base64 = map._canvas.toDataURL();
522
- downloadFileByBase64(base64,guid())
523
- target.remove()
548
+ map.on('load',async ()=>{
549
+ if(!imageList || imageList.length == 0){
550
+ let base64 = map._canvas.toDataURL();
551
+ if(config.type == 'download'){
552
+ downloadFileByBase64(base64,guid())
553
+ }//downloadFileByBase64(base64,guid())
554
+ else if(config.type == 'blob'){
555
+ config.callback(downloadFileBlobByBase64(base64))
556
+ }
557
+ }else{
558
+ let scanLayer = map.getLayer('threescan-layer');
559
+ if(!scanLayer){
560
+ scanLayer= new EmComponents.ThreeScanLayer('threescan-layer',{
561
+ opacity:config.opacity,
562
+ textClass:' map-time zmax ',
563
+ })
564
+ map.addLayer(scanLayer);
565
+ }
566
+ for(let i in imageList){
567
+ let a = imageList[i]
568
+ let base64 = await scanLayer.drawImageList(a,config.delay)
569
+ // map.getCanvas().toDataURL()
570
+ config.callback(downloadFileBlobByBase64(base64))
571
+ }
572
+ }
573
+
574
+ //target.remove()
524
575
  })
525
576
  }
526
577
 
package/main.js CHANGED
@@ -12,7 +12,9 @@ import {ShaderPass} from 'three/examples/jsm/postprocessing/ShaderPass.js';
12
12
  import {OutlinePass} from 'three/examples/jsm/postprocessing/OutlinePass.js';
13
13
  import {FXAAShader} from 'three/examples/jsm/shaders/FXAAShader.js';
14
14
  import { UnrealBloomPass } from 'three/examples/jsm/postprocessing/UnrealBloomPass'
15
-
15
+ import { LineGeometry } from 'three/addons/lines/LineGeometry.js';
16
+ import { Line2 } from 'three/addons/lines/Line2.js';
17
+ import {LineMaterial} from 'three/examples/jsm/lines/LineMaterial.js'
16
18
  import {
17
19
  GammaCorrectionShader
18
20
  } from 'three/examples/jsm/shaders/GammaCorrectionShader.js';
@@ -29,6 +31,7 @@ export {
29
31
  EmComponents,
30
32
  EmUtils,
31
33
  mapboxgl,
34
+ Line2,
32
35
  OrbitControls,
33
36
  UnrealBloomPass,
34
37
  ant7,
@@ -38,6 +41,8 @@ export {
38
41
  RenderPass,
39
42
  ShaderPass,
40
43
  OutlinePass,
44
+ LineGeometry,
45
+ LineMaterial,
41
46
  FXAAShader,
42
47
  GammaCorrectionShader
43
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ohuoy/easymap",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "self map easy use",
5
5
  "main": "main.js",
6
6
  "scripts": {
@@ -1,5 +1,5 @@
1
1
 
2
- import {hasProperty,transform} from '../../utils/util'
2
+ import {hasProperty,transform,downloadFileByBase64, sleep} from '../../utils/util'
3
3
  import mapboxgl from '../../../lib/mapbox-gl/dist/mapbox-gl.js';
4
4
  import * as THREE from 'three'
5
5
  import { Threebox } from 'threebox-plugin';
@@ -17,9 +17,9 @@ export default class ThreeScanLayer{
17
17
  }
18
18
 
19
19
  //同时渲染多个地点图片文本
20
- drawImageList(list){
20
+ async drawImageList(list,delay = 300){
21
21
  for(let i in list){
22
- this.update(list[i])
22
+ await this.update(list[i])
23
23
  //this.drawArray.push(list[i])
24
24
  }
25
25
  for(let i in this.drawArray){
@@ -30,6 +30,10 @@ export default class ThreeScanLayer{
30
30
  }
31
31
  }
32
32
  this.drawArray = this.drawArray.filter(a=>a)
33
+ tb.update();
34
+ this.map.triggerRepaint();
35
+ await sleep(delay)
36
+ return this.map.getCanvas().toDataURL();
33
37
  }
34
38
 
35
39
  remove(point){
@@ -44,7 +48,7 @@ export default class ThreeScanLayer{
44
48
  }
45
49
  }
46
50
 
47
- update(point){
51
+ async update(point){
48
52
  let texture
49
53
  point.text = point.text ? point.text:''
50
54
  if(point.image){
@@ -65,10 +69,15 @@ export default class ThreeScanLayer{
65
69
  //texture = new THREE.DataTexture(data, width, height, THREE.RGBFormat);
66
70
  texture.needsUpdate = true; //纹理更新
67
71
  }else if(point.url){
68
- texture = new THREE.TextureLoader().load(point.url)
72
+ let p = ()=>new Promise(function(resolve,reject){
73
+ new THREE.TextureLoader().load(point.url,(_texture)=>{
74
+ resolve(_texture)
75
+ })
76
+ })
77
+ texture = await p()
69
78
  }
70
79
  texture.encoding = THREE.sRGBEncoding;
71
- texture.flipY = false;
80
+ texture.flipY = false;
72
81
  //texture.flipX = true;
73
82
  let index = this.drawArray.findIndex(a=>a.center[0] == point.center[0] && a.center[1] == point.center[1])
74
83
  if(index >= 0){
package/src/utils/util.js CHANGED
@@ -102,6 +102,10 @@ export function downloadFileByBase64(base64,name){
102
102
  downloadFile(myUrl,name)
103
103
  }
104
104
 
105
+ export function downloadFileBlobByBase64(base64){
106
+ return dataURLtoBlob(base64)
107
+ }
108
+
105
109
 
106
110
  /**
107
111
  * 生成GUID