tg-map-core 4.2.3 → 4.2.5

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/README.md CHANGED
@@ -1,3 +1,3 @@
1
- # tg-map-core
2
-
3
- 封装 百度地图, Google地图, Here地图(未完成), Maptalks 的地图库
1
+ # tg-map-core
2
+
3
+ 封装 百度地图, Google地图, Here地图(未完成), Maptalks 的地图库
@@ -18,7 +18,7 @@ export interface MapTypeControlOptions {
18
18
  mapTypes?: MapType[];
19
19
  }
20
20
  export declare class BaiduMapTypeControl extends BaiduControl<BMap.MapTypeControl> implements MapTypeControl {
21
- static create(this: BaiduMap, options: MapTypeControlOptions): BaiduMapTypeControl | EmptyControl;
21
+ static create(this: BaiduMap, options: MapTypeControlOptions): EmptyControl | BaiduMapTypeControl;
22
22
  }
23
23
  export declare class GoogleMapTypeControl extends GoogleControl implements MapTypeControl {
24
24
  type: MapTypeControlType;
@@ -34,6 +34,8 @@ export declare class TalksMap extends BaseMap {
34
34
  * @see computeBaseLayerId
35
35
  */
36
36
  private baseLayoutIds;
37
+ /** 复写图层内部定义的attribution */
38
+ private overrideLayerAttribution?;
37
39
  private map;
38
40
  private attributionControl;
39
41
  private baseLayerGroup;
@@ -43,7 +45,9 @@ export declare class TalksMap extends BaseMap {
43
45
  * 最多8项, 前四项对应{@link MapType.BUILD_IN_MAP_TYPES}的四个值(普通、卫星、混合、地形)的亮色版, 后四项对应暗色版
44
46
  * @see computeBaseLayerId
45
47
  */
46
- baseLayoutIds: [TalksBaseLayerId, ...(TalksBaseLayerId | undefined)[]]);
48
+ baseLayoutIds: [TalksBaseLayerId, ...(TalksBaseLayerId | undefined)[]],
49
+ /** 复写图层内部定义的attribution */
50
+ overrideLayerAttribution?: string | undefined);
47
51
  private getCurrentBaseLayer;
48
52
  private onBaseLayerChanged;
49
53
  private computeBaseLayerId;
@@ -33,6 +33,8 @@ export interface TgMapConfig {
33
33
  layerId?: TalksBaseLayerId | '';
34
34
  /** 只有第一个元素非空, 才是有效的值; 默认`bing` */
35
35
  layerIds?: (TalksBaseLayerId | undefined)[];
36
+ /** 复写图层内部定义的attribution */
37
+ overrideLayerAttribution?: string;
36
38
  };
37
39
  }
38
40
  export type PartialTgMapConfig = DeepPartial<TgMapConfig>;
@@ -1,12 +1,12 @@
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", "osm-terrain", "google", "baidu", "baidu-detail", "amap", "amap-terrain", "tencent", "geoq", "tianditu", "yandex", "bing"];
3
+ export declare const talksBaseLayerIds: readonly ["osm", "osm-light", "osm-dark", "osm-terrain", "google", "baidu", "baidu-https", "baidu-detail", "amap", "amap-terrain", "tencent", "geoq", "tianditu", "yandex", "bing"];
4
4
  export type TalksBaseLayerId = typeof talksBaseLayerIds[number];
5
5
  export declare function talksBaseLayerIdToCoordType(layerId: TalksBaseLayerId | (string & {
6
6
  readonly __flavor__?: 'layerId';
7
7
  })): CoordType;
8
8
  declare function createTalksBaseLayerImpl(layerId: TalksBaseLayerId, { id, visible, }?: {
9
- id?: "google" | "osm" | "osm-light" | "osm-dark" | "osm-terrain" | "baidu" | "baidu-detail" | "amap" | "amap-terrain" | "tencent" | "geoq" | "tianditu" | "yandex" | "bing" | undefined;
9
+ id?: "osm" | "osm-light" | "osm-dark" | "osm-terrain" | "google" | "baidu" | "baidu-https" | "baidu-detail" | "amap" | "amap-terrain" | "tencent" | "geoq" | "tianditu" | "yandex" | "bing" | undefined;
10
10
  visible?: boolean | undefined;
11
11
  }): maptalks.TileLayer;
12
12
  export declare const createTalksBaseLayer: typeof createTalksBaseLayerImpl;
