@gis_victory/gismap 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.
Files changed (48) hide show
  1. package/.vscode/extensions.json +3 -0
  2. package/README.md +5 -0
  3. package/dist/gismap.css +1 -0
  4. package/dist/gismap.es.js +34794 -0
  5. package/dist/gismap.umd.js +2767 -0
  6. package/dist/index.d.ts +1 -0
  7. package/dist/vite.svg +1 -0
  8. package/index.html +13 -0
  9. package/package.json +32 -0
  10. package/public/vite.svg +1 -0
  11. package/src/App.vue +24 -0
  12. package/src/components/MapLayer/MCheckbox.vue +38 -0
  13. package/src/components/MapLayer/MapLayerApi.ts +97 -0
  14. package/src/components/MapLayer/index.vue +34 -0
  15. package/src/components/MapLegend/index.vue +20 -0
  16. package/src/components/MapTools/index.vue +20 -0
  17. package/src/components/MapView/index.vue +70 -0
  18. package/src/components/Widgets/MapCompass/index.vue +89 -0
  19. package/src/gismap.css +21 -0
  20. package/src/index.css +11 -0
  21. package/src/index.ts +7 -0
  22. package/src/main.ts +6 -0
  23. package/src/manager/EraserManager.ts +50 -0
  24. package/src/manager/IconManager.ts +40 -0
  25. package/src/manager/InitManager.ts +35 -0
  26. package/src/manager/LayerManager.ts +119 -0
  27. package/src/manager/MarkerManager.ts +65 -0
  28. package/src/manager/MaskManager.ts +37 -0
  29. package/src/manager/PopupManager.ts +46 -0
  30. package/src/manager/RadarManager.ts +156 -0
  31. package/src/manager/TDTManager.ts +149 -0
  32. package/src/manager/TemplateManager.ts +13 -0
  33. package/src/manager/TerrainManager.ts +61 -0
  34. package/src/manager/VectorManager.ts +51 -0
  35. package/src/manager/layer/Tile3DLayer.ts +114 -0
  36. package/src/style/gismap-layer.css +3 -0
  37. package/src/style/gismap-legend.css +3 -0
  38. package/src/style/gismap-maptools.css +3 -0
  39. package/src/style/mapbox-gl.css +1 -0
  40. package/src/types/GSMap.ts +25 -0
  41. package/src/utils/index.ts +22 -0
  42. package/src/utils/pubsub.ts +54 -0
  43. package/src/views/MapLayout.vue +28 -0
  44. package/src/vite-env.d.ts +1 -0
  45. package/tsconfig.app.json +15 -0
  46. package/tsconfig.json +7 -0
  47. package/tsconfig.node.json +25 -0
  48. package/vite.config.ts +35 -0
