jgis 1.0.2 → 1.0.3

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/dist/3d/index.mjs CHANGED
@@ -1,73 +1,138 @@
1
- var c = (r, a, e) => new Promise((o, s) => {
2
- var d = (t) => {
3
- try {
4
- m(e.next(t));
5
- } catch (n) {
6
- s(n);
7
- }
8
- }, l = (t) => {
9
- try {
10
- m(e.throw(t));
11
- } catch (n) {
12
- s(n);
13
- }
14
- }, m = (t) => t.done ? o(t.value) : Promise.resolve(t.value).then(d, l);
15
- m((e = e.apply(r, a)).next());
16
- });
17
- import * as i from "cesium";
18
- function g(r, a) {
1
+ var C = Object.defineProperty, M = Object.defineProperties;
2
+ var I = Object.getOwnPropertyDescriptors;
3
+ var p = Object.getOwnPropertySymbols;
4
+ var x = Object.prototype.hasOwnProperty, k = Object.prototype.propertyIsEnumerable;
5
+ var h = (r, t, e) => t in r ? C(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e, u = (r, t) => {
6
+ for (var e in t || (t = {}))
7
+ x.call(t, e) && h(r, e, t[e]);
8
+ if (p)
9
+ for (var e of p(t))
10
+ k.call(t, e) && h(r, e, t[e]);
11
+ return r;
12
+ }, f = (r, t) => M(r, I(t));
13
+ import * as o from "cesium";
14
+ import { getLonLat as w } from "../index.mjs";
15
+ function L(r, t) {
19
16
  const e = {
20
- img_w: !0,
21
- ibo_w: !0,
22
- cia_w: !0,
17
+ baseType: "img",
18
+ noteType: "cia",
23
19
  token: "dadcbbdb5206b626a29ca739686b3087"
24
- }, { img_w: o, ibo_w: s, cia_w: d, token: l } = Object.assign(e, a), m = "https://t{s}.tianditu.gov.cn/", t = ["0", "1", "2", "3", "4", "5", "6", "7"];
25
- if (o) {
26
- const n = new i.UrlTemplateImageryProvider({
27
- url: m + "DataServer?T=img_w&x={x}&y={y}&l={z}&tk=" + l,
28
- subdomains: t,
29
- tilingScheme: new i.WebMercatorTilingScheme(),
30
- maximumLevel: 18
31
- });
32
- let u = r.imageryLayers.addImageryProvider(n);
33
- u.gamma = 1;
34
- } else {
35
- const n = new i.UrlTemplateImageryProvider({
36
- url: "https://tile-{s}.openstreetmap.fr/hot/{z}/{x}/{y}.png",
37
- subdomains: ["a", "b", "c", "d"],
38
- tilingScheme: new i.WebMercatorTilingScheme(),
39
- maximumLevel: 18
40
- });
41
- r.imageryLayers.addImageryProvider(n);
42
- }
43
- if (s) {
44
- const n = new i.UrlTemplateImageryProvider({
45
- url: m + "DataServer?T=ibo_w&x={x}&y={y}&l={z}&tk=" + l,
46
- subdomains: t,
47
- tilingScheme: new i.WebMercatorTilingScheme(),
48
- maximumLevel: 10
49
- });
50
- r.imageryLayers.addImageryProvider(n);
20
+ }, { baseType: a, noteType: n, token: i } = Object.assign(e, t), c = "https://t{s}.tianditu.gov.cn", s = ["0", "1", "2", "3", "4", "5", "6", "7"], l = new o.UrlTemplateImageryProvider({
21
+ url: `${c}/DataServer?T=${a}_w&x={x}&y={y}&l={z}&tk=${i}`,
22
+ subdomains: s,
23
+ tilingScheme: new o.WebMercatorTilingScheme()
24
+ });
25
+ let d = r.imageryLayers.addImageryProvider(l);
26
+ d.gamma = 1;
27
+ const S = new o.UrlTemplateImageryProvider({
28
+ url: `${c}/DataServer?T=ibo_w&x={x}&y={y}&l={z}&tk=${i}`,
29
+ subdomains: s,
30
+ tilingScheme: new o.WebMercatorTilingScheme()
31
+ });
32
+ r.imageryLayers.addImageryProvider(S);
33
+ const v = new o.UrlTemplateImageryProvider({
34
+ url: `${c}/DataServer?T=${n}_w&x={x}&y={y}&l={z}&tk=${i}`,
35
+ subdomains: s,
36
+ tilingScheme: new o.WebMercatorTilingScheme()
37
+ // maximumLevel: 18
38
+ });
39
+ r.imageryLayers.addImageryProvider(v);
40
+ }
41
+ function O(r, t) {
42
+ L(r, t);
43
+ }
44
+ function P(r, t, e, a) {
45
+ (!a || !a.type) && (a = Object.assign({}, e, a));
46
+ const n = a.type || "Point";
47
+ let i;
48
+ switch (n) {
49
+ case "Point":
50
+ i = B(r, t, e, a);
51
+ break;
52
+ case "LineString":
53
+ i = _(r, t, e, a);
54
+ break;
51
55
  }
52
- if (d) {
53
- const n = new i.UrlTemplateImageryProvider({
54
- url: m + "DataServer?T=cia_w&x={x}&y={y}&l={z}&tk=" + l,
55
- subdomains: t,
56
- tilingScheme: new i.WebMercatorTilingScheme(),
57
- maximumLevel: 18
58
- });
59
- r.imageryLayers.addImageryProvider(n);
56
+ return i;
57
+ }
58
+ function B(r, t, e, a) {
59
+ const n = r.scene.primitives.add(new o.BillboardCollection());
60
+ return n._layerName = t, e.forEach((i, c) => {
61
+ const s = {
62
+ scale: 1,
63
+ // 缩放比例
64
+ verticalOrigin: o.VerticalOrigin.BOTTOM,
65
+ // 以底部为定位中心
66
+ show: !0,
67
+ disableDepthTestDistance: Number.POSITIVE_INFINITY,
68
+ // 禁止深度测试距离
69
+ scaleByDistance: new o.NearFarScalar(1, 1, 1e5, 0.2)
70
+ // 根据相机距离缩放
71
+ }, l = {
72
+ position: o.Cartesian3.fromDegrees(...w(i), 1),
73
+ image: a.style || a.getStyle(i),
74
+ id: i.id || `point_${c}`
75
+ }, d = n.add(u(u(u({}, s), a), l));
76
+ d._originStyle = f(u(u(u({}, s), a), l), { color: o.Color.WHITE }), d.properties = i;
77
+ }), r.scene.requestRender(), n;
78
+ }
79
+ function _(r, t, e, a) {
80
+ if (e.length < 2) return;
81
+ const n = D(e, a), i = new o.GroundPolylinePrimitive({
82
+ geometryInstances: n,
83
+ appearance: new o.PolylineColorAppearance({
84
+ translucent: !0
85
+ }),
86
+ interleave: !0,
87
+ allowPicking: !0,
88
+ asynchronous: !1
89
+ });
90
+ i._layerName = t, r.scene.groundPrimitives.add(i);
91
+ }
92
+ function D(r, t) {
93
+ const e = [], a = r.map((c) => o.Cartesian3.fromDegrees(...w(c), 0)), n = new o.GroundPolylineGeometry({
94
+ positions: a,
95
+ width: t.width || 4,
96
+ granularity: t.granularity || 2e3
97
+ }), i = new o.GeometryInstance({
98
+ id: "pipeLine",
99
+ geometry: n,
100
+ attributes: {
101
+ color: o.ColorGeometryInstanceAttribute.fromColor(o.Color.fromCssColorString(t.color))
102
+ }
103
+ });
104
+ return e.push(i), e;
105
+ }
106
+ function E(r, t) {
107
+ const e = r.scene.primitives, a = e.length;
108
+ for (let n = 0; n < a; n++) {
109
+ const i = e.get(n);
110
+ if (i._layerName === t)
111
+ return i;
60
112
  }
113
+ return null;
61
114
  }
62
- function y(r, a) {
63
- let e;
64
- i.defined(a) && (e = c(null, null, function* () {
65
- return yield i.CesiumTerrainProvider.fromUrl(a, {
66
- requestVertexNormals: !0,
67
- requestWaterMask: !0
68
- });
69
- })), i.defined(e) || (e = new i.EllipsoidTerrainProvider());
70
- const o = new i.Viewer(r, {
115
+ const y = /* @__PURE__ */ new Map(), m = {}, g = {}, R = (r, t) => {
116
+ y.has(r) && console.warn(`Map with target '${r}' already exists. Overwriting...`), y.set(r, t), m[r] && (m[r].forEach((e) => e(t)), delete m[r]), g[r] && (g[r].forEach((e) => e(t)), delete g[r]);
117
+ };
118
+ function b(r) {
119
+ const t = y.get(r);
120
+ return t ? Promise.resolve(t) : new Promise((e) => {
121
+ g[r] = g[r] || [], g[r].push(e);
122
+ });
123
+ }
124
+ const N = (r) => {
125
+ y.has(r) && (y.delete(r), delete m[r]);
126
+ }, T = (r, t) => {
127
+ const e = y.get(r);
128
+ if (e) {
129
+ t(e);
130
+ return;
131
+ }
132
+ m[r] || (m[r] = []), m[r].push(t);
133
+ };
134
+ function $(r, t = {}) {
135
+ const e = new o.Viewer(r, {
71
136
  requestRenderMode: !0,
72
137
  //减少应用程序的 CPU/GPU 使用率
73
138
  maximumRenderTimeChange: 1 / 0,
@@ -83,7 +148,7 @@ function y(r, a) {
83
148
  //控制右上角home按钮显示
84
149
  baseLayerPicker: !1,
85
150
  //地图切换控件(底图以及地形图)是否显示,默认显示true
86
- imageryProvider: new i.GridImageryProvider(),
151
+ // imageryProvider: new Cesium.GridImageryProvider({}),
87
152
  sceneModePicker: !1,
88
153
  navigationHelpButton: !1,
89
154
  infoBox: !1,
@@ -92,7 +157,7 @@ function y(r, a) {
92
157
  //全屏按钮,默认显示true
93
158
  shouldAnimate: !0,
94
159
  // Enable animations
95
- terrainProvider: e,
160
+ // terrainProvider: _terrainProvider, //地形
96
161
  contextOptions: {
97
162
  webgl: {
98
163
  preserveDrawingBuffer: !0
@@ -100,21 +165,130 @@ function y(r, a) {
100
165
  }
101
166
  }
102
167
  });
103
- return o._cesiumWidget._creditContainer.style.display = "none", o;
168
+ let a;
169
+ return o.defined(t.terrainUrl) ? o.CesiumTerrainProvider.fromUrl(t.terrainUrl, {
170
+ requestVertexNormals: !0,
171
+ requestWaterMask: !0
172
+ }).then((n) => {
173
+ a = n, e.terrainProvider = a;
174
+ }) : a = new o.EllipsoidTerrainProvider(), e.terrainProvider = a, e._cesiumWidget._creditContainer.style.display = "none", e.scene.globe.baseColor = new o.Color(0, 0, 0, 0), e.scene.screenSpaceCameraController.minimumZoomDistance = t.minZoom || 1, e.scene.screenSpaceCameraController.maximumZoomDistance = t.maxZoom || 1e7, e.resolutionScale = window.devicePixelRatio > 2 ? 2 : window.devicePixelRatio, e;
104
175
  }
105
- function f(r, a) {
106
- g(r, a);
176
+ function H(r, t, e, a) {
177
+ P(r, t, e, f(u({}, a), { type: "Point" }));
107
178
  }
108
- function v(r, a, e) {
109
- console.log("添加标记", r, a, e);
179
+ function V(r, t, e) {
180
+ return new Promise((a, n) => {
181
+ r.camera.flyTo({
182
+ destination: o.Cartesian3.fromDegrees(...t),
183
+ duration: e.duration || 1.2,
184
+ // 飞行动画时间(秒)
185
+ orientation: {
186
+ heading: e.heading || 0,
187
+ pitch: e.pitch || -Math.PI / 2,
188
+ roll: e.roll || 0
189
+ },
190
+ easingFunction: e.easing || o.EasingFunction.LINEAR_NONE,
191
+ // 飞行动画缓动函数
192
+ maximumHeight: e.maxHeight || 1e6,
193
+ // 相机最大飞行高度
194
+ complete: () => {
195
+ a(!0);
196
+ },
197
+ cancel: () => {
198
+ a(!1);
199
+ }
200
+ });
201
+ });
202
+ }
203
+ function j(r, t = 1) {
204
+ return r.camera.flyHome(t);
205
+ }
206
+ function G(r, t, e) {
207
+ return new Promise((a, n) => {
208
+ r.camera.flyToBoundingSphere(t, {
209
+ duration: e.duration || 1e3,
210
+ // 飞行动画时间(秒)
211
+ offset: new o.HeadingPitchRange(e.heading || 0, e.pitch || -Math.PI / 4, e.roll || 0),
212
+ easingFunction: e.easing,
213
+ // 飞行动画缓动函数
214
+ maximumHeight: e.maxHeight || 1e6,
215
+ // 相机最大飞行高度
216
+ complete: () => {
217
+ a(!0);
218
+ },
219
+ cancel: () => {
220
+ a(!1);
221
+ }
222
+ });
223
+ });
110
224
  }
111
- function p(r, a) {
112
- const e = y(r);
113
- return f(e, a), {
225
+ function U(r, t, e) {
226
+ r.camera.setView({
227
+ destination: o.Cartesian3.fromDegrees(...t),
228
+ orientation: {
229
+ heading: e.heading || 0,
230
+ pitch: e.pitch || -Math.PI / 2,
231
+ roll: e.roll || 0
232
+ }
233
+ });
234
+ }
235
+ function q(r, t) {
236
+ r.destroy(), N(t);
237
+ }
238
+ function F(r, t) {
239
+ const e = /* @__PURE__ */ new Set(), a = new o.ScreenSpaceEventHandler(r.scene.canvas);
240
+ let n = null;
241
+ a.setInputAction((c) => {
242
+ const s = r.scene.pick(c.position);
243
+ if (n && (Object.assign(n, n._originStyle), n = null, r.scene.requestRender()), o.defined(s) && s.primitive instanceof o.Billboard) {
244
+ const l = s.primitive, d = {
245
+ billboard: l,
246
+ properties: l.properties,
247
+ event: c,
248
+ pick: s
249
+ };
250
+ n = l, i(d), Object.assign(l, t.style || t.getStyle(l)), r.scene.requestRender();
251
+ }
252
+ }, o.ScreenSpaceEventType.LEFT_CLICK);
253
+ const i = (c) => e.forEach((s) => s(c));
254
+ return {
255
+ onSelect: (c) => (e.add(c), () => e.delete(c)),
256
+ clear() {
257
+ e.clear();
258
+ },
259
+ destroy() {
260
+ e.clear();
261
+ }
262
+ };
263
+ }
264
+ function Z(r, t) {
265
+ const e = $(r, t);
266
+ O(e, t);
267
+ const a = {
268
+ targetId: r,
114
269
  instance: e,
115
- addMarker: (o, s) => v(e, o, s)
270
+ addMarker: (n, i, c) => H(e, n, i, c),
271
+ createLayer: (n, i, c) => P(e, n, i, c),
272
+ getLayerByName: (n) => E(e, n),
273
+ useSelect: (n) => F(e, n),
274
+ flyTo: (n, i) => V(e, n, i),
275
+ flyHome: (n) => j(e, n),
276
+ flyToBoundingSphere: (n, i) => G(e, n, i),
277
+ setView: (n, i) => U(e, n, i),
278
+ getMapContext: (n) => b(n),
279
+ onMapReady: (n, i) => T(n, i),
280
+ destroyMap: (n) => q(e, n)
116
281
  };
282
+ return R(r, a), a;
283
+ }
284
+ function z(r, t) {
285
+ T(r, t);
286
+ }
287
+ function K(r) {
288
+ return b(r);
117
289
  }
118
290
  export {
119
- p as useMap
291
+ K as getMapContext,
292
+ z as onMapReady,
293
+ Z as useMap
120
294
  };
@@ -0,0 +1,5 @@
1
+ export declare function useSelect(viewer: any, options: any): {
2
+ onSelect: (cb: (e: any) => void) => () => boolean;
3
+ clear(): void;
4
+ destroy(): void;
5
+ };
@@ -0,0 +1,29 @@
1
+ import * as Cesium from 'cesium';
2
+ /**
3
+ * 初始化地图
4
+ * @param {Cesium.Viewer} viewer 视图
5
+ * @param {any} options 配置项
6
+ */
7
+ export declare function createBaseLayer(viewer: Cesium.Viewer, options: any): void;
8
+ /**
9
+ * 创建图层
10
+ * @param {Cesium.Viewer} viewer {Map} 地图
11
+ * @param {string} layerName 图层名称
12
+ * @param {any} data 数据
13
+ * @param options 配置项
14
+ * @returns 图层
15
+ */
16
+ export declare function createLayer(viewer: Cesium.Viewer, layerName: string, data: any, options: any): any;
17
+ /**
18
+ * 创建点图层
19
+ * @param viewer 视图
20
+ * @param layerName 图层名称
21
+ * @param data 数据
22
+ * @param options 配置项
23
+ */
24
+ export declare function createPointLayer(viewer: Cesium.Viewer, layerName: string, data: any[], options: Cesium.Billboard.ConstructorOptions & {
25
+ style?: any;
26
+ getStyle?: (item: any) => any;
27
+ }): any;
28
+ export declare function createLineLayer(viewer: any, layerName: string, data: any[], options: any): void;
29
+ export declare function getLayerByName(viewer: any, layerName: any): any;
@@ -0,0 +1,16 @@
1
+ import { MapContext } from './types';
2
+ /**
3
+ * 注册地图
4
+ * @param id 地图容器的 ID (target)
5
+ */
6
+ export declare const registerMap: (id: string, context: MapContext) => void;
7
+ /**
8
+ * 获取已创建的地图上下文
9
+ * @param id 地图容器的 ID (target)
10
+ */
11
+ export declare function getMapContext(id: string): Promise<MapContext>;
12
+ /**
13
+ * 销毁并移除
14
+ */
15
+ export declare const unregisterMap: (id: string) => void;
16
+ export declare const onMapReady: (id: string, callback: (ctx: MapContext) => void) => void;
@@ -0,0 +1,56 @@
1
+ import * as Cesium from 'cesium';
2
+ export interface flyOptions {
3
+ heading?: number;
4
+ pitch?: number;
5
+ roll?: number;
6
+ duration?: number;
7
+ maxHeight?: number;
8
+ easing?: (t: number) => number;
9
+ }
10
+ export interface LayerOptions {
11
+ name?: string;
12
+ type?: string;
13
+ data?: any;
14
+ style?: any;
15
+ visible?: boolean;
16
+ opacity?: number;
17
+ interactive?: boolean;
18
+ }
19
+ export interface SelectResult {
20
+ billboard: Cesium.Billboard;
21
+ properties: any;
22
+ event: Cesium.Cartesian2;
23
+ pick: any;
24
+ }
25
+ export interface UseSelectResult {
26
+ onSelect: (result: (SelectResult: any) => void) => void;
27
+ clear: () => void;
28
+ destroy: () => void;
29
+ }
30
+ export type Coordinates = [number, number, number];
31
+ export interface MapContext {
32
+ targetId: string;
33
+ instance: Cesium.Viewer;
34
+ addMarker: (layerName: string, data: any, options?: LayerOptions) => void;
35
+ createLayer: (layerName: string, data: any, options?: LayerOptions) => Layer;
36
+ removeLayer: (layerName: string) => void;
37
+ visibleLayer: (layerName: string, visible: boolean) => Layer;
38
+ getLayerByName: (layerName: string) => Layer;
39
+ getSourceByName: (layerName: string) => Source;
40
+ getLonLat: (data: any) => [number, number];
41
+ createBlankLayer: (layerName: string, options: LayerOptions) => Layer;
42
+ lightFeature: (layerName: string, feature: FeatureLike, options: HighLightOptions, zoomFlag: boolean) => void;
43
+ flashFeature: (layerName: string, feature: FeatureLike & customFeature, options: FlashOptions) => void;
44
+ queryFeature: (layerName: string, properties: any) => FeatureLike;
45
+ useSelect: (options: any) => UseSelectResult;
46
+ useHover: (options: HoverOptions) => UseHoverResult;
47
+ flyTo: (coordinate: Coordinates, options: flyOptions) => Promise<boolean>;
48
+ flyHome: (duration?: number) => void;
49
+ flyToBoundingSphere: (boundingSphere: Cesium.BoundingSphere, options?: flyOptions) => Promise<boolean>;
50
+ getProjection: () => void;
51
+ getZoom: () => number;
52
+ setView: (coordinate: Coordinates, options?: flyOptions) => void;
53
+ getMapContext: (id: string) => Promise<MapContext>;
54
+ onMapReady: (id: string, callback: () => void) => void;
55
+ destroyMap: (id: string) => void;
56
+ }
package/dist/index.d.ts CHANGED
@@ -1,2 +1,25 @@
1
1
  export declare const version = "1.0.0";
2
2
  export declare const author = "zhangjianfeng";
3
+ type dataType = {
4
+ lttd?: number;
5
+ lgtd?: number;
6
+ } & {
7
+ jd?: number;
8
+ wd?: number;
9
+ } & {
10
+ latitude?: number;
11
+ longitude?: number;
12
+ } & {
13
+ lon?: number;
14
+ lat?: number;
15
+ };
16
+ /**
17
+ * 解析出数据中的经纬度
18
+ * @param data 数据
19
+ * @returns [经度, 纬度]
20
+ */
21
+ export declare function getLonLat(data: dataType, options?: {
22
+ lonLabel: string;
23
+ latLabel: string;
24
+ }): [number, number];
25
+ export {};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="1.0.0",o="zhangjianfeng";exports.author=o;exports.version=e;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r="1.0.0",u="zhangjianfeng";function n(e,l){return typeof e!="object"||e===null?null:l&&l.lonLabel&&l.latLabel?[Number(e[l.lonLabel]),Number(e[l.latLabel])]:e.lttd&&e.lgtd?[Number(e.lgtd),Number(e.lttd)]:e.jd&&e.wd?[Number(e.jd),Number(e.wd)]:e.latitude&&e.longitude?[Number(e.longitude),Number(e.latitude)]:e.lon&&e.lat?[Number(e.lon),Number(e.lat)]:null}exports.author=u;exports.getLonLat=n;exports.version=r;
package/dist/index.mjs CHANGED
@@ -1,5 +1,9 @@
1
- const n = "1.0.0", o = "zhangjianfeng";
1
+ const r = "1.0.0", u = "zhangjianfeng";
2
+ function n(e, l) {
3
+ return typeof e != "object" || e === null ? null : l && l.lonLabel && l.latLabel ? [Number(e[l.lonLabel]), Number(e[l.latLabel])] : e.lttd && e.lgtd ? [Number(e.lgtd), Number(e.lttd)] : e.jd && e.wd ? [Number(e.jd), Number(e.wd)] : e.latitude && e.longitude ? [Number(e.longitude), Number(e.latitude)] : e.lon && e.lat ? [Number(e.lon), Number(e.lat)] : null;
4
+ }
2
5
  export {
3
- o as author,
4
- n as version
6
+ u as author,
7
+ n as getLonLat,
8
+ r as version
5
9
  };
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jgis",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "快速创建二维、三维工具库",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -1,23 +0,0 @@
1
- import { Map } from 'ol';
2
- import { JGisInstance, JGisConfig, JGisInitOptions } from './types';
3
- export default class JGis implements JGisInstance {
4
- protected Map: Map;
5
- protected config: JGisConfig;
6
- constructor(map: Map, options: JGisConfig);
7
- init(options: JGisInitOptions): void;
8
- /**
9
- * 移动事件
10
- * @param options
11
- */
12
- private moveEvent;
13
- /**
14
- * 点击事件
15
- * @param options
16
- */
17
- private clickEvent;
18
- private handleClick;
19
- /**
20
- * 清除选中要素
21
- */
22
- clearSelectFeature(): void;
23
- }