@@ -7352,10 +7352,21 @@ class TalksMarkerClusterer {
7352
7352
  if (process.env.NODE_ENV !== 'production' && options.stylesIndexCalculator && !createDefaultStylesIndexCalculator(options.styles)) {
7353
7353
  console.warn('talks不支持stylesIndexCalculator选项, 应该同时在styles中设置minMarkersLength');
7354
7354
  }
7355
+ let isBaiduBaseLayer;
7356
+ switch (map.cachedBaseLayerId) {
7357
+ case 'baidu':
7358
+ case 'baidu-detail':
7359
+ case 'baidu-https':
7360
+ isBaiduBaseLayer = true;
7361
+ break;
7362
+ default:
7363
+ isBaiduBaseLayer = false;
7364
+ break;
7365
+ }
7355
7366
  this.inner = new maptalks_markercluster.ClusterLayer('cluster', options.markers?.map(it => it.innerOverlay), exports.Objects.deleteUndefinedPropertyOnPlainObjectDeeply({
7356
7367
  ...ClusterIconStyle.toTalks(options.styles),
7357
7368
  // {@macro marker_clusterer_grid_size}
7358
- maxClusterRadius: options.gridSize ?? (map.cachedBaseLayerId === 'baidu' || map.cachedBaseLayerId === 'baidu-detail' ? 60 : 100),
7369
+ maxClusterRadius: options.gridSize ?? (isBaiduBaseLayer ? 60 : 100),
7359
7370
  maxClusterZoom: options.maxZoom,
7360
7371
  zIndex: options.zIndex,
7361
7372
  }));
@@ -9217,9 +9228,9 @@ class BaiduLabelOverlay extends BaiduOverlay {
9217
9228
  icon.__icon__.scale,
9218
9229
  icon.__icon__.strokeWeight,
9219
9230
  ].map(it => it ?? '').join(',');
9220
- console.warn('BaiduLabelOverlay.attachIcon', icon.__icon__, exports.Strings.trimIndent(`
9221
- 为了保证Label的位置正确, 请将SymbolIcon(${iconInfo})中baiduLabelOffset的值改写成:
9222
- ${JSON.stringify({ x, y })}
9231
+ console.warn('BaiduLabelOverlay.attachIcon', icon.__icon__, exports.Strings.trimIndent(`
9232
+ 为了保证Label的位置正确, 请将SymbolIcon(${iconInfo})中baiduLabelOffset的值改写成:
9233
+ ${JSON.stringify({ x, y })}
9223
9234
  `));
9224
9235
  }
9225
9236
  }, 1);
@@ -11053,6 +11064,7 @@ const talksBaseLayerIds = [
11053
11064
  'osm-terrain',
11054
11065
  'google',
11055
11066
  'baidu',
11067
+ 'baidu-https',
11056
11068
  'baidu-detail',
11057
11069
  'amap',
11058
11070
  'amap-terrain',
@@ -11065,6 +11077,7 @@ const talksBaseLayerIds = [
11065
11077
  function talksBaseLayerIdToCoordType(layerId) {
11066
11078
  switch (layerId) {
11067
11079
  case 'baidu':
11080
+ case 'baidu-https':
11068
11081
  case 'baidu-detail':
11069
11082
  return exports.CoordType.bd09;
11070
11083
  case 'osm-light':
@@ -11114,6 +11127,7 @@ function createTalksBaseLayerImpl(layerId, { id = layerId, visible = true, } = {
11114
11127
  spatialReference: { projection: 'EPSG:3857' },
11115
11128
  });
11116
11129
  case 'baidu':
11130
+ // 废弃, https的网站上瓦片url也会自动变成https, 然后会报证书错误
11117
11131
  return new maptalks__namespace.TileLayer(id, {
11118
11132
  visible,
11119
11133
  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}`,
@@ -11125,6 +11139,19 @@ function createTalksBaseLayerImpl(layerId, { id = layerId, visible = true, } = {
11125
11139
  maxZoom: 20,
11126
11140
  attribution: '&copy; <a target="_blank" href="http://map.baidu.com">Baidu</a>',
11127
11141
  });
11142
+ case 'baidu-https':
11143
+ // gemini提供的瓦片地址
11144
+ return new maptalks__namespace.TileLayer(id, {
11145
+ visible,
11146
+ urlTemplate: `https://maponline{s}.bdimg.com/tile/?qt=vtile&x={x}&y={y}&z={z}&styles=pl&type=sate&scaler=${TILE_LAYER_BAIDU_SCALER}`,
11147
+ subdomains: ['0', '1', '2', '3'],
11148
+ spatialReference: {
11149
+ projection: 'BAIDU',
11150
+ },
11151
+ minZoom: 3,
11152
+ maxZoom: 20,
11153
+ attribution: '&copy; <a target="_blank" href="http://map.baidu.com">Baidu</a>',
11154
+ });
11128
11155
  case 'baidu-detail':
11129
11156
  // https://maptalks.org/examples/cn/tilelayer-projection/baidu/#tilelayer-projection_baidu
11130
11157
  return new maptalks__namespace.TileLayer(id, {
@@ -11249,6 +11276,7 @@ const MAP_ATTRIBUTION_TG = { content: 'TG' };
11249
11276
  class TalksMap extends BaseMap {
11250
11277
  mapOptions;
11251
11278
  baseLayoutIds;
11279
+ overrideLayerAttribution;
11252
11280
  map;
11253
11281
  attributionControl;
11254
11282
  baseLayerGroup;
@@ -11268,10 +11296,13 @@ class TalksMap extends BaseMap {
11268
11296
  * 最多8项, 前四项对应{@link MapType.BUILD_IN_MAP_TYPES}的四个值(普通、卫星、混合、地形)的亮色版, 后四项对应暗色版
11269
11297
  * @see computeBaseLayerId
11270
11298
  */
11271
- baseLayoutIds) {
11299
+ baseLayoutIds,
11300
+ /** 复写图层内部定义的attribution */
11301
+ overrideLayerAttribution) {
11272
11302
  super(element);
11273
11303
  this.mapOptions = mapOptions;
11274
11304
  this.baseLayoutIds = baseLayoutIds;
11305
+ this.overrideLayerAttribution = overrideLayerAttribution;
11275
11306
  this.mapStyleTheme = mapOptions.mapStyle?.talks?.theme ?? 'light';
11276
11307
  this.cachedBaseLayerId = this.computeBaseLayerId(mapOptions.buildInMapTypeId, this.mapStyleTheme);
11277
11308
  this.baseLayerGroup = new maptalks__namespace.GroupTileLayer('base', baseLayoutIds
@@ -11314,7 +11345,7 @@ class TalksMap extends BaseMap {
11314
11345
  return;
11315
11346
  // 更新cacheBaseLayerId, attribution, spatialReference, 但并没有更新minZoom/maxZoom, 因为感觉必要性不大
11316
11347
  this.cachedBaseLayerId = baseLayer.getId();
11317
- const layerAttribution = baseLayer.options.attribution;
11348
+ const layerAttribution = this.overrideLayerAttribution ?? baseLayer.options.attribution;
11318
11349
  this.attributionControl.setContent(MAP_ATTRIBUTION_TG.content + (layerAttribution ? ` - ${layerAttribution}` : ''));
11319
11350
  if (this.map.getSpatialReference().options.projection !== baseLayer.getSpatialReference().options.projection) {
11320
11351
  console.debug('setSpatialReference', this.map.getSpatialReference().options, '==>', baseLayer.getSpatialReference().options);
@@ -11564,7 +11595,7 @@ exports.TgMapFactory = void 0;
11564
11595
  case exports.TgMapType.here:
11565
11596
  return new HereMap($map, options);
11566
11597
  case exports.TgMapType.baiduFree:
11567
- return new TalksMap($map, options, ['baidu', 'amap-terrain', undefined, undefined, 'osm-dark']);
11598
+ return new TalksMap($map, options, ['baidu-https', 'amap-terrain', undefined, undefined, 'osm-dark']);
11568
11599
  case exports.TgMapType.googleFree:
11569
11600
  return new TalksMap($map, options, ['google', 'osm-terrain', undefined, undefined, 'osm-dark']);
11570
11601
  case exports.TgMapType.amap:
@@ -11576,7 +11607,7 @@ exports.TgMapFactory = void 0;
11576
11607
  case exports.TgMapType.talks: {
11577
11608
  const hasDefinedFirstElement = (array) => !!(array && array.length && array[0]);
11578
11609
  const talks = getTgMapConfig().talks;
11579
- return new TalksMap($map, options, hasDefinedFirstElement(talks.layerIds) ? talks.layerIds : [talks.layerId || 'bing']);
11610
+ return new TalksMap($map, options, hasDefinedFirstElement(talks.layerIds) ? talks.layerIds : [talks.layerId || 'bing'], talks.overrideLayerAttribution);
11580
11611
  }
11581
11612
  default:
11582
11613
  tgCommons.assertNever(type);
@@ -7325,10 +7325,21 @@ class TalksMarkerClusterer {
7325
7325
  if (process.env.NODE_ENV !== 'production' && options.stylesIndexCalculator && !createDefaultStylesIndexCalculator(options.styles)) {
7326
7326
  console.warn('talks不支持stylesIndexCalculator选项, 应该同时在styles中设置minMarkersLength');
7327
7327
  }
7328
+ let isBaiduBaseLayer;
7329
+ switch (map.cachedBaseLayerId) {
7330
+ case 'baidu':
7331
+ case 'baidu-detail':
7332
+ case 'baidu-https':
7333
+ isBaiduBaseLayer = true;
7334
+ break;
7335
+ default:
7336
+ isBaiduBaseLayer = false;
7337
+ break;
7338
+ }
7328
7339
  this.inner = new ClusterLayer('cluster', options.markers?.map(it => it.innerOverlay), Objects.deleteUndefinedPropertyOnPlainObjectDeeply({
7329
7340
  ...ClusterIconStyle.toTalks(options.styles),
7330
7341
  // {@macro marker_clusterer_grid_size}
7331
- maxClusterRadius: options.gridSize ?? (map.cachedBaseLayerId === 'baidu' || map.cachedBaseLayerId === 'baidu-detail' ? 60 : 100),
7342
+ maxClusterRadius: options.gridSize ?? (isBaiduBaseLayer ? 60 : 100),
7332
7343
  maxClusterZoom: options.maxZoom,
7333
7344
  zIndex: options.zIndex,
7334
7345
  }));
@@ -9190,9 +9201,9 @@ class BaiduLabelOverlay extends BaiduOverlay {
9190
9201
  icon.__icon__.scale,
9191
9202
  icon.__icon__.strokeWeight,
9192
9203
  ].map(it => it ?? '').join(',');
9193
- console.warn('BaiduLabelOverlay.attachIcon', icon.__icon__, Strings.trimIndent(`
9194
- 为了保证Label的位置正确, 请将SymbolIcon(${iconInfo})中baiduLabelOffset的值改写成:
9195
- ${JSON.stringify({ x, y })}
9204
+ console.warn('BaiduLabelOverlay.attachIcon', icon.__icon__, Strings.trimIndent(`
9205
+ 为了保证Label的位置正确, 请将SymbolIcon(${iconInfo})中baiduLabelOffset的值改写成:
9206
+ ${JSON.stringify({ x, y })}
9196
9207
  `));
9197
9208
  }
9198
9209
  }, 1);
@@ -11026,6 +11037,7 @@ const talksBaseLayerIds = [
11026
11037
  'osm-terrain',
11027
11038
  'google',
11028
11039
  'baidu',
11040
+ 'baidu-https',
11029
11041
  'baidu-detail',
11030
11042
  'amap',
11031
11043
  'amap-terrain',
@@ -11038,6 +11050,7 @@ const talksBaseLayerIds = [
11038
11050
  function talksBaseLayerIdToCoordType(layerId) {
11039
11051
  switch (layerId) {
11040
11052
  case 'baidu':
11053
+ case 'baidu-https':
11041
11054
  case 'baidu-detail':
11042
11055
  return CoordType.bd09;
11043
11056
  case 'osm-light':
@@ -11087,6 +11100,7 @@ function createTalksBaseLayerImpl(layerId, { id = layerId, visible = true, } = {
11087
11100
  spatialReference: { projection: 'EPSG:3857' },
11088
11101
  });
11089
11102
  case 'baidu':
11103
+ // 废弃, https的网站上瓦片url也会自动变成https, 然后会报证书错误
11090
11104
  return new maptalks.TileLayer(id, {
11091
11105
  visible,
11092
11106
  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}`,
@@ -11098,6 +11112,19 @@ function createTalksBaseLayerImpl(layerId, { id = layerId, visible = true, } = {
11098
11112
  maxZoom: 20,
11099
11113
  attribution: '&copy; <a target="_blank" href="http://map.baidu.com">Baidu</a>',
11100
11114
  });
11115
+ case 'baidu-https':
11116
+ // gemini提供的瓦片地址
11117
+ return new maptalks.TileLayer(id, {
11118
+ visible,
11119
+ urlTemplate: `https://maponline{s}.bdimg.com/tile/?qt=vtile&x={x}&y={y}&z={z}&styles=pl&type=sate&scaler=${TILE_LAYER_BAIDU_SCALER}`,
11120
+ subdomains: ['0', '1', '2', '3'],
11121
+ spatialReference: {
11122
+ projection: 'BAIDU',
11123
+ },
11124
+ minZoom: 3,
11125
+ maxZoom: 20,
11126
+ attribution: '&copy; <a target="_blank" href="http://map.baidu.com">Baidu</a>',
11127
+ });
11101
11128
  case 'baidu-detail':
11102
11129
  // https://maptalks.org/examples/cn/tilelayer-projection/baidu/#tilelayer-projection_baidu
11103
11130
  return new maptalks.TileLayer(id, {
@@ -11222,6 +11249,7 @@ const MAP_ATTRIBUTION_TG = { content: 'TG' };
11222
11249
  class TalksMap extends BaseMap {
11223
11250
  mapOptions;
11224
11251
  baseLayoutIds;
11252
+ overrideLayerAttribution;
11225
11253
  map;
11226
11254
  attributionControl;
11227
11255
  baseLayerGroup;
@@ -11241,10 +11269,13 @@ class TalksMap extends BaseMap {
11241
11269
  * 最多8项, 前四项对应{@link MapType.BUILD_IN_MAP_TYPES}的四个值(普通、卫星、混合、地形)的亮色版, 后四项对应暗色版
11242
11270
  * @see computeBaseLayerId
11243
11271
  */
11244
- baseLayoutIds) {
11272
+ baseLayoutIds,
11273
+ /** 复写图层内部定义的attribution */
11274
+ overrideLayerAttribution) {
11245
11275
  super(element);
11246
11276
  this.mapOptions = mapOptions;
11247
11277
  this.baseLayoutIds = baseLayoutIds;
11278
+ this.overrideLayerAttribution = overrideLayerAttribution;
11248
11279
  this.mapStyleTheme = mapOptions.mapStyle?.talks?.theme ?? 'light';
11249
11280
  this.cachedBaseLayerId = this.computeBaseLayerId(mapOptions.buildInMapTypeId, this.mapStyleTheme);
11250
11281
  this.baseLayerGroup = new maptalks.GroupTileLayer('base', baseLayoutIds
@@ -11287,7 +11318,7 @@ class TalksMap extends BaseMap {
11287
11318
  return;
11288
11319
  // 更新cacheBaseLayerId, attribution, spatialReference, 但并没有更新minZoom/maxZoom, 因为感觉必要性不大
11289
11320
  this.cachedBaseLayerId = baseLayer.getId();
11290
- const layerAttribution = baseLayer.options.attribution;
11321
+ const layerAttribution = this.overrideLayerAttribution ?? baseLayer.options.attribution;
11291
11322
  this.attributionControl.setContent(MAP_ATTRIBUTION_TG.content + (layerAttribution ? ` - ${layerAttribution}` : ''));
11292
11323
  if (this.map.getSpatialReference().options.projection !== baseLayer.getSpatialReference().options.projection) {
11293
11324
  console.debug('setSpatialReference', this.map.getSpatialReference().options, '==>', baseLayer.getSpatialReference().options);
@@ -11537,7 +11568,7 @@ var TgMapFactory;
11537
11568
  case TgMapType.here:
11538
11569
  return new HereMap($map, options);
11539
11570
  case TgMapType.baiduFree:
11540
- return new TalksMap($map, options, ['baidu', 'amap-terrain', undefined, undefined, 'osm-dark']);
11571
+ return new TalksMap($map, options, ['baidu-https', 'amap-terrain', undefined, undefined, 'osm-dark']);
11541
11572
  case TgMapType.googleFree:
11542
11573
  return new TalksMap($map, options, ['google', 'osm-terrain', undefined, undefined, 'osm-dark']);
11543
11574
  case TgMapType.amap:
@@ -11549,7 +11580,7 @@ var TgMapFactory;
11549
11580
  case TgMapType.talks: {
11550
11581
  const hasDefinedFirstElement = (array) => !!(array && array.length && array[0]);
11551
11582
  const talks = getTgMapConfig().talks;
11552
- return new TalksMap($map, options, hasDefinedFirstElement(talks.layerIds) ? talks.layerIds : [talks.layerId || 'bing']);
11583
+ return new TalksMap($map, options, hasDefinedFirstElement(talks.layerIds) ? talks.layerIds : [talks.layerId || 'bing'], talks.overrideLayerAttribution);
11553
11584
  }
11554
11585
  default:
11555
11586
  assertNever(type);