@ohuoy/easymap 1.0.0

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 ADDED
@@ -0,0 +1,597 @@
1
+ import { Scene ,HeatmapLayer,LineLayer, PointLayer, PolygonLayer,ExportImage,Fullscreen} from '@antv/l7';
2
+ import { Mapbox } from '@antv/l7-maps';
3
+ import mapboxgl from 'mapbox-gl';
4
+ import * as mdi from '@mdi/js'
5
+ //import * as mdiSvg from '@mdi/font'
6
+ import 'mapbox-gl/dist/mapbox-gl.css';
7
+ import * as turf from '@turf/turf'
8
+ import {getLayerMapPosition, transform,downloadFileByBase64,guid,downloadFile,downloadFileByBlob} from './src/utils/util.js';
9
+ import Toobars from './src/components/control/Toobars.js'
10
+ import { ScanLayer } from './src/components/index.js';
11
+ import JSZip from 'jszip';
12
+ import gif from './src/components/gif/gif.js'
13
+ import { getGifWorker } from './src/components/gif/gif.worker.js'
14
+
15
+ //导出组件
16
+ export class EasyMap {
17
+ map;
18
+ scene;
19
+ markers;
20
+ target;
21
+ contextMenu;
22
+ dialog;
23
+
24
+ //control
25
+ ScaleControl = null;
26
+ NavigationControl = null;
27
+ ToobarsControl = null;
28
+ placesLabels = {
29
+ 'type': 'FeatureCollection',
30
+ 'features':[]
31
+ }
32
+ labelLayer = null;
33
+
34
+ constructor(target,styleUrl,config) {
35
+ let scene = new Scene({
36
+ id: target,
37
+ // map: new Mapbox({
38
+ // mapInstance: map,
39
+ // }),
40
+ map: new Mapbox({
41
+ style:styleUrl,
42
+ preserveDrawingBuffer:true,
43
+ center:config?.center?transform(config.center): transform([114.7198975,23.0446]),
44
+ pitch: config?.pitch?config.pitch:0,
45
+ zoom: config?.zoom?config.zoom:0,
46
+ rotation: config?.rotation?config.rotation:0,
47
+ token: ''//'pk.eyJ1Ijoid2hpdGVidWxkaW5nIiwiYSI6ImNsc3UwaXlnZDIwbDkybG1qbXJ6YnRtcmwifQ.jtQeo0gt3UNTCWw5FEyv_w',
48
+ })
49
+ })
50
+ let map = scene.map;
51
+ this.scene = scene;
52
+ this.map = map;
53
+ this.target = map.target;
54
+ let that = this;
55
+ this.map.on('load',()=>{
56
+ that.map.addSource('placesLabels', {
57
+ 'type': 'geojson',
58
+ 'data': that.placesLabels
59
+ });
60
+ that.addPlaceLabelsLayer()
61
+
62
+ // that.labelLayer = new PolygonLayer({})
63
+ // .source(that.placesLabels)
64
+ // .color('blue')
65
+ // .shape('label', 'text')
66
+ // .size(18)
67
+ // .style({
68
+ // textAnchor: 'center', // 文本相对锚点的位置 center|left|right|top|bottom|top-left
69
+ // textOffset: [0, 0], // 文本相对锚点的偏移量 [水平, 垂直]
70
+ // spacing: 2, // 字符间距
71
+ // padding: [1, 1], // 文本包围盒 padding [水平,垂直],影响碰撞检测结果,避免相邻文本靠的太近
72
+ // stroke: '#ffffff', // 描边颜色
73
+ // strokeWidth: 0.3, // 描边宽度
74
+ // strokeOpacity: 1.0,
75
+ // });
76
+ // that.scene.addLayer(that.labelLayer);
77
+ config?.callback?config?.callback(that):null;
78
+ that.contextMenu = new mapboxgl.Popup();
79
+ that.dialog = new mapboxgl.Popup();
80
+ })
81
+ }
82
+
83
+ addScale(){
84
+ if(this.ScaleControl){
85
+ this.map.addControl(this.ScaleControl);
86
+ }else{
87
+ this.ScaleControl = new mapboxgl.ScaleControl()
88
+ this.map.addControl(this.ScaleControl);
89
+ }
90
+ }
91
+
92
+ addNav(){
93
+ if(this.NavigationControl){
94
+ this.map.addControl(this.NavigationControl);
95
+ }else{
96
+ this.NavigationControl = new mapboxgl.NavigationControl()
97
+ this.map.addControl(this.NavigationControl);
98
+ }
99
+ }
100
+
101
+ addToorbars(config){
102
+ if(this.ToobarsControl){
103
+ this.ToobarsControl.config = config;
104
+ this.map.addControl(this.ToobarsControl);
105
+ }else{
106
+ this.ToobarsControl = new Toobars(config)
107
+ this.map.addControl(this.ToobarsControl);
108
+ }
109
+ }
110
+
111
+ /*
112
+ 按钮列表
113
+ 类型 info btn 图片
114
+ {
115
+ type:'info',
116
+ content:''//字符,
117
+ height:20px
118
+ }
119
+ {
120
+ type:'btn',
121
+ content:event//字符,
122
+ height:20px
123
+ }
124
+ {
125
+ type:'image',
126
+ content:image//字符
127
+ height:20px
128
+ }
129
+ */
130
+ addContextMenu(btnlist){
131
+ let propertys = ['type','content']
132
+ this.map.off('contextmenu')
133
+ if(btnlist instanceof Array){
134
+ this.map.on('contextmenu', (e) => {
135
+ let lngLat = transform([e.lngLat.lng,e.lngLat.lat])
136
+ //创建el
137
+ let dom = document.createElement('div');
138
+ dom.style = `min-width:120px;min-height:30px;margin:0 -10px;`;
139
+ let el = '';
140
+
141
+ for(let i in btnlist){
142
+ let _item = btnlist[i];
143
+ for(let prop in propertys){
144
+ if(!_item.hasOwnProperty(propertys[prop]) && _item?.type !='line'){
145
+ throw new Error(`Item ${i} is wrong,The ${propertys[prop]} property is not included`)
146
+ }
147
+ }
148
+ if( _item?.type =='image'){
149
+ if(!_item.hasOwnProperty('width') || !_item.hasOwnProperty('height')){
150
+ throw new Error(`Item ${i} is wrong,The image width and height is needed`)
151
+ }
152
+ }
153
+ switch(_item.type){
154
+ case 'title':
155
+ el+=(`<div style='${_item?.style ? _item?.style:''},font-size:18px;font-weight:600;width:calc(100% - 10px);height:${_item?.height?_item?.height:22}px;margin:5px;display:flex'>
156
+ <div>${_item.content}</div>
157
+ </div>`)
158
+ break;
159
+ case 'line':
160
+ el+=(`<hr style='display: block;
161
+ flex: 1 1 100%;
162
+ height: 0px;
163
+ max-height: 0px;
164
+ opacity: 0.12;
165
+ transition: inherit;
166
+ border-style: solid;
167
+ border-width: thin 0 0 0;' aria-orientation="horizontal" role="separator">`)
168
+ break;
169
+ case 'btn':
170
+ el+=(`<div style='${_item?.style ? _item?.style:''},width:calc(100% - 10px);height:${_item?.height?_item?.height:22}px;margin:5px;display:flex'>
171
+ <div style='width:16px;height:${_item?.height?_item?.height:22}px'>
172
+ <img style='display:${_item.iconPre? 'block':'none'}' src='${_item.iconPre}' />
173
+ </div>
174
+
175
+ <div style='width:calc(100% - 32PX)'>${_item.content}</div>
176
+ <div style='width:16px;height:${_item?.height?_item?.height:22}px'>
177
+ <img src='${_item.iconApp}' style='display:${_item.iconApp? 'block':'none'}' />
178
+ </div>
179
+ </div>`)
180
+ break;
181
+ case 'text':
182
+ let textContent = _item.content;
183
+ textContent = textContent.replaceAll('$lng$',e.lngLat.lng.toFixed(6)).replaceAll('$lat$',e.lngLat.lat.toFixed(6))
184
+ el+=(`<div style='${_item?.style ? _item?.style:''},width:calc(100% - 10px);margin:5px;display:flex'>
185
+ <div style='width:100%;text-wrap:wrap;'>${textContent}</div>
186
+ </div>`)
187
+ break;
188
+ case 'image':
189
+ _item.width = typeof(_item.width) == 'number' ? _item.width + 'px' :_item.width;
190
+ _item.height = typeof(_item.height) == 'number' ? _item.height + 'px' :_item.height;
191
+ el+=(`<div style='${_item?.style ? _item?.style:''},width:calc(100% - 10px);margin:5px;display:flex'>
192
+ <img src='${_item.content}' style='width:${_item.width};height:${_item.height}' />
193
+ </div>`)
194
+ break;
195
+ default:
196
+ throw new Error('type must is one of "line, text,title, image, btn"')
197
+ }
198
+ }
199
+ dom.innerHTML = el;
200
+ for(let i in btnlist) {
201
+ let item = dom.children[i]
202
+ let _item = btnlist[i];
203
+ if(typeof(item) == 'object'){
204
+ if(_item.type == 'btn'){
205
+ item?.addEventListener('mouseenter',(e)=>{
206
+ let elm = e.target;
207
+ elm.style.background='#e6f1ff'
208
+ })
209
+ item?.addEventListener('mouseleave',(e)=>{
210
+ let elm = e.target;
211
+ elm.style.background=''
212
+ })
213
+ }
214
+ if(_item.event){
215
+ item?.addEventListener(_item.event.type,(_event)=>{
216
+ _event.stopPropagation()
217
+ let _obj = Object.assign({},e)
218
+ _obj.lngLat = transform([_obj.lngLat.lng,_obj.lngLat.lat])
219
+ _item.event.fun(_event,_obj)
220
+ })
221
+ }
222
+ }
223
+ }
224
+ this.contextMenu.addTo(this.map).setLngLat({lng:lngLat[0],lat:lngLat[1]}).setDOMContent(dom)
225
+ })
226
+ }
227
+ else{
228
+ throw new Error('parmas must be array')
229
+ }
230
+ }
231
+
232
+ addDialog(btnlist,_lngLat){
233
+ let propertys = ['type','content']
234
+ if(!_lngLat){
235
+ throw new Error(`params 2 is needed, please input [lng,lat] at params 2`)
236
+ }
237
+ if(btnlist instanceof Array){
238
+ let lngLat = transform(_lngLat)
239
+ //创建el
240
+ let dom = document.createElement('div');
241
+ dom.style = `min-width:120px;min-height:30px;margin:0 -10px;`;
242
+ let el = '';
243
+
244
+ for(let i in btnlist){
245
+ let _item = btnlist[i];
246
+ for(let prop in propertys){
247
+ if(!_item.hasOwnProperty(propertys[prop]) && _item?.type !='line'){
248
+ throw new Error(`Item ${i} is wrong,The ${propertys[prop]} property is not included`)
249
+ }
250
+ }
251
+ if( _item?.type =='image'){
252
+ if(!_item.hasOwnProperty('width') || !_item.hasOwnProperty('height')){
253
+ throw new Error(`Item ${i} is wrong,The image width and height is needed`)
254
+ }
255
+ }
256
+ switch(_item.type){
257
+ case 'title':
258
+ el+=(`<div style='${_item?.style ? _item?.style:''},font-size:18px;font-weight:600;width:calc(100% - 10px);height:${_item?.height?_item?.height:22}px;margin:5px;display:flex'>
259
+ <div>${_item.content}</div>
260
+ </div>`)
261
+ break;
262
+ case 'line':
263
+ el+=(`<hr style='display: block;
264
+ flex: 1 1 100%;
265
+ height: 0px;
266
+ max-height: 0px;
267
+ opacity: 0.12;
268
+ transition: inherit;
269
+ border-style: solid;
270
+ border-width: thin 0 0 0;' aria-orientation="horizontal" role="separator">`)
271
+ break;
272
+ case 'btn':
273
+ el+=(`<div style='${_item?.style ? _item?.style:''},width:calc(100% - 10px);height:${_item?.height?_item?.height:22}px;margin:5px;display:flex'>
274
+ <div style='width:16px;height:${_item?.height?_item?.height:22}px'>
275
+ <img style='display:${_item.iconPre? 'block':'none'}' src='${_item.iconPre}' />
276
+ </div>
277
+
278
+ <div style='width:calc(100% - 32PX)'>${_item.content}</div>
279
+ <div style='width:16px;height:${_item?.height?_item?.height:22}px'>
280
+ <img src='${_item.iconApp}' style='display:${_item.iconApp? 'block':'none'}' />
281
+ </div>
282
+ </div>`)
283
+ break;
284
+ case 'text':
285
+ el+=(`<div style='${_item?.style ? _item?.style:''},width:calc(100% - 10px);margin:5px;display:flex'>
286
+ <div style='width:100%;text-wrap:wrap;'>${_item.content}</div>
287
+ </div>`)
288
+ break;
289
+ case 'image':
290
+ _item.width = typeof(_item.width) == 'number' ? _item.width + 'px' :_item.width;
291
+ _item.height = typeof(_item.height) == 'number' ? _item.height + 'px' :_item.height;
292
+ el+=(`<div style='${_item?.style ? _item?.style:''},width:calc(100% - 10px);margin:5px;display:flex'>
293
+ <img src='${_item.content}' style='width:${_item.width};height:${_item.height}' />
294
+ </div>`)
295
+ break;
296
+ default:
297
+ throw new Error('type must is one of "line, text,title, image, btn"')
298
+ }
299
+ }
300
+ dom.innerHTML = el;
301
+ for(let i in btnlist) {
302
+ let item = dom.children[i]
303
+ let _item = btnlist[i];
304
+ if(typeof(item) == 'object'){
305
+ if(_item.type == 'btn'){
306
+ item?.addEventListener('mouseenter',(e)=>{
307
+ let elm = e.target;
308
+ elm.style.background='#e6f1ff'
309
+ })
310
+ item?.addEventListener('mouseleave',(e)=>{
311
+ let elm = e.target;
312
+ elm.style.background=''
313
+ })
314
+ }
315
+ if(_item.event){
316
+ item?.addEventListener(_item.event.type,(_event)=>{
317
+ _item.event.fun(_event,e)
318
+ })
319
+ }
320
+ }
321
+ }
322
+ this.dialog.addTo(this.map).setLngLat({lng:lngLat[0],lat:lngLat[1]}).setDOMContent(dom)
323
+ }
324
+ else{
325
+ throw new Error('parmas must be array')
326
+ }
327
+ }
328
+
329
+ addPlaceLabelsLayer(){
330
+ this.map.addLayer({
331
+ 'id': 'poi-labels',
332
+ 'type': 'symbol',
333
+ 'source': 'placesLabels',
334
+ 'layout': {
335
+ 'text-field': ['get', 'label'],
336
+ //'text-anchor':'center',
337
+ 'text-size':18,
338
+ 'text-variable-anchor': ['top', 'bottom', 'left', 'right'],
339
+ //'text-radial-offset': 0.5,
340
+ 'text-justify': 'auto',
341
+ 'icon-image': ['get', 'icon'],
342
+ 'icon-anchor':'center',
343
+ 'icon-offset':['get', 'icon-offset'],
344
+ 'text-ignore-placement':true,
345
+ 'icon-ignore-placement':true
346
+ //'icon-text-fit':'width',
347
+ },
348
+ 'paint':{
349
+ 'text-color':['get', 'text-color'],
350
+ 'icon-color':'#0f3ad0',
351
+ 'text-halo-color':['get', 'text-border-color'],
352
+ 'text-halo-width':1
353
+ }
354
+ });
355
+ }
356
+
357
+ removePlaceLabelsLayer(){
358
+ this.map.remove('poi-labels')
359
+ }
360
+ //type = 0 替换
361
+ //type = 1 增加 经纬度一样替换
362
+ updateLabels(labels,style,type=0){
363
+ let label = {
364
+ name:'',
365
+ icon:'',
366
+ coords:[]
367
+ }
368
+ let icon = {
369
+ name:'',
370
+ image:'',
371
+ type:''
372
+ }
373
+ let geojsonFeatures = [];
374
+ if(labels instanceof Array){
375
+ for(let _i in labels){
376
+ let _item = labels[_i];
377
+ for(let i in label) {
378
+ if(!_item.hasOwnProperty(i)){
379
+ throw new Error(`The index ${_i} is wrong , ${i} property is not included`)
380
+ }
381
+ }
382
+ if(_item.icon){
383
+ if(typeof(_item.icon) == 'string' && !this.map.hasImage(_item.icon)){
384
+ let imgUrl = `data:image/svg+xml;utf8,%3Csvg xmlns="http://www.w3.org/2000/svg" style='fill:%230f3ad0' width="24" height="24">%3Cpath d="${mdi[_item.icon]}"/>%3C/svg>`
385
+ let image = new Image(20,20)
386
+ image.src = imgUrl;
387
+ image.onload = (e)=>{
388
+ if(!this.map.hasImage(_item.icon)){
389
+ this.map.addImage(_item.icon, e.target);
390
+ }
391
+ }
392
+
393
+ }
394
+ }else{
395
+ //this.map.
396
+ }
397
+ geojsonFeatures.push({
398
+ 'type': 'Feature',
399
+ 'properties': {
400
+ 'label':_item.name,
401
+ 'text-color':'#0f3ad0',
402
+ 'text-border-color':'#fff',
403
+ 'icon': _item.icon,
404
+ 'icon-offset':[_item.name.length * -10,10]
405
+ },
406
+ 'geometry': {
407
+ 'type': 'Point',
408
+ 'coordinates': transform(_item.coords)
409
+ }
410
+ })
411
+ }
412
+ if(type == 0){
413
+ this.placesLabels.features = geojsonFeatures;
414
+ }
415
+ else{
416
+ for(let i in geojsonFeatures){
417
+ let item = geojsonFeatures[i]
418
+ let index = this.placesLabels.features.findIndex(a=>a.coordinates == item.coords)
419
+ if(index >= 0){
420
+ this.placesLabels.features[index] = item
421
+ }else{
422
+ this.placesLabels.features.push(item)
423
+ }
424
+ }
425
+
426
+ }
427
+ const placesLabelsSource = this.map.getSource('placesLabels');
428
+
429
+ placesLabelsSource.setData(this.placesLabels)
430
+ // this.labelLayer.setData(this.placesLabels)
431
+ // console.log(this.labelLayer)
432
+ }else{
433
+ throw new Error(`The params 0 must be array`)
434
+ }
435
+ }
436
+
437
+ addMarker(marker){
438
+ this.map.addMarker(marker)
439
+ this.markers.push(marker)
440
+ }
441
+
442
+ getMarker(id){
443
+ return this.markers.find(a=>a.id == id)
444
+ }
445
+
446
+ //获取指定位置指定距离截图
447
+ getMapImageByDistance(center,distance,_target){
448
+ let target;
449
+ let bounds = getLayerMapPosition(distance,transform(center))
450
+ if(!_target) target = document.createElement('div');
451
+ else target = _target;
452
+ let pix = 1024;
453
+ target.style = `width:${pix}px;height:${pix}px;`
454
+ document.body.appendChild(target)
455
+ let scene = new Scene({
456
+ id: target,
457
+ // map: new Mapbox({
458
+ // mapInstance: map,
459
+ // }),
460
+ map: new Mapbox({
461
+ style:'http://192.168.11.93:1234/api/styles/osm',
462
+ preserveDrawingBuffer:true,
463
+ center:transform([114.7198975,23.0446]),
464
+ bounds:[bounds[0],bounds[2]],
465
+ container:target,
466
+ pitch: 0,
467
+ zoom: 0,
468
+ rotation: 0,
469
+ token: ''//'pk.eyJ1Ijoid2hpdGVidWxkaW5nIiwiYSI6ImNsc3UwaXlnZDIwbDkybG1qbXJ6YnRtcmwifQ.jtQeo0gt3UNTCWw5FEyv_w',
470
+ })
471
+ })
472
+ let map = scene.map;
473
+ map.on('load',()=>{
474
+ let base64 = map._canvas.toDataURL();
475
+ downloadFileByBase64(base64,guid())
476
+ target.remove()
477
+ })
478
+ }
479
+
480
+
481
+ //获取指定位置指定距离截图
482
+ getMapImageWithScan(_center,distance,imgList,_target,downloadType = 'file',callback=null){
483
+ if(imgList instanceof Array){
484
+ let jsZip = new JSZip();
485
+ let gif = new GIF({
486
+ repeat:0,
487
+ workers:2,
488
+ quality:64,
489
+ workerScript: getGifWorker(),
490
+ debug: true
491
+ })
492
+ if(imgList.length == 0) return;
493
+ let target;
494
+ let dataUrlList = []
495
+ let center = transform(_center)
496
+ let bounds = getLayerMapPosition(distance,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;z-index:1;position:relative;`
501
+ document.body.appendChild(target)
502
+ let scene = new Scene({
503
+ id: target,
504
+ // map: new Mapbox({
505
+ // mapInstance: map,
506
+ // }),
507
+ map: new Mapbox({
508
+ style:'http://192.168.11.93:1234/api/styles/osm',
509
+ preserveDrawingBuffer:true,
510
+ center:center,
511
+ bounds:[bounds[0],bounds[2]],
512
+ pitch: 0,
513
+ zoom: 0,
514
+ rotation: 0,
515
+ token: ''//'pk.eyJ1Ijoid2hpdGVidWxkaW5nIiwiYSI6ImNsc3UwaXlnZDIwbDkybG1qbXJ6YnRtcmwifQ.jtQeo0gt3UNTCWw5FEyv_w',
516
+ })
517
+ })
518
+ let map = scene.map;
519
+ map.on('load',()=>{
520
+ //添加图层
521
+ let _canLayer = new ScanLayer('scanimage');
522
+ let _canvas = target.getElementsByClassName('mapboxgl-canvas')[0]
523
+ let i = 0
524
+ let _interval = setInterval(() => {
525
+ if(i >= imgList.length){
526
+ clearInterval(_interval)
527
+ setTimeout(() => {
528
+ callback?callback():''
529
+ }, 500);
530
+ return;
531
+ }
532
+ let url = imgList[i]
533
+ map.loadImage(url,(err,image)=>{
534
+ console.log(i)
535
+ let _i = i;
536
+ if(err){
537
+ throw new Error(err);
538
+ }
539
+ _canLayer.drawList({
540
+ id:'SD01',
541
+ image:image,
542
+ coords:getLayerMapPosition(distance,_center)
543
+ })
544
+ _canLayer.renderBack=()=>{
545
+ if(dataUrlList.findIndex(a=>a.i == _i) < 0){
546
+ dataUrlList.push({
547
+ i:_i,
548
+ base64:_canvas.toDataURL()
549
+ })
550
+ i+=1
551
+ if(downloadType == 'gif'){
552
+ gif.addFrame(_canvas,{ delay: 1000 ,copy:true})
553
+ }
554
+ }
555
+
556
+ if(_i == imgList.length -1){
557
+ _canLayer.renderBack = null
558
+ if(downloadType == 'file'){
559
+ dataUrlList.forEach(a=>downloadFileByBase64(a.base64,a.i + '.png'))
560
+ }
561
+ if(downloadType == 'zip'){
562
+
563
+ dataUrlList.forEach(a=>jsZip.file(a.i + '.png',a.base64.replace(/^data:image\/(png|jpg);base64,/, ""),{base64:true}))
564
+ jsZip.generateAsync({ type: "blob" }).then(blob => {
565
+ let url = window.URL.createObjectURL(blob);
566
+ downloadFile(url, "pnglist.zip");
567
+ });
568
+ }
569
+ if(downloadType == 'obj'){
570
+ return dataUrlList
571
+ }
572
+ if(downloadType == 'gif'){
573
+ // 将每一帧渲染成一张完成的gif
574
+ gif.render();
575
+ gif.on('finished', function(blob) {
576
+ let url = URL.createObjectURL(blob);
577
+ downloadFile(url, "pnglist.gif");
578
+ });
579
+ }
580
+
581
+ }
582
+ }
583
+ })
584
+
585
+ }, 200);
586
+ setTimeout(() => {
587
+ map.addLayer(_canLayer)
588
+ }, 201);
589
+ })
590
+ target.remove()
591
+ }else
592
+ throw new Error('The params 2 image list must be array ')
593
+ }
594
+
595
+
596
+
597
+ }
package/main.js ADDED
@@ -0,0 +1,16 @@
1
+ import { EasyMap } from "./index";
2
+ import * as EmComponents from './src/components/index'
3
+ import * as EmUtils from './src/utils/util'
4
+ window.EasyMap = EasyMap
5
+ window.EmComponents = EmComponents
6
+ window.EmUtils = EmUtils
7
+ // const modulesFiles = import.meta.glob('./src/components/*.js')
8
+ // console.log(modulesFiles)
9
+ // Object.entries(modulesFiles).forEach(a=>{
10
+ // console.log(a)
11
+ // })
12
+ export {
13
+ EasyMap,
14
+ EmComponents,
15
+ EmUtils
16
+ }
Binary file
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@ohuoy/easymap",
3
+ "version": "1.0.0",
4
+ "description": "self map easy use",
5
+ "main": "main.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "dev": "webpack"
9
+ },
10
+ "author": "weichong song",
11
+ "license": "ISC",
12
+ "dependencies": {
13
+ "@antv/l7": "^2.21.10",
14
+ "@mdi/js": "^7.4.47",
15
+ "@turf/turf": "^6.5.0",
16
+ "gcoord": "^1.0.6",
17
+ "gif.js": "^0.2.0",
18
+ "jszip": "^3.10.1",
19
+ "mapbox-gl": "^3.4.0"
20
+ },
21
+ "devDependencies": {
22
+ "@babel/core": "^7.24.7",
23
+ "@babel/preset-env": "^7.24.7",
24
+ "babel-loader": "^9.1.3",
25
+ "css-loader": "^7.1.2",
26
+ "style-loader": "^4.0.0",
27
+ "webpack": "^5.91.0",
28
+ "webpack-cli": "^5.1.4"
29
+ }
30
+ }
@@ -0,0 +1,30 @@
1
+ import mapboxgl from 'mapbox-gl';
2
+ import { transform } from '../utils/util';
3
+ export default class EasyMapMarker{
4
+ marker;
5
+ config = {
6
+ id:'',
7
+ position:[117.2,22.4],
8
+ popup:null,
9
+ map:{},
10
+ event:null
11
+ }
12
+ constructor(_config){
13
+ if(_config){
14
+ for(let i in this.config){
15
+ if(!_config.hasOwnProperty(i) && this.config[i]!=null){
16
+ throw new Error(i + ' property is needed')
17
+ }
18
+ }
19
+ this.config =Object.assign({}, this.config, _config);
20
+ this.marker = new mapboxgl.Marker()
21
+ .setLngLat(transform(this.config.position))
22
+ .addTo(this.config.map);
23
+ if(this.config.popup){
24
+ this.marker.setPopup(this.config.popup)
25
+ }
26
+ }else{
27
+ throw new Error('no config')
28
+ }
29
+ }
30
+ }