@hzab/map-combine 0.2.8 → 0.3.0-beta1

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/CHANGELOG.md CHANGED
@@ -1,48 +1,55 @@
1
- # @hzab/map-combine0.2.8
2
-
3
- fix: reactpoint 添加状态回调
4
-
5
- # @hzab/map-combine0.2.7
6
-
7
- fix: flyToViewer 支持配置 minRadius 最小判断半径
8
-
9
- # @hzab/map-combine0.2.6
10
-
11
- fix: flyToViewer 修复点位过近导致高度异常问题
12
-
13
- # @hzab/map-combine0.2.5
14
-
15
- feat: flyTo 函数
16
-
17
- # @hzab/map-combine0.2.4
18
-
19
- fix: Cesium flyToViewer use flyTo
20
-
21
- # @hzab/map-combine0.2.3
22
-
23
- fix: 流动线可配置图形+颜色
24
-
25
- # @hzab/map-combine0.2.2
26
-
27
- fix: openlayer point 问题修复
28
-
29
- # @hzab/map-combine0.2.1
30
-
31
- feat: openLayer 对除 EPSG:3857 和 EPSG:4326 的瓦片坐标系取消偏移
32
-
33
- # @hzab/map-combine0.2.0
34
-
35
- feat: flyToViewer 所有点位移动至视口,调整位置及层级
36
-
37
- # @hzab/map-combine0.1.3
38
-
39
- feat: 添加地图 preRender 事件
40
-
41
- # @hzab/map-combine@0.1.0
42
-
43
- feat: BIM 模型加载;旋转、平移、缩放
44
- feat: 地图瓦片转 84 坐标系
45
-
46
- # @hzab/map-combine@0.0.1
47
-
48
- 组件初始化
1
+ # @hzab/map-combine0.3.0
2
+
3
+ fix: reactpoint 添加高德地图引擎并添加相应点线面绘制
4
+ feat: 高德地图支持 ReactPoint
5
+ feat: 增加 loadPromise 参数,用于地图异步加载判断是否加载完成
6
+ fix: 解决 ReactPoint 点击事件无法触发的问题
7
+
8
+ # @hzab/map-combine0.2.8
9
+
10
+ fix: reactpoint 添加状态回调
11
+
12
+ # @hzab/map-combine0.2.7
13
+
14
+ fix: flyToViewer 支持配置 minRadius 最小判断半径
15
+
16
+ # @hzab/map-combine0.2.6
17
+
18
+ fix: flyToViewer 修复点位过近导致高度异常问题
19
+
20
+ # @hzab/map-combine0.2.5
21
+
22
+ feat: flyTo 函数
23
+
24
+ # @hzab/map-combine0.2.4
25
+
26
+ fix: Cesium flyToViewer use flyTo
27
+
28
+ # @hzab/map-combine0.2.3
29
+
30
+ fix: 流动线可配置图形+颜色
31
+
32
+ # @hzab/map-combine0.2.2
33
+
34
+ fix: openlayer point 问题修复
35
+
36
+ # @hzab/map-combine0.2.1
37
+
38
+ feat: openLayer 对除 EPSG:3857 和 EPSG:4326 的瓦片坐标系取消偏移
39
+
40
+ # @hzab/map-combine0.2.0
41
+
42
+ feat: flyToViewer 所有点位移动至视口,调整位置及层级
43
+
44
+ # @hzab/map-combine0.1.3
45
+
46
+ feat: 添加地图 preRender 事件
47
+
48
+ # @hzab/map-combine@0.1.0
49
+
50
+ feat: BIM 模型加载;旋转、平移、缩放
51
+ feat: 地图瓦片转 84 坐标系
52
+
53
+ # @hzab/map-combine@0.0.1
54
+
55
+ 组件初始化
package/README.md CHANGED
@@ -1,67 +1,83 @@
1
- # @hzab/map-combine
2
-
3
- 组件模板
4
-
5
- - node@16.16.0
6
-
7
- # 组件
8
-
9
- ## 示例
10
-
11
- ```jsx
12
- import Demo from "@hzab/map-combine";
13
-
14
- <Demo />;
15
- ```
16
-
17
- ## API
18
-
19
- ### InfoPanel Attributes
20
-
21
- | 参数 | 类型 | 必填 | 默认值 | 说明 |
22
- | ------ | ------ | ---- | ------ | ----------------- |
23
- | schema | Object | 是 | - | 数据信息的 schema |
24
-
25
- # 组件开发流程
26
-
27
- - 在 config/webpack.config.js 中按需修改 library 配置的文件名
28
- - 在 config/webpack.config.js 中按需修改 alias 配置的包名,便于本地调试
29
- - 在 tsconfig.json 中按需修改 paths 配置的包名,解决 ts 报错问题
30
- - npm run dev
31
-
32
- ## 文件目录
33
-
34
- - example 本地开发测试代码
35
- - src 组件源码
36
- - lib 组件打包编译后的代码
37
-
38
- ## 命令
39
-
40
- - Mac 执行该命令,设置 pre-commit 为可执行文件
41
-
42
- - npm run mac-chmod
43
- - chmod +x .husky && chmod +x .husky/pre-commit
44
-
45
- - 生成文档:npm run docs
46
- - 本地运行:npm run dev
47
- - 打包编译:npm run build
48
-
49
- ## 发布
50
-
51
- - 注意:示例代码生效,但发布之后未生效。确认是否执行了编译!!!
52
-
53
- - 编译组件:npm run build
54
- - 命令:npm publish --access public
55
- - 发布目录:
56
- - lib
57
- - src
58
-
59
- ## 配置
60
-
61
- ### 配置文件
62
-
63
- - 本地配置文件:config/config.js
64
-
65
- ### webpack 配置文件
66
-
67
- - config/webpack.config.js
1
+ # @hzab/map-combine
2
+
3
+ 组件模板
4
+
5
+ - node@16.16.0
6
+
7
+ # 组件
8
+
9
+ ## 示例
10
+
11
+ ```jsx
12
+ import Demo from "@hzab/map-combine";
13
+
14
+ <Demo />;
15
+ ```
16
+
17
+ ## API
18
+
19
+ ### InfoPanel Attributes
20
+
21
+ | 参数 | 类型 | 必填 | 默认值 | 说明 |
22
+ | ------ | ------ | ---- | ------ | ----------------- |
23
+ | schema | Object | 是 | - | 数据信息的 schema |
24
+
25
+ # 组件开发流程
26
+
27
+ - 在 config/webpack.config.js 中按需修改 library 配置的文件名
28
+ - 在 config/webpack.config.js 中按需修改 alias 配置的包名,便于本地调试
29
+ - 在 tsconfig.json 中按需修改 paths 配置的包名,解决 ts 报错问题
30
+ - npm run dev
31
+
32
+ ## 文件目录
33
+
34
+ - example 本地开发测试代码
35
+ - src 组件源码
36
+ - lib 组件打包编译后的代码
37
+
38
+ ## 命令
39
+
40
+ - Mac 执行该命令,设置 pre-commit 为可执行文件
41
+
42
+ - npm run mac-chmod
43
+ - chmod +x .husky && chmod +x .husky/pre-commit
44
+
45
+ - 生成文档:npm run docs
46
+ - 本地运行:npm run dev
47
+
48
+ ## 发布
49
+
50
+ - npm 源和云效源都需要发布
51
+
52
+ - 命令:npm publish --access public
53
+ - 发布目录:
54
+ - src
55
+
56
+ ### 迭代发布命令-版本自增
57
+
58
+ - beta: 需要手动修改 package.json 中的 version,添加 -betaX 版本号。使用 npm publish --beta 发布
59
+ - 0.0.x: npm run publish-patch
60
+ - 0.x.0: npm run publish-minor
61
+ - x.0.0: npm run publish-major
62
+
63
+ ### nrm
64
+
65
+ - 安装
66
+ npm install -g nrm
67
+ - 增加源
68
+ nrm add aliyun https://packages.aliyun.com/62046985b3ead41b374a17f7/npm/npm-registry/
69
+ - 切换源
70
+ nrm use aliyun
71
+ nrm use npm
72
+ - 登录(账号密码在 https://packages.aliyun.com/npm/npm-registry/guide 查看)
73
+ npm login --registry=https://packages.aliyun.com/62046985b3ead41b374a17f7/npm/npm-registry/
74
+
75
+ ## 配置
76
+
77
+ ### 配置文件
78
+
79
+ - 本地配置文件:config/config.js
80
+
81
+ ### webpack 配置文件
82
+
83
+ - config/webpack.config.js
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@hzab/map-combine",
3
- "version": "0.2.8",
3
+ "version": "0.3.0-beta1",
4
4
  "description": "地图组件",
5
5
  "main": "src",
6
6
  "scripts": {
7
7
  "dev": "npm run prepare && webpack serve -c ./config/webpack.config.js --env local",
8
8
  "build": "webpack -c ./config/webpack.config.js --env production",
9
+ "publish-beta": "npm publish --beta",
9
10
  "publish-patch": "npm version patch && npm publish --access public",
10
11
  "publish-minor": "npm version minor && npm publish --access public",
11
12
  "publish-major": "npm version major && npm publish --access public",
@@ -21,9 +22,11 @@
21
22
  "author": "CaiYansong",
22
23
  "license": "ISC",
23
24
  "devDependencies": {
25
+ "@amap/amap-jsapi-loader": "^1.0.1",
24
26
  "@hzab/permissions": "0.1.1",
25
27
  "@hzab/webpack-config": "^0.2.1",
26
28
  "@turf/turf": "6.5",
29
+ "@types/amap-js-api": "^1.4.16",
27
30
  "@types/react": "^17.0.62",
28
31
  "@types/react-dom": "^17.0.20",
29
32
  "antd": "^4.14.0",
@@ -33,6 +36,7 @@
33
36
  "lil-gui": "^0.19.2",
34
37
  "mobx": "^6.7.0",
35
38
  "mobx-react": "^7.6.0",
39
+ "ol": "^7.4.0",
36
40
  "react": "^17.0.2",
37
41
  "react-dom": "^17.0.2",
38
42
  "react-router-dom": "^6.14.1",
@@ -46,7 +50,6 @@
46
50
  "@turf/turf": "6.5",
47
51
  "coordtransform": "^2.1.2",
48
52
  "lodash": ">=4.17.21",
49
- "ol": "^7.4.0",
50
53
  "react-dom": "^17.0.2",
51
54
  "zrender": "^5.4.4"
52
55
  },
@@ -54,5 +57,6 @@
54
57
  "**.{js,jsx,ts,tsx,css,scss,less,json,html}": [
55
58
  "prettier --write"
56
59
  ]
57
- }
60
+ },
61
+ "dependencies": {}
58
62
  }
