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.
@@ -1,5 +1,5 @@
1
1
  import * as maptalks from 'maptalks';
2
- import { noop, throwError, assert, lateinit, Arrays as Arrays$1, identical, throwUnsupported, delay, assertNever, Strings as Strings$1, StringEnums } from 'tg-commons';
2
+ import { noop, throwError, assert, lateinit, Arrays as Arrays$1, identical, throwUnsupported, delay, assertNever, Strings as Strings$1, isTruthy } from 'tg-commons';
3
3
  import coordtransform from 'coordtransform';
4
4
  import deepmerge from 'deepmerge';
5
5
  import { ClusterLayer } from 'maptalks.markercluster';
@@ -1528,6 +1528,8 @@ class TalksEventTargetDelegate extends AbstractEventTargetDelegate {
1528
1528
  static EVENT_TYPE_MAP = typedRecord({
1529
1529
  'center-changed': 'movestart moving moveend zoomend',
1530
1530
  'zoom-changed': 'zoomend',
1531
+ // https://maptalks.org/maptalks.js/api/1.x/Map.html#event:setbaselayer
1532
+ 'map-type-changed': 'setbaselayer',
1531
1533
  });
1532
1534
  eventTypeMap;
1533
1535
  /**
@@ -1732,6 +1734,19 @@ function hideBaiduMapUnauthWarn() {
1732
1734
  }
1733
1735
  return false;
1734
1736
  };
1737
+ if (!isBaiduGL()) {
1738
+ // 新的V3版也会直接从签名的`B_BUSINESS_INFO`中检测是否弹窗警告, 强制清空它可以规避检测(
1739
+ Object.defineProperty(window, 'B_BUSINESS_INFO', {
1740
+ configurable: true,
1741
+ enumerable: true,
1742
+ get: () => {
1743
+ return undefined;
1744
+ },
1745
+ set: (v) => {
1746
+ console.debug('B_BUSINESS_INFO', 'set', v);
1747
+ },
1748
+ });
1749
+ }
1735
1750
  let originalBMap;
1736
1751
  let originalBMapVerifyCbk;
1737
1752
  Object.defineProperty(window, 'BMap', {
@@ -2168,13 +2183,17 @@ var BuildInMapTypeId;
2168
2183
  })(BuildInMapTypeId || (BuildInMapTypeId = {}));
2169
2184
  class BuildInMapType {
2170
2185
  id;
2186
+ index;
2171
2187
  baidu;
2172
2188
  google;
2173
2189
  googleCoordType;
2174
- constructor(id, baidu, // 需要延迟初始化, 故写成方法
2190
+ constructor(id,
2191
+ /** 在{@link MapType.BUILD_IN_MAP_TYPES.values}中的index */
2192
+ index, baidu, // 需要延迟初始化, 故写成方法
2175
2193
  google, // 同上
2176
2194
  googleCoordType) {
2177
2195
  this.id = id;
2196
+ this.index = index;
2178
2197
  this.baidu = baidu;
2179
2198
  this.google = google;
2180
2199
  this.googleCoordType = googleCoordType;
@@ -2284,10 +2303,10 @@ class TrafficLayer {
2284
2303
  }
2285
2304
  var MapType;
2286
2305
  (function (MapType) {
2287
- MapType.NORMAL = new BuildInMapType(BuildInMapTypeId.normal, () => BMAP_NORMAL_MAP, () => google.maps.MapTypeId.ROADMAP, CoordType.gcj02);
2288
- MapType.SATELLITE = new BuildInMapType(BuildInMapTypeId.satellite, () => BMAP_SATELLITE_MAP, () => google.maps.MapTypeId.SATELLITE, CoordType.wgs84);
2289
- MapType.HYBRID = new BuildInMapType(BuildInMapTypeId.hybrid, () => BMAP_HYBRID_MAP, () => google.maps.MapTypeId.HYBRID, CoordType.gcj02);
2290
- MapType.TERRAIN = new BuildInMapType('terrain', () => /* 三维 */ BMAP_PERSPECTIVE_MAP, () => /* 地形 */ google.maps.MapTypeId.TERRAIN, CoordType.wgs84);
2306
+ MapType.NORMAL = new BuildInMapType(BuildInMapTypeId.normal, 0, () => BMAP_NORMAL_MAP, () => google.maps.MapTypeId.ROADMAP, CoordType.gcj02);
2307
+ MapType.SATELLITE = new BuildInMapType(BuildInMapTypeId.satellite, 1, () => BMAP_SATELLITE_MAP, () => google.maps.MapTypeId.SATELLITE, CoordType.wgs84);
2308
+ MapType.HYBRID = new BuildInMapType(BuildInMapTypeId.hybrid, 2, () => BMAP_HYBRID_MAP, () => google.maps.MapTypeId.HYBRID, CoordType.gcj02);
2309
+ MapType.TERRAIN = new BuildInMapType('terrain', 3, () => /* 三维 */ BMAP_PERSPECTIVE_MAP, () => /* 地形 */ google.maps.MapTypeId.TERRAIN, CoordType.wgs84);
2291
2310
  MapType.BUILD_IN_MAP_TYPES = new FastFindValues([MapType.NORMAL, MapType.SATELLITE, MapType.HYBRID, MapType.TERRAIN]);
2292
2311
  })(MapType || (MapType = {}));
2293
2312
 
@@ -2300,6 +2319,10 @@ var MapTypeControlType;
2300
2319
  const MAP_TYPES_DEFAULT = [MapType.NORMAL, MapType.SATELLITE, MapType.HYBRID];
2301
2320
  class BaiduMapTypeControl extends BaiduControl {
2302
2321
  static create(options) {
2322
+ if (isBaiduGL()) {
2323
+ // GL版, 不存在MapTypeControl...故返回空
2324
+ return new EmptyControl(true, options.position ?? ControlPosition.TOP_LEFT);
2325
+ }
2303
2326
  const mapTypes = options.mapTypes ?? MAP_TYPES_DEFAULT;
2304
2327
  const type2baidu = {
2305
2328
  [MapTypeControlType.DEFAULT]: BMAP_MAPTYPE_CONTROL_HORIZONTAL,
@@ -2351,9 +2374,13 @@ class GoogleMapTypeControl extends GoogleControl {
2351
2374
  });
2352
2375
  }
2353
2376
  }
2354
- class TalksMapTypeControl extends EmptyControl {
2377
+ class TalksMapTypeControl extends TalksControl {
2355
2378
  static create(options) {
2356
- return new TalksMapTypeControl(true, options.position ?? ControlPosition.TOP_LEFT);
2379
+ const position = options.position ?? ControlPosition.TOP_LEFT;
2380
+ const inner = new maptalks.control.LayerSwitcher({
2381
+ position: ControlPositionConverter.getTalks().toValue(position),
2382
+ });
2383
+ return new TalksMapTypeControl(inner, position);
2357
2384
  }
2358
2385
  }
2359
2386
 
@@ -7301,7 +7328,7 @@ class TalksMarkerClusterer {
7301
7328
  this.inner = new ClusterLayer('cluster', options.markers?.map(it => it.innerOverlay), Objects.deleteUndefinedPropertyOnPlainObjectDeeply({
7302
7329
  ...ClusterIconStyle.toTalks(options.styles),
7303
7330
  // {@macro marker_clusterer_grid_size}
7304
- maxClusterRadius: options.gridSize ?? (map.currentBaseLayerId === 'baidu' || map.currentBaseLayerId === 'baidu-detail' ? 60 : 100),
7331
+ maxClusterRadius: options.gridSize ?? (map.cachedBaseLayerId === 'baidu' || map.cachedBaseLayerId === 'baidu-detail' ? 60 : 100),
7305
7332
  maxClusterZoom: options.maxZoom,
7306
7333
  zIndex: options.zIndex,
7307
7334
  }));
@@ -7852,7 +7879,7 @@ class TalksShape extends TalksOverlay {
7852
7879
  * @see setEditable
7853
7880
  */
7854
7881
  isEditable() {
7855
- return this.innerOverlay.config().editable ?? false;
7882
+ return this.innerOverlay.options.editable ?? false;
7856
7883
  }
7857
7884
  setEditable(editable) {
7858
7885
  // 同步设置editable和isEditing
@@ -9231,7 +9258,7 @@ class TalksLabelOverlay extends TalksOverlay {
9231
9258
  this.innerOverlay.setCoordinates(position.toTalks(this.coordType));
9232
9259
  }
9233
9260
  getOffset() {
9234
- const options = this.innerOverlay.config();
9261
+ const options = this.innerOverlay.options;
9235
9262
  return { x: options.dx ?? 0, y: options.dy ?? 0 };
9236
9263
  }
9237
9264
  setOffset(offset) {
@@ -9779,13 +9806,13 @@ class TalksMarker extends TalksOverlay {
9779
9806
  this.innerOverlay.config('interactive', enable);
9780
9807
  }
9781
9808
  isClickable() {
9782
- return this.innerOverlay.config().interactive ?? true;
9809
+ return this.innerOverlay.options.interactive ?? true;
9783
9810
  }
9784
9811
  setDraggable(enable) {
9785
9812
  this.innerOverlay.config('draggable', enable);
9786
9813
  }
9787
9814
  isDraggable() {
9788
- return this.innerOverlay.config().draggable ?? false;
9815
+ return this.innerOverlay.options.draggable ?? false;
9789
9816
  }
9790
9817
  setZIndex(zIndex) {
9791
9818
  this.innerOverlay.setZIndex(zIndex ?? 0);
@@ -10967,10 +10994,12 @@ const talksBaseLayerIds = [
10967
10994
  'osm',
10968
10995
  'osm-light',
10969
10996
  'osm-dark',
10997
+ 'osm-terrain',
10970
10998
  'google',
10971
10999
  'baidu',
10972
11000
  'baidu-detail',
10973
11001
  'amap',
11002
+ 'amap-terrain',
10974
11003
  'tencent',
10975
11004
  'geoq',
10976
11005
  'tianditu',
@@ -11004,15 +11033,29 @@ function talksBaseLayerIdToCoordType(layerId) {
11004
11033
  * @see https://maptalks.org/examples/cn/tilelayer-projection/baidu/#tilelayer-projection_baidu
11005
11034
  */
11006
11035
  const TILE_LAYER_BAIDU_SCALER = 1;
11007
- function createTalksBaseLayer(layerId, { id = layerId, visible = true, } = {}) {
11036
+ function createTalksBaseLayerImpl(layerId, { id = layerId, visible = true, } = {}) {
11008
11037
  switch (layerId) {
11009
11038
  case 'amap':
11010
11039
  return new maptalks.TileLayer(id, {
11011
11040
  visible,
11012
- urlTemplate: 'http://webrd03.is.autonavi.com/appmaptile?style=8&x={x}&y={y}&z={z}&lang=zh_cn',
11041
+ urlTemplate: 'http://webrd{s}.is.autonavi.com/appmaptile?style=8&x={x}&y={y}&z={z}&lang=zh_cn',
11042
+ subdomains: ['01', '02', '03', '04'],
11013
11043
  minZoom: 3,
11014
11044
  maxZoom: 18,
11015
11045
  attribution: '&copy; <a target="_blank" href="https://amap.com/">AMap</a>',
11046
+ spatialReference: { projection: 'EPSG:3857' },
11047
+ });
11048
+ case 'amap-terrain':
11049
+ // http://examples.maptalks.com/examples/cn/3d/terrain/load
11050
+ return new maptalks.TileLayer(id, {
11051
+ visible,
11052
+ minZoom: 1,
11053
+ // 深圳最大可以到18级, 一些偏远地带, 18级可能没有数据
11054
+ maxZoom: 18,
11055
+ urlTemplate: 'http://webst{s}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}',
11056
+ subdomains: ['01', '02', '03', '04'],
11057
+ attribution: '&copy; <a target="_blank" href="https://amap.com/">AMap</a>',
11058
+ spatialReference: { projection: 'EPSG:3857' },
11016
11059
  });
11017
11060
  case 'baidu':
11018
11061
  return new maptalks.TileLayer(id, {
@@ -11020,20 +11063,20 @@ function createTalksBaseLayer(layerId, { id = layerId, visible = true, } = {}) {
11020
11063
  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}`,
11021
11064
  subdomains: ['0', '1', '2', '3'],
11022
11065
  spatialReference: {
11023
- projection: 'baidu',
11066
+ projection: 'BAIDU',
11024
11067
  },
11025
11068
  minZoom: 3,
11026
11069
  maxZoom: 20,
11027
11070
  attribution: '&copy; <a target="_blank" href="http://map.baidu.com">Baidu</a>',
11028
11071
  });
11029
11072
  case 'baidu-detail':
11030
- // 参考: https://maptalks.org/examples/cn/tilelayer-projection/baidu/#tilelayer-projection_baidu
11073
+ // https://maptalks.org/examples/cn/tilelayer-projection/baidu/#tilelayer-projection_baidu
11031
11074
  return new maptalks.TileLayer(id, {
11032
11075
  visible,
11033
11076
  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`,
11034
11077
  subdomains: ['0', '1', '2', '3'],
11035
11078
  spatialReference: {
11036
- projection: 'baidu',
11079
+ projection: 'BAIDU',
11037
11080
  },
11038
11081
  minZoom: 3,
11039
11082
  maxZoom: 19,
@@ -11048,6 +11091,7 @@ function createTalksBaseLayer(layerId, { id = layerId, visible = true, } = {}) {
11048
11091
  subdomains: ['0', '1', '2', '3'],
11049
11092
  minZoom: 3,
11050
11093
  maxZoom: 18,
11094
+ spatialReference: { projection: 'EPSG:3857' },
11051
11095
  });
11052
11096
  case 'google':
11053
11097
  return new maptalks.TileLayer(id, {
@@ -11055,6 +11099,7 @@ function createTalksBaseLayer(layerId, { id = layerId, visible = true, } = {}) {
11055
11099
  urlTemplate: 'https://api.xiox.top/proxy/https://maps.google.com/maps/vt?lyrs=m&x={x}&y={y}&z={z}&hl=zh-CN',
11056
11100
  subdomains: ['0', '1', '2', '3'],
11057
11101
  attribution: '&copy; <a target="_blank" href="https://www.google.com/maps">Google</a>',
11102
+ spatialReference: { projection: 'EPSG:3857' },
11058
11103
  });
11059
11104
  case 'geoq':
11060
11105
  // 不知道是哪家的, 无法显示
@@ -11062,6 +11107,7 @@ function createTalksBaseLayer(layerId, { id = layerId, visible = true, } = {}) {
11062
11107
  visible,
11063
11108
  urlTemplate: 'https://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer/tile/{z}/{y}/{x}',
11064
11109
  subdomains: ['0', '1', '2', '3'],
11110
+ spatialReference: { projection: 'EPSG:3857' },
11065
11111
  });
11066
11112
  case 'tianditu':
11067
11113
  // key已失效, 无法显示
@@ -11084,6 +11130,7 @@ function createTalksBaseLayer(layerId, { id = layerId, visible = true, } = {}) {
11084
11130
  subdomains: ['1', '2', '3', '4'],
11085
11131
  maxZoom: 21,
11086
11132
  attribution: '&copy; <a target="_blank" href="https://yandex.com/maps/">Yandex</a>',
11133
+ spatialReference: { projection: 'EPSG:3857' },
11087
11134
  });
11088
11135
  case 'bing':
11089
11136
  return new maptalks.TileLayer(id, {
@@ -11092,58 +11139,97 @@ function createTalksBaseLayer(layerId, { id = layerId, visible = true, } = {}) {
11092
11139
  subdomains: ['1', '2', '3'],
11093
11140
  minZoom: 3,
11094
11141
  maxZoom: 18,
11142
+ spatialReference: { projection: 'EPSG:3857' },
11095
11143
  });
11096
11144
  case 'osm':
11145
+ // https://operations.osmfoundation.org/policies/tiles/
11097
11146
  return new maptalks.TileLayer(id, {
11098
11147
  visible,
11099
11148
  urlTemplate: 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
11100
11149
  subdomains: ['a', 'b', 'c'],
11101
11150
  attribution: '&copy; <a target="_blank" href="http://www.osm.org/copyright">OSM</a>',
11151
+ spatialReference: { projection: 'EPSG:3857' },
11102
11152
  });
11103
11153
  case 'osm-light':
11154
+ // https://github.com/CartoDB/basemap-styles
11104
11155
  return new maptalks.TileLayer(id, {
11105
11156
  visible,
11106
11157
  urlTemplate: 'http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
11107
11158
  subdomains: ['a', 'b', 'c', 'd'],
11108
11159
  attribution: '&copy; <a target="_blank" href="http://www.osm.org/copyright">OSM</a> contributors, &copy; <a target="_blank" href="https://carto.com/attributions">CARTO</a>',
11160
+ spatialReference: { projection: 'EPSG:3857' },
11109
11161
  });
11110
11162
  case 'osm-dark':
11163
+ // https://github.com/CartoDB/basemap-styles
11111
11164
  return new maptalks.TileLayer(id, {
11112
11165
  visible,
11113
11166
  urlTemplate: 'http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png',
11114
11167
  subdomains: ['a', 'b', 'c', 'd'],
11115
11168
  attribution: '&copy; <a target="_blank" href="http://www.osm.org/copyright">OSM</a> contributors, &copy; <a target="_blank" href="https://carto.com/attributions">CARTO</a>',
11169
+ spatialReference: { projection: 'EPSG:3857' },
11170
+ });
11171
+ case 'osm-terrain':
11172
+ // https://wiki.openstreetmap.org/wiki/OpenTopoMap#Usage
11173
+ return new maptalks.TileLayer(id, {
11174
+ visible,
11175
+ urlTemplate: 'https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png',
11176
+ subdomains: ['a', 'b', 'c'],
11177
+ attribution: '&copy; <a target="_blank" href="http://www.osm.org/copyright">OSM</a>',
11178
+ spatialReference: { projection: 'EPSG:3857' },
11116
11179
  });
11117
11180
  }
11118
11181
  }
11182
+ const createTalksBaseLayer = process.env.NODE_ENV !== 'production'
11183
+ ? (layerId, options) => {
11184
+ const layer = createTalksBaseLayerImpl(layerId, options);
11185
+ if (layer.options.visible == null || layer.options.spatialReference == null) {
11186
+ console.warn('创建的baseLayer必须设置visible和spatialReference', layer.options);
11187
+ }
11188
+ return layer;
11189
+ }
11190
+ : createTalksBaseLayerImpl;
11119
11191
 
11120
11192
  const MAP_ATTRIBUTION_TG = { content: 'TG' };
11121
11193
  class TalksMap extends BaseMap {
11122
11194
  mapOptions;
11195
+ baseLayoutIds;
11123
11196
  map;
11124
- /** @internal */
11125
- currentBaseLayerId;
11197
+ attributionControl;
11198
+ baseLayerGroup;
11199
+ mapStyleTheme;
11200
+ /**
11201
+ * 由于通过{@link MapTypeControl}, maptalks可以在内部切换可见的baseLayer, 所以要获取实际当前的显示的baseLayer, 应该使用{@link getCurrentBaseLayer}
11202
+ * 但为了方便快速的执行{@link coordType}, 因而增加了这个缓存的值
11203
+ * @internal
11204
+ * */
11205
+ cachedBaseLayerId;
11126
11206
  /** @internal */
11127
11207
  markerLayer;
11128
11208
  /** @internal */
11129
11209
  overlayLayer;
11130
- constructor(element, mapOptions, baseLayoutIds) {
11210
+ constructor(element, mapOptions,
11211
+ /**
11212
+ * 最多8项, 前四项对应{@link MapType.BUILD_IN_MAP_TYPES}的四个值(普通、卫星、混合、地形)的亮色版, 后四项对应暗色版
11213
+ * @see computeBaseLayerId
11214
+ */
11215
+ baseLayoutIds) {
11131
11216
  super(element);
11132
11217
  this.mapOptions = mapOptions;
11133
- // TODO: 2025/11/05 ipcjs 实现MapType机制
11134
- const buildInMapTypeIdIndex = StringEnums.values(BuildInMapTypeId).indexOf(mapOptions.buildInMapTypeId ?? BuildInMapTypeId.normal);
11135
- this.currentBaseLayerId = baseLayoutIds[buildInMapTypeIdIndex] ?? baseLayoutIds[0];
11136
- const baseLayers = baseLayoutIds.map(id => createTalksBaseLayer(id, { visible: id === this.currentBaseLayerId }));
11137
- const baseLayer = baseLayers.find(it => it.isVisible());
11218
+ this.baseLayoutIds = baseLayoutIds;
11219
+ this.mapStyleTheme = mapOptions.mapStyle?.talks?.theme ?? 'light';
11220
+ this.cachedBaseLayerId = this.computeBaseLayerId(mapOptions.buildInMapTypeId, this.mapStyleTheme);
11221
+ this.baseLayerGroup = new maptalks.GroupTileLayer('base', baseLayoutIds
11222
+ .filter(isTruthy)
11223
+ .map(id => createTalksBaseLayer(id, { visible: id === this.cachedBaseLayerId })));
11138
11224
  this.markerLayer = new maptalks.VectorLayer('markers');
11139
11225
  this.overlayLayer = new maptalks.VectorLayer('overlays');
11226
+ const baseLayer = this.getCurrentBaseLayer();
11140
11227
  this.map = new maptalks.Map(element, {
11141
- attribution: mapOptions.hideLogo ? false : MAP_ATTRIBUTION_TG,
11142
- // TODO: 使用GroupTileLayer, Map无法正确读取到当前显示的Layer的attribution, 故暂时不使用它
11143
- // baseLayer: new maptalks.GroupTileLayer('base', baseLayers),
11144
- baseLayer: baseLayer,
11228
+ // 默认的attribution不会显示GroupTileLayer的子layer的attribution, 故不显示, 使用自己的this.attributionControl来处理
11229
+ attribution: false,
11230
+ baseLayer: this.baseLayerGroup,
11145
11231
  // {@macro layer_baidu_spatial_reference}
11146
- spatialReference: baseLayer?.config().spatialReference,
11232
+ spatialReference: baseLayer?.options.spatialReference,
11147
11233
  // 参考google, marker和其他overlay分属不同layer, 并且marker位于overlay上方
11148
11234
  layers: [
11149
11235
  this.overlayLayer, this.markerLayer,
@@ -11152,11 +11238,60 @@ class TalksMap extends BaseMap {
11152
11238
  seamlessZoom: mapOptions.fractionalZoom ?? false,
11153
11239
  zoom: mapOptions.zoom,
11154
11240
  // 默认使用baseLayer的Zoom范围
11155
- minZoom: mapOptions.minZoom ?? baseLayer?.config().minZoom,
11156
- maxZoom: mapOptions.maxZoom ?? baseLayer?.config().maxZoom,
11241
+ minZoom: mapOptions.minZoom ?? baseLayer?.options.minZoom,
11242
+ maxZoom: mapOptions.maxZoom ?? baseLayer?.options.maxZoom,
11157
11243
  });
11158
11244
  this.setGestureHandling(mapOptions.gestureHandling);
11159
11245
  this.setEventTargetDelegate(new TalksEventTargetDelegate(this.map, this));
11246
+ this.attributionControl = new maptalks.control.Attribution(MAP_ATTRIBUTION_TG);
11247
+ this.map.addControl(this.attributionControl);
11248
+ this.setHideLogo(mapOptions.hideLogo ?? false);
11249
+ this.map.on('setbaselayer', this.onBaseLayerChanged);
11250
+ this.onBaseLayerChanged();
11251
+ }
11252
+ getCurrentBaseLayer() {
11253
+ return this.baseLayerGroup.layers.find(it => it.isVisible());
11254
+ }
11255
+ onBaseLayerChanged = () => {
11256
+ const baseLayer = this.getCurrentBaseLayer();
11257
+ if (!baseLayer)
11258
+ return;
11259
+ // 更新cacheBaseLayerId, attribution, spatialReference, 但并没有更新minZoom/maxZoom, 因为感觉必要性不大
11260
+ this.cachedBaseLayerId = baseLayer.getId();
11261
+ const layerAttribution = baseLayer.options.attribution;
11262
+ this.attributionControl.setContent(MAP_ATTRIBUTION_TG.content + (layerAttribution ? ` - ${layerAttribution}` : ''));
11263
+ if (this.map.getSpatialReference().options.projection !== baseLayer.getSpatialReference().options.projection) {
11264
+ console.debug('setSpatialReference', this.map.getSpatialReference().options, '==>', baseLayer.getSpatialReference().options);
11265
+ this.map.setSpatialReference(baseLayer.getSpatialReference().options);
11266
+ }
11267
+ };
11268
+ computeBaseLayerId(buildInMapTypeId = BuildInMapTypeId.normal, theme = 'light') {
11269
+ const mapType = MapType.BUILD_IN_MAP_TYPES.get(BuildInMapType.prototype.getId, buildInMapTypeId);
11270
+ if (theme === 'dark') {
11271
+ const darkOffset = MapType.BUILD_IN_MAP_TYPES.values.length;
11272
+ // 遍历: 7, 6, 5, 4, 查找设置了值的暗色layerId
11273
+ for (let i = Math.min((mapType.index + darkOffset), this.baseLayoutIds.length - 1); i >= darkOffset; i--) {
11274
+ if (this.baseLayoutIds[i]) {
11275
+ return this.baseLayoutIds[i];
11276
+ }
11277
+ }
11278
+ }
11279
+ // 遍历: 3, 2, 1, 0, 查找设置了值的亮色layerId
11280
+ for (let i = Math.min(mapType.index, this.baseLayoutIds.length - 1); i >= 0; i--) {
11281
+ if (this.baseLayoutIds[i]) {
11282
+ return this.baseLayoutIds[i];
11283
+ }
11284
+ }
11285
+ return this.baseLayoutIds[0];
11286
+ }
11287
+ setBaseLayer(id, theme) {
11288
+ this.mapStyleTheme = theme;
11289
+ const baseLayerId = this.computeBaseLayerId(id, theme);
11290
+ const currentBaseLayerId = this.getCurrentBaseLayer()?.getId();
11291
+ if (currentBaseLayerId !== baseLayerId) {
11292
+ this.baseLayerGroup.layers.forEach((layer) => Talks.setVisible(layer, layer.getId() === baseLayerId));
11293
+ this.onBaseLayerChanged();
11294
+ }
11160
11295
  }
11161
11296
  setGestureHandling(gestureHandling = GestureHandlingOptions.auto) {
11162
11297
  if (gestureHandling === GestureHandlingOptions.auto) {
@@ -11192,7 +11327,7 @@ class TalksMap extends BaseMap {
11192
11327
  return this.map;
11193
11328
  }
11194
11329
  get coordType() {
11195
- return talksBaseLayerIdToCoordType(this.currentBaseLayerId);
11330
+ return talksBaseLayerIdToCoordType(this.cachedBaseLayerId);
11196
11331
  }
11197
11332
  fromContainerPointToLatLng(point) {
11198
11333
  const coordinate = this.map.containerPointToCoordinate(new maptalks.Point(point.x, point.y));
@@ -11203,7 +11338,7 @@ class TalksMap extends BaseMap {
11203
11338
  return point; // maptalks.Point符合Point接口, 可以直接返回
11204
11339
  }
11205
11340
  setHideLogo(hideLogo) {
11206
- this.map.config('attribution', hideLogo ? false : MAP_ATTRIBUTION_TG);
11341
+ Talks.setVisible(this.attributionControl, !hideLogo);
11207
11342
  }
11208
11343
  setFractionalZoom(enabled) {
11209
11344
  this.map.config('seamlessZoom', enabled);
@@ -11230,16 +11365,31 @@ class TalksMap extends BaseMap {
11230
11365
  this.map.setMaxZoom(zoom);
11231
11366
  }
11232
11367
  setMapStyle(mapStyle) {
11233
- // TODO: 2026/01/05 ipcjs 下一版再实现该功能
11368
+ if (mapStyle?.talks?.theme) {
11369
+ const mapType = this.getMapType();
11370
+ if (mapType instanceof BuildInMapType) {
11371
+ this.setBaseLayer(mapType.id, mapStyle.talks.theme);
11372
+ }
11373
+ else {
11374
+ console.log('自定义MapType不支持设置地图样式', mapType);
11375
+ }
11376
+ }
11234
11377
  }
11235
11378
  setBuildInMapTypeId(id) {
11236
- // TODO: 2026/01/05 ipcjs 下一版再实现该功能
11379
+ this.setBaseLayer(id, this.mapStyleTheme);
11237
11380
  }
11238
11381
  setMapType(mapType) {
11239
- // TODO: 2026/01/05 ipcjs 下一版再实现该功能
11382
+ if (mapType instanceof BuildInMapType) {
11383
+ this.setBaseLayer(mapType.getId(), this.mapStyleTheme);
11384
+ }
11240
11385
  }
11241
11386
  getMapType() {
11242
- // TODO: 2026/01/05 ipcjs 下一版再实现该功能
11387
+ const currentBaseLayerId = this.getCurrentBaseLayer()?.getId();
11388
+ const index = this.baseLayoutIds.findIndex(it => it === currentBaseLayerId);
11389
+ if (index !== -1) {
11390
+ return MapType.BUILD_IN_MAP_TYPES.values[index % MapType.BUILD_IN_MAP_TYPES.values.length];
11391
+ }
11392
+ // TODO: 2026/01/05 ipcjs 自定义MapType, 下一版再实现该功能
11243
11393
  return MapType.NORMAL;
11244
11394
  }
11245
11395
  addLayer(layer) {
@@ -11354,17 +11504,20 @@ var TgMapFactory;
11354
11504
  case TgMapType.here:
11355
11505
  return new HereMap($map, options);
11356
11506
  case TgMapType.baiduFree:
11357
- return new TalksMap($map, options, ['baidu', 'osm']);
11507
+ return new TalksMap($map, options, ['baidu', 'amap-terrain', undefined, undefined, 'osm-dark']);
11358
11508
  case TgMapType.googleFree:
11359
- return new TalksMap($map, options, ['google', 'osm']);
11509
+ return new TalksMap($map, options, ['google', 'osm-terrain', undefined, undefined, 'osm-dark']);
11360
11510
  case TgMapType.amap:
11361
- return new TalksMap($map, options, ['amap']);
11511
+ return new TalksMap($map, options, ['amap', 'amap-terrain', undefined, undefined, 'osm-dark']);
11362
11512
  case TgMapType.osm:
11363
- return new TalksMap($map, options, ['osm']);
11513
+ return new TalksMap($map, options, ['osm-light', 'osm-terrain', undefined, undefined, 'osm-dark']);
11364
11514
  case TgMapType.yandex:
11365
- return new TalksMap($map, options, ['yandex']);
11366
- case TgMapType.talks:
11367
- return new TalksMap($map, options, [getTgMapConfig().talks.layerId || 'bing']);
11515
+ return new TalksMap($map, options, ['yandex', undefined, undefined, undefined, 'osm-dark']);
11516
+ case TgMapType.talks: {
11517
+ const hasDefinedFirstElement = (array) => !!(array && array.length && array[0]);
11518
+ const talks = getTgMapConfig().talks;
11519
+ return new TalksMap($map, options, hasDefinedFirstElement(talks.layerIds) ? talks.layerIds : [talks.layerId || 'bing']);
11520
+ }
11368
11521
  default:
11369
11522
  assertNever(type);
11370
11523
  }