@@ -0,0 +1,119 @@
1
+ export default class LayerManager {
2
+ private map: mapboxgl.Map;
3
+ private checkedParentLayers: Map<string, any> = new Map();
4
+ private checkedLayers: Map<string, any> = new Map();
5
+ public queryLayerIds: string[] = [];
6
+ private symbolLayerIds: string[] = [];
7
+ private pointLayerIds: string[] = [];
8
+ private lineLayerIds: string[] = [];
9
+ private polygonLayerIds: string[] = [];
10
+ constructor(map: mapboxgl.Map) {
11
+ this.map = map;
12
+ }
13
+
14
+ private addSource(sourceConfig: any) {
15
+ if (!this.map.getSource(sourceConfig.id)) {
16
+ const source = Object.assign(
17
+ {
18
+ type: "geojson",
19
+ tiles: [sourceConfig.url],
20
+ },
21
+ sourceConfig
22
+ );
23
+ this.map.addSource(sourceConfig.id, source);
24
+ }
25
+ return this;
26
+ }
27
+
28
+ addLayer(layerConfig: any) {
29
+ this.addSource(layerConfig.source);
30
+ const layer = Object.assign(
31
+ {
32
+ id: layerConfig.id,
33
+ source: layerConfig.id,
34
+ },
35
+ layerConfig.layer
36
+ );
37
+ this.map.addLayer(layer);
38
+ this.checkedLayers.set(layer.id, {
39
+ layer,
40
+ extension: layerConfig?.extension,
41
+ });
42
+ if (layerConfig.isQuery) {
43
+ this.queryLayerIds.push(layer.id);
44
+ }
45
+ switch (layer.type) {
46
+ case "symbol":
47
+ this.symbolLayerIds.push(layer.id);
48
+ break;
49
+ case "point":
50
+ this.pointLayerIds.push(layer.id);
51
+ break;
52
+ case "line":
53
+ this.lineLayerIds.push(layer.id);
54
+ break;
55
+ case "fill":
56
+ case "fill-extrusion":
57
+ this.polygonLayerIds.push(layer.id);
58
+ break;
59
+ default:
60
+ break;
61
+ }
62
+ return this;
63
+ }
64
+
65
+ addGroupLayer(layer: any) {
66
+ const { id, layers } = layer;
67
+ if (layers) {
68
+ layers.forEach((_layer: any) => {
69
+ _layer.layer = Object.assign(
70
+ {
71
+ id: id,
72
+ source: id,
73
+ },
74
+ _layer.layer
75
+ );
76
+ _layer.source = Object.assign(
77
+ {
78
+ id: id,
79
+ },
80
+ _layer.source
81
+ );
82
+ this.addLayer(_layer);
83
+ });
84
+ this.checkedParentLayers.set(id, layer);
85
+ }
86
+ }
87
+
88
+ removeLayer(layer: any) {
89
+ if (this.map.getLayer(layer.layer.id)) {
90
+ this.map.removeLayer(layer.layer.id);
91
+ }
92
+ // if (this.map.getSource(layer.source.id)) {
93
+ // this.map.removeSource(layer.source.id);
94
+ // }
95
+ this.checkedLayers.delete(layer.id);
96
+
97
+ if (layer.isQuery) {
98
+ this.queryLayerIds = this.queryLayerIds.filter(
99
+ (item) => item !== layer.layer.id
100
+ );
101
+ }
102
+ }
103
+
104
+ removeGroupLayer(layer: any) {
105
+ const { id, layers } = layer;
106
+ if (layers) {
107
+ layers.forEach((_layer: any) => {
108
+ _layer.layer = Object.assign({ id: id }, _layer.layer);
109
+ _layer.source = Object.assign({ id: id }, _layer.source);
110
+ this.removeLayer(_layer);
111
+ });
112
+ }
113
+ this.checkedParentLayers.delete(id);
114
+ }
115
+
116
+ getLayer(id: string) {
117
+ return id ? this.checkedLayers.get(id) : null;
118
+ }
119
+ }
@@ -0,0 +1,65 @@
1
+ import mapboxgl from "@gis_victory/mapbox-gl";
2
+ import type GSMap from "../types/GSMap";
3
+
4
+ export default class MarkerManager {
5
+ private map: GSMap;
6
+ private marker?: mapboxgl.Marker;
7
+ constructor(map: GSMap) {
8
+ this.map = map;
9
+ }
10
+
11
+ show({
12
+ position,
13
+ html,
14
+ markerIcon = "marker",
15
+ offset = [0, -30],
16
+ iconName,
17
+ flyTo = false,
18
+ }: {
19
+ position: any;
20
+ html?: string;
21
+ markerIcon?: string;
22
+ offset?: number[];
23
+ iconName?: string;
24
+ flyTo?: boolean;
25
+ }) {
26
+ if (this.marker) {
27
+ this.marker.remove();
28
+ }
29
+ debugger;
30
+ const markerContainer = document.createElement("div");
31
+ markerContainer.className = "marker-container";
32
+ const markerIconElement = document.createElement("div");
33
+ markerIconElement.className = `${markerIcon}`;
34
+ if (iconName) {
35
+ markerIconElement.innerHTML = `<img src='${iconName}' class="marker-icon" />`;
36
+ }
37
+ markerContainer.appendChild(markerIconElement);
38
+ this.marker = new mapboxgl.Marker({
39
+ element: markerContainer,
40
+ anchor: "bottom",
41
+ })
42
+ .setLngLat(position)
43
+ .addTo(this.map);
44
+ if (html) {
45
+ this.marker.setPopup(
46
+ new mapboxgl.Popup({
47
+ closeOnClick: false,
48
+ closeOnMove: false,
49
+ className: "map-popup",
50
+ anchor: "bottom",
51
+ offset: offset as [number, number],
52
+ }).setHTML(html)
53
+ ).togglePopup();
54
+ }
55
+ if (flyTo) {
56
+ this.map.flyTo({
57
+ center: position,
58
+ });
59
+ }
60
+ }
61
+
62
+ close() {
63
+ this.marker?.remove();
64
+ }
65
+ }
@@ -0,0 +1,37 @@
1
+ import type GSMap from "../types/GSMap";
2
+
3
+ export default class MaskManager {
4
+ private map: GSMap;
5
+ private layerId: string = "mask_layer";
6
+ constructor(map: GSMap) {
7
+ this.map = map;
8
+ }
9
+ add(url: string, style: any = {}, beforeId?: string) {
10
+ if (!this.map.getSource(this.layerId)) {
11
+ this.map.addSource(this.layerId, {
12
+ type: "geojson",
13
+ data: url,
14
+ });
15
+ }
16
+ const option = Object.assign(
17
+ {
18
+ id: this.layerId,
19
+ source: this.layerId,
20
+ type: "fill",
21
+ paint: {
22
+ "fill-color": "#000000",
23
+ "fill-opacity": 0.5,
24
+ },
25
+ },
26
+ style
27
+ );
28
+ if (!this.map.getLayer(this.layerId)) {
29
+ this.map.addLayer(option, beforeId);
30
+ }
31
+ }
32
+
33
+ remove() {
34
+ this.map.removeLayer(this.layerId);
35
+ this.map.removeSource(this.layerId);
36
+ }
37
+ }
@@ -0,0 +1,46 @@
1
+ import mapboxgl from "@gis_victory/mapbox-gl";
2
+ import type GSMap from "../types/GSMap";
3
+
4
+ export default class PopupManager {
5
+ private map: GSMap;
6
+ private popup: mapboxgl.Popup;
7
+ constructor(map: GSMap) {
8
+ this.map = map;
9
+ this.popup = new mapboxgl.Popup({
10
+ closeOnClick: false,
11
+ closeOnMove: false,
12
+ className: "map-popup",
13
+ anchor: "bottom",
14
+ });
15
+ }
16
+
17
+ show({
18
+ position,
19
+ html,
20
+ offset = [0, -10],
21
+ flyTo = false,
22
+ }: {
23
+ position: any;
24
+ html: string;
25
+ offset: any;
26
+ flyTo: boolean;
27
+ }) {
28
+ if (html) {
29
+ this.popup.setHTML(html);
30
+ }
31
+ if (offset) {
32
+ this.popup.setOffset(offset);
33
+ }
34
+ this.popup.setLngLat(position);
35
+ this.popup.addTo(this.map);
36
+ if (flyTo) {
37
+ this.map.flyTo({
38
+ center: position,
39
+ });
40
+ }
41
+ }
42
+
43
+ close() {
44
+ this.popup.remove();
45
+ }
46
+ }
@@ -0,0 +1,156 @@
1
+ import { GeoJSONSource } from "@gis_victory/mapbox-gl";
2
+ import GSMap from "../types/GSMap";
3
+ import * as turf from "@turf/turf";
4
+
5
+ export default class RadarManager {
6
+ private map?: GSMap;
7
+ private id: string = `radar-${Math.random()}`;
8
+ private radius: number = 100; // 半径(米)
9
+ private period: number = 3000; // 扫描一圈时间(毫秒)
10
+ private backgroundColor: string = "rgba(255,0,0,0.1)"; // 背景颜色
11
+ private borderColor: string = "rgba(255,0,0,0.8)"; // 边框颜色
12
+ private borderWidth: number = 2; // 边框宽度
13
+ private sectorAngle: number = 30; // 扫描扇形角度(度)
14
+ private sectorColor: string = "rgba(0,255,0,0.4)"; // 扇形颜色
15
+ private sectorBorderColor: string = "rgba(0,0,255,0.8)"; // 扇形边框颜色
16
+ private center: [number, number] = [0, 0];
17
+ private animationId: number | null = null; // 添加动画ID属性
18
+ constructor(map?: GSMap) {
19
+ this.map = map;
20
+ }
21
+
22
+ add(options: any) {
23
+ this.center = options.center;
24
+ if (options.radius) {
25
+ this.radius = options.radius;
26
+ }
27
+ if (options.period) {
28
+ this.period = options.period;
29
+ }
30
+ if (options.backgroundColor) {
31
+ this.backgroundColor = options.backgroundColor;
32
+ }
33
+ if (options.borderColor) {
34
+ this.borderColor = options.borderColor;
35
+ }
36
+ if (options.borderWidth) {
37
+ this.borderWidth = options.borderWidth;
38
+ }
39
+ if (options.sectorAngle) {
40
+ this.sectorAngle = options.sectorAngle;
41
+ }
42
+ if (options.sectorColor) {
43
+ this.sectorColor = options.sectorColor;
44
+ }
45
+ if (options.sectorBorderColor) {
46
+ this.sectorBorderColor = options.sectorBorderColor;
47
+ }
48
+ // 圆背景数据
49
+ const circle = turf.circle(this.center, this.radius, {
50
+ steps: 64,
51
+ units: "meters",
52
+ });
53
+ // 初始扇形
54
+ const sector = turf.sector(this.center, this.radius, 0, this.sectorAngle, {
55
+ steps: 64,
56
+ units: "meters",
57
+ });
58
+ //添加圆背景图层
59
+ this.map?.addSource(this.id + "-circle", {
60
+ type: "geojson",
61
+ data: circle,
62
+ });
63
+ //添加扇形图层
64
+ this.map?.addSource(this.id + "-sector", {
65
+ type: "geojson",
66
+ data: sector,
67
+ });
68
+
69
+ //增加页面
70
+ this.map?.addLayer({
71
+ id: this.id + "-circle-fill",
72
+ type: "fill",
73
+ source: this.id + "-circle",
74
+ paint: {
75
+ "fill-color": this.backgroundColor,
76
+ "fill-outline-color": this.borderColor,
77
+ },
78
+ });
79
+
80
+ // 圆环边框
81
+ this.map?.addLayer({
82
+ id: this.id + "-circle-outline",
83
+ type: "line",
84
+ source: this.id + "-circle",
85
+ paint: {
86
+ "line-color": this.borderColor,
87
+ "line-width": this.borderWidth,
88
+ },
89
+ });
90
+
91
+ // 扇形
92
+ this.map?.addLayer({
93
+ id: this.id + "-sector-fill",
94
+ type: "fill",
95
+ source: this.id + "-sector",
96
+ paint: {
97
+ "fill-color": this.sectorColor,
98
+ "fill-outline-color": this.sectorBorderColor,
99
+ },
100
+ });
101
+ return this;
102
+ }
103
+
104
+ // 扫描
105
+ startScan() {
106
+ this.stopScan();
107
+ // 动画
108
+ let startTime = performance.now();
109
+ const animate = (time: number) => {
110
+ let elapsed = time - startTime;
111
+ let angle = ((elapsed % this.period) / this.period) * 360;
112
+ const newSector = turf.sector(this.center, this.radius, angle, angle + this.sectorAngle, {
113
+ steps: 64,
114
+ units: "meters",
115
+ });
116
+ if (this.map?.getSource(this.id + "-sector")) {
117
+ (this.map?.getSource(this.id + "-sector") as GeoJSONSource)?.setData(
118
+ newSector
119
+ );
120
+ }
121
+ this.animationId = requestAnimationFrame(animate);
122
+ };
123
+ this.animationId = requestAnimationFrame(animate);
124
+ return this;
125
+ }
126
+
127
+ stopScan() {
128
+ // 确保先停止之前可能存在的动画
129
+ if (this.animationId) {
130
+ cancelAnimationFrame(this.animationId);
131
+ this.animationId = null;
132
+ }
133
+ return this;
134
+ }
135
+
136
+ remove() {
137
+ this.stopScan();
138
+ // 移除图层
139
+ if (this.map?.getLayer(this.id + "-circle-fill")) {
140
+ this.map?.removeLayer(this.id + "-circle-fill");
141
+ }
142
+ if (this.map?.getLayer(this.id + "-circle-outline")) {
143
+ this.map?.removeLayer(this.id + "-circle-outline");
144
+ }
145
+ if (this.map?.getLayer(this.id + "-sector-fill")) {
146
+ this.map?.removeLayer(this.id + "-sector-fill");
147
+ }
148
+ // 移除数据源
149
+ if (this.map?.getSource(this.id + "-circle")) {
150
+ this.map?.removeSource(this.id + "-circle");
151
+ }
152
+ if (this.map?.getSource(this.id + "-sector")) {
153
+ this.map?.removeSource(this.id + "-sector");
154
+ }
155
+ }
156
+ }
@@ -0,0 +1,149 @@
1
+ import type GSMap from "../types/GSMap";
2
+
3
+ export default class TDTManager {
4
+ private map: GSMap;
5
+ private tdtImgId: string = "tdt-img";
6
+ private tdtVecId: string = "tdt-vec";
7
+ private tdtCiaId: string = "tdt-cia";
8
+ private tdtLayer: Map<string, any> = new Map();
9
+ private token: string = "6c8a0fffe8f584f8310306723f5bc776";
10
+ constructor(map: GSMap, token?: string) {
11
+ this.map = map;
12
+ this.token = token || this.token;
13
+ this.tdtLayer.set(this.tdtImgId, {
14
+ type: "raster",
15
+ tiles: [
16
+ `https://t0.tianditu.gov.cn/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=${this.token}`,
17
+ `https://t1.tianditu.gov.cn/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=${this.token}`,
18
+ `https://t2.tianditu.gov.cn/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=${this.token}`,
19
+ `https://t3.tianditu.gov.cn/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=${this.token}`,
20
+ `https://t4.tianditu.gov.cn/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=${this.token}`,
21
+ `https://t5.tianditu.gov.cn/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=${this.token}`,
22
+ `https://t6.tianditu.gov.cn/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=${this.token}`,
23
+ `https://t7.tianditu.gov.cn/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=${this.token}`,
24
+ ],
25
+ tileSize: 256,
26
+ maxzoom: 17,
27
+ crs: "EPSG:4326",
28
+ });
29
+ this.tdtLayer.set(this.tdtCiaId, {
30
+ type: "raster",
31
+ tiles: [
32
+ `https://t0.tianditu.gov.cn/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=${this.token}`,
33
+ `https://t1.tianditu.gov.cn/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=${this.token}`,
34
+ `https://t2.tianditu.gov.cn/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=${this.token}`,
35
+ `https://t3.tianditu.gov.cn/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=${this.token}`,
36
+ `https://t4.tianditu.gov.cn/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=${this.token}`,
37
+ `https://t5.tianditu.gov.cn/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=${this.token}`,
38
+ `https://t6.tianditu.gov.cn/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=${this.token}`,
39
+ `https://t7.tianditu.gov.cn/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=${this.token}`,
40
+ ],
41
+ tileSize: 256,
42
+ maxzoom: 17,
43
+ crs: "EPSG:4326",
44
+ });
45
+ this.tdtLayer.set(this.tdtVecId, {
46
+ type: "raster",
47
+ tiles: [
48
+ `http://t0.tianditu.gov.cn/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=${this.token}`,
49
+ `http://t1.tianditu.gov.cn/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=${this.token}`,
50
+ `http://t2.tianditu.gov.cn/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=${this.token}`,
51
+ `http://t3.tianditu.gov.cn/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=${this.token}`,
52
+ `http://t4.tianditu.gov.cn/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=${this.token}`,
53
+ `http://t5.tianditu.gov.cn/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=${this.token}`,
54
+ `http://t6.tianditu.gov.cn/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=${this.token}`,
55
+ `http://t7.tianditu.gov.cn/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=${this.token}`,
56
+ ],
57
+ tileSize: 256,
58
+ maxzoom: 18,
59
+ crs: "EPSG:4326",
60
+ });
61
+ }
62
+
63
+ addImgLayer(beforeId?: string) {
64
+ let source: any = this.map.getSource(this.tdtImgId);
65
+ if (!source) {
66
+ source = this.tdtLayer.get(this.tdtImgId);
67
+ this.map.addSource(this.tdtImgId, source);
68
+ }
69
+ if (beforeId && this.map.getLayer(beforeId)) {
70
+ this.map.addLayer({
71
+ id: this.tdtImgId,
72
+ type: "raster",
73
+ source: this.tdtImgId,
74
+ }, beforeId);
75
+ } else {
76
+ this.map.addLayer({
77
+ id: this.tdtImgId,
78
+ type: "raster",
79
+ source: this.tdtImgId,
80
+ });
81
+ }
82
+ }
83
+
84
+ removeImgLayer() {
85
+ if (this.map.getLayer(this.tdtImgId)) {
86
+ this.map.removeLayer(this.tdtImgId);
87
+ }
88
+ }
89
+
90
+ addVecLayer(beforeId?: string) {
91
+ let source: any = this.map.getSource(this.tdtVecId);
92
+ if (!source) {
93
+ source = this.tdtLayer.get(this.tdtVecId);
94
+ this.map.addSource(this.tdtVecId, source);
95
+ }
96
+ if (beforeId && this.map.getLayer(beforeId)) {
97
+ this.map.addLayer({
98
+ id: this.tdtVecId,
99
+ type: "raster",
100
+ source: this.tdtVecId
101
+ }, beforeId);
102
+ } else {
103
+ this.map.addLayer({
104
+ id: this.tdtVecId,
105
+ type: "raster",
106
+ source: this.tdtVecId
107
+ });
108
+ }
109
+ }
110
+
111
+ removeVecLayer() {
112
+ if (this.map.getLayer(this.tdtVecId)) {
113
+ this.map.removeLayer(this.tdtVecId);
114
+ }
115
+ }
116
+
117
+ addCiaLayer(beforeId?: string) {
118
+ let source: any = this.map.getSource(this.tdtCiaId);
119
+ if (!source) {
120
+ source = this.tdtLayer.get(this.tdtCiaId);
121
+ this.map.addSource(this.tdtCiaId, source);
122
+ }
123
+ if (beforeId && this.map.getLayer(beforeId)) {
124
+ this.map.addLayer({
125
+ id: this.tdtCiaId,
126
+ type: "raster",
127
+ source: this.tdtCiaId
128
+ }, beforeId);
129
+ } else {
130
+ this.map.addLayer({
131
+ id: this.tdtCiaId,
132
+ type: "raster",
133
+ source: this.tdtCiaId
134
+ });
135
+ }
136
+ }
137
+
138
+ removeCiaLayer() {
139
+ if (this.map.getLayer(this.tdtCiaId)) {
140
+ this.map.removeLayer(this.tdtCiaId);
141
+ }
142
+ }
143
+
144
+ clear() {
145
+ this.removeImgLayer();
146
+ this.removeVecLayer();
147
+ this.removeCiaLayer();
148
+ }
149
+ }
@@ -0,0 +1,13 @@
1
+ export default class TemplateManager {
2
+ private templates: Map<string, string> = new Map();
3
+ constructor() {}
4
+ add(id: string, template: string) {
5
+ this.templates.set(id, template);
6
+ }
7
+ remove(id: string) {
8
+ this.templates.delete(id);
9
+ }
10
+ get(id: string) {
11
+ return this.templates.get(id);
12
+ }
13
+ }
@@ -0,0 +1,61 @@
1
+ import GSMap from "../types/GSMap";
2
+
3
+ export default class TerrainManager {
4
+ private map: GSMap;
5
+ constructor(map: GSMap) {
6
+ this.map = map;
7
+ }
8
+
9
+ addSource() {
10
+ // map.addSource("raster-dem", {
11
+ // type: "raster-dem",
12
+ // tiles: [
13
+ // "http://121.228.31.116:8066/geoserver/gwc/service/tms/1.0.0/cite%3Asx_dem30@EPSG%3A900913@png/{z}/{x}/{y}.png",
14
+ // ],
15
+ // scheme: "tms",
16
+ // minzoom: 6,
17
+ // maxzoom: 18,
18
+ // tileSize: 256,
19
+ // });
20
+ // map.setTerrain({
21
+ // source: "raster-dem",
22
+ // exaggeration: 1, // 地形拉升强度(1.0为原始高度)
23
+ // });
24
+ this.map.addSource("raster-dem", {
25
+ type: "raster-dem",
26
+ url: "mapbox://mapbox.mapbox-terrain-dem-v1",
27
+ minzoom: 6,
28
+ maxzoom: 18,
29
+ tileSize: 256,
30
+ });
31
+ return this;
32
+ }
33
+
34
+ setTerrain() {
35
+ if (!this.map.getSource("raster-dem")) {
36
+ this.addSource();
37
+ }
38
+ this.map.setTerrain({
39
+ source: "raster-dem",
40
+ exaggeration: 1.5, // 地形拉升强度(1.0为原始高度)
41
+ });
42
+ return this;
43
+ }
44
+
45
+ addHillshade() {
46
+ if (!this.map.getSource("raster-dem")) {
47
+ this.addSource();
48
+ }
49
+ this.map.addLayer({
50
+ id: "hillshade",
51
+ type: "hillshade",
52
+ source: "raster-dem",
53
+ paint: {
54
+ "hillshade-exaggeration": 0.5, //地形起伏强度(默认 0.5)
55
+ "hillshade-highlight-color": "#FFFFFF", // 受光面颜色 :ml-citation{ref="1" data="citationList"}
56
+ "hillshade-shadow-color": "#025505", // 阴影区颜色 :ml-citation{ref="1" data="citationList"}
57
+ },
58
+ });
59
+ return this;
60
+ }
61
+ }
@@ -0,0 +1,51 @@
1
+ import type GSMap from "../types/GSMap";
2
+
3
+ export default class VectorManager {
4
+ private map: GSMap;
5
+ constructor(map: GSMap) {
6
+ this.map = map;
7
+ }
8
+
9
+ addSource(config: any) {
10
+ if (!this.map.getSource(config.id)) {
11
+ const source = Object.assign(
12
+ {
13
+ type: "geojson",
14
+ tiles: [config.url],
15
+ tileSize: 256,
16
+ },
17
+ config
18
+ );
19
+ this.map.addSource(config.id, source);
20
+ }
21
+ return this;
22
+ }
23
+
24
+ addLayer(config: any) {
25
+ if (!this.map.getLayer(config.id)) {
26
+ const layer = Object.assign(
27
+ {
28
+ id: config.id,
29
+ source: config.source,
30
+ },
31
+ config
32
+ );
33
+ this.map.addLayer(layer);
34
+ }
35
+ return this;
36
+ }
37
+
38
+ removeSource(id: string) {
39
+ if (this.map.getSource(id)) {
40
+ this.map.removeSource(id);
41
+ }
42
+ return this;
43
+ }
44
+
45
+ removeLayer(id: string) {
46
+ if (this.map.getLayer(id)) {
47
+ this.map.removeLayer(id);
48
+ }
49
+ return this;
50
+ }
51
+ }