tg-map-core 4.2.0 → 4.2.1
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/src/map/event-target.d.ts +1 -0
- package/dist/src/map/map/controls/map-type.control.d.ts +4 -3
- package/dist/src/map/map/map-options.d.ts +5 -0
- package/dist/src/map/map/map-type.d.ts +5 -1
- package/dist/src/map/map/overlay/icon.d.ts +1 -1
- package/dist/src/map/map/talks-map.d.ts +18 -1
- package/dist/src/map/map-config.d.ts +3 -1
- package/dist/src/utils/talks-layers.d.ts +8 -4
- package/dist/tg-map-core.cjs +198 -45
- package/dist/tg-map-core.mjs +199 -46
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/map/dts/maptalks.d.ts +13 -12
|
@@ -65,6 +65,7 @@ export declare class TalksEventTargetDelegate<T extends UnionTalksEventTarget =
|
|
|
65
65
|
static EVENT_TYPE_MAP: {
|
|
66
66
|
'center-changed': string;
|
|
67
67
|
'zoom-changed': string;
|
|
68
|
+
'map-type-changed': string;
|
|
68
69
|
} & Record<string, string | undefined>;
|
|
69
70
|
private eventTypeMap;
|
|
70
71
|
/**
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import * as maptalks from 'maptalks';
|
|
1
2
|
import type { BaiduMap } from '../baidu-map';
|
|
2
3
|
import type { GoogleMap } from '../google-map';
|
|
3
4
|
import { MapType } from '../map-type';
|
|
4
5
|
import type { TalksMap } from '../talks-map';
|
|
5
|
-
import { AbstractControl, BaiduControl, ControlPosition, EmptyControl, GoogleControl } from './control';
|
|
6
|
+
import { AbstractControl, BaiduControl, ControlPosition, EmptyControl, GoogleControl, TalksControl } from './control';
|
|
6
7
|
export interface MapTypeControl extends AbstractControl {
|
|
7
8
|
}
|
|
8
9
|
export declare enum MapTypeControlType {
|
|
@@ -17,7 +18,7 @@ export interface MapTypeControlOptions {
|
|
|
17
18
|
mapTypes?: MapType[];
|
|
18
19
|
}
|
|
19
20
|
export declare class BaiduMapTypeControl extends BaiduControl<BMap.MapTypeControl> implements MapTypeControl {
|
|
20
|
-
static create(this: BaiduMap, options: MapTypeControlOptions): BaiduMapTypeControl;
|
|
21
|
+
static create(this: BaiduMap, options: MapTypeControlOptions): EmptyControl | BaiduMapTypeControl;
|
|
21
22
|
}
|
|
22
23
|
export declare class GoogleMapTypeControl extends GoogleControl implements MapTypeControl {
|
|
23
24
|
type: MapTypeControlType;
|
|
@@ -28,6 +29,6 @@ export declare class GoogleMapTypeControl extends GoogleControl implements MapTy
|
|
|
28
29
|
onCreateOptions(): any;
|
|
29
30
|
addTo(map: GoogleMap): void;
|
|
30
31
|
}
|
|
31
|
-
export declare class TalksMapTypeControl extends
|
|
32
|
+
export declare class TalksMapTypeControl extends TalksControl<maptalks.control.LayerSwitcher> implements MapTypeControl {
|
|
32
33
|
static create(this: TalksMap, options: MapTypeControlOptions): TalksMapTypeControl;
|
|
33
34
|
}
|
|
@@ -42,10 +42,14 @@ export interface Layer {
|
|
|
42
42
|
export type OverlayMapType = MapType & Layer;
|
|
43
43
|
export declare class BuildInMapType implements MapType {
|
|
44
44
|
id: BuildInMapTypeIdIncludeIncompatible;
|
|
45
|
+
/** 在{@link MapType.BUILD_IN_MAP_TYPES.values}中的index */
|
|
46
|
+
index: number;
|
|
45
47
|
private baidu;
|
|
46
48
|
private google;
|
|
47
49
|
private googleCoordType;
|
|
48
|
-
constructor(id: BuildInMapTypeIdIncludeIncompatible,
|
|
50
|
+
constructor(id: BuildInMapTypeIdIncludeIncompatible,
|
|
51
|
+
/** 在{@link MapType.BUILD_IN_MAP_TYPES.values}中的index */
|
|
52
|
+
index: number, baidu: () => BMap.MapType, // 需要延迟初始化, 故写成方法
|
|
49
53
|
google: () => google.maps.MapTypeId, // 同上
|
|
50
54
|
googleCoordType: CoordType);
|
|
51
55
|
getId(): BuildInMapTypeIdIncludeIncompatible;
|
|
@@ -29,8 +29,25 @@ import { TalksPolyline } from './overlay/polyline';
|
|
|
29
29
|
import { TalksRectangle } from './overlay/rectangle';
|
|
30
30
|
export declare class TalksMap extends BaseMap {
|
|
31
31
|
mapOptions: MapOptions;
|
|
32
|
+
/**
|
|
33
|
+
* 最多8项, 前四项对应{@link MapType.BUILD_IN_MAP_TYPES}的四个值(普通、卫星、混合、地形)的亮色版, 后四项对应暗色版
|
|
34
|
+
* @see computeBaseLayerId
|
|
35
|
+
*/
|
|
36
|
+
private baseLayoutIds;
|
|
32
37
|
private map;
|
|
33
|
-
|
|
38
|
+
private attributionControl;
|
|
39
|
+
private baseLayerGroup;
|
|
40
|
+
private mapStyleTheme;
|
|
41
|
+
constructor(element: HTMLElement, mapOptions: MapOptions,
|
|
42
|
+
/**
|
|
43
|
+
* 最多8项, 前四项对应{@link MapType.BUILD_IN_MAP_TYPES}的四个值(普通、卫星、混合、地形)的亮色版, 后四项对应暗色版
|
|
44
|
+
* @see computeBaseLayerId
|
|
45
|
+
*/
|
|
46
|
+
baseLayoutIds: [TalksBaseLayerId, ...(TalksBaseLayerId | undefined)[]]);
|
|
47
|
+
private getCurrentBaseLayer;
|
|
48
|
+
private onBaseLayerChanged;
|
|
49
|
+
private computeBaseLayerId;
|
|
50
|
+
private setBaseLayer;
|
|
34
51
|
setGestureHandling(gestureHandling?: GestureHandlingOptions): void;
|
|
35
52
|
get innerMap(): maptalks.Map;
|
|
36
53
|
get coordType(): CoordType;
|
|
@@ -29,8 +29,10 @@ export interface TgMapConfig {
|
|
|
29
29
|
amap: EmptyObject;
|
|
30
30
|
osm: EmptyObject;
|
|
31
31
|
talks: {
|
|
32
|
-
/** @
|
|
32
|
+
/** @deprecated 使用layerIds替代 */
|
|
33
33
|
layerId?: TalksBaseLayerId | '';
|
|
34
|
+
/** 只有第一个元素非空, 才是有效的值; 默认`bing` */
|
|
35
|
+
layerIds?: (TalksBaseLayerId | undefined)[];
|
|
34
36
|
};
|
|
35
37
|
}
|
|
36
38
|
export type PartialTgMapConfig = DeepPartial<TgMapConfig>;
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import * as maptalks from 'maptalks';
|
|
2
2
|
import { CoordType } from '../map/lat-lng';
|
|
3
|
-
export declare const talksBaseLayerIds: readonly ["osm", "osm-light", "osm-dark", "google", "baidu", "baidu-detail", "amap", "tencent", "geoq", "tianditu", "yandex", "bing"];
|
|
3
|
+
export declare const talksBaseLayerIds: readonly ["osm", "osm-light", "osm-dark", "osm-terrain", "google", "baidu", "baidu-detail", "amap", "amap-terrain", "tencent", "geoq", "tianditu", "yandex", "bing"];
|
|
4
4
|
export type TalksBaseLayerId = typeof talksBaseLayerIds[number];
|
|
5
|
-
export declare function talksBaseLayerIdToCoordType(layerId: TalksBaseLayerId
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export declare function talksBaseLayerIdToCoordType(layerId: TalksBaseLayerId | (string & {
|
|
6
|
+
readonly __flavor__?: 'layerId';
|
|
7
|
+
})): CoordType;
|
|
8
|
+
declare function createTalksBaseLayerImpl(layerId: TalksBaseLayerId, { id, visible, }?: {
|
|
9
|
+
id?: "osm" | "osm-light" | "osm-dark" | "osm-terrain" | "google" | "baidu" | "baidu-detail" | "amap" | "amap-terrain" | "tencent" | "geoq" | "tianditu" | "yandex" | "bing" | undefined;
|
|
8
10
|
visible?: boolean | undefined;
|
|
9
11
|
}): maptalks.TileLayer;
|
|
12
|
+
export declare const createTalksBaseLayer: typeof createTalksBaseLayerImpl;
|
|
13
|
+
export {};
|
package/dist/tg-map-core.cjs
CHANGED
|
@@ -1555,6 +1555,8 @@ class TalksEventTargetDelegate extends AbstractEventTargetDelegate {
|
|
|
1555
1555
|
static EVENT_TYPE_MAP = typedRecord({
|
|
1556
1556
|
'center-changed': 'movestart moving moveend zoomend',
|
|
1557
1557
|
'zoom-changed': 'zoomend',
|
|
1558
|
+
// https://maptalks.org/maptalks.js/api/1.x/Map.html#event:setbaselayer
|
|
1559
|
+
'map-type-changed': 'setbaselayer',
|
|
1558
1560
|
});
|
|
1559
1561
|
eventTypeMap;
|
|
1560
1562
|
/**
|
|
@@ -1759,6 +1761,19 @@ function hideBaiduMapUnauthWarn() {
|
|
|
1759
1761
|
}
|
|
1760
1762
|
return false;
|
|
1761
1763
|
};
|
|
1764
|
+
if (!isBaiduGL()) {
|
|
1765
|
+
// 新的V3版也会直接从签名的`B_BUSINESS_INFO`中检测是否弹窗警告, 强制清空它可以规避检测(
|
|
1766
|
+
Object.defineProperty(window, 'B_BUSINESS_INFO', {
|
|
1767
|
+
configurable: true,
|
|
1768
|
+
enumerable: true,
|
|
1769
|
+
get: () => {
|
|
1770
|
+
return undefined;
|
|
1771
|
+
},
|
|
1772
|
+
set: (v) => {
|
|
1773
|
+
console.debug('B_BUSINESS_INFO', 'set', v);
|
|
1774
|
+
},
|
|
1775
|
+
});
|
|
1776
|
+
}
|
|
1762
1777
|
let originalBMap;
|
|
1763
1778
|
let originalBMapVerifyCbk;
|
|
1764
1779
|
Object.defineProperty(window, 'BMap', {
|
|
@@ -2195,13 +2210,17 @@ exports.BuildInMapTypeId = void 0;
|
|
|
2195
2210
|
})(exports.BuildInMapTypeId || (exports.BuildInMapTypeId = {}));
|
|
2196
2211
|
class BuildInMapType {
|
|
2197
2212
|
id;
|
|
2213
|
+
index;
|
|
2198
2214
|
baidu;
|
|
2199
2215
|
google;
|
|
2200
2216
|
googleCoordType;
|
|
2201
|
-
constructor(id,
|
|
2217
|
+
constructor(id,
|
|
2218
|
+
/** 在{@link MapType.BUILD_IN_MAP_TYPES.values}中的index */
|
|
2219
|
+
index, baidu, // 需要延迟初始化, 故写成方法
|
|
2202
2220
|
google, // 同上
|
|
2203
2221
|
googleCoordType) {
|
|
2204
2222
|
this.id = id;
|
|
2223
|
+
this.index = index;
|
|
2205
2224
|
this.baidu = baidu;
|
|
2206
2225
|
this.google = google;
|
|
2207
2226
|
this.googleCoordType = googleCoordType;
|
|
@@ -2311,10 +2330,10 @@ class TrafficLayer {
|
|
|
2311
2330
|
}
|
|
2312
2331
|
exports.MapType = void 0;
|
|
2313
2332
|
(function (MapType) {
|
|
2314
|
-
MapType.NORMAL = new BuildInMapType(exports.BuildInMapTypeId.normal, () => BMAP_NORMAL_MAP, () => google.maps.MapTypeId.ROADMAP, exports.CoordType.gcj02);
|
|
2315
|
-
MapType.SATELLITE = new BuildInMapType(exports.BuildInMapTypeId.satellite, () => BMAP_SATELLITE_MAP, () => google.maps.MapTypeId.SATELLITE, exports.CoordType.wgs84);
|
|
2316
|
-
MapType.HYBRID = new BuildInMapType(exports.BuildInMapTypeId.hybrid, () => BMAP_HYBRID_MAP, () => google.maps.MapTypeId.HYBRID, exports.CoordType.gcj02);
|
|
2317
|
-
MapType.TERRAIN = new BuildInMapType('terrain', () => /* 三维 */ BMAP_PERSPECTIVE_MAP, () => /* 地形 */ google.maps.MapTypeId.TERRAIN, exports.CoordType.wgs84);
|
|
2333
|
+
MapType.NORMAL = new BuildInMapType(exports.BuildInMapTypeId.normal, 0, () => BMAP_NORMAL_MAP, () => google.maps.MapTypeId.ROADMAP, exports.CoordType.gcj02);
|
|
2334
|
+
MapType.SATELLITE = new BuildInMapType(exports.BuildInMapTypeId.satellite, 1, () => BMAP_SATELLITE_MAP, () => google.maps.MapTypeId.SATELLITE, exports.CoordType.wgs84);
|
|
2335
|
+
MapType.HYBRID = new BuildInMapType(exports.BuildInMapTypeId.hybrid, 2, () => BMAP_HYBRID_MAP, () => google.maps.MapTypeId.HYBRID, exports.CoordType.gcj02);
|
|
2336
|
+
MapType.TERRAIN = new BuildInMapType('terrain', 3, () => /* 三维 */ BMAP_PERSPECTIVE_MAP, () => /* 地形 */ google.maps.MapTypeId.TERRAIN, exports.CoordType.wgs84);
|
|
2318
2337
|
MapType.BUILD_IN_MAP_TYPES = new FastFindValues([MapType.NORMAL, MapType.SATELLITE, MapType.HYBRID, MapType.TERRAIN]);
|
|
2319
2338
|
})(exports.MapType || (exports.MapType = {}));
|
|
2320
2339
|
|
|
@@ -2327,6 +2346,10 @@ exports.MapTypeControlType = void 0;
|
|
|
2327
2346
|
const MAP_TYPES_DEFAULT = [exports.MapType.NORMAL, exports.MapType.SATELLITE, exports.MapType.HYBRID];
|
|
2328
2347
|
class BaiduMapTypeControl extends BaiduControl {
|
|
2329
2348
|
static create(options) {
|
|
2349
|
+
if (isBaiduGL()) {
|
|
2350
|
+
// GL版, 不存在MapTypeControl...故返回空
|
|
2351
|
+
return new EmptyControl(true, options.position ?? exports.ControlPosition.TOP_LEFT);
|
|
2352
|
+
}
|
|
2330
2353
|
const mapTypes = options.mapTypes ?? MAP_TYPES_DEFAULT;
|
|
2331
2354
|
const type2baidu = {
|
|
2332
2355
|
[exports.MapTypeControlType.DEFAULT]: BMAP_MAPTYPE_CONTROL_HORIZONTAL,
|
|
@@ -2378,9 +2401,13 @@ class GoogleMapTypeControl extends GoogleControl {
|
|
|
2378
2401
|
});
|
|
2379
2402
|
}
|
|
2380
2403
|
}
|
|
2381
|
-
class TalksMapTypeControl extends
|
|
2404
|
+
class TalksMapTypeControl extends TalksControl {
|
|
2382
2405
|
static create(options) {
|
|
2383
|
-
|
|
2406
|
+
const position = options.position ?? exports.ControlPosition.TOP_LEFT;
|
|
2407
|
+
const inner = new maptalks__namespace.control.LayerSwitcher({
|
|
2408
|
+
position: exports.ControlPositionConverter.getTalks().toValue(position),
|
|
2409
|
+
});
|
|
2410
|
+
return new TalksMapTypeControl(inner, position);
|
|
2384
2411
|
}
|
|
2385
2412
|
}
|
|
2386
2413
|
|
|
@@ -7328,7 +7355,7 @@ class TalksMarkerClusterer {
|
|
|
7328
7355
|
this.inner = new maptalks_markercluster.ClusterLayer('cluster', options.markers?.map(it => it.innerOverlay), exports.Objects.deleteUndefinedPropertyOnPlainObjectDeeply({
|
|
7329
7356
|
...ClusterIconStyle.toTalks(options.styles),
|
|
7330
7357
|
// {@macro marker_clusterer_grid_size}
|
|
7331
|
-
maxClusterRadius: options.gridSize ?? (map.
|
|
7358
|
+
maxClusterRadius: options.gridSize ?? (map.cachedBaseLayerId === 'baidu' || map.cachedBaseLayerId === 'baidu-detail' ? 60 : 100),
|
|
7332
7359
|
maxClusterZoom: options.maxZoom,
|
|
7333
7360
|
zIndex: options.zIndex,
|
|
7334
7361
|
}));
|
|
@@ -7879,7 +7906,7 @@ class TalksShape extends TalksOverlay {
|
|
|
7879
7906
|
* @see setEditable
|
|
7880
7907
|
*/
|
|
7881
7908
|
isEditable() {
|
|
7882
|
-
return this.innerOverlay.
|
|
7909
|
+
return this.innerOverlay.options.editable ?? false;
|
|
7883
7910
|
}
|
|
7884
7911
|
setEditable(editable) {
|
|
7885
7912
|
// 同步设置editable和isEditing
|
|
@@ -9258,7 +9285,7 @@ class TalksLabelOverlay extends TalksOverlay {
|
|
|
9258
9285
|
this.innerOverlay.setCoordinates(position.toTalks(this.coordType));
|
|
9259
9286
|
}
|
|
9260
9287
|
getOffset() {
|
|
9261
|
-
const options = this.innerOverlay.
|
|
9288
|
+
const options = this.innerOverlay.options;
|
|
9262
9289
|
return { x: options.dx ?? 0, y: options.dy ?? 0 };
|
|
9263
9290
|
}
|
|
9264
9291
|
setOffset(offset) {
|
|
@@ -9806,13 +9833,13 @@ class TalksMarker extends TalksOverlay {
|
|
|
9806
9833
|
this.innerOverlay.config('interactive', enable);
|
|
9807
9834
|
}
|
|
9808
9835
|
isClickable() {
|
|
9809
|
-
return this.innerOverlay.
|
|
9836
|
+
return this.innerOverlay.options.interactive ?? true;
|
|
9810
9837
|
}
|
|
9811
9838
|
setDraggable(enable) {
|
|
9812
9839
|
this.innerOverlay.config('draggable', enable);
|
|
9813
9840
|
}
|
|
9814
9841
|
isDraggable() {
|
|
9815
|
-
return this.innerOverlay.
|
|
9842
|
+
return this.innerOverlay.options.draggable ?? false;
|
|
9816
9843
|
}
|
|
9817
9844
|
setZIndex(zIndex) {
|
|
9818
9845
|
this.innerOverlay.setZIndex(zIndex ?? 0);
|
|
@@ -10994,10 +11021,12 @@ const talksBaseLayerIds = [
|
|
|
10994
11021
|
'osm',
|
|
10995
11022
|
'osm-light',
|
|
10996
11023
|
'osm-dark',
|
|
11024
|
+
'osm-terrain',
|
|
10997
11025
|
'google',
|
|
10998
11026
|
'baidu',
|
|
10999
11027
|
'baidu-detail',
|
|
11000
11028
|
'amap',
|
|
11029
|
+
'amap-terrain',
|
|
11001
11030
|
'tencent',
|
|
11002
11031
|
'geoq',
|
|
11003
11032
|
'tianditu',
|
|
@@ -11031,15 +11060,29 @@ function talksBaseLayerIdToCoordType(layerId) {
|
|
|
11031
11060
|
* @see https://maptalks.org/examples/cn/tilelayer-projection/baidu/#tilelayer-projection_baidu
|
|
11032
11061
|
*/
|
|
11033
11062
|
const TILE_LAYER_BAIDU_SCALER = 1;
|
|
11034
|
-
function
|
|
11063
|
+
function createTalksBaseLayerImpl(layerId, { id = layerId, visible = true, } = {}) {
|
|
11035
11064
|
switch (layerId) {
|
|
11036
11065
|
case 'amap':
|
|
11037
11066
|
return new maptalks__namespace.TileLayer(id, {
|
|
11038
11067
|
visible,
|
|
11039
|
-
urlTemplate: 'http://
|
|
11068
|
+
urlTemplate: 'http://webrd{s}.is.autonavi.com/appmaptile?style=8&x={x}&y={y}&z={z}&lang=zh_cn',
|
|
11069
|
+
subdomains: ['01', '02', '03', '04'],
|
|
11040
11070
|
minZoom: 3,
|
|
11041
11071
|
maxZoom: 18,
|
|
11042
11072
|
attribution: '© <a target="_blank" href="https://amap.com/">AMap</a>',
|
|
11073
|
+
spatialReference: { projection: 'EPSG:3857' },
|
|
11074
|
+
});
|
|
11075
|
+
case 'amap-terrain':
|
|
11076
|
+
// http://examples.maptalks.com/examples/cn/3d/terrain/load
|
|
11077
|
+
return new maptalks__namespace.TileLayer(id, {
|
|
11078
|
+
visible,
|
|
11079
|
+
minZoom: 1,
|
|
11080
|
+
// 深圳最大可以到18级, 一些偏远地带, 18级可能没有数据
|
|
11081
|
+
maxZoom: 18,
|
|
11082
|
+
urlTemplate: 'http://webst{s}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}',
|
|
11083
|
+
subdomains: ['01', '02', '03', '04'],
|
|
11084
|
+
attribution: '© <a target="_blank" href="https://amap.com/">AMap</a>',
|
|
11085
|
+
spatialReference: { projection: 'EPSG:3857' },
|
|
11043
11086
|
});
|
|
11044
11087
|
case 'baidu':
|
|
11045
11088
|
return new maptalks__namespace.TileLayer(id, {
|
|
@@ -11047,20 +11090,20 @@ function createTalksBaseLayer(layerId, { id = layerId, visible = true, } = {}) {
|
|
|
11047
11090
|
urlTemplate: `http://online{s}.map.bdimg.com/tile/?qt=vtile&x={x}&y={y}&z={z}&styles=pl&type=sate&scaler=${TILE_LAYER_BAIDU_SCALER}`,
|
|
11048
11091
|
subdomains: ['0', '1', '2', '3'],
|
|
11049
11092
|
spatialReference: {
|
|
11050
|
-
projection: '
|
|
11093
|
+
projection: 'BAIDU',
|
|
11051
11094
|
},
|
|
11052
11095
|
minZoom: 3,
|
|
11053
11096
|
maxZoom: 20,
|
|
11054
11097
|
attribution: '© <a target="_blank" href="http://map.baidu.com">Baidu</a>',
|
|
11055
11098
|
});
|
|
11056
11099
|
case 'baidu-detail':
|
|
11057
|
-
//
|
|
11100
|
+
// https://maptalks.org/examples/cn/tilelayer-projection/baidu/#tilelayer-projection_baidu
|
|
11058
11101
|
return new maptalks__namespace.TileLayer(id, {
|
|
11059
11102
|
visible,
|
|
11060
11103
|
urlTemplate: `https://gss{s}.bdstatic.com/8bo_dTSlRsgBo1vgoIiO_jowehsv/tile/?qt=tile&x={x}&y={y}&z={z}&styles=pl&scaler=${TILE_LAYER_BAIDU_SCALER}&udt=20170927`,
|
|
11061
11104
|
subdomains: ['0', '1', '2', '3'],
|
|
11062
11105
|
spatialReference: {
|
|
11063
|
-
projection: '
|
|
11106
|
+
projection: 'BAIDU',
|
|
11064
11107
|
},
|
|
11065
11108
|
minZoom: 3,
|
|
11066
11109
|
maxZoom: 19,
|
|
@@ -11075,6 +11118,7 @@ function createTalksBaseLayer(layerId, { id = layerId, visible = true, } = {}) {
|
|
|
11075
11118
|
subdomains: ['0', '1', '2', '3'],
|
|
11076
11119
|
minZoom: 3,
|
|
11077
11120
|
maxZoom: 18,
|
|
11121
|
+
spatialReference: { projection: 'EPSG:3857' },
|
|
11078
11122
|
});
|
|
11079
11123
|
case 'google':
|
|
11080
11124
|
return new maptalks__namespace.TileLayer(id, {
|
|
@@ -11082,6 +11126,7 @@ function createTalksBaseLayer(layerId, { id = layerId, visible = true, } = {}) {
|
|
|
11082
11126
|
urlTemplate: 'https://api.xiox.top/proxy/https://maps.google.com/maps/vt?lyrs=m&x={x}&y={y}&z={z}&hl=zh-CN',
|
|
11083
11127
|
subdomains: ['0', '1', '2', '3'],
|
|
11084
11128
|
attribution: '© <a target="_blank" href="https://www.google.com/maps">Google</a>',
|
|
11129
|
+
spatialReference: { projection: 'EPSG:3857' },
|
|
11085
11130
|
});
|
|
11086
11131
|
case 'geoq':
|
|
11087
11132
|
// 不知道是哪家的, 无法显示
|
|
@@ -11089,6 +11134,7 @@ function createTalksBaseLayer(layerId, { id = layerId, visible = true, } = {}) {
|
|
|
11089
11134
|
visible,
|
|
11090
11135
|
urlTemplate: 'https://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer/tile/{z}/{y}/{x}',
|
|
11091
11136
|
subdomains: ['0', '1', '2', '3'],
|
|
11137
|
+
spatialReference: { projection: 'EPSG:3857' },
|
|
11092
11138
|
});
|
|
11093
11139
|
case 'tianditu':
|
|
11094
11140
|
// key已失效, 无法显示
|
|
@@ -11111,6 +11157,7 @@ function createTalksBaseLayer(layerId, { id = layerId, visible = true, } = {}) {
|
|
|
11111
11157
|
subdomains: ['1', '2', '3', '4'],
|
|
11112
11158
|
maxZoom: 21,
|
|
11113
11159
|
attribution: '© <a target="_blank" href="https://yandex.com/maps/">Yandex</a>',
|
|
11160
|
+
spatialReference: { projection: 'EPSG:3857' },
|
|
11114
11161
|
});
|
|
11115
11162
|
case 'bing':
|
|
11116
11163
|
return new maptalks__namespace.TileLayer(id, {
|
|
@@ -11119,58 +11166,97 @@ function createTalksBaseLayer(layerId, { id = layerId, visible = true, } = {}) {
|
|
|
11119
11166
|
subdomains: ['1', '2', '3'],
|
|
11120
11167
|
minZoom: 3,
|
|
11121
11168
|
maxZoom: 18,
|
|
11169
|
+
spatialReference: { projection: 'EPSG:3857' },
|
|
11122
11170
|
});
|
|
11123
11171
|
case 'osm':
|
|
11172
|
+
// https://operations.osmfoundation.org/policies/tiles/
|
|
11124
11173
|
return new maptalks__namespace.TileLayer(id, {
|
|
11125
11174
|
visible,
|
|
11126
11175
|
urlTemplate: 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
|
11127
11176
|
subdomains: ['a', 'b', 'c'],
|
|
11128
11177
|
attribution: '© <a target="_blank" href="http://www.osm.org/copyright">OSM</a>',
|
|
11178
|
+
spatialReference: { projection: 'EPSG:3857' },
|
|
11129
11179
|
});
|
|
11130
11180
|
case 'osm-light':
|
|
11181
|
+
// https://github.com/CartoDB/basemap-styles
|
|
11131
11182
|
return new maptalks__namespace.TileLayer(id, {
|
|
11132
11183
|
visible,
|
|
11133
11184
|
urlTemplate: 'http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
|
|
11134
11185
|
subdomains: ['a', 'b', 'c', 'd'],
|
|
11135
11186
|
attribution: '© <a target="_blank" href="http://www.osm.org/copyright">OSM</a> contributors, © <a target="_blank" href="https://carto.com/attributions">CARTO</a>',
|
|
11187
|
+
spatialReference: { projection: 'EPSG:3857' },
|
|
11136
11188
|
});
|
|
11137
11189
|
case 'osm-dark':
|
|
11190
|
+
// https://github.com/CartoDB/basemap-styles
|
|
11138
11191
|
return new maptalks__namespace.TileLayer(id, {
|
|
11139
11192
|
visible,
|
|
11140
11193
|
urlTemplate: 'http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png',
|
|
11141
11194
|
subdomains: ['a', 'b', 'c', 'd'],
|
|
11142
11195
|
attribution: '© <a target="_blank" href="http://www.osm.org/copyright">OSM</a> contributors, © <a target="_blank" href="https://carto.com/attributions">CARTO</a>',
|
|
11196
|
+
spatialReference: { projection: 'EPSG:3857' },
|
|
11197
|
+
});
|
|
11198
|
+
case 'osm-terrain':
|
|
11199
|
+
// https://wiki.openstreetmap.org/wiki/OpenTopoMap#Usage
|
|
11200
|
+
return new maptalks__namespace.TileLayer(id, {
|
|
11201
|
+
visible,
|
|
11202
|
+
urlTemplate: 'https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png',
|
|
11203
|
+
subdomains: ['a', 'b', 'c'],
|
|
11204
|
+
attribution: '© <a target="_blank" href="http://www.osm.org/copyright">OSM</a>',
|
|
11205
|
+
spatialReference: { projection: 'EPSG:3857' },
|
|
11143
11206
|
});
|
|
11144
11207
|
}
|
|
11145
11208
|
}
|
|
11209
|
+
const createTalksBaseLayer = process.env.NODE_ENV !== 'production'
|
|
11210
|
+
? (layerId, options) => {
|
|
11211
|
+
const layer = createTalksBaseLayerImpl(layerId, options);
|
|
11212
|
+
if (layer.options.visible == null || layer.options.spatialReference == null) {
|
|
11213
|
+
console.warn('创建的baseLayer必须设置visible和spatialReference', layer.options);
|
|
11214
|
+
}
|
|
11215
|
+
return layer;
|
|
11216
|
+
}
|
|
11217
|
+
: createTalksBaseLayerImpl;
|
|
11146
11218
|
|
|
11147
11219
|
const MAP_ATTRIBUTION_TG = { content: 'TG' };
|
|
11148
11220
|
class TalksMap extends BaseMap {
|
|
11149
11221
|
mapOptions;
|
|
11222
|
+
baseLayoutIds;
|
|
11150
11223
|
map;
|
|
11151
|
-
|
|
11152
|
-
|
|
11224
|
+
attributionControl;
|
|
11225
|
+
baseLayerGroup;
|
|
11226
|
+
mapStyleTheme;
|
|
11227
|
+
/**
|
|
11228
|
+
* 由于通过{@link MapTypeControl}, maptalks可以在内部切换可见的baseLayer, 所以要获取实际当前的显示的baseLayer, 应该使用{@link getCurrentBaseLayer}
|
|
11229
|
+
* 但为了方便快速的执行{@link coordType}, 因而增加了这个缓存的值
|
|
11230
|
+
* @internal
|
|
11231
|
+
* */
|
|
11232
|
+
cachedBaseLayerId;
|
|
11153
11233
|
/** @internal */
|
|
11154
11234
|
markerLayer;
|
|
11155
11235
|
/** @internal */
|
|
11156
11236
|
overlayLayer;
|
|
11157
|
-
constructor(element, mapOptions,
|
|
11237
|
+
constructor(element, mapOptions,
|
|
11238
|
+
/**
|
|
11239
|
+
* 最多8项, 前四项对应{@link MapType.BUILD_IN_MAP_TYPES}的四个值(普通、卫星、混合、地形)的亮色版, 后四项对应暗色版
|
|
11240
|
+
* @see computeBaseLayerId
|
|
11241
|
+
*/
|
|
11242
|
+
baseLayoutIds) {
|
|
11158
11243
|
super(element);
|
|
11159
11244
|
this.mapOptions = mapOptions;
|
|
11160
|
-
|
|
11161
|
-
|
|
11162
|
-
this.
|
|
11163
|
-
|
|
11164
|
-
|
|
11245
|
+
this.baseLayoutIds = baseLayoutIds;
|
|
11246
|
+
this.mapStyleTheme = mapOptions.mapStyle?.talks?.theme ?? 'light';
|
|
11247
|
+
this.cachedBaseLayerId = this.computeBaseLayerId(mapOptions.buildInMapTypeId, this.mapStyleTheme);
|
|
11248
|
+
this.baseLayerGroup = new maptalks__namespace.GroupTileLayer('base', baseLayoutIds
|
|
11249
|
+
.filter(tgCommons.isTruthy)
|
|
11250
|
+
.map(id => createTalksBaseLayer(id, { visible: id === this.cachedBaseLayerId })));
|
|
11165
11251
|
this.markerLayer = new maptalks__namespace.VectorLayer('markers');
|
|
11166
11252
|
this.overlayLayer = new maptalks__namespace.VectorLayer('overlays');
|
|
11253
|
+
const baseLayer = this.getCurrentBaseLayer();
|
|
11167
11254
|
this.map = new maptalks__namespace.Map(element, {
|
|
11168
|
-
attribution
|
|
11169
|
-
|
|
11170
|
-
|
|
11171
|
-
baseLayer: baseLayer,
|
|
11255
|
+
// 默认的attribution不会显示GroupTileLayer的子layer的attribution, 故不显示, 使用自己的this.attributionControl来处理
|
|
11256
|
+
attribution: false,
|
|
11257
|
+
baseLayer: this.baseLayerGroup,
|
|
11172
11258
|
// {@macro layer_baidu_spatial_reference}
|
|
11173
|
-
spatialReference: baseLayer?.
|
|
11259
|
+
spatialReference: baseLayer?.options.spatialReference,
|
|
11174
11260
|
// 参考google, marker和其他overlay分属不同layer, 并且marker位于overlay上方
|
|
11175
11261
|
layers: [
|
|
11176
11262
|
this.overlayLayer, this.markerLayer,
|
|
@@ -11179,11 +11265,60 @@ class TalksMap extends BaseMap {
|
|
|
11179
11265
|
seamlessZoom: mapOptions.fractionalZoom ?? false,
|
|
11180
11266
|
zoom: mapOptions.zoom,
|
|
11181
11267
|
// 默认使用baseLayer的Zoom范围
|
|
11182
|
-
minZoom: mapOptions.minZoom ?? baseLayer?.
|
|
11183
|
-
maxZoom: mapOptions.maxZoom ?? baseLayer?.
|
|
11268
|
+
minZoom: mapOptions.minZoom ?? baseLayer?.options.minZoom,
|
|
11269
|
+
maxZoom: mapOptions.maxZoom ?? baseLayer?.options.maxZoom,
|
|
11184
11270
|
});
|
|
11185
11271
|
this.setGestureHandling(mapOptions.gestureHandling);
|
|
11186
11272
|
this.setEventTargetDelegate(new TalksEventTargetDelegate(this.map, this));
|
|
11273
|
+
this.attributionControl = new maptalks__namespace.control.Attribution(MAP_ATTRIBUTION_TG);
|
|
11274
|
+
this.map.addControl(this.attributionControl);
|
|
11275
|
+
this.setHideLogo(mapOptions.hideLogo ?? false);
|
|
11276
|
+
this.map.on('setbaselayer', this.onBaseLayerChanged);
|
|
11277
|
+
this.onBaseLayerChanged();
|
|
11278
|
+
}
|
|
11279
|
+
getCurrentBaseLayer() {
|
|
11280
|
+
return this.baseLayerGroup.layers.find(it => it.isVisible());
|
|
11281
|
+
}
|
|
11282
|
+
onBaseLayerChanged = () => {
|
|
11283
|
+
const baseLayer = this.getCurrentBaseLayer();
|
|
11284
|
+
if (!baseLayer)
|
|
11285
|
+
return;
|
|
11286
|
+
// 更新cacheBaseLayerId, attribution, spatialReference, 但并没有更新minZoom/maxZoom, 因为感觉必要性不大
|
|
11287
|
+
this.cachedBaseLayerId = baseLayer.getId();
|
|
11288
|
+
const layerAttribution = baseLayer.options.attribution;
|
|
11289
|
+
this.attributionControl.setContent(MAP_ATTRIBUTION_TG.content + (layerAttribution ? ` - ${layerAttribution}` : ''));
|
|
11290
|
+
if (this.map.getSpatialReference().options.projection !== baseLayer.getSpatialReference().options.projection) {
|
|
11291
|
+
console.debug('setSpatialReference', this.map.getSpatialReference().options, '==>', baseLayer.getSpatialReference().options);
|
|
11292
|
+
this.map.setSpatialReference(baseLayer.getSpatialReference().options);
|
|
11293
|
+
}
|
|
11294
|
+
};
|
|
11295
|
+
computeBaseLayerId(buildInMapTypeId = exports.BuildInMapTypeId.normal, theme = 'light') {
|
|
11296
|
+
const mapType = exports.MapType.BUILD_IN_MAP_TYPES.get(BuildInMapType.prototype.getId, buildInMapTypeId);
|
|
11297
|
+
if (theme === 'dark') {
|
|
11298
|
+
const darkOffset = exports.MapType.BUILD_IN_MAP_TYPES.values.length;
|
|
11299
|
+
// 遍历: 7, 6, 5, 4, 查找设置了值的暗色layerId
|
|
11300
|
+
for (let i = Math.min((mapType.index + darkOffset), this.baseLayoutIds.length - 1); i >= darkOffset; i--) {
|
|
11301
|
+
if (this.baseLayoutIds[i]) {
|
|
11302
|
+
return this.baseLayoutIds[i];
|
|
11303
|
+
}
|
|
11304
|
+
}
|
|
11305
|
+
}
|
|
11306
|
+
// 遍历: 3, 2, 1, 0, 查找设置了值的亮色layerId
|
|
11307
|
+
for (let i = Math.min(mapType.index, this.baseLayoutIds.length - 1); i >= 0; i--) {
|
|
11308
|
+
if (this.baseLayoutIds[i]) {
|
|
11309
|
+
return this.baseLayoutIds[i];
|
|
11310
|
+
}
|
|
11311
|
+
}
|
|
11312
|
+
return this.baseLayoutIds[0];
|
|
11313
|
+
}
|
|
11314
|
+
setBaseLayer(id, theme) {
|
|
11315
|
+
this.mapStyleTheme = theme;
|
|
11316
|
+
const baseLayerId = this.computeBaseLayerId(id, theme);
|
|
11317
|
+
const currentBaseLayerId = this.getCurrentBaseLayer()?.getId();
|
|
11318
|
+
if (currentBaseLayerId !== baseLayerId) {
|
|
11319
|
+
this.baseLayerGroup.layers.forEach((layer) => exports.Talks.setVisible(layer, layer.getId() === baseLayerId));
|
|
11320
|
+
this.onBaseLayerChanged();
|
|
11321
|
+
}
|
|
11187
11322
|
}
|
|
11188
11323
|
setGestureHandling(gestureHandling = exports.GestureHandlingOptions.auto) {
|
|
11189
11324
|
if (gestureHandling === exports.GestureHandlingOptions.auto) {
|
|
@@ -11219,7 +11354,7 @@ class TalksMap extends BaseMap {
|
|
|
11219
11354
|
return this.map;
|
|
11220
11355
|
}
|
|
11221
11356
|
get coordType() {
|
|
11222
|
-
return talksBaseLayerIdToCoordType(this.
|
|
11357
|
+
return talksBaseLayerIdToCoordType(this.cachedBaseLayerId);
|
|
11223
11358
|
}
|
|
11224
11359
|
fromContainerPointToLatLng(point) {
|
|
11225
11360
|
const coordinate = this.map.containerPointToCoordinate(new maptalks__namespace.Point(point.x, point.y));
|
|
@@ -11230,7 +11365,7 @@ class TalksMap extends BaseMap {
|
|
|
11230
11365
|
return point; // maptalks.Point符合Point接口, 可以直接返回
|
|
11231
11366
|
}
|
|
11232
11367
|
setHideLogo(hideLogo) {
|
|
11233
|
-
|
|
11368
|
+
exports.Talks.setVisible(this.attributionControl, !hideLogo);
|
|
11234
11369
|
}
|
|
11235
11370
|
setFractionalZoom(enabled) {
|
|
11236
11371
|
this.map.config('seamlessZoom', enabled);
|
|
@@ -11257,16 +11392,31 @@ class TalksMap extends BaseMap {
|
|
|
11257
11392
|
this.map.setMaxZoom(zoom);
|
|
11258
11393
|
}
|
|
11259
11394
|
setMapStyle(mapStyle) {
|
|
11260
|
-
|
|
11395
|
+
if (mapStyle?.talks?.theme) {
|
|
11396
|
+
const mapType = this.getMapType();
|
|
11397
|
+
if (mapType instanceof BuildInMapType) {
|
|
11398
|
+
this.setBaseLayer(mapType.id, mapStyle.talks.theme);
|
|
11399
|
+
}
|
|
11400
|
+
else {
|
|
11401
|
+
console.log('自定义MapType不支持设置地图样式', mapType);
|
|
11402
|
+
}
|
|
11403
|
+
}
|
|
11261
11404
|
}
|
|
11262
11405
|
setBuildInMapTypeId(id) {
|
|
11263
|
-
|
|
11406
|
+
this.setBaseLayer(id, this.mapStyleTheme);
|
|
11264
11407
|
}
|
|
11265
11408
|
setMapType(mapType) {
|
|
11266
|
-
|
|
11409
|
+
if (mapType instanceof BuildInMapType) {
|
|
11410
|
+
this.setBaseLayer(mapType.getId(), this.mapStyleTheme);
|
|
11411
|
+
}
|
|
11267
11412
|
}
|
|
11268
11413
|
getMapType() {
|
|
11269
|
-
|
|
11414
|
+
const currentBaseLayerId = this.getCurrentBaseLayer()?.getId();
|
|
11415
|
+
const index = this.baseLayoutIds.findIndex(it => it === currentBaseLayerId);
|
|
11416
|
+
if (index !== -1) {
|
|
11417
|
+
return exports.MapType.BUILD_IN_MAP_TYPES.values[index % exports.MapType.BUILD_IN_MAP_TYPES.values.length];
|
|
11418
|
+
}
|
|
11419
|
+
// TODO: 2026/01/05 ipcjs 自定义MapType, 下一版再实现该功能
|
|
11270
11420
|
return exports.MapType.NORMAL;
|
|
11271
11421
|
}
|
|
11272
11422
|
addLayer(layer) {
|
|
@@ -11381,17 +11531,20 @@ exports.TgMapFactory = void 0;
|
|
|
11381
11531
|
case exports.TgMapType.here:
|
|
11382
11532
|
return new HereMap($map, options);
|
|
11383
11533
|
case exports.TgMapType.baiduFree:
|
|
11384
|
-
return new TalksMap($map, options, ['baidu', 'osm']);
|
|
11534
|
+
return new TalksMap($map, options, ['baidu', 'amap-terrain', undefined, undefined, 'osm-dark']);
|
|
11385
11535
|
case exports.TgMapType.googleFree:
|
|
11386
|
-
return new TalksMap($map, options, ['google', 'osm']);
|
|
11536
|
+
return new TalksMap($map, options, ['google', 'osm-terrain', undefined, undefined, 'osm-dark']);
|
|
11387
11537
|
case exports.TgMapType.amap:
|
|
11388
|
-
return new TalksMap($map, options, ['amap']);
|
|
11538
|
+
return new TalksMap($map, options, ['amap', 'amap-terrain', undefined, undefined, 'osm-dark']);
|
|
11389
11539
|
case exports.TgMapType.osm:
|
|
11390
|
-
return new TalksMap($map, options, ['osm']);
|
|
11540
|
+
return new TalksMap($map, options, ['osm-light', 'osm-terrain', undefined, undefined, 'osm-dark']);
|
|
11391
11541
|
case exports.TgMapType.yandex:
|
|
11392
|
-
return new TalksMap($map, options, ['yandex']);
|
|
11393
|
-
case exports.TgMapType.talks:
|
|
11394
|
-
|
|
11542
|
+
return new TalksMap($map, options, ['yandex', undefined, undefined, undefined, 'osm-dark']);
|
|
11543
|
+
case exports.TgMapType.talks: {
|
|
11544
|
+
const hasDefinedFirstElement = (array) => !!(array && array.length && array[0]);
|
|
11545
|
+
const talks = getTgMapConfig().talks;
|
|
11546
|
+
return new TalksMap($map, options, hasDefinedFirstElement(talks.layerIds) ? talks.layerIds : [talks.layerId || 'bing']);
|
|
11547
|
+
}
|
|
11395
11548
|
default:
|
|
11396
11549
|
tgCommons.assertNever(type);
|
|
11397
11550
|
}
|