@@ -0,0 +1,248 @@
1
+ import { MapCombine } from "../basic/MapCombine";
2
+ import { PointOption, Point } from "../basic/Point";
3
+ import { ReactPointOption, ReactPoint, drawReactPoint } from "../basic/ReactPoint";
4
+ import { PolylineOption, Polyline } from "../basic/Polyline";
5
+ import { PolygonOption, Polygon } from "../basic/Polygon";
6
+ import { Tile3DOption, Tile3D } from "../basic/Tile3D";
7
+
8
+ import AMapLoader from "./loader";
9
+ import { bindEvent } from "./AMapEvent";
10
+ import { drawPoint } from "./AMapPoint";
11
+ import { drawPolyline } from "./AMapPolyline";
12
+ import { drawPolygon } from "./AMapPolygon";
13
+
14
+ export interface IAMapOption {
15
+ container;
16
+ url?: string | string[];
17
+ center?: number[];
18
+ zoom?: number;
19
+ maxZoom?: number;
20
+ minZoom?: number;
21
+ /** 地图瓦片转换规则 GCJ02 转 WGS84 */
22
+ proj?: "GCJ02->WGS84";
23
+ /** 高德地图 key */
24
+ key: string;
25
+ /** 高德地图 securityJsCode */
26
+ securityJsCode: string;
27
+ /** 加载的插件列表 */
28
+ plugins?: [string];
29
+ }
30
+
31
+ export interface IFlyToViewerOpt {
32
+ /**
33
+ * 立即缩放到指定位置
34
+ */
35
+ immediately?: boolean;
36
+ /**
37
+ * (Array<number> = [0,0,0,0]) 距离边框的内边距,顺序:上、下、左、右
38
+ */
39
+ avoid?: [number, number, number, number];
40
+ }
41
+
42
+ export class AMap extends MapCombine {
43
+ viewer: any;
44
+ container: HTMLDivElement;
45
+ option;
46
+ offset: number[];
47
+ fov = 0.9272952180016121;
48
+ isFromLonLat = true;
49
+ LbsAMap;
50
+ get cursor(): string {
51
+ return this.container.style.cursor;
52
+ }
53
+ set cursor(val: string) {
54
+ this.container.style.cursor = val;
55
+ }
56
+
57
+ get moveable(): boolean {
58
+ return this.viewer?.getStatus()?.dragEnable;
59
+ }
60
+ set moveable(val: boolean) {
61
+ this.viewer?.setStatus({ dragEnable: val });
62
+ }
63
+
64
+ get center(): number[] {
65
+ return this.viewer?.getCenter();
66
+ }
67
+ set center(val: number[]) {
68
+ this.viewer?.setCenter(val);
69
+ }
70
+ get zoom(): number {
71
+ return this.viewer?.getZoom();
72
+ }
73
+ set zoom(val: number) {
74
+ this.viewer?.setZoom(val);
75
+ }
76
+
77
+ constructor(viewer = undefined) {
78
+ super();
79
+ viewer && this._initParamsEvent(viewer);
80
+ }
81
+
82
+ private _initParamsEvent(viewer) {
83
+ if (!viewer) {
84
+ return;
85
+ }
86
+ this.viewer = viewer;
87
+
88
+ this.container = this.viewer.getContainer();
89
+ // this.markers = this.viewer.scene.primitives.add(new Cesium.BillboardCollection());
90
+
91
+ bindEvent(this);
92
+ }
93
+
94
+ init(opt: IAMapOption) {
95
+ this.option = opt;
96
+ const {
97
+ container,
98
+ center = [120.2288892, 30.2349677, 0],
99
+ zoom = 13,
100
+ url,
101
+ maxZoom,
102
+ minZoom,
103
+ proj,
104
+ key,
105
+ securityJsCode,
106
+ plugins,
107
+ } = opt || {};
108
+
109
+ this.loadPromise = new Promise((resolve, reject) => {
110
+ AMapLoader({
111
+ key,
112
+ securityJsCode,
113
+ plugins,
114
+ })
115
+ .then((LbsAMap: any) => {
116
+ this.LbsAMap = LbsAMap;
117
+ let _urls = Array.isArray(url) ? url : [url];
118
+ this.viewer = new LbsAMap.Map(container, {
119
+ zoom: zoom || 14,
120
+ center: center || [120.160217, 30.243861],
121
+ doubleClickZoom: false,
122
+ zooms: minZoom && maxZoom && [minZoom, maxZoom],
123
+ layers: url
124
+ ? _urls.map((it: any) => {
125
+ let opt = { tileUrl: "", getTileUrl: undefined };
126
+ if (typeof it === "string") {
127
+ opt.tileUrl = it;
128
+ } else {
129
+ opt = it;
130
+ }
131
+ // 使用 getTileUrl 解决接口地址强制改为 https 的问题
132
+ opt.getTileUrl = function (x, y, z) {
133
+ return opt.tileUrl.replace("{x}", x).replace("{y}", y).replace("{z}", z);
134
+ };
135
+
136
+ return new LbsAMap.TileLayer(opt);
137
+ })
138
+ : undefined,
139
+ });
140
+ this.viewer.on("complete", () => {
141
+ resolve(this);
142
+ });
143
+
144
+ this._initParamsEvent(this.viewer);
145
+ return this;
146
+ })
147
+ .catch(reject);
148
+ });
149
+ this.loadPromise.then(() => {
150
+ this.container.appendChild(this.htmllayer);
151
+ });
152
+ return this.loadPromise;
153
+ }
154
+
155
+ createPoint<K>(option?: Partial<PointOption<K>>): Point<K> {
156
+ const e = new Point(this, option);
157
+ this.loadPromise.then(() => {
158
+ drawPoint(this, e);
159
+ });
160
+ return e;
161
+ }
162
+
163
+ createReactPoint<K>(option?: Partial<ReactPointOption<K>>): ReactPoint<K> {
164
+ const e = new ReactPoint(this, option);
165
+ this.loadPromise.then(() => {
166
+ drawReactPoint(this, e);
167
+ });
168
+ return e;
169
+ }
170
+
171
+ createPolyline<K>(option?: Partial<PolylineOption<K>>): Polyline<K> {
172
+ const e = new Polyline(this, option);
173
+ this.loadPromise.then(() => {
174
+ drawPolyline(this, e);
175
+ });
176
+ return e;
177
+ }
178
+ createPolygon<K>(option?: Partial<PolygonOption<K>>): Polygon<K> {
179
+ const e = new Polygon(this, option);
180
+ this.loadPromise.then(() => {
181
+ drawPolygon(this, e);
182
+ });
183
+ return e;
184
+ }
185
+ createTile3D(option?: Partial<Tile3DOption>): Tile3D {
186
+ throw new Error("Method not implemented.");
187
+ }
188
+
189
+ /**
190
+ * 将高德地图 Canvas 像素坐标转换为经纬度
191
+ * @param {Array} p - canvas 点位数组 [x, y]
192
+ * @returns {Array} p - 经纬度数组 [lng, lat]
193
+ */
194
+ canvasTgeography(p: number[]) {
195
+ const mapInstance = this.viewer;
196
+ if (!mapInstance) {
197
+ this.loadPromise.then(() => {
198
+ this.canvasTgeography(p);
199
+ });
200
+ return [];
201
+ }
202
+ try {
203
+ const lngLat = this.viewer.lngLatToContainer(p);
204
+ return [lngLat.lng, lngLat.lat];
205
+ } catch (error) {
206
+ console.error("canvasPixelToLngLat 转换出错:", error);
207
+ return [];
208
+ }
209
+ }
210
+
211
+ /**
212
+ * 经纬度转换为高德地图 Canvas 像素坐标
213
+ * @param {Array} p - 经纬度数组 [lng, lat]
214
+ * @returns {Array} Canvas 像素坐标 [x, y]
215
+ */
216
+ geographyTcanvas(p: number[]): number[] {
217
+ const mapInstance = this.viewer;
218
+ if (!mapInstance) {
219
+ this.loadPromise.then(() => {
220
+ this.geographyTcanvas(p);
221
+ });
222
+ return [];
223
+ }
224
+ try {
225
+ const containerPixel = this.viewer.lngLatToContainer(p);
226
+ return [containerPixel.x, containerPixel.y];
227
+ } catch (error) {
228
+ console.error("lngLatToCanvasPixel 转换出错:", error);
229
+ return [];
230
+ }
231
+ }
232
+ /**
233
+ * 所有点位移动至视口,调整位置及层级
234
+ * @param points
235
+ * @param opt
236
+ * @param {Array<number> = [0,0,0,0]} opt.avoid 距离边框的内边距,顺序:上、下、左、右
237
+ */
238
+ flyToViewer(points: number[][], opt: IFlyToViewerOpt = { avoid: [0, 0, 0, 0], immediately: true }): void {
239
+ this.loadPromise.then(() => {
240
+ this.viewer.setBounds(
241
+ this.getBounds(points, { canvas: this.viewer.canvas, ...opt }),
242
+ opt?.immediately,
243
+ opt?.avoid,
244
+ );
245
+ });
246
+ }
247
+ flyTo() {}
248
+ }
@@ -0,0 +1,49 @@
1
+ import { AMap } from "./AMap";
2
+
3
+ /**
4
+ * 高德地图事件
5
+ * 高德地图 元素事件由各自元素处理
6
+ * @param map
7
+ */
8
+ export function bindEvent(map: AMap) {
9
+ const { event, viewer, container } = map;
10
+
11
+ const frame = () => {
12
+ if (map.isAlive) {
13
+ requestAnimationFrame(frame);
14
+ event.trigger("view-preRender");
15
+ }
16
+ };
17
+ frame();
18
+
19
+ container.addEventListener("mousedown", (e) => {
20
+ event.trigger("pointer-down");
21
+ });
22
+
23
+ container.addEventListener("mouseup", (e) => {
24
+ event.trigger("pointer-up");
25
+ });
26
+
27
+ // 解决 ReactPoint 点击事件无法触发的问题
28
+ container.addEventListener("click", (e) => {
29
+ event.trigger("left-click");
30
+ });
31
+
32
+ viewer.on("mousemove", (e) => {
33
+ event.trigger("pointer-move");
34
+ event.canvas = [e.pixel.x, e.pixel.y];
35
+ event.geography = [e.lnglat.lng, e.lnglat.lat];
36
+ });
37
+
38
+ viewer.on("mapmove", () => {
39
+ event.trigger("view-change");
40
+ });
41
+
42
+ viewer.on("click", (e) => {
43
+ event.trigger("left-click");
44
+ });
45
+
46
+ viewer.on("dblclick", (e) => {
47
+ map.event.trigger("double-click");
48
+ });
49
+ }