@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.
@@ -9,7 +9,11 @@
9
9
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
10
10
  <meta charset="utf-8" name="referrer" content="strict-origin-when-cross-origin" />
11
11
  <title>easymap</title>
12
- <style>
12
+ <style>
13
+ .messageClass23333{
14
+ left: 250px;
15
+ position: absolute;
16
+ }
13
17
  .buttonList{
14
18
  position: absolute;
15
19
  top: 0;
@@ -587,7 +591,7 @@ function resetToolBar(){
587
591
  function init(){
588
592
  let target = document.getElementById('test')
589
593
  //类比高德 AMap.Map
590
- emap = new EasyMap(target,'http://dbcenter.gyquantum.com/easymap/styles/light',{
594
+ emap = new EasyMap(target,'http://dbcenter.gyquantum.com/easymap/styles/sworld',{
591
595
  //config
592
596
  // {
593
597
  // center:[108.7198975,35.0446],
@@ -606,8 +610,17 @@ function resetToolBar(){
606
610
  emap.addScale("bottom-left")
607
611
  emap.addNav("bottom-left")
608
612
  emap.addToorbars({
613
+ line:{
614
+ show:true,
615
+ btnClass:'',
616
+ messageClass:'messageClass23333',
617
+
618
+ },
619
+ position:{
620
+ show:false
621
+ },
609
622
  location:{
610
- show:true, //是否显示
623
+ show:false, //是否显示
611
624
  center:[108.7198975,35.0446] //定位工具中心点为止
612
625
  }
613
626
  },"bottom-left");
@@ -724,6 +737,22 @@ function resetToolBar(){
724
737
  }
725
738
 
726
739
 
740
+ let adirectionLine = true
741
+ function addRShow(){
742
+ let point = [117.701466,32.511041];distance = 6;r=120
743
+ if(adirectionLine){
744
+ emap.addDirectionLine(point,r,distance,'#37a2eb',8) // 可添加color width,不填有默认值 '#37a2eb',8),
745
+ }else{
746
+ emap.removeDirectionLine()
747
+ }
748
+ adirectionLine=!adirectionLine;
749
+ emap.jumpTo({
750
+ center:point,
751
+ zoom: 12
752
+ });
753
+ }
754
+
755
+
727
756
  function getBoundsImage2(center,distance){
728
757
 
729
758
  console.log(mapOutScreen)
@@ -812,6 +841,7 @@ function resetToolBar(){
812
841
  <button id="setTile" onclick="setMapTile()">设置图层【点击自动切换】【当前标准图层】</button>
813
842
  <input id="lnglat" />
814
843
  <button onclick="markerTo()">标记位置[经纬度用,隔开]</button>
844
+ <button onclick="addRShow()">添加角度显示,再次点击取消显示</button>
815
845
  </div>
816
846
  <div id="test">
817
847
 
package/index.js CHANGED
@@ -6,7 +6,7 @@ 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,downloadFileBlobByBase64,guid,downloadFile,downloadFileByBlob, sleep} from './src/utils/util.js';
9
+ import {getLayerMapPosition, transform,downloadFileByBase64,downloadFileBlobByBase64,guid,downloadFile,destination,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'
@@ -14,7 +14,7 @@ import { ScanLayer } from './src/components/index.js';
14
14
  import JSZip from 'jszip';
15
15
  import gif from './src/components/gif/gif.js'
16
16
  import * as EmComponents from './src/components/index'
17
-
17
+ import { observe } from './src/utils/mapWatch.js';
18
18
  import { getGifWorker } from './src/components/gif/gif.worker.js'
19
19
 
20
20
  //导出组件
@@ -50,7 +50,7 @@ export class EasyMap {
50
50
  alert('Your browser does not support Mapbox GL');
51
51
  }
52
52
  config.center = config?.center? transform(config.center): transform([108.7198975,35.0446]);
53
- this.config = Object.assign(this.config,config)
53
+ this.config = Object.assign(this.config,config)
54
54
  let scene = new Scene({
55
55
  id: target,
56
56
  logoVisible:false,
@@ -64,17 +64,25 @@ export class EasyMap {
64
64
  pitch: config?.pitch?config.pitch:0,
65
65
  projection:config.projection?config.projection:'mercator',
66
66
  zoom: config?.zoom?config.zoom:13,
67
+ maxZoom:config?.maxZoom?config.maxZoom:17.4,
68
+ minZoom:config.minZoom?config.minZoom:1,
67
69
  fadeDuration:300,
68
70
  rotation: config?.rotation?config.rotation:0,
69
71
  token: ''//'pk.eyJ1Ijoid2hpdGVidWxkaW5nIiwiYSI6ImNsc3UwaXlnZDIwbDkybG1qbXJ6YnRtcmwifQ.jtQeo0gt3UNTCWw5FEyv_w',
70
72
  })
71
73
  })
72
- let map = scene.map;
74
+ let map = scene.map;
75
+ // let _currentTheme = map.style.stylesheet.theme;
73
76
  this.scene = scene;
74
- this.map = map;
77
+ this.map = map;
78
+
79
+ // this.map.currentTheme = new Proxy(_currentTheme,)
75
80
  this.target = map.target;
76
81
  let that = this;
82
+ this.map.theme = observe({value:""})
77
83
  this.map.on('load',()=>{
84
+ this.map.theme.value = this.map.style.stylesheet.theme
85
+ // console.log(this.map)
78
86
  that.map.addSource('placesLabels', {
79
87
  'type': 'geojson',
80
88
  'data': that.placesLabels
@@ -217,7 +225,7 @@ export class EasyMap {
217
225
  case 'btn':
218
226
  el+=(`<div class='context-map-btn' style='${_item?.style ? _item?.style:''},width:calc(100% - 10px);height:${_item?.height?_item?.height:22}px;margin:5px;display:flex'>
219
227
  <div style='width:14px;height:${_item?.height?_item?.height:22}px;margin:0 8px'>
220
- <img style='display:${_item.iconPre? 'block':'none'};height:16px' src='${_item.iconPre}' />
228
+ <img style='display:${_item.iconPre? 'block':'none'};height:16px' src="${_item.iconPre.replace('"',"'")}" />
221
229
  </div>
222
230
 
223
231
  <div style='width:calc(100% - 32PX)'>${_item.content}</div>
@@ -737,7 +745,187 @@ export class EasyMap {
737
745
 
738
746
  removeLayer(layerId)
739
747
  {
740
- if (this.map.getLayer(layerId)) this.map.removeLayer(layerId)
748
+ if (this.map.getLayer(layerId)) {
749
+ this.map.removeLayer(layerId)
750
+ }
751
+ }
752
+
753
+ removeDirectionLine(){
754
+ let source = this.map.getSource('direction-source');
755
+ if(source){
756
+ source.setData({
757
+ type: 'Feature',
758
+ geometry: {
759
+ type: 'LineString',
760
+ coordinates: [
761
+ ]
762
+ },
763
+ properties: {}})
764
+ }
765
+ }
766
+
767
+ addDirectionLine(center,r = 0,distance=6,color='#37a2eb',width=8){
768
+ center = transform(center);
769
+ let point = destination(center,r,distance).geometry.coordinates
770
+ const lineData = {
771
+ type: 'Feature',
772
+ geometry: {
773
+ type: 'LineString',
774
+ coordinates: [
775
+ center,
776
+ point
777
+ ]
778
+ },
779
+ properties: {}
780
+ };
781
+ let source = this.map.getSource('direction-source');
782
+ if(!source){
783
+ this.map.addSource('direction-source', {
784
+ type: 'geojson',
785
+ data:lineData
786
+ });
787
+ source = this.map.getSource('direction-source');
788
+ }else{
789
+ source.setData(lineData)
790
+ }
791
+ let layer = this.map.getLayer('direction-layers-custom');
792
+ if(!layer){
793
+ this.map.addLayer({
794
+ id: 'direction-layers-custom',
795
+ type: 'line',
796
+ source: 'direction-source',
797
+ paint: {
798
+ 'line-width': width,
799
+ 'line-color': color
800
+ }
801
+ })
802
+ }else{
803
+ this.map.setPaintProperty('direction-layers-custom','line-width',width)
804
+ this.map.setPaintProperty('direction-layers-custom','line-color',color)
805
+ }
806
+ let layerSym = this.map.getLayer('direction-sym-layers-custom');
807
+ if(!layerSym){
808
+ this.map.addLayer({
809
+ id: 'direction-sym-layers-custom',
810
+ type: 'symbol',
811
+ source: 'direction-source',
812
+ layout: {
813
+ 'symbol-placement': 'line',
814
+ 'symbol-spacing': 50, // 图标间隔,默认为250
815
+ 'icon-image': 'arrow', //箭头图标
816
+ 'icon-size': 0.1 * width/8
817
+ }
818
+ })
819
+ }else{
820
+ this.map.setLayoutProperty('direction-sym-layers-custom','icon-size',0.1 * width/8)
821
+ }
822
+
823
+ }
824
+
825
+ removeHeatmap(){
826
+ let source = this.map.getSource('heatmap-source');
827
+ if(source){
828
+ source.setData({
829
+ 'type': 'FeatureCollection',
830
+ 'features': []})
831
+ }
832
+ }
833
+
834
+ addHeatmap(dataList){
835
+ let geojson = {
836
+ 'type': 'FeatureCollection',
837
+ 'features': dataList.map(a=>{
838
+ return {
839
+ 'type': 'Feature',
840
+ 'geometry': {
841
+ 'type': 'Point',
842
+ 'coordinates': transform([a.lng, a.lat])
843
+ },
844
+ "properties": {
845
+ "count": a.count
846
+ }
847
+ }
848
+ }),
849
+ }
850
+
851
+ // const layer = new ant7.HeatmapLayer({})
852
+ // .source(geojson)
853
+ // .size('count', [0, 1])
854
+ // .shape('heatmap3D')
855
+ // // weight映射通道
856
+ // .style({
857
+ // intensity: 5,
858
+ // radius: 10,
859
+ // rampColors: {
860
+ // colors: ['#2E8AE6', '#69D1AB', '#DAF291', '#FFD591', '#FF7A45', '#CF1D49'],
861
+ // positions: [0, 0.2, 0.4, 0.6, 0.8, 1.0],
862
+ // },
863
+ // });
864
+ // emap.scene.addLayer(layer);
865
+
866
+ let source = this.map.getSource('heatmap-source');
867
+ if(!source){
868
+ this.map.addSource('heatmap-source', {
869
+ type: 'geojson',
870
+ data:geojson
871
+ });
872
+ source = this.map.getSource('heatmap-source');
873
+ }else{
874
+ source.setData(geojson)
875
+ }
876
+ let layer = this.map.getLayer('heatmap-layers-custom');
877
+ if(!layer){
878
+ this.map.addLayer({
879
+ id: 'heatmap-layers-custom',
880
+ type: 'heatmap',
881
+ source: 'heatmap-source',
882
+ paint: {
883
+ // Increase the heatmap weight based on frequency and property magnitude
884
+ 'heatmap-weight': [
885
+ 'interpolate',
886
+ ['linear'],
887
+ ['get', 'count'],
888
+ 0,
889
+ 0,
890
+ 16,
891
+ 1
892
+ ],
893
+ // Increase the heatmap color weight weight by zoom level
894
+ // heatmap-intensity is a multiplier on top of heatmap-weight
895
+ 'heatmap-intensity': [
896
+ 'interpolate',
897
+ ['linear'],
898
+ ['zoom'],
899
+ 0,
900
+ 1,
901
+ 1,
902
+ 3
903
+ ],
904
+ // Color ramp for heatmap. Domain is 0 (low) to 1 (high).
905
+ // Begin color ramp at 0-stop with a 0-transparancy color
906
+ // to create a blur-like effect.
907
+ 'heatmap-color': [
908
+ "interpolate",
909
+ ["linear"],
910
+ ["heatmap-density"],
911
+ 0,
912
+ "rgba(0, 0, 255, 0)",
913
+ 0.1,
914
+ "royalblue",
915
+ 0.3,
916
+ "cyan",
917
+ 0.5,
918
+ "lime",
919
+ 0.7,
920
+ "yellow",
921
+ 1,
922
+ "red"
923
+ ],
924
+ // Adjust the heatmap radius by zoom level
925
+ 'heatmap-radius': 30
926
+ }
927
+ });
928
+ }
741
929
  }
742
930
 
743
931
 
@@ -705,6 +705,7 @@ class Vector2 {
705
705
 
706
706
  }
707
707
 
708
+
708
709
  setComponent( index, value ) {
709
710
 
710
711
  switch ( index ) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ohuoy/easymap",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
4
4
  "description": "self map easy use",
5
5
  "main": "main.js",
6
6
  "scripts": {
@@ -27,7 +27,7 @@
27
27
  "jszip": "^3.10.1",
28
28
  "mapbox-gl": "file:lib/mapbox-gl",
29
29
  "regl": "1.6.1",
30
- "three": "^0.170.0",
30
+ "three": "^0.175.0",
31
31
  "threebox-plugin": "^2.2.7",
32
32
  "viewport-mercator-project": "^6.2.1"
33
33
  },
@@ -32,9 +32,13 @@ export default class EasyMapMarker{
32
32
  this.markerList.push(marker)
33
33
  pointList.push(position)
34
34
  }
35
- _config[0].map.fitBounds(getBBox(pointList), {
36
- padding: {top: 35, bottom:25, left: 15, right: 15}
37
- });
35
+ if(pointList.length >=2){
36
+ _config[0].map.fitBounds(getBBox(pointList), {
37
+ padding: {top: 35, bottom:25, left: 15, right: 15}
38
+ });
39
+ }else if(pointList.length == 1){
40
+ _config[0].map.jumpTo({center:pointList[0]})
41
+ }
38
42
  }else{
39
43
  for(let i in this.config){
40
44
  if(!_config.hasOwnProperty(i) && this.config[i]!=null){
@@ -6,7 +6,7 @@ export default class TilesBar {
6
6
  }
7
7
  openBtn=['standard','satellite','tiandi','gaode','arcgis']
8
8
  constructor(openBtn){
9
- this.openBtn = ['standard','satellite','tiandi']
9
+ this.openBtn = openBtn && openBtn.length > 0 ? openBtn: ['standard','satellite','tiandi']
10
10
  }
11
11
 
12
12
  getBtnList(){
@@ -106,72 +106,147 @@ export default class TilesBar {
106
106
 
107
107
  addEvent(btn,key){
108
108
  btn.addEventListener('click',()=>{
109
- let currentFillLayerIndex = this._map.style.stylesheet.layers.findIndex(a=>a.type!='fill' && a.type!='background')
109
+ let currentFillLayerIndex = this._map.style.stylesheet.layers.findIndex(a=>a.type!='fill' && a.type!='background' && a.type != 'line')
110
110
  let beforeId = this._map.style.stylesheet.layers[currentFillLayerIndex].id
111
111
  if(key == 'standard'){
112
112
  if (this._map.getLayer('yingxiang')) this._map.removeLayer('yingxiang');
113
113
  if (this._map.getLayer('tiandi')) this._map.removeLayer('tiandi');
114
114
  if (this._map.getLayer('gode')) this._map.removeLayer('gode');
115
- if (this._map.getLayer('arcgis')) this._map.removeLayer('arcgis');
116
- if (this._map.getLayer('zhuji')) this._map.removeLayer('zhuji');
115
+ if (this._map.getLayer('arcgis')) this._map.removeLayer('arcgis');
116
+ if (this._map.getLayer('mask')) this._map.removeLayer('mask');
117
+ if (!this._map.getLayer('zhuji')){
118
+ this._map.addLayer({
119
+ "id": "zhuji",
120
+ "source": "zhuji",
121
+ "type": "raster"
122
+ },beforeId)
123
+ };
124
+ // if (this._map.getLayer('zhuji')) this._map.removeLayer('zhuji');
125
+ // if (!this._map.getLayer('standard')){
126
+ // this._map.addLayer({
127
+ // "id": "standard",
128
+ // "source": "standard",
129
+ // "type": "raster"
130
+ // },beforeId)
131
+ // this._map.theme.value = "dark"
132
+ // };
133
+ this._map.theme.value = "dark"
117
134
  }
118
- if(key == 'satellite'){
135
+ if(key == 'satellite'){
136
+ //移除基本图层
137
+
138
+ // if (this._map.getLayer('standard')) this._map.removeLayer('standard');
119
139
  if (this._map.getLayer('tiandi')) this._map.removeLayer('tiandi');
120
- if (this._map.getLayer('zhuji')) this._map.removeLayer('zhuji');
140
+ // if (this._map.getLayer('zhuji')) this._map.removeLayer('zhuji');
121
141
  if (this._map.getLayer('gode')) this._map.removeLayer('gode');
122
- if (this._map.getLayer('arcgis')) this._map.removeLayer('arcgis');
142
+ if (this._map.getLayer('arcgis')) this._map.removeLayer('arcgis');
143
+ if (!this._map.getLayer('mask')){
144
+ this._map.addLayer({
145
+ "id": "mask",
146
+ "type": "background",
147
+ "layout": {},
148
+ "paint": {
149
+ "background-emissive-strength": 1,
150
+ "background-color": "#3269c8"
151
+ }
152
+ },beforeId)
153
+ };
154
+ if (!this._map.getLayer('zhuji')){
155
+ this._map.addLayer({
156
+ "id": "zhuji",
157
+ "source": "zhuji",
158
+ "type": "raster"
159
+ },beforeId)
160
+ };
123
161
  if (!this._map.getLayer('yingxiang')){
124
162
  this._map.addLayer({
125
163
  "id": "yingxiang",
126
164
  "source": "yingxiang",
127
165
  "type": "raster"
128
- })
166
+ },beforeId)
167
+ this._map.theme.value = "dark"
129
168
  };
130
169
  }
131
170
  if(key == 'tiandi'){
132
171
  if (this._map.getLayer('yingxiang')) this._map.removeLayer('yingxiang');
133
172
  if (this._map.getLayer('gode')) this._map.removeLayer('gode');
134
173
  if (this._map.getLayer('arcgis')) this._map.removeLayer('arcgis');
174
+ if (!this._map.getLayer('mask')){
175
+ this._map.addLayer({
176
+ "id": "mask",
177
+ "type": "background",
178
+ "layout": {},
179
+ "paint": {
180
+ "background-emissive-strength": 1,
181
+ "background-color": "#3269c8"
182
+ }
183
+ },beforeId)
184
+ };
135
185
  if (!this._map.getLayer('tiandi')){
136
186
  this._map.addLayer({
137
187
  "id": "tiandi",
138
188
  "source": "tianditu",
139
189
  "type": "raster"
140
- })
190
+ },beforeId)
141
191
  };
142
192
  if (!this._map.getLayer('zhuji')){
143
193
  this._map.addLayer({
144
194
  "id": "zhuji",
145
195
  "source": "zhuji",
146
196
  "type": "raster"
147
- })
197
+ },beforeId)
148
198
  };
199
+ this._map.theme.value = "light"
149
200
  }
150
201
  if(key == 'gaode'){
151
202
  if (this._map.getLayer('yingxiang')) this._map.removeLayer('yingxiang');
152
203
  if (this._map.getLayer('tiandi')) this._map.removeLayer('tiandi');
153
204
  if (this._map.getLayer('zhuji')) this._map.removeLayer('zhuji');
154
205
  if (this._map.getLayer('arcgis')) this._map.removeLayer('arcgis');
206
+ if (!this._map.getLayer('mask')){
207
+ this._map.addLayer({
208
+ "id": "mask",
209
+ "type": "background",
210
+ "layout": {},
211
+ "paint": {
212
+ "background-emissive-strength": 1,
213
+ "background-color": "#3269c8"
214
+ }
215
+ },beforeId)
216
+ };
155
217
  if (!this._map.getLayer('gaode')){
156
218
  this._map.addLayer({
157
219
  "id": "gaode",
158
220
  "source": "gaode",
159
221
  "type": "raster"
160
- })
222
+ },beforeId)
161
223
  };
224
+ this._map.theme.value = "light"
162
225
  }
163
226
  if(key == 'arcgis'){
164
227
  if (this._map.getLayer('yingxiang')) this._map.removeLayer('yingxiang');
165
228
  if (this._map.getLayer('tiandi')) this._map.removeLayer('tiandi');
166
229
  if (this._map.getLayer('zhuji')) this._map.removeLayer('zhuji');
167
230
  if (this._map.getLayer('gode')) this._map.removeLayer('gode');
231
+ if (!this._map.getLayer('mask')){
232
+ this._map.addLayer({
233
+ "id": "mask",
234
+ "type": "background",
235
+ "layout": {},
236
+ "paint": {
237
+ "background-emissive-strength": 1,
238
+ "background-color": "#3269c8"
239
+ }
240
+ },beforeId)
241
+ };
168
242
  if (!this._map.getLayer('arcgis')){
169
243
  this._map.addLayer({
170
244
  "id": "arcgis",
171
245
  "source": "arcgis",
172
246
  "type": "raster"
173
- })
247
+ },beforeId)
174
248
  };
249
+ this._map.theme.value = "dark"
175
250
  }
176
251
  })
177
252
  }