@tianditu/core 0.1.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/LICENSE +21 -0
- package/README.md +68 -0
- package/dist/index.d.mts +662 -0
- package/dist/index.mjs +1617 -0
- package/package.json +53 -0
- package/types/base.d.ts +97 -0
- package/types/control/control.d.ts +55 -0
- package/types/control/copyright.d.ts +30 -0
- package/types/control/index.d.ts +6 -0
- package/types/control/mapType.d.ts +63 -0
- package/types/control/overviewMap.d.ts +64 -0
- package/types/control/scale.d.ts +17 -0
- package/types/control/zoom.d.ts +24 -0
- package/types/global.d.mts +2 -0
- package/types/index.d.ts +19 -0
- package/types/layer/gridlineLayer.d.ts +33 -0
- package/types/layer/index.d.ts +4 -0
- package/types/layer/tdt.d.ts +14 -0
- package/types/layer/tileLayer.d.ts +78 -0
- package/types/layer/wms.d.ts +24 -0
- package/types/map.d.ts +290 -0
- package/types/militarySymbols/base.d.ts +71 -0
- package/types/militarySymbols/control.d.ts +24 -0
- package/types/militarySymbols/entities.d.ts +547 -0
- package/types/militarySymbols/index.d.ts +4 -0
- package/types/militarySymbols/tools.d.ts +191 -0
- package/types/modular.d.ts +258 -0
- package/types/mousetool/circleTool.d.ts +32 -0
- package/types/mousetool/coordinatePickup.d.ts +28 -0
- package/types/mousetool/index.d.ts +8 -0
- package/types/mousetool/markTool.d.ts +40 -0
- package/types/mousetool/mousetool.d.ts +28 -0
- package/types/mousetool/paintBrushTool.d.ts +23 -0
- package/types/mousetool/polygonTool.d.ts +47 -0
- package/types/mousetool/polylineTool.d.ts +47 -0
- package/types/mousetool/rectangleTool.d.ts +28 -0
- package/types/overlay/circle.d.ts +67 -0
- package/types/overlay/cloudMarkerCollection.d.ts +50 -0
- package/types/overlay/contextMenu.d.ts +75 -0
- package/types/overlay/icon.d.ts +33 -0
- package/types/overlay/index.d.ts +13 -0
- package/types/overlay/infowindow.d.ts +59 -0
- package/types/overlay/label.d.ts +53 -0
- package/types/overlay/marker.d.ts +50 -0
- package/types/overlay/markerClusterer.d.ts +103 -0
- package/types/overlay/overlay.d.ts +109 -0
- package/types/overlay/polygon.d.ts +59 -0
- package/types/overlay/polyline.d.ts +47 -0
- package/types/overlay/rectangle.d.ts +57 -0
- package/types/overlay/svg.d.ts +19 -0
- package/types/service/administrativeDivision.d.ts +48 -0
- package/types/service/busLineSearch.d.ts +89 -0
- package/types/service/dataSources.d.ts +30 -0
- package/types/service/drivingRoute.d.ts +135 -0
- package/types/service/geocoder.d.ts +47 -0
- package/types/service/geolocation.d.ts +39 -0
- package/types/service/index.d.ts +9 -0
- package/types/service/localCity.d.ts +24 -0
- package/types/service/localSearch.d.ts +178 -0
- package/types/service/transitRoute.d.ts +132 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,1617 @@
|
|
|
1
|
+
import { effect, stop } from "@vue/reactivity";
|
|
2
|
+
//#region src/events.ts
|
|
3
|
+
var EventBridge = class {
|
|
4
|
+
constructor(target) {
|
|
5
|
+
this.target = target;
|
|
6
|
+
this.listeners = [];
|
|
7
|
+
}
|
|
8
|
+
/** 注册监听器,返回解绑函数 */
|
|
9
|
+
on(event, handler) {
|
|
10
|
+
this.target.addEventListener(event, handler);
|
|
11
|
+
this.listeners.push([event, handler]);
|
|
12
|
+
return () => this.off(event, handler);
|
|
13
|
+
}
|
|
14
|
+
off(event, handler) {
|
|
15
|
+
this.target.removeEventListener(event, handler);
|
|
16
|
+
const index = this.listeners.findIndex(([e, h]) => e === event && h === handler);
|
|
17
|
+
if (index >= 0) this.listeners.splice(index, 1);
|
|
18
|
+
}
|
|
19
|
+
/** 移除全部经由本桥注册的监听器 */
|
|
20
|
+
destroy() {
|
|
21
|
+
for (const [event, handler] of this.listeners.splice(0)) this.target.removeEventListener(event, handler);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* 以宽松事件签名挂接命名事件集。SDK 侧(Mousetool/TileLayer 等)的事件
|
|
26
|
+
* 方法为泛型签名(keyof E),跨实体统一挂接时按宽签名收口;
|
|
27
|
+
* 目标缺少事件 API 时静默跳过。
|
|
28
|
+
*/
|
|
29
|
+
function bindEventNames(target, names, dispatch) {
|
|
30
|
+
const bridge = target;
|
|
31
|
+
const listeners = [];
|
|
32
|
+
for (const name of names) {
|
|
33
|
+
const handler = (event) => dispatch(name, event);
|
|
34
|
+
bridge.addEventListener?.(name, handler);
|
|
35
|
+
listeners.push([name, handler]);
|
|
36
|
+
}
|
|
37
|
+
return () => {
|
|
38
|
+
for (const [name, handler] of listeners.splice(0)) bridge.removeEventListener?.(name, handler);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/compact.ts
|
|
43
|
+
/**
|
|
44
|
+
* SDK 构造参数对显式 undefined 与字段默认不等价(如控件 options 携带
|
|
45
|
+
* position: undefined 时 addControl 直接报错),构造前统一剔除。
|
|
46
|
+
*/
|
|
47
|
+
function compact(options) {
|
|
48
|
+
return Object.fromEntries(Object.entries(options).filter(([, value]) => value !== void 0));
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/loader.ts
|
|
52
|
+
const DEFAULT_VERSION = "4.0";
|
|
53
|
+
const DEFAULT_BASE_URL = "https://api.tianditu.gov.cn";
|
|
54
|
+
const LOAD_TIMEOUT = 3e4;
|
|
55
|
+
let pending;
|
|
56
|
+
function loadTdt(options) {
|
|
57
|
+
if (globalThis.T) return Promise.resolve(globalThis.T);
|
|
58
|
+
if (pending) return pending;
|
|
59
|
+
const version = options.version ?? DEFAULT_VERSION;
|
|
60
|
+
const baseURL = options.baseURL ?? DEFAULT_BASE_URL;
|
|
61
|
+
pending = (async () => {
|
|
62
|
+
try {
|
|
63
|
+
if (typeof document === "undefined") throw new Error("[tianditu] loadTdt 只能在浏览器环境中调用");
|
|
64
|
+
const mainScript = await fetchText(`${baseURL}/api?v=${version}&tk=${options.tk}`, LOAD_TIMEOUT);
|
|
65
|
+
try {
|
|
66
|
+
await primeComponentCache(baseURL, mainScript);
|
|
67
|
+
} catch {}
|
|
68
|
+
runMainScript(mainScript);
|
|
69
|
+
if (!globalThis.T) throw new Error("[tianditu] SDK 脚本已执行但 window.T 不可用,请检查 tk 是否有效");
|
|
70
|
+
await repairComponentPacks(baseURL, version);
|
|
71
|
+
return globalThis.T;
|
|
72
|
+
} catch (error) {
|
|
73
|
+
pending = void 0;
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
})();
|
|
77
|
+
return pending;
|
|
78
|
+
}
|
|
79
|
+
function fetchText(url, timeout) {
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
const controller = new AbortController();
|
|
82
|
+
const timer = setTimeout(() => {
|
|
83
|
+
controller.abort();
|
|
84
|
+
reject(/* @__PURE__ */ new Error(`[tianditu] SDK 脚本加载超时:${url}`));
|
|
85
|
+
}, timeout);
|
|
86
|
+
fetch(url, { signal: controller.signal }).then((response) => {
|
|
87
|
+
clearTimeout(timer);
|
|
88
|
+
if (!response.ok) throw new Error(`[tianditu] SDK 脚本加载失败(HTTP ${response.status}):${url}`);
|
|
89
|
+
return response.text();
|
|
90
|
+
}).then(resolve).catch((error) => {
|
|
91
|
+
clearTimeout(timer);
|
|
92
|
+
reject(error);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/** 从主脚本文本提取组件包清单(A:[...])与缓存版本号(ZR:"...") */
|
|
97
|
+
function parseComponentMeta(mainScript) {
|
|
98
|
+
const files = mainScript.match(/A:(\["[^\]]*"\])/)?.[1];
|
|
99
|
+
const cacheVersion = mainScript.match(/ZR:"([^"]+)"/)?.[1];
|
|
100
|
+
if (!files || !cacheVersion) return;
|
|
101
|
+
try {
|
|
102
|
+
return {
|
|
103
|
+
files: JSON.parse(files),
|
|
104
|
+
cacheVersion
|
|
105
|
+
};
|
|
106
|
+
} catch {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* 预填 SDK 组件包缓存:主脚本执行时按 `TDT_components{i}` 检查 localStorage,
|
|
112
|
+
* 命中即同步顺序执行。这里并行拉取、按序写入,使首次访问也走命中路径。
|
|
113
|
+
*/
|
|
114
|
+
async function primeComponentCache(baseURL, mainScript) {
|
|
115
|
+
const meta = parseComponentMeta(mainScript);
|
|
116
|
+
if (!meta) return;
|
|
117
|
+
const versionMatched = localStorage.getItem("TDT_version") === meta.cacheVersion;
|
|
118
|
+
await Promise.all(meta.files.map(async (file, index) => {
|
|
119
|
+
const key = `TDT_components${index}`;
|
|
120
|
+
if (versionMatched && localStorage.getItem(key)) return;
|
|
121
|
+
const code = await fetchText(`${baseURL}${file}`, LOAD_TIMEOUT);
|
|
122
|
+
localStorage.setItem(key, code);
|
|
123
|
+
}));
|
|
124
|
+
localStorage.setItem("TDT_version", meta.cacheVersion);
|
|
125
|
+
}
|
|
126
|
+
/** 内联执行主脚本(同步),保持全局作用域与官方 script 标签一致 */
|
|
127
|
+
function runMainScript(code) {
|
|
128
|
+
const script = document.createElement("script");
|
|
129
|
+
script.text = code;
|
|
130
|
+
document.head.appendChild(script);
|
|
131
|
+
script.remove();
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* SDK 组件包就绪哨兵:哨兵存在即该包执行完整。补载前先等 SDK 自身的
|
|
135
|
+
* 加载波结束(键数稳定),避免与飞行中的包重复执行;补载重执行类定义
|
|
136
|
+
* 为幂等覆写,且发生在任何用户实例构造之前,安全。
|
|
137
|
+
*/
|
|
138
|
+
const COMPONENT_PACKS = [
|
|
139
|
+
{
|
|
140
|
+
file: "components.js",
|
|
141
|
+
ready: () => typeof T.PolylineTool === "function"
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
file: "service.js",
|
|
145
|
+
ready: () => typeof T.LocalSearch === "function"
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
file: "military.js",
|
|
149
|
+
ready: () => typeof T.Control?.militarySymbols === "function"
|
|
150
|
+
}
|
|
151
|
+
];
|
|
152
|
+
async function repairComponentPacks(baseURL, version) {
|
|
153
|
+
if (COMPONENT_PACKS.every((pack) => pack.ready())) return;
|
|
154
|
+
await waitModulesSettled();
|
|
155
|
+
for (const pack of COMPONENT_PACKS) {
|
|
156
|
+
if (pack.ready()) continue;
|
|
157
|
+
await injectScript(`${baseURL}/v${version}/${pack.file}`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/** 重新注入组件包脚本,等待其执行完成 */
|
|
161
|
+
function injectScript(url) {
|
|
162
|
+
return new Promise((resolve, reject) => {
|
|
163
|
+
const script = document.createElement("script");
|
|
164
|
+
const timer = setTimeout(() => {
|
|
165
|
+
script.onload = script.onerror = null;
|
|
166
|
+
reject(/* @__PURE__ */ new Error(`[tianditu] 组件包加载超时:${url}`));
|
|
167
|
+
}, LOAD_TIMEOUT);
|
|
168
|
+
script.onload = () => {
|
|
169
|
+
clearTimeout(timer);
|
|
170
|
+
resolve();
|
|
171
|
+
};
|
|
172
|
+
script.onerror = () => {
|
|
173
|
+
clearTimeout(timer);
|
|
174
|
+
reject(/* @__PURE__ */ new Error(`[tianditu] 组件包加载失败:${url}`));
|
|
175
|
+
};
|
|
176
|
+
script.src = url;
|
|
177
|
+
document.head.appendChild(script);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
/** 轮询到模块清单连续稳定即认为 SDK 自身加载波结束;限时兜底 */
|
|
181
|
+
function waitModulesSettled(timeout = 5e3) {
|
|
182
|
+
return new Promise((resolve) => {
|
|
183
|
+
const started = Date.now();
|
|
184
|
+
let lastCount = NaN;
|
|
185
|
+
let stableRounds = 0;
|
|
186
|
+
const poll = setInterval(() => {
|
|
187
|
+
const count = Object.keys(globalThis.T ?? {}).length;
|
|
188
|
+
stableRounds = count === lastCount ? stableRounds + 1 : 0;
|
|
189
|
+
lastCount = count;
|
|
190
|
+
if (stableRounds >= 5 || Date.now() - started > timeout) {
|
|
191
|
+
clearInterval(poll);
|
|
192
|
+
resolve();
|
|
193
|
+
}
|
|
194
|
+
}, 150);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
const NOT_READY_PATTERN = / is not a (?:constructor|function)$/;
|
|
198
|
+
/**
|
|
199
|
+
* 构造就绪守卫:SDK 扩展类构造过早会抛 "is not a constructor",此类
|
|
200
|
+
* 时序错误按固定间隔重试直至成功;超时抛出最后一次的真实错误,其余
|
|
201
|
+
* 错误立即抛出。
|
|
202
|
+
*/
|
|
203
|
+
async function createWhenReady(create, timeout = LOAD_TIMEOUT) {
|
|
204
|
+
const started = Date.now();
|
|
205
|
+
for (;;) try {
|
|
206
|
+
return create();
|
|
207
|
+
} catch (error) {
|
|
208
|
+
if (!(error instanceof TypeError && NOT_READY_PATTERN.test(error.message.trim())) || Date.now() - started > timeout) throw error;
|
|
209
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/session.ts
|
|
214
|
+
/** 官方示例通用的默认中心(北京)与级别 */
|
|
215
|
+
const DEFAULT_CENTER = [116.404, 39.915];
|
|
216
|
+
/** 各级定位的最长等待 */
|
|
217
|
+
const LOCATE_TIMEOUT = 3e3;
|
|
218
|
+
/** 官方 IP 定位接口,返回 {code, data: {lng, lat, city, level}},CORS 全开 */
|
|
219
|
+
const IP_LOCATE_URL = "https://location.tianditu.gov.cn/data/getCityName";
|
|
220
|
+
/**
|
|
221
|
+
* 浏览器定位(高精度)。locate 为显式开启的选项,触发浏览器的授权请求
|
|
222
|
+
* 属预期语义;拒绝、失败或超时回退 undefined 交由 IP 定位兜底。
|
|
223
|
+
*/
|
|
224
|
+
function locateByGeolocation() {
|
|
225
|
+
return new Promise((resolve) => {
|
|
226
|
+
if (typeof navigator === "undefined" || !navigator.geolocation) {
|
|
227
|
+
resolve(void 0);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
navigator.geolocation.getCurrentPosition((position) => resolve([position.coords.longitude, position.coords.latitude]), () => resolve(void 0), {
|
|
231
|
+
timeout: LOCATE_TIMEOUT,
|
|
232
|
+
maximumAge: 6e5
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* 官方 IP 定位(城市级精度、无需授权),失败或超时回退 undefined。
|
|
238
|
+
*
|
|
239
|
+
* 不走 SDK 的 T.LocalCity:其内部为 JSONP 实现(script 注入
|
|
240
|
+
* location.tianditu.gov.cn/data/getCityName?callback=query),而该端点已
|
|
241
|
+
* 改版为返回裸 JSON 且字段更名(lon/lat → data.lng/data.lat),SDK 的
|
|
242
|
+
* 回调因此永远不会触发,定位静默失效。
|
|
243
|
+
*/
|
|
244
|
+
async function locateByIp() {
|
|
245
|
+
try {
|
|
246
|
+
const controller = new AbortController();
|
|
247
|
+
const timer = setTimeout(() => controller.abort(), LOCATE_TIMEOUT);
|
|
248
|
+
const response = await fetch(IP_LOCATE_URL, { signal: controller.signal });
|
|
249
|
+
clearTimeout(timer);
|
|
250
|
+
if (!response.ok) return;
|
|
251
|
+
const result = await response.json();
|
|
252
|
+
const lng = Number(result.data?.lng);
|
|
253
|
+
const lat = Number(result.data?.lat);
|
|
254
|
+
return result.code === 200 && Number.isFinite(lng) && Number.isFinite(lat) ? [lng, lat] : void 0;
|
|
255
|
+
} catch {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
/** 默认中心:按模式定位,各级失败逐级回退至 DEFAULT_CENTER */
|
|
260
|
+
async function resolveDefaultCenter(mode) {
|
|
261
|
+
if (mode !== "ip") {
|
|
262
|
+
const located = await locateByGeolocation();
|
|
263
|
+
if (located) return located;
|
|
264
|
+
}
|
|
265
|
+
if (mode !== "geolocation") {
|
|
266
|
+
const located = await locateByIp();
|
|
267
|
+
if (located) return located;
|
|
268
|
+
}
|
|
269
|
+
return DEFAULT_CENTER;
|
|
270
|
+
}
|
|
271
|
+
async function createMapSession(el, options) {
|
|
272
|
+
await loadTdt({
|
|
273
|
+
tk: options.tk,
|
|
274
|
+
version: options.version,
|
|
275
|
+
baseURL: options.baseURL
|
|
276
|
+
});
|
|
277
|
+
const locate = options.locate;
|
|
278
|
+
const center = toLngLat(options.center ?? (locate ? await resolveDefaultCenter(locate === true ? "auto" : locate) : DEFAULT_CENTER));
|
|
279
|
+
const zoom = options.zoom ?? 12;
|
|
280
|
+
const map = new T.Map(el, compact({
|
|
281
|
+
projection: options.projection,
|
|
282
|
+
minZoom: options.minZoom,
|
|
283
|
+
maxZoom: options.maxZoom,
|
|
284
|
+
maxBounds: options.maxBounds,
|
|
285
|
+
center,
|
|
286
|
+
zoom
|
|
287
|
+
}));
|
|
288
|
+
map.centerAndZoom(center, zoom);
|
|
289
|
+
const events = new EventBridge(map);
|
|
290
|
+
return {
|
|
291
|
+
map,
|
|
292
|
+
el,
|
|
293
|
+
events,
|
|
294
|
+
setCenter(value) {
|
|
295
|
+
map.centerAndZoom(toLngLat(value), map.getZoom());
|
|
296
|
+
},
|
|
297
|
+
destroy() {
|
|
298
|
+
events.destroy();
|
|
299
|
+
map.clearOverLays();
|
|
300
|
+
map.clearLayers();
|
|
301
|
+
el.innerHTML = "";
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
function toLngLat(value) {
|
|
306
|
+
return Array.isArray(value) ? new T.LngLat(value[0], value[1]) : value;
|
|
307
|
+
}
|
|
308
|
+
function toLngLats(value) {
|
|
309
|
+
return value.map(toLngLat);
|
|
310
|
+
}
|
|
311
|
+
//#endregion
|
|
312
|
+
//#region src/props-sync.ts
|
|
313
|
+
/**
|
|
314
|
+
* 跟踪 target 与 props 两个响应式源:props 变化时按 key 浅比较后调用对应
|
|
315
|
+
* setter;首次执行或 target 就绪(从未就绪变为就绪)时对所有 key 做一次
|
|
316
|
+
* 全量应用(skipInitialApply 为 true 时跳过,适用于构造时已携带全部
|
|
317
|
+
* props 的实例,避免冗余 setter 调用)。返回 stop 函数,由适配层在卸载时调用。
|
|
318
|
+
*/
|
|
319
|
+
function createPropsSync(target, props, defs, options) {
|
|
320
|
+
let prevTarget;
|
|
321
|
+
let prevProps;
|
|
322
|
+
let initialDone = !options?.skipInitialApply;
|
|
323
|
+
const runner = effect(() => {
|
|
324
|
+
const nextTarget = target();
|
|
325
|
+
const next = props();
|
|
326
|
+
if (!nextTarget) {
|
|
327
|
+
prevTarget = void 0;
|
|
328
|
+
prevProps = next;
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
const firstReady = !prevTarget;
|
|
332
|
+
const fullApply = firstReady && initialDone;
|
|
333
|
+
const skipApply = firstReady && !initialDone;
|
|
334
|
+
initialDone = true;
|
|
335
|
+
for (const key in defs) {
|
|
336
|
+
const apply = defs[key];
|
|
337
|
+
if (!apply) continue;
|
|
338
|
+
const value = next[key];
|
|
339
|
+
const prev = prevProps?.[key];
|
|
340
|
+
if (skipApply) continue;
|
|
341
|
+
if (fullApply || !Object.is(value, prev)) apply(nextTarget, value, prev);
|
|
342
|
+
}
|
|
343
|
+
prevTarget = nextTarget;
|
|
344
|
+
prevProps = next;
|
|
345
|
+
});
|
|
346
|
+
return () => stop(runner);
|
|
347
|
+
}
|
|
348
|
+
//#endregion
|
|
349
|
+
//#region src/map.ts
|
|
350
|
+
/**
|
|
351
|
+
* Map 类的官方事件与交互开关,清单以官方 Map 文档页为准。
|
|
352
|
+
* 文档外的事件(如 dblclick/mousemove 等 SDK 内部事件)不进直发表,
|
|
353
|
+
* 可经 map 会话的事件桥命令式挂接。
|
|
354
|
+
*/
|
|
355
|
+
const MAP_EVENT_NAMES = [
|
|
356
|
+
"click",
|
|
357
|
+
"contextmenu",
|
|
358
|
+
"mouseover",
|
|
359
|
+
"movestart",
|
|
360
|
+
"moveend",
|
|
361
|
+
"zoomend",
|
|
362
|
+
"removeoverlay",
|
|
363
|
+
"removecontrol",
|
|
364
|
+
"dragstart",
|
|
365
|
+
"dragend",
|
|
366
|
+
"layerremove",
|
|
367
|
+
"resize",
|
|
368
|
+
"touchstart",
|
|
369
|
+
"touchend"
|
|
370
|
+
];
|
|
371
|
+
/** 初始化时一次性应用交互开关;未配置的项保持 SDK 默认(启用) */
|
|
372
|
+
function applyMapInteractions(map, options) {
|
|
373
|
+
const apply = (value, on, off) => {
|
|
374
|
+
if (value === void 0) return;
|
|
375
|
+
value ? on() : off();
|
|
376
|
+
};
|
|
377
|
+
apply(options.dragging, () => map.enableDrag(), () => map.disableDrag());
|
|
378
|
+
apply(options.scrollWheelZoom, () => map.enableScrollWheelZoom(), () => map.disableScrollWheelZoom());
|
|
379
|
+
apply(options.doubleClickZoom, () => map.enableDoubleClickZoom(), () => map.disableDoubleClickZoom());
|
|
380
|
+
apply(options.keyboard, () => map.enableKeyboard(), () => map.disableKeyboard());
|
|
381
|
+
apply(options.inertia, () => map.enableInertia(), () => map.disableInertia());
|
|
382
|
+
apply(options.continuousZoom, () => map.enableContinuousZoom(), () => map.disableContinuousZoom());
|
|
383
|
+
apply(options.pinchToZoom, () => map.enablePinchToZoom(), () => map.disablePinchToZoom());
|
|
384
|
+
apply(options.autoResize, () => map.enableAutoResize(), () => map.disableAutoResize());
|
|
385
|
+
}
|
|
386
|
+
//#endregion
|
|
387
|
+
//#region src/overlay.ts
|
|
388
|
+
function mountOverlay(ctx, spec) {
|
|
389
|
+
const instance = spec.create(ctx);
|
|
390
|
+
const attach = spec.attach ?? defaultAttach;
|
|
391
|
+
const detach = spec.detach ?? defaultDetach;
|
|
392
|
+
attach(instance, ctx);
|
|
393
|
+
const unbind = bindEventNames(instance, spec.events ?? [], spec.dispatch);
|
|
394
|
+
const stopSync = spec.sync ? createPropsSync(() => instance, spec.props, spec.sync, { skipInitialApply: true }) : void 0;
|
|
395
|
+
return {
|
|
396
|
+
instance,
|
|
397
|
+
context: ctx,
|
|
398
|
+
destroy() {
|
|
399
|
+
stopSync?.();
|
|
400
|
+
unbind();
|
|
401
|
+
detach(instance, ctx);
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
function defaultAttach(instance, ctx) {
|
|
406
|
+
if (ctx.collector) ctx.collector.addMarker(instance);
|
|
407
|
+
else ctx.map.addOverLay(instance);
|
|
408
|
+
}
|
|
409
|
+
function defaultDetach(instance, ctx) {
|
|
410
|
+
if (ctx.collector) ctx.collector.removeMarker(instance);
|
|
411
|
+
else ctx.map.removeOverLay(instance);
|
|
412
|
+
}
|
|
413
|
+
//#endregion
|
|
414
|
+
//#region src/infoWindow.ts
|
|
415
|
+
const INFO_WINDOW_EVENT_NAMES = [
|
|
416
|
+
"open",
|
|
417
|
+
"close",
|
|
418
|
+
"clickclose"
|
|
419
|
+
];
|
|
420
|
+
function createInfoWindow(spec, dispatch) {
|
|
421
|
+
const container = spec.content instanceof HTMLElement ? spec.content : document.createElement("div");
|
|
422
|
+
const win = new T.InfoWindow(container, compact({
|
|
423
|
+
minWidth: spec.minWidth,
|
|
424
|
+
maxWidth: spec.maxWidth,
|
|
425
|
+
maxHeight: spec.maxHeight,
|
|
426
|
+
autoPan: spec.autoPan,
|
|
427
|
+
closeButton: spec.closeButton,
|
|
428
|
+
offset: spec.offset,
|
|
429
|
+
autoPanPadding: spec.autoPanPadding,
|
|
430
|
+
closeOnClick: spec.closeOnClick
|
|
431
|
+
}));
|
|
432
|
+
const unbind = bindEventNames(win, INFO_WINDOW_EVENT_NAMES, (name, event) => dispatch(name, event));
|
|
433
|
+
return {
|
|
434
|
+
win,
|
|
435
|
+
container,
|
|
436
|
+
openOn(host, lnglat) {
|
|
437
|
+
if (host instanceof T.Map) host.openInfoWindow(win, lnglat ? toLngLat(lnglat) : host.getCenter());
|
|
438
|
+
else host.openInfoWindow(win);
|
|
439
|
+
},
|
|
440
|
+
close() {
|
|
441
|
+
win.closeInfoWindow();
|
|
442
|
+
},
|
|
443
|
+
isOpen() {
|
|
444
|
+
return win.isOpen();
|
|
445
|
+
},
|
|
446
|
+
destroy() {
|
|
447
|
+
unbind();
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
//#endregion
|
|
452
|
+
//#region src/tools.ts
|
|
453
|
+
/**
|
|
454
|
+
* 地图工具(Mousetool 体系及 CoordinatePickup)的协议与生命周期编排。
|
|
455
|
+
*
|
|
456
|
+
* Mousetool 基类以 open/close 开关并暴露泛型事件签名;CoordinatePickup
|
|
457
|
+
* 以 addEvent/removeEvent 开关且无事件监听,因此协议只约定开关动作,
|
|
458
|
+
* 事件按宽松签名挂接。
|
|
459
|
+
*/
|
|
460
|
+
function mountTool(options) {
|
|
461
|
+
const tool = options.create();
|
|
462
|
+
const activate = options.activate ?? ((current) => current.open?.());
|
|
463
|
+
const deactivate = options.deactivate ?? ((current) => current.close?.());
|
|
464
|
+
const unbind = bindEventNames(tool, options.events ?? [], options.dispatch);
|
|
465
|
+
let active;
|
|
466
|
+
return {
|
|
467
|
+
tool,
|
|
468
|
+
setActive(value) {
|
|
469
|
+
if (value === active) return;
|
|
470
|
+
active = value;
|
|
471
|
+
value ? activate(tool) : deactivate(tool);
|
|
472
|
+
},
|
|
473
|
+
destroy() {
|
|
474
|
+
unbind();
|
|
475
|
+
deactivate(tool);
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
//#endregion
|
|
480
|
+
//#region src/layer.ts
|
|
481
|
+
/**
|
|
482
|
+
* 瓦片图层的挂载与事件编排。图层构造(TileLayer/TileLayerWMS/GridlineLayer)
|
|
483
|
+
* 由调用方完成,此处统一处理上屏、事件挂接与卸载。
|
|
484
|
+
*/
|
|
485
|
+
const TILE_LAYER_EVENT_NAMES = [
|
|
486
|
+
"loading",
|
|
487
|
+
"load",
|
|
488
|
+
"tileloadstart",
|
|
489
|
+
"tileload",
|
|
490
|
+
"tileunload",
|
|
491
|
+
"tileerror"
|
|
492
|
+
];
|
|
493
|
+
/** 挂接事件并上屏,返回卸载函数(解绑事件 + removeLayer) */
|
|
494
|
+
function mountTileLayer(options) {
|
|
495
|
+
const { map, layer } = options;
|
|
496
|
+
const unbind = bindEventNames(layer, options.events ?? TILE_LAYER_EVENT_NAMES, options.dispatch);
|
|
497
|
+
map.addLayer(layer);
|
|
498
|
+
return () => {
|
|
499
|
+
unbind();
|
|
500
|
+
map.removeLayer(layer);
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
//#endregion
|
|
504
|
+
//#region src/defs/converters.ts
|
|
505
|
+
/**
|
|
506
|
+
* WC attribute 字符串的解析器,供 defs 的 PropDef.converter 声明。
|
|
507
|
+
* 分隔约定:坐标 "lng,lat",坐标集合用 ";" 分段。
|
|
508
|
+
*/
|
|
509
|
+
function parseLnglat(value) {
|
|
510
|
+
const [lng, lat] = value.split(",").map(Number);
|
|
511
|
+
return [lng, lat];
|
|
512
|
+
}
|
|
513
|
+
function parsePath(value) {
|
|
514
|
+
return value.split(";").map((pair) => pair.trim()).filter(Boolean).map(parseLnglat);
|
|
515
|
+
}
|
|
516
|
+
/** "swLng,swLat;neLng,neLat" → [[swLng, swLat], [neLng, neLat]] */
|
|
517
|
+
function parseBounds(value) {
|
|
518
|
+
const [sw, ne] = value.split(";").map(parseLnglat);
|
|
519
|
+
return [sw, ne];
|
|
520
|
+
}
|
|
521
|
+
/** "w,h" → [width, height] */
|
|
522
|
+
function parseSize(value) {
|
|
523
|
+
const [w, h] = value.split(",").map(Number);
|
|
524
|
+
return [w, h];
|
|
525
|
+
}
|
|
526
|
+
function parseJson(value) {
|
|
527
|
+
return JSON.parse(value);
|
|
528
|
+
}
|
|
529
|
+
//#endregion
|
|
530
|
+
//#region src/defs/controls.ts
|
|
531
|
+
const zoomDef = {
|
|
532
|
+
name: "TdtControlZoom",
|
|
533
|
+
tag: "tdt-control-zoom",
|
|
534
|
+
props: {
|
|
535
|
+
position: {
|
|
536
|
+
type: String,
|
|
537
|
+
default: void 0,
|
|
538
|
+
attribute: "position"
|
|
539
|
+
},
|
|
540
|
+
zoomInText: {
|
|
541
|
+
type: String,
|
|
542
|
+
default: void 0,
|
|
543
|
+
attribute: "zoom-in-text"
|
|
544
|
+
},
|
|
545
|
+
zoomOutText: {
|
|
546
|
+
type: String,
|
|
547
|
+
default: void 0,
|
|
548
|
+
attribute: "zoom-out-text"
|
|
549
|
+
},
|
|
550
|
+
zoomInTitle: {
|
|
551
|
+
type: String,
|
|
552
|
+
default: void 0,
|
|
553
|
+
attribute: "zoom-in-title"
|
|
554
|
+
},
|
|
555
|
+
zoomOutTitle: {
|
|
556
|
+
type: String,
|
|
557
|
+
default: void 0,
|
|
558
|
+
attribute: "zoom-out-title"
|
|
559
|
+
}
|
|
560
|
+
},
|
|
561
|
+
create: (props) => new T.Control.Zoom(compact({
|
|
562
|
+
position: props.position,
|
|
563
|
+
zoomInText: props.zoomInText,
|
|
564
|
+
zoomOutText: props.zoomOutText,
|
|
565
|
+
zoomInTitle: props.zoomInTitle,
|
|
566
|
+
zoomOutTitle: props.zoomOutTitle
|
|
567
|
+
}))
|
|
568
|
+
};
|
|
569
|
+
const scaleDef = {
|
|
570
|
+
name: "TdtControlScale",
|
|
571
|
+
tag: "tdt-control-scale",
|
|
572
|
+
props: {
|
|
573
|
+
position: {
|
|
574
|
+
type: String,
|
|
575
|
+
default: void 0,
|
|
576
|
+
attribute: "position"
|
|
577
|
+
},
|
|
578
|
+
color: {
|
|
579
|
+
type: String,
|
|
580
|
+
default: void 0,
|
|
581
|
+
attribute: "color"
|
|
582
|
+
}
|
|
583
|
+
},
|
|
584
|
+
create: (props) => {
|
|
585
|
+
const control = new T.Control.Scale(compact({ position: props.position }));
|
|
586
|
+
if (props.color !== void 0) control.setColor(props.color);
|
|
587
|
+
return control;
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
function toBounds$1(value) {
|
|
591
|
+
if (!value) return;
|
|
592
|
+
if (Array.isArray(value)) {
|
|
593
|
+
const [[swLng, swLat], [neLng, neLat]] = value;
|
|
594
|
+
return new T.LngLatBounds(new T.LngLat(swLng, swLat), new T.LngLat(neLng, neLat));
|
|
595
|
+
}
|
|
596
|
+
return value;
|
|
597
|
+
}
|
|
598
|
+
const copyrightDef = {
|
|
599
|
+
name: "TdtControlCopyright",
|
|
600
|
+
tag: "tdt-control-copyright",
|
|
601
|
+
props: {
|
|
602
|
+
position: {
|
|
603
|
+
type: String,
|
|
604
|
+
default: void 0,
|
|
605
|
+
attribute: "position"
|
|
606
|
+
},
|
|
607
|
+
id: {
|
|
608
|
+
type: String,
|
|
609
|
+
default: void 0,
|
|
610
|
+
attribute: "id"
|
|
611
|
+
},
|
|
612
|
+
content: {
|
|
613
|
+
type: String,
|
|
614
|
+
default: void 0,
|
|
615
|
+
attribute: "content"
|
|
616
|
+
},
|
|
617
|
+
bounds: {
|
|
618
|
+
type: Array,
|
|
619
|
+
default: void 0,
|
|
620
|
+
attribute: "bounds",
|
|
621
|
+
converter: parseBounds
|
|
622
|
+
}
|
|
623
|
+
},
|
|
624
|
+
create: (props) => new T.Control.Copyright(compact({
|
|
625
|
+
position: props.position,
|
|
626
|
+
id: props.id,
|
|
627
|
+
content: props.content,
|
|
628
|
+
bounds: toBounds$1(props.bounds)
|
|
629
|
+
}))
|
|
630
|
+
};
|
|
631
|
+
const overviewMapDef = {
|
|
632
|
+
name: "TdtControlOverviewMap",
|
|
633
|
+
tag: "tdt-control-overview-map",
|
|
634
|
+
props: {
|
|
635
|
+
position: {
|
|
636
|
+
type: String,
|
|
637
|
+
default: void 0,
|
|
638
|
+
attribute: "position"
|
|
639
|
+
},
|
|
640
|
+
size: {
|
|
641
|
+
type: Array,
|
|
642
|
+
default: void 0,
|
|
643
|
+
attribute: "size",
|
|
644
|
+
converter: parseSize
|
|
645
|
+
},
|
|
646
|
+
isOpen: {
|
|
647
|
+
type: Boolean,
|
|
648
|
+
default: void 0,
|
|
649
|
+
attribute: "is-open"
|
|
650
|
+
}
|
|
651
|
+
},
|
|
652
|
+
create: (props) => new T.Control.OverviewMap(compact({
|
|
653
|
+
anchor: props.position,
|
|
654
|
+
size: props.size ? new T.Point(props.size[0], props.size[1]) : void 0,
|
|
655
|
+
isOpen: props.isOpen
|
|
656
|
+
}))
|
|
657
|
+
};
|
|
658
|
+
const mapTypeDef = {
|
|
659
|
+
name: "TdtControlMapType",
|
|
660
|
+
tag: "tdt-control-map-type",
|
|
661
|
+
props: {
|
|
662
|
+
position: {
|
|
663
|
+
type: String,
|
|
664
|
+
default: void 0,
|
|
665
|
+
attribute: "position"
|
|
666
|
+
},
|
|
667
|
+
mapTypes: {
|
|
668
|
+
type: Array,
|
|
669
|
+
default: void 0
|
|
670
|
+
}
|
|
671
|
+
},
|
|
672
|
+
create: (props) => new T.Control.MapType(compact({
|
|
673
|
+
position: props.position,
|
|
674
|
+
mapTypes: props.mapTypes
|
|
675
|
+
}))
|
|
676
|
+
};
|
|
677
|
+
//#endregion
|
|
678
|
+
//#region src/defs/overlays.ts
|
|
679
|
+
function toIcon(value) {
|
|
680
|
+
return value instanceof T.Icon ? value : new T.Icon(value);
|
|
681
|
+
}
|
|
682
|
+
const markerDef = {
|
|
683
|
+
name: "TdtMarker",
|
|
684
|
+
tag: "tdt-marker",
|
|
685
|
+
props: {
|
|
686
|
+
lnglat: {
|
|
687
|
+
type: Array,
|
|
688
|
+
required: true,
|
|
689
|
+
attribute: "lnglat",
|
|
690
|
+
converter: parseLnglat
|
|
691
|
+
},
|
|
692
|
+
icon: {
|
|
693
|
+
type: Object,
|
|
694
|
+
default: void 0,
|
|
695
|
+
attribute: "icon",
|
|
696
|
+
converter: parseJson
|
|
697
|
+
},
|
|
698
|
+
draggable: {
|
|
699
|
+
type: Boolean,
|
|
700
|
+
default: false,
|
|
701
|
+
attribute: "draggable"
|
|
702
|
+
},
|
|
703
|
+
title: {
|
|
704
|
+
type: String,
|
|
705
|
+
default: void 0,
|
|
706
|
+
attribute: "title"
|
|
707
|
+
},
|
|
708
|
+
zIndexOffset: {
|
|
709
|
+
type: Number,
|
|
710
|
+
default: void 0,
|
|
711
|
+
attribute: "z-index-offset"
|
|
712
|
+
},
|
|
713
|
+
opacity: {
|
|
714
|
+
type: Number,
|
|
715
|
+
default: void 0,
|
|
716
|
+
attribute: "opacity"
|
|
717
|
+
}
|
|
718
|
+
},
|
|
719
|
+
events: [
|
|
720
|
+
"click",
|
|
721
|
+
"dblclick",
|
|
722
|
+
"mousedown",
|
|
723
|
+
"mouseup",
|
|
724
|
+
"mouseover",
|
|
725
|
+
"mouseout",
|
|
726
|
+
"dragstart",
|
|
727
|
+
"drag",
|
|
728
|
+
"dragend",
|
|
729
|
+
"remove"
|
|
730
|
+
],
|
|
731
|
+
create: (props) => new T.Marker(toLngLat(props.lnglat), compact({
|
|
732
|
+
icon: props.icon && toIcon(props.icon),
|
|
733
|
+
draggable: props.draggable,
|
|
734
|
+
title: props.title,
|
|
735
|
+
zIndexOffset: props.zIndexOffset,
|
|
736
|
+
opacity: props.opacity
|
|
737
|
+
})),
|
|
738
|
+
sync: {
|
|
739
|
+
lnglat: (marker, value) => marker.setLngLat(toLngLat(value)),
|
|
740
|
+
icon: (marker, value) => {
|
|
741
|
+
if (value !== void 0) marker.setIcon(toIcon(value));
|
|
742
|
+
},
|
|
743
|
+
draggable: (marker, value) => value === false ? marker.disableDragging() : marker.enableDragging(),
|
|
744
|
+
opacity: (marker, value) => {
|
|
745
|
+
if (value !== void 0) marker.setOpacity(value);
|
|
746
|
+
},
|
|
747
|
+
zIndexOffset: (marker, value) => {
|
|
748
|
+
if (value !== void 0) marker.setZIndexOffset(value);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
};
|
|
752
|
+
/** 线样式四件套的 props 定义(polyline/polygon/rectangle/线型工具共用) */
|
|
753
|
+
const lineStylePropDefs = {
|
|
754
|
+
color: {
|
|
755
|
+
type: String,
|
|
756
|
+
default: void 0,
|
|
757
|
+
attribute: "color"
|
|
758
|
+
},
|
|
759
|
+
weight: {
|
|
760
|
+
type: Number,
|
|
761
|
+
default: void 0,
|
|
762
|
+
attribute: "weight"
|
|
763
|
+
},
|
|
764
|
+
opacity: {
|
|
765
|
+
type: Number,
|
|
766
|
+
default: void 0,
|
|
767
|
+
attribute: "opacity"
|
|
768
|
+
},
|
|
769
|
+
lineStyle: {
|
|
770
|
+
type: String,
|
|
771
|
+
default: void 0,
|
|
772
|
+
attribute: "line-style"
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
/** 线样式 setter 同步(polyline/polygon/rectangle/circle 同构复用) */
|
|
776
|
+
const lineStyleSync = {
|
|
777
|
+
color: (target, value) => {
|
|
778
|
+
if (value !== void 0) target.setColor(value);
|
|
779
|
+
},
|
|
780
|
+
weight: (target, value) => {
|
|
781
|
+
if (value !== void 0) target.setWeight(value);
|
|
782
|
+
},
|
|
783
|
+
opacity: (target, value) => {
|
|
784
|
+
if (value !== void 0) target.setOpacity(value);
|
|
785
|
+
},
|
|
786
|
+
lineStyle: (target, value) => {
|
|
787
|
+
if (value !== void 0) target.setLineStyle(value);
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
const fillStylePropDefs = {
|
|
791
|
+
fillColor: {
|
|
792
|
+
type: String,
|
|
793
|
+
default: void 0,
|
|
794
|
+
attribute: "fill-color"
|
|
795
|
+
},
|
|
796
|
+
fillOpacity: {
|
|
797
|
+
type: Number,
|
|
798
|
+
default: void 0,
|
|
799
|
+
attribute: "fill-opacity"
|
|
800
|
+
}
|
|
801
|
+
};
|
|
802
|
+
/** 填充 setter 同步(polygon/circle/rectangle 同构复用) */
|
|
803
|
+
const fillStyleSync = {
|
|
804
|
+
fillColor: (target, value) => {
|
|
805
|
+
if (value !== void 0) target.setFillColor(value);
|
|
806
|
+
},
|
|
807
|
+
fillOpacity: (target, value) => {
|
|
808
|
+
if (value !== void 0) target.setFillOpacity(value);
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
const polylineDef = {
|
|
812
|
+
name: "TdtPolyline",
|
|
813
|
+
tag: "tdt-polyline",
|
|
814
|
+
props: {
|
|
815
|
+
path: {
|
|
816
|
+
type: Array,
|
|
817
|
+
required: true,
|
|
818
|
+
attribute: "path",
|
|
819
|
+
converter: parsePath
|
|
820
|
+
},
|
|
821
|
+
...lineStylePropDefs
|
|
822
|
+
},
|
|
823
|
+
events: [
|
|
824
|
+
"click",
|
|
825
|
+
"dblclick",
|
|
826
|
+
"mousedown",
|
|
827
|
+
"mouseup",
|
|
828
|
+
"mouseover",
|
|
829
|
+
"mouseout",
|
|
830
|
+
"remove"
|
|
831
|
+
],
|
|
832
|
+
create(props) {
|
|
833
|
+
return new T.Polyline(toLngLats(props.path), compact({
|
|
834
|
+
color: props.color,
|
|
835
|
+
weight: props.weight,
|
|
836
|
+
opacity: props.opacity,
|
|
837
|
+
lineStyle: props.lineStyle
|
|
838
|
+
}));
|
|
839
|
+
},
|
|
840
|
+
sync: {
|
|
841
|
+
path: (polyline, value) => polyline.setLngLats(toLngLats(value)),
|
|
842
|
+
...lineStyleSync
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
const polygonDef = {
|
|
846
|
+
name: "TdtPolygon",
|
|
847
|
+
tag: "tdt-polygon",
|
|
848
|
+
props: {
|
|
849
|
+
path: {
|
|
850
|
+
type: Array,
|
|
851
|
+
required: true,
|
|
852
|
+
attribute: "path",
|
|
853
|
+
converter: parsePath
|
|
854
|
+
},
|
|
855
|
+
...lineStylePropDefs,
|
|
856
|
+
...fillStylePropDefs
|
|
857
|
+
},
|
|
858
|
+
events: [
|
|
859
|
+
"click",
|
|
860
|
+
"dblclick",
|
|
861
|
+
"mousedown",
|
|
862
|
+
"mouseup",
|
|
863
|
+
"mouseover",
|
|
864
|
+
"mouseout",
|
|
865
|
+
"remove"
|
|
866
|
+
],
|
|
867
|
+
create(props) {
|
|
868
|
+
return new T.Polygon(toLngLats(props.path), compact({
|
|
869
|
+
color: props.color,
|
|
870
|
+
weight: props.weight,
|
|
871
|
+
opacity: props.opacity,
|
|
872
|
+
lineStyle: props.lineStyle,
|
|
873
|
+
fillColor: props.fillColor,
|
|
874
|
+
fillOpacity: props.fillOpacity
|
|
875
|
+
}));
|
|
876
|
+
},
|
|
877
|
+
sync: {
|
|
878
|
+
path: (polygon, value) => polygon.setLngLats(toLngLats(value)),
|
|
879
|
+
...lineStyleSync,
|
|
880
|
+
...fillStyleSync
|
|
881
|
+
}
|
|
882
|
+
};
|
|
883
|
+
const circleDef = {
|
|
884
|
+
name: "TdtCircle",
|
|
885
|
+
tag: "tdt-circle",
|
|
886
|
+
props: {
|
|
887
|
+
center: {
|
|
888
|
+
type: Array,
|
|
889
|
+
required: true,
|
|
890
|
+
attribute: "center",
|
|
891
|
+
converter: parseLnglat
|
|
892
|
+
},
|
|
893
|
+
radius: {
|
|
894
|
+
type: Number,
|
|
895
|
+
required: true,
|
|
896
|
+
attribute: "radius"
|
|
897
|
+
},
|
|
898
|
+
...lineStylePropDefs,
|
|
899
|
+
...fillStylePropDefs
|
|
900
|
+
},
|
|
901
|
+
events: [
|
|
902
|
+
"click",
|
|
903
|
+
"dblclick",
|
|
904
|
+
"mousedown",
|
|
905
|
+
"mouseup",
|
|
906
|
+
"mouseover",
|
|
907
|
+
"mouseout",
|
|
908
|
+
"remove"
|
|
909
|
+
],
|
|
910
|
+
create(props) {
|
|
911
|
+
return new T.Circle(toLngLat(props.center), props.radius, compact({
|
|
912
|
+
color: props.color,
|
|
913
|
+
weight: props.weight,
|
|
914
|
+
opacity: props.opacity,
|
|
915
|
+
lineStyle: props.lineStyle,
|
|
916
|
+
fillColor: props.fillColor,
|
|
917
|
+
fillOpacity: props.fillOpacity
|
|
918
|
+
}));
|
|
919
|
+
},
|
|
920
|
+
sync: {
|
|
921
|
+
center: (circle, value) => circle.setCenter(toLngLat(value)),
|
|
922
|
+
radius: (circle, value) => circle.setRadius(value),
|
|
923
|
+
...lineStyleSync,
|
|
924
|
+
...fillStyleSync
|
|
925
|
+
}
|
|
926
|
+
};
|
|
927
|
+
function toBounds(value) {
|
|
928
|
+
if (Array.isArray(value)) {
|
|
929
|
+
const [[swLng, swLat], [neLng, neLat]] = value;
|
|
930
|
+
return new T.LngLatBounds(new T.LngLat(swLng, swLat), new T.LngLat(neLng, neLat));
|
|
931
|
+
}
|
|
932
|
+
return value;
|
|
933
|
+
}
|
|
934
|
+
const rectangleDef = {
|
|
935
|
+
name: "TdtRectangle",
|
|
936
|
+
tag: "tdt-rectangle",
|
|
937
|
+
props: {
|
|
938
|
+
bounds: {
|
|
939
|
+
type: Array,
|
|
940
|
+
required: true,
|
|
941
|
+
attribute: "bounds",
|
|
942
|
+
converter: parseBounds
|
|
943
|
+
},
|
|
944
|
+
...lineStylePropDefs,
|
|
945
|
+
...fillStylePropDefs
|
|
946
|
+
},
|
|
947
|
+
events: [
|
|
948
|
+
"click",
|
|
949
|
+
"dblclick",
|
|
950
|
+
"mousedown",
|
|
951
|
+
"mouseup",
|
|
952
|
+
"mouseover",
|
|
953
|
+
"mouseout",
|
|
954
|
+
"remove"
|
|
955
|
+
],
|
|
956
|
+
create(props) {
|
|
957
|
+
return new T.Rectangle(toBounds(props.bounds), compact({
|
|
958
|
+
color: props.color,
|
|
959
|
+
weight: props.weight,
|
|
960
|
+
opacity: props.opacity,
|
|
961
|
+
lineStyle: props.lineStyle,
|
|
962
|
+
fillColor: props.fillColor,
|
|
963
|
+
fillOpacity: props.fillOpacity
|
|
964
|
+
}));
|
|
965
|
+
},
|
|
966
|
+
sync: {
|
|
967
|
+
bounds: (rectangle, value) => rectangle.setBounds(toBounds(value)),
|
|
968
|
+
...lineStyleSync,
|
|
969
|
+
...fillStyleSync
|
|
970
|
+
}
|
|
971
|
+
};
|
|
972
|
+
const labelDef = {
|
|
973
|
+
name: "TdtLabel",
|
|
974
|
+
tag: "tdt-label",
|
|
975
|
+
props: {
|
|
976
|
+
text: {
|
|
977
|
+
type: String,
|
|
978
|
+
required: true,
|
|
979
|
+
attribute: "text"
|
|
980
|
+
},
|
|
981
|
+
lnglat: {
|
|
982
|
+
type: Array,
|
|
983
|
+
required: true,
|
|
984
|
+
attribute: "lnglat",
|
|
985
|
+
converter: parseLnglat
|
|
986
|
+
},
|
|
987
|
+
offset: {
|
|
988
|
+
type: Object,
|
|
989
|
+
default: void 0,
|
|
990
|
+
attribute: "offset",
|
|
991
|
+
converter: parseJson
|
|
992
|
+
},
|
|
993
|
+
fontColor: {
|
|
994
|
+
type: String,
|
|
995
|
+
default: void 0,
|
|
996
|
+
attribute: "font-color"
|
|
997
|
+
},
|
|
998
|
+
fontSize: {
|
|
999
|
+
type: Number,
|
|
1000
|
+
default: void 0,
|
|
1001
|
+
attribute: "font-size"
|
|
1002
|
+
},
|
|
1003
|
+
backgroundColor: {
|
|
1004
|
+
type: String,
|
|
1005
|
+
default: void 0,
|
|
1006
|
+
attribute: "background-color"
|
|
1007
|
+
},
|
|
1008
|
+
title: {
|
|
1009
|
+
type: String,
|
|
1010
|
+
default: void 0,
|
|
1011
|
+
attribute: "title"
|
|
1012
|
+
}
|
|
1013
|
+
},
|
|
1014
|
+
events: [
|
|
1015
|
+
"click",
|
|
1016
|
+
"dblclick",
|
|
1017
|
+
"mousedown",
|
|
1018
|
+
"mouseup",
|
|
1019
|
+
"mouseout"
|
|
1020
|
+
],
|
|
1021
|
+
create(props) {
|
|
1022
|
+
const label = new T.Label(compact({
|
|
1023
|
+
text: props.text,
|
|
1024
|
+
position: toLngLat(props.lnglat),
|
|
1025
|
+
offset: props.offset
|
|
1026
|
+
}));
|
|
1027
|
+
if (props.fontColor) label.setFontColor(props.fontColor);
|
|
1028
|
+
if (props.fontSize) label.setFontSize(props.fontSize);
|
|
1029
|
+
if (props.backgroundColor) label.setBackgroundColor(props.backgroundColor);
|
|
1030
|
+
if (props.title) label.setTitle(props.title);
|
|
1031
|
+
return label;
|
|
1032
|
+
},
|
|
1033
|
+
sync: {
|
|
1034
|
+
text: (label, value) => label.setLabel(value),
|
|
1035
|
+
lnglat: (label, value) => label.setLngLat(toLngLat(value)),
|
|
1036
|
+
offset: (label, value) => {
|
|
1037
|
+
if (value !== void 0) label.setOffset(value);
|
|
1038
|
+
},
|
|
1039
|
+
fontColor: (label, value) => {
|
|
1040
|
+
if (value !== void 0) label.setFontColor(value);
|
|
1041
|
+
},
|
|
1042
|
+
fontSize: (label, value) => {
|
|
1043
|
+
if (value !== void 0) label.setFontSize(value);
|
|
1044
|
+
},
|
|
1045
|
+
backgroundColor: (label, value) => {
|
|
1046
|
+
if (value !== void 0) label.setBackgroundColor(value);
|
|
1047
|
+
},
|
|
1048
|
+
title: (label, value) => {
|
|
1049
|
+
if (value !== void 0) label.setTitle(value);
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
};
|
|
1053
|
+
const cloudMarkerDef = {
|
|
1054
|
+
name: "TdtCloudMarker",
|
|
1055
|
+
tag: "tdt-cloud-marker",
|
|
1056
|
+
props: {
|
|
1057
|
+
lnglats: {
|
|
1058
|
+
type: Array,
|
|
1059
|
+
required: true,
|
|
1060
|
+
attribute: "lnglats",
|
|
1061
|
+
converter: parsePath
|
|
1062
|
+
},
|
|
1063
|
+
styles: {
|
|
1064
|
+
type: Object,
|
|
1065
|
+
default: void 0,
|
|
1066
|
+
attribute: "styles",
|
|
1067
|
+
converter: parseJson
|
|
1068
|
+
}
|
|
1069
|
+
},
|
|
1070
|
+
events: [
|
|
1071
|
+
"click",
|
|
1072
|
+
"mouseover",
|
|
1073
|
+
"mouseout"
|
|
1074
|
+
],
|
|
1075
|
+
create: (props) => new T.CloudMarkerCollection(props.lnglats.map(toLngLat), props.styles ?? {}),
|
|
1076
|
+
sync: {
|
|
1077
|
+
lnglats: (collection, value) => collection.setLnglats(value.map(toLngLat)),
|
|
1078
|
+
styles: (collection, value) => {
|
|
1079
|
+
if (value) collection.setStyles(value);
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
};
|
|
1083
|
+
function toMarkers(value) {
|
|
1084
|
+
return value.map((item) => Array.isArray(item) ? new T.Marker(toLngLat(item)) : item);
|
|
1085
|
+
}
|
|
1086
|
+
const markerClustererDef = {
|
|
1087
|
+
name: "TdtMarkerCluster",
|
|
1088
|
+
tag: "tdt-marker-clusterer",
|
|
1089
|
+
props: {
|
|
1090
|
+
markers: {
|
|
1091
|
+
type: Array,
|
|
1092
|
+
default: void 0
|
|
1093
|
+
},
|
|
1094
|
+
gridSize: {
|
|
1095
|
+
type: Number,
|
|
1096
|
+
default: void 0,
|
|
1097
|
+
attribute: "grid-size"
|
|
1098
|
+
},
|
|
1099
|
+
maxZoom: {
|
|
1100
|
+
type: Number,
|
|
1101
|
+
default: void 0,
|
|
1102
|
+
attribute: "max-zoom"
|
|
1103
|
+
},
|
|
1104
|
+
styles: {
|
|
1105
|
+
type: Array,
|
|
1106
|
+
default: void 0,
|
|
1107
|
+
attribute: "styles",
|
|
1108
|
+
converter: parseJson
|
|
1109
|
+
}
|
|
1110
|
+
},
|
|
1111
|
+
detach(cluster) {
|
|
1112
|
+
cluster.clearMarkers();
|
|
1113
|
+
},
|
|
1114
|
+
create(props, { map }) {
|
|
1115
|
+
const cluster = new T.MarkerClusterer(map, compact({
|
|
1116
|
+
girdSize: props.gridSize,
|
|
1117
|
+
maxZoom: props.maxZoom,
|
|
1118
|
+
styles: props.styles
|
|
1119
|
+
}));
|
|
1120
|
+
if (props.markers?.length) cluster.addMarkers(toMarkers(props.markers));
|
|
1121
|
+
return cluster;
|
|
1122
|
+
},
|
|
1123
|
+
sync: {
|
|
1124
|
+
markers: (cluster, value) => {
|
|
1125
|
+
if (value) {
|
|
1126
|
+
cluster.clearMarkers();
|
|
1127
|
+
cluster.addMarkers(toMarkers(value));
|
|
1128
|
+
}
|
|
1129
|
+
},
|
|
1130
|
+
gridSize: (cluster, value) => {
|
|
1131
|
+
if (value !== void 0) cluster.setGridSize(value);
|
|
1132
|
+
},
|
|
1133
|
+
maxZoom: (cluster, value) => {
|
|
1134
|
+
if (value !== void 0) cluster.setMaxZoom(value);
|
|
1135
|
+
},
|
|
1136
|
+
styles: (cluster, value) => {
|
|
1137
|
+
if (value !== void 0) cluster.setStyles(value);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
};
|
|
1141
|
+
const layerGroupDef = {
|
|
1142
|
+
name: "TdtLayerGroup",
|
|
1143
|
+
tag: "tdt-layer-group",
|
|
1144
|
+
props: {},
|
|
1145
|
+
create: () => new T.LayerGroup([]),
|
|
1146
|
+
detach(group) {
|
|
1147
|
+
group.clearLayers();
|
|
1148
|
+
}
|
|
1149
|
+
};
|
|
1150
|
+
//#endregion
|
|
1151
|
+
//#region src/defs/layers.ts
|
|
1152
|
+
function toBoundsProp(value) {
|
|
1153
|
+
if (!value) return;
|
|
1154
|
+
if (Array.isArray(value)) {
|
|
1155
|
+
const [[swLng, swLat], [neLng, neLat]] = value;
|
|
1156
|
+
return new T.LngLatBounds(new T.LngLat(swLng, swLat), new T.LngLat(neLng, neLat));
|
|
1157
|
+
}
|
|
1158
|
+
return value;
|
|
1159
|
+
}
|
|
1160
|
+
/** 三个瓦片图层共用的基础 props(minZoom/maxZoom 仅构造生效) */
|
|
1161
|
+
const tileLayerBasePropDefs = {
|
|
1162
|
+
url: {
|
|
1163
|
+
type: String,
|
|
1164
|
+
required: true,
|
|
1165
|
+
attribute: "url"
|
|
1166
|
+
},
|
|
1167
|
+
minZoom: {
|
|
1168
|
+
type: Number,
|
|
1169
|
+
default: void 0,
|
|
1170
|
+
attribute: "min-zoom"
|
|
1171
|
+
},
|
|
1172
|
+
maxZoom: {
|
|
1173
|
+
type: Number,
|
|
1174
|
+
default: void 0,
|
|
1175
|
+
attribute: "max-zoom"
|
|
1176
|
+
},
|
|
1177
|
+
opacity: {
|
|
1178
|
+
type: Number,
|
|
1179
|
+
default: void 0,
|
|
1180
|
+
attribute: "opacity"
|
|
1181
|
+
},
|
|
1182
|
+
zIndex: {
|
|
1183
|
+
type: Number,
|
|
1184
|
+
default: void 0,
|
|
1185
|
+
attribute: "z-index"
|
|
1186
|
+
},
|
|
1187
|
+
errorTileUrl: {
|
|
1188
|
+
type: String,
|
|
1189
|
+
default: void 0,
|
|
1190
|
+
attribute: "error-tile-url"
|
|
1191
|
+
},
|
|
1192
|
+
bounds: {
|
|
1193
|
+
type: Array,
|
|
1194
|
+
default: void 0,
|
|
1195
|
+
attribute: "bounds",
|
|
1196
|
+
converter: parseBounds
|
|
1197
|
+
}
|
|
1198
|
+
};
|
|
1199
|
+
/** url/opacity/zIndex 的 setter 同步(SDK 无 minZoom/maxZoom setter) */
|
|
1200
|
+
const tileLayerSync = {
|
|
1201
|
+
opacity: (layer, value) => layer.setOpacity(value ?? 1),
|
|
1202
|
+
zIndex: (layer, value) => layer.setZIndex(value ?? 0),
|
|
1203
|
+
url: (layer, value) => layer.setUrl(value)
|
|
1204
|
+
};
|
|
1205
|
+
const tileLayerDef = {
|
|
1206
|
+
name: "TdtTileLayer",
|
|
1207
|
+
tag: "tdt-tile-layer",
|
|
1208
|
+
props: tileLayerBasePropDefs,
|
|
1209
|
+
events: TILE_LAYER_EVENT_NAMES,
|
|
1210
|
+
create: (props) => new T.TileLayer(props.url, compact({
|
|
1211
|
+
minZoom: props.minZoom,
|
|
1212
|
+
maxZoom: props.maxZoom,
|
|
1213
|
+
opacity: props.opacity,
|
|
1214
|
+
zIndex: props.zIndex,
|
|
1215
|
+
errorTileUrl: props.errorTileUrl,
|
|
1216
|
+
bounds: toBoundsProp(props.bounds)
|
|
1217
|
+
})),
|
|
1218
|
+
sync: tileLayerSync
|
|
1219
|
+
};
|
|
1220
|
+
const tileLayerWmsDef = {
|
|
1221
|
+
name: "TdtTileLayerWMS",
|
|
1222
|
+
tag: "tdt-tile-layer-wms",
|
|
1223
|
+
props: {
|
|
1224
|
+
...tileLayerBasePropDefs,
|
|
1225
|
+
layers: {
|
|
1226
|
+
type: String,
|
|
1227
|
+
default: void 0,
|
|
1228
|
+
attribute: "layers"
|
|
1229
|
+
},
|
|
1230
|
+
styles: {
|
|
1231
|
+
type: String,
|
|
1232
|
+
default: void 0,
|
|
1233
|
+
attribute: "styles"
|
|
1234
|
+
},
|
|
1235
|
+
format: {
|
|
1236
|
+
type: String,
|
|
1237
|
+
default: void 0,
|
|
1238
|
+
attribute: "format"
|
|
1239
|
+
},
|
|
1240
|
+
transparent: {
|
|
1241
|
+
type: Boolean,
|
|
1242
|
+
default: void 0,
|
|
1243
|
+
attribute: "transparent"
|
|
1244
|
+
},
|
|
1245
|
+
version: {
|
|
1246
|
+
type: String,
|
|
1247
|
+
default: void 0,
|
|
1248
|
+
attribute: "version"
|
|
1249
|
+
},
|
|
1250
|
+
srs: {
|
|
1251
|
+
type: String,
|
|
1252
|
+
default: void 0,
|
|
1253
|
+
attribute: "srs"
|
|
1254
|
+
}
|
|
1255
|
+
},
|
|
1256
|
+
events: TILE_LAYER_EVENT_NAMES,
|
|
1257
|
+
create: (props) => new T.TileLayerWMS(props.url, compact({
|
|
1258
|
+
minZoom: props.minZoom,
|
|
1259
|
+
maxZoom: props.maxZoom,
|
|
1260
|
+
opacity: props.opacity,
|
|
1261
|
+
zIndex: props.zIndex,
|
|
1262
|
+
layers: props.layers,
|
|
1263
|
+
styles: props.styles,
|
|
1264
|
+
format: props.format,
|
|
1265
|
+
transparent: props.transparent,
|
|
1266
|
+
version: props.version,
|
|
1267
|
+
srs: props.srs
|
|
1268
|
+
})),
|
|
1269
|
+
sync: tileLayerSync
|
|
1270
|
+
};
|
|
1271
|
+
const tileLayerTdtDef = {
|
|
1272
|
+
name: "TdtTileLayerTDT",
|
|
1273
|
+
tag: "tdt-tile-layer-tdt",
|
|
1274
|
+
props: {
|
|
1275
|
+
...tileLayerBasePropDefs,
|
|
1276
|
+
attribution: {
|
|
1277
|
+
type: String,
|
|
1278
|
+
default: void 0,
|
|
1279
|
+
attribute: "attribution"
|
|
1280
|
+
}
|
|
1281
|
+
},
|
|
1282
|
+
events: TILE_LAYER_EVENT_NAMES,
|
|
1283
|
+
create: (props) => new T.TileLayerTDT(props.url, compact({
|
|
1284
|
+
minZoom: props.minZoom,
|
|
1285
|
+
maxZoom: props.maxZoom,
|
|
1286
|
+
opacity: props.opacity,
|
|
1287
|
+
zIndex: props.zIndex,
|
|
1288
|
+
errorTileUrl: props.errorTileUrl,
|
|
1289
|
+
bounds: toBoundsProp(props.bounds),
|
|
1290
|
+
attribution: props.attribution
|
|
1291
|
+
})),
|
|
1292
|
+
sync: tileLayerSync
|
|
1293
|
+
};
|
|
1294
|
+
const gridlineLayerDef = {
|
|
1295
|
+
name: "TdtGridlineLayer",
|
|
1296
|
+
tag: "tdt-gridline-layer",
|
|
1297
|
+
props: {
|
|
1298
|
+
tileSize: {
|
|
1299
|
+
type: Number,
|
|
1300
|
+
default: void 0,
|
|
1301
|
+
attribute: "tile-size"
|
|
1302
|
+
},
|
|
1303
|
+
minZoom: {
|
|
1304
|
+
type: Number,
|
|
1305
|
+
default: void 0,
|
|
1306
|
+
attribute: "min-zoom"
|
|
1307
|
+
},
|
|
1308
|
+
maxZoom: {
|
|
1309
|
+
type: Number,
|
|
1310
|
+
default: void 0,
|
|
1311
|
+
attribute: "max-zoom"
|
|
1312
|
+
},
|
|
1313
|
+
opacity: {
|
|
1314
|
+
type: Number,
|
|
1315
|
+
default: void 0,
|
|
1316
|
+
attribute: "opacity"
|
|
1317
|
+
},
|
|
1318
|
+
outlineSize: {
|
|
1319
|
+
type: Object,
|
|
1320
|
+
default: void 0,
|
|
1321
|
+
attribute: "outline-size",
|
|
1322
|
+
converter: parseJson
|
|
1323
|
+
},
|
|
1324
|
+
textSize: {
|
|
1325
|
+
type: Object,
|
|
1326
|
+
default: void 0,
|
|
1327
|
+
attribute: "text-size",
|
|
1328
|
+
converter: parseJson
|
|
1329
|
+
}
|
|
1330
|
+
},
|
|
1331
|
+
events: ["loading", "load"],
|
|
1332
|
+
create: (props) => new T.GridlineLayer(compact({
|
|
1333
|
+
tileSize: props.tileSize,
|
|
1334
|
+
minZoom: props.minZoom,
|
|
1335
|
+
maxZoom: props.maxZoom,
|
|
1336
|
+
opacity: props.opacity,
|
|
1337
|
+
outlineSize: props.outlineSize,
|
|
1338
|
+
textSize: props.textSize
|
|
1339
|
+
})),
|
|
1340
|
+
sync: { opacity: (layer, value) => layer.setOpacity(value ?? 1) }
|
|
1341
|
+
};
|
|
1342
|
+
//#endregion
|
|
1343
|
+
//#region src/defs/plot-entities.ts
|
|
1344
|
+
const plotEntityPropDefs = {
|
|
1345
|
+
path: {
|
|
1346
|
+
type: Array,
|
|
1347
|
+
required: true,
|
|
1348
|
+
attribute: "path",
|
|
1349
|
+
converter: parsePath
|
|
1350
|
+
},
|
|
1351
|
+
...lineStylePropDefs
|
|
1352
|
+
};
|
|
1353
|
+
const plotFillPropDefs = {
|
|
1354
|
+
fillColor: {
|
|
1355
|
+
type: String,
|
|
1356
|
+
default: void 0,
|
|
1357
|
+
attribute: "fill-color"
|
|
1358
|
+
},
|
|
1359
|
+
fillOpacity: {
|
|
1360
|
+
type: Number,
|
|
1361
|
+
default: void 0,
|
|
1362
|
+
attribute: "fill-opacity"
|
|
1363
|
+
}
|
|
1364
|
+
};
|
|
1365
|
+
const plotEntitySync = { path: (entity, value) => entity.setLngLats(toLngLats(value)) };
|
|
1366
|
+
function linePlotDef(name, tag, instantiate) {
|
|
1367
|
+
return {
|
|
1368
|
+
name,
|
|
1369
|
+
tag,
|
|
1370
|
+
props: plotEntityPropDefs,
|
|
1371
|
+
create: (props) => instantiate(toLngLats(props.path), compact({
|
|
1372
|
+
color: props.color,
|
|
1373
|
+
weight: props.weight,
|
|
1374
|
+
opacity: props.opacity,
|
|
1375
|
+
lineStyle: props.lineStyle
|
|
1376
|
+
})),
|
|
1377
|
+
sync: plotEntitySync
|
|
1378
|
+
};
|
|
1379
|
+
}
|
|
1380
|
+
function fillPlotDef(name, tag, instantiate) {
|
|
1381
|
+
return {
|
|
1382
|
+
name,
|
|
1383
|
+
tag,
|
|
1384
|
+
props: {
|
|
1385
|
+
...plotEntityPropDefs,
|
|
1386
|
+
...plotFillPropDefs
|
|
1387
|
+
},
|
|
1388
|
+
create: (props) => instantiate(toLngLats(props.path), compact({
|
|
1389
|
+
color: props.color,
|
|
1390
|
+
weight: props.weight,
|
|
1391
|
+
opacity: props.opacity,
|
|
1392
|
+
lineStyle: props.lineStyle,
|
|
1393
|
+
fillColor: props.fillColor,
|
|
1394
|
+
fillOpacity: props.fillOpacity
|
|
1395
|
+
})),
|
|
1396
|
+
sync: plotEntitySync
|
|
1397
|
+
};
|
|
1398
|
+
}
|
|
1399
|
+
const arcDef = linePlotDef("TdtArc", "tdt-arc", (p, o) => new T.Arc(p, o));
|
|
1400
|
+
const bezierCurve2Def = linePlotDef("TdtBezierCurve2", "tdt-bezier-curve2", (p, o) => new T.BezierCurve2(p, o));
|
|
1401
|
+
const bezierCurve3Def = linePlotDef("TdtBezierCurve3", "tdt-bezier-curve3", (p, o) => new T.BezierCurve3(p, o));
|
|
1402
|
+
const bezierCurveArrowDef = linePlotDef("TdtBezierCurveArrow", "tdt-bezier-curve-arrow", (p, o) => new T.BezierCurveArrow(p, o));
|
|
1403
|
+
const bezierCurveNDef = linePlotDef("TdtBezierCurveN", "tdt-bezier-curve-n", (p, o) => new T.BezierCurveN(p, o));
|
|
1404
|
+
const cardinalCurveDef = linePlotDef("TdtCardinalCurve", "tdt-cardinal-curve", (p, o) => new T.CardinalCurve(p, o));
|
|
1405
|
+
const cardinalCurveArrowDef = linePlotDef("TdtCardinalCurveArrow", "tdt-cardinal-curve-arrow", (p, o) => new T.CardinalCurveArrow(p, o));
|
|
1406
|
+
const parallelSearchDef = linePlotDef("TdtParallelSearch", "tdt-parallel-search", (p, o) => new T.ParallelSearch(p, o));
|
|
1407
|
+
const polylineArrowDef = linePlotDef("TdtPolylineArrow", "tdt-polyline-arrow", (p, o) => new T.PolylineArrow(p, o));
|
|
1408
|
+
const sectorSearchDef = linePlotDef("TdtSectorSearch", "tdt-sector-search", (p, o) => new T.SectorSearch(p, o));
|
|
1409
|
+
const closeCurveDef = fillPlotDef("TdtCloseCurve", "tdt-close-curve", (p, o) => new T.CloseCurve(p, o));
|
|
1410
|
+
const curveFlagDef = fillPlotDef("TdtCurveFlag", "tdt-curve-flag", (p, o) => new T.CurveFlag(p, o));
|
|
1411
|
+
const diagonalArrowDef = fillPlotDef("TdtDiagonalArrow", "tdt-diagonal-arrow", (p, o) => new T.DiagonalArrow(p, o));
|
|
1412
|
+
const doubleArrowDef = fillPlotDef("TdtDoubleArrow", "tdt-double-arrow", (p, o) => new T.DoubleArrow(p, o));
|
|
1413
|
+
const doveTailDiagonalArrowDef = fillPlotDef("TdtDoveTailDiagonalArrow", "tdt-dove-tail-diagonal-arrow", (p, o) => new T.DoveTailDiagonalArrow(p, o));
|
|
1414
|
+
const doveTailStraightArrowDef = fillPlotDef("TdtDoveTailStraightArrow", "tdt-dove-tail-straight-arrow", (p, o) => new T.DoveTailStraightArrow(p, o));
|
|
1415
|
+
const gatheringPlaceDef = fillPlotDef("TdtGatheringPlace", "tdt-gathering-place", (p, o) => new T.GatheringPlace(p, o));
|
|
1416
|
+
const rectFlagDef = fillPlotDef("TdtRectFlag", "tdt-rect-flag", (p, o) => new T.RectFlag(p, o));
|
|
1417
|
+
const roundRectDef = fillPlotDef("TdtRoundRect", "tdt-round-rect", (p, o) => new T.RoundRect(p, o));
|
|
1418
|
+
const sectorDef = fillPlotDef("TdtSector", "tdt-sector", (p, o) => new T.Sector(p, o));
|
|
1419
|
+
const straightArrowDef = fillPlotDef("TdtStraightArrow", "tdt-straight-arrow", (p, o) => new T.StraightArrow(p, o));
|
|
1420
|
+
const triangleFlagDef = fillPlotDef("TdtTriangleFlag", "tdt-triangle-flag", (p, o) => new T.TriangleFlag(p, o));
|
|
1421
|
+
//#endregion
|
|
1422
|
+
//#region src/defs/plot-tools.ts
|
|
1423
|
+
const plotToolPropDefs = {
|
|
1424
|
+
style: {
|
|
1425
|
+
type: Object,
|
|
1426
|
+
default: void 0,
|
|
1427
|
+
attribute: "style",
|
|
1428
|
+
converter: parseJson
|
|
1429
|
+
},
|
|
1430
|
+
layers: {
|
|
1431
|
+
type: Object,
|
|
1432
|
+
default: void 0
|
|
1433
|
+
}
|
|
1434
|
+
};
|
|
1435
|
+
const PLOT_TOOL_EVENTS = [
|
|
1436
|
+
"click",
|
|
1437
|
+
"move",
|
|
1438
|
+
"dbclick"
|
|
1439
|
+
];
|
|
1440
|
+
/** TdtArcTool → tdt-arc-tool:tag 由 SDK 类名展开 */
|
|
1441
|
+
function tagOf(name) {
|
|
1442
|
+
return "tdt-" + name.slice(3).replace(/[A-Z]/g, (char) => "-" + char.toLowerCase()).slice(1);
|
|
1443
|
+
}
|
|
1444
|
+
function plotToolDef(name, instantiate) {
|
|
1445
|
+
return {
|
|
1446
|
+
name,
|
|
1447
|
+
tag: tagOf(name),
|
|
1448
|
+
props: plotToolPropDefs,
|
|
1449
|
+
events: PLOT_TOOL_EVENTS,
|
|
1450
|
+
create: (props, map) => instantiate(map, compact({
|
|
1451
|
+
style: props.style,
|
|
1452
|
+
layers: props.layers
|
|
1453
|
+
}))
|
|
1454
|
+
};
|
|
1455
|
+
}
|
|
1456
|
+
const arcToolDef = plotToolDef("TdtArcTool", (map, o) => new T.ArcTool(map, o));
|
|
1457
|
+
const bezierCurve2ToolDef = plotToolDef("TdtBezierCurve2Tool", (map, o) => new T.BezierCurve2Tool(map, o));
|
|
1458
|
+
const bezierCurve3ToolDef = plotToolDef("TdtBezierCurve3Tool", (map, o) => new T.BezierCurve3Tool(map, o));
|
|
1459
|
+
const bezierCurveArrowToolDef = plotToolDef("TdtBezierCurveArrowTool", (map, o) => new T.BezierCurveArrowTool(map, o));
|
|
1460
|
+
const bezierCurveNToolDef = plotToolDef("TdtBezierCurveNTool", (map, o) => new T.BezierCurveNTool(map, o));
|
|
1461
|
+
const cardinalCurveArrowToolDef = plotToolDef("TdtCardinalCurveArrowTool", (map, o) => new T.CardinalCurveArrowTool(map, o));
|
|
1462
|
+
const cardinalCurveToolDef = plotToolDef("TdtCardinalCurveTool", (map, o) => new T.CardinalCurveTool(map, o));
|
|
1463
|
+
const closeCurveToolDef = plotToolDef("TdtCloseCurveTool", (map, o) => new T.CloseCurveTool(map, o));
|
|
1464
|
+
const curveFlagToolDef = plotToolDef("TdtCurveFlagTool", (map, o) => new T.CurveFlagTool(map, o));
|
|
1465
|
+
const diagonalArrowToolDef = plotToolDef("TdtDiagonalArrowTool", (map, o) => new T.DiagonalArrowTool(map, o));
|
|
1466
|
+
const doubleArrowToolDef = plotToolDef("TdtDoubleArrowTool", (map, o) => new T.DoubleArrowTool(map, o));
|
|
1467
|
+
const doveTailDiagonalArrowToolDef = plotToolDef("TdtDoveTailDiagonalArrowTool", (map, o) => new T.DoveTailDiagonalArrowTool(map, o));
|
|
1468
|
+
const doveTailStraightArrowToolDef = plotToolDef("TdtDoveTailStraightArrowTool", (map, o) => new T.DoveTailStraightArrowTool(map, o));
|
|
1469
|
+
const gatheringPlaceToolDef = plotToolDef("TdtGatheringPlaceTool", (map, o) => new T.GatheringPlaceTool(map, o));
|
|
1470
|
+
const handDrawingToolDef = plotToolDef("TdtHandDrawingTool", (map, o) => new T.HandDrawingTool(map, o));
|
|
1471
|
+
const parallelSearchToolDef = plotToolDef("TdtParallelSearchTool", (map, o) => new T.ParallelSearchTool(map, o));
|
|
1472
|
+
const polylineArrowToolDef = plotToolDef("TdtPolylineArrowTool", (map, o) => new T.PolylineArrowTool(map, o));
|
|
1473
|
+
const rectFlagToolDef = plotToolDef("TdtRectFlagTool", (map, o) => new T.RectFlagTool(map, o));
|
|
1474
|
+
const roundRectToolDef = plotToolDef("TdtRoundRectTool", (map, o) => new T.RoundRectTool(map, o));
|
|
1475
|
+
const sectorSearchToolDef = plotToolDef("TdtSectorSearchTool", (map, o) => new T.SectorSearchTool(map, o));
|
|
1476
|
+
const sectorToolDef = plotToolDef("TdtSectorTool", (map, o) => new T.SectorTool(map, o));
|
|
1477
|
+
const straightArrowToolDef = plotToolDef("TdtStraightArrowTool", (map, o) => new T.StraightArrowTool(map, o));
|
|
1478
|
+
const triangleFlagToolDef = plotToolDef("TdtTriangleFlagTool", (map, o) => new T.TriangleFlagTool(map, o));
|
|
1479
|
+
//#endregion
|
|
1480
|
+
//#region src/defs/tools.ts
|
|
1481
|
+
const polylineToolDef = {
|
|
1482
|
+
name: "TdtPolylineTool",
|
|
1483
|
+
tag: "tdt-polyline-tool",
|
|
1484
|
+
props: {
|
|
1485
|
+
showLabel: {
|
|
1486
|
+
type: Boolean,
|
|
1487
|
+
default: void 0,
|
|
1488
|
+
attribute: "show-label"
|
|
1489
|
+
},
|
|
1490
|
+
...lineStylePropDefs
|
|
1491
|
+
},
|
|
1492
|
+
events: ["draw", "addpoint"],
|
|
1493
|
+
create: (props, map) => new T.PolylineTool(map, compact({
|
|
1494
|
+
showLabel: props.showLabel,
|
|
1495
|
+
color: props.color,
|
|
1496
|
+
weight: props.weight,
|
|
1497
|
+
opacity: props.opacity,
|
|
1498
|
+
lineStyle: props.lineStyle
|
|
1499
|
+
}))
|
|
1500
|
+
};
|
|
1501
|
+
const polygonToolDef = {
|
|
1502
|
+
name: "TdtPolygonTool",
|
|
1503
|
+
tag: "tdt-polygon-tool",
|
|
1504
|
+
props: {
|
|
1505
|
+
showLabel: {
|
|
1506
|
+
type: Boolean,
|
|
1507
|
+
default: void 0,
|
|
1508
|
+
attribute: "show-label"
|
|
1509
|
+
},
|
|
1510
|
+
...lineStylePropDefs
|
|
1511
|
+
},
|
|
1512
|
+
events: ["draw", "addpoint"],
|
|
1513
|
+
create: (props, map) => new T.PolygonTool(map, compact({
|
|
1514
|
+
showLabel: props.showLabel,
|
|
1515
|
+
color: props.color,
|
|
1516
|
+
weight: props.weight,
|
|
1517
|
+
opacity: props.opacity,
|
|
1518
|
+
lineStyle: props.lineStyle
|
|
1519
|
+
}))
|
|
1520
|
+
};
|
|
1521
|
+
const circleToolDef = {
|
|
1522
|
+
name: "TdtCircleTool",
|
|
1523
|
+
tag: "tdt-circle-tool",
|
|
1524
|
+
props: {
|
|
1525
|
+
...lineStylePropDefs,
|
|
1526
|
+
fillColor: {
|
|
1527
|
+
type: String,
|
|
1528
|
+
default: void 0,
|
|
1529
|
+
attribute: "fill-color"
|
|
1530
|
+
},
|
|
1531
|
+
fillOpacity: {
|
|
1532
|
+
type: Number,
|
|
1533
|
+
default: void 0,
|
|
1534
|
+
attribute: "fill-opacity"
|
|
1535
|
+
}
|
|
1536
|
+
},
|
|
1537
|
+
events: ["draw", "drawend"],
|
|
1538
|
+
create: (props, map) => new T.CircleTool(map, compact({
|
|
1539
|
+
color: props.color,
|
|
1540
|
+
weight: props.weight,
|
|
1541
|
+
opacity: props.opacity,
|
|
1542
|
+
fillColor: props.fillColor,
|
|
1543
|
+
fillOpacity: props.fillOpacity,
|
|
1544
|
+
lineStyle: props.lineStyle
|
|
1545
|
+
}))
|
|
1546
|
+
};
|
|
1547
|
+
const rectangleToolDef = {
|
|
1548
|
+
name: "TdtRectangleTool",
|
|
1549
|
+
tag: "tdt-rectangle-tool",
|
|
1550
|
+
props: {
|
|
1551
|
+
...lineStylePropDefs,
|
|
1552
|
+
fillColor: {
|
|
1553
|
+
type: String,
|
|
1554
|
+
default: void 0,
|
|
1555
|
+
attribute: "fill-color"
|
|
1556
|
+
},
|
|
1557
|
+
fillOpacity: {
|
|
1558
|
+
type: Number,
|
|
1559
|
+
default: void 0,
|
|
1560
|
+
attribute: "fill-opacity"
|
|
1561
|
+
}
|
|
1562
|
+
},
|
|
1563
|
+
events: ["draw"],
|
|
1564
|
+
create: (props, map) => new T.RectangleTool(map, compact({
|
|
1565
|
+
color: props.color,
|
|
1566
|
+
weight: props.weight,
|
|
1567
|
+
opacity: props.opacity,
|
|
1568
|
+
fillColor: props.fillColor,
|
|
1569
|
+
fillOpacity: props.fillOpacity,
|
|
1570
|
+
lineStyle: props.lineStyle
|
|
1571
|
+
}))
|
|
1572
|
+
};
|
|
1573
|
+
const markToolDef = {
|
|
1574
|
+
name: "TdtMarkTool",
|
|
1575
|
+
tag: "tdt-mark-tool",
|
|
1576
|
+
props: {
|
|
1577
|
+
icon: {
|
|
1578
|
+
type: Object,
|
|
1579
|
+
default: void 0,
|
|
1580
|
+
attribute: "icon",
|
|
1581
|
+
converter: parseJson
|
|
1582
|
+
},
|
|
1583
|
+
follow: {
|
|
1584
|
+
type: Boolean,
|
|
1585
|
+
default: void 0,
|
|
1586
|
+
attribute: "follow"
|
|
1587
|
+
}
|
|
1588
|
+
},
|
|
1589
|
+
events: ["mouseup"],
|
|
1590
|
+
create: (props, map) => new T.MarkTool(map, compact({
|
|
1591
|
+
icon: props.icon,
|
|
1592
|
+
follow: props.follow
|
|
1593
|
+
}))
|
|
1594
|
+
};
|
|
1595
|
+
const paintBrushToolDef = {
|
|
1596
|
+
name: "TdtPaintBrushTool",
|
|
1597
|
+
tag: "tdt-paint-brush-tool",
|
|
1598
|
+
props: {
|
|
1599
|
+
keepdrawing: {
|
|
1600
|
+
type: Boolean,
|
|
1601
|
+
default: void 0,
|
|
1602
|
+
attribute: "keepdrawing"
|
|
1603
|
+
},
|
|
1604
|
+
style: {
|
|
1605
|
+
type: Object,
|
|
1606
|
+
default: void 0,
|
|
1607
|
+
attribute: "style",
|
|
1608
|
+
converter: parseJson
|
|
1609
|
+
}
|
|
1610
|
+
},
|
|
1611
|
+
create: (props, map) => new T.PaintBrushTool(map, compact({
|
|
1612
|
+
keepdrawing: props.keepdrawing,
|
|
1613
|
+
style: props.style
|
|
1614
|
+
}))
|
|
1615
|
+
};
|
|
1616
|
+
//#endregion
|
|
1617
|
+
export { DEFAULT_CENTER, EventBridge, MAP_EVENT_NAMES, TILE_LAYER_EVENT_NAMES, applyMapInteractions, arcDef, arcToolDef, bezierCurve2Def, bezierCurve2ToolDef, bezierCurve3Def, bezierCurve3ToolDef, bezierCurveArrowDef, bezierCurveArrowToolDef, bezierCurveNDef, bezierCurveNToolDef, bindEventNames, cardinalCurveArrowDef, cardinalCurveArrowToolDef, cardinalCurveDef, cardinalCurveToolDef, circleDef, circleToolDef, closeCurveDef, closeCurveToolDef, cloudMarkerDef, compact, copyrightDef, createInfoWindow, createMapSession, createPropsSync, createWhenReady, curveFlagDef, curveFlagToolDef, diagonalArrowDef, diagonalArrowToolDef, doubleArrowDef, doubleArrowToolDef, doveTailDiagonalArrowDef, doveTailDiagonalArrowToolDef, doveTailStraightArrowDef, doveTailStraightArrowToolDef, gatheringPlaceDef, gatheringPlaceToolDef, gridlineLayerDef, handDrawingToolDef, labelDef, layerGroupDef, lineStylePropDefs, lineStyleSync, loadTdt, mapTypeDef, markToolDef, markerClustererDef, markerDef, mountOverlay, mountTileLayer, mountTool, overviewMapDef, paintBrushToolDef, parallelSearchDef, parallelSearchToolDef, parseBounds, parseJson, parseLnglat, parsePath, parseSize, plotEntityPropDefs, plotEntitySync, plotFillPropDefs, plotToolPropDefs, polygonDef, polygonToolDef, polylineArrowDef, polylineArrowToolDef, polylineDef, polylineToolDef, rectFlagDef, rectFlagToolDef, rectangleDef, rectangleToolDef, roundRectDef, roundRectToolDef, scaleDef, sectorDef, sectorSearchDef, sectorSearchToolDef, sectorToolDef, straightArrowDef, straightArrowToolDef, tileLayerDef, tileLayerTdtDef, tileLayerWmsDef, toLngLat, toLngLats, triangleFlagDef, triangleFlagToolDef, zoomDef };
|