tg-map-core 4.2.3 → 4.2.4

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',
@@ -11114,6 +11126,7 @@ function createTalksBaseLayerImpl(layerId, { id = layerId, visible = true, } = {
11114
11126
  spatialReference: { projection: 'EPSG:3857' },
11115
11127
  });
11116
11128
  case 'baidu':
11129
+ // 废弃, https的网站上瓦片url也会自动变成https, 然后会报证书错误
11117
11130
  return new maptalks__namespace.TileLayer(id, {
11118
11131
  visible,
11119
11132
  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 +11138,19 @@ function createTalksBaseLayerImpl(layerId, { id = layerId, visible = true, } = {
11125
11138
  maxZoom: 20,
11126
11139
  attribution: '&copy; <a target="_blank" href="http://map.baidu.com">Baidu</a>',
11127
11140
  });
11141
+ case 'baidu-https':
11142
+ // gemini提供的瓦片地址
11143
+ return new maptalks__namespace.TileLayer(id, {
11144
+ visible,
11145
+ urlTemplate: `https://maponline{s}.bdimg.com/tile/?qt=vtile&x={x}&y={y}&z={z}&styles=pl&type=sate&scaler=${TILE_LAYER_BAIDU_SCALER}`,
11146
+ subdomains: ['0', '1', '2', '3'],
11147
+ spatialReference: {
11148
+ projection: 'BAIDU',
11149
+ },
11150
+ minZoom: 3,
11151
+ maxZoom: 20,
11152
+ attribution: '&copy; <a target="_blank" href="http://map.baidu.com">Baidu</a>',
11153
+ });
11128
11154
  case 'baidu-detail':
11129
11155
  // https://maptalks.org/examples/cn/tilelayer-projection/baidu/#tilelayer-projection_baidu
11130
11156
  return new maptalks__namespace.TileLayer(id, {
@@ -11249,6 +11275,7 @@ const MAP_ATTRIBUTION_TG = { content: 'TG' };
11249
11275
  class TalksMap extends BaseMap {
11250
11276
  mapOptions;
11251
11277
  baseLayoutIds;
11278
+ overrideLayerAttribution;
11252
11279
  map;
11253
11280
  attributionControl;
11254
11281
  baseLayerGroup;
@@ -11268,10 +11295,13 @@ class TalksMap extends BaseMap {
11268
11295
  * 最多8项, 前四项对应{@link MapType.BUILD_IN_MAP_TYPES}的四个值(普通、卫星、混合、地形)的亮色版, 后四项对应暗色版
11269
11296
  * @see computeBaseLayerId
11270
11297
  */
11271
- baseLayoutIds) {
11298
+ baseLayoutIds,
11299
+ /** 复写图层内部定义的attribution */
11300
+ overrideLayerAttribution) {
11272
11301
  super(element);
11273
11302
  this.mapOptions = mapOptions;
11274
11303
  this.baseLayoutIds = baseLayoutIds;
11304
+ this.overrideLayerAttribution = overrideLayerAttribution;
11275
11305
  this.mapStyleTheme = mapOptions.mapStyle?.talks?.theme ?? 'light';
11276
11306
  this.cachedBaseLayerId = this.computeBaseLayerId(mapOptions.buildInMapTypeId, this.mapStyleTheme);
11277
11307
  this.baseLayerGroup = new maptalks__namespace.GroupTileLayer('base', baseLayoutIds
@@ -11314,7 +11344,7 @@ class TalksMap extends BaseMap {
11314
11344
  return;
11315
11345
  // 更新cacheBaseLayerId, attribution, spatialReference, 但并没有更新minZoom/maxZoom, 因为感觉必要性不大
11316
11346
  this.cachedBaseLayerId = baseLayer.getId();
11317
- const layerAttribution = baseLayer.options.attribution;
11347
+ const layerAttribution = this.overrideLayerAttribution ?? baseLayer.options.attribution;
11318
11348
  this.attributionControl.setContent(MAP_ATTRIBUTION_TG.content + (layerAttribution ? ` - ${layerAttribution}` : ''));
11319
11349
  if (this.map.getSpatialReference().options.projection !== baseLayer.getSpatialReference().options.projection) {
11320
11350
  console.debug('setSpatialReference', this.map.getSpatialReference().options, '==>', baseLayer.getSpatialReference().options);
@@ -11564,7 +11594,7 @@ exports.TgMapFactory = void 0;
11564
11594
  case exports.TgMapType.here:
11565
11595
  return new HereMap($map, options);
11566
11596
  case exports.TgMapType.baiduFree:
11567
- return new TalksMap($map, options, ['baidu', 'amap-terrain', undefined, undefined, 'osm-dark']);
11597
+ return new TalksMap($map, options, ['baidu-https', 'amap-terrain', undefined, undefined, 'osm-dark']);
11568
11598
  case exports.TgMapType.googleFree:
11569
11599
  return new TalksMap($map, options, ['google', 'osm-terrain', undefined, undefined, 'osm-dark']);
11570
11600
  case exports.TgMapType.amap:
@@ -11576,7 +11606,7 @@ exports.TgMapFactory = void 0;
11576
11606
  case exports.TgMapType.talks: {
11577
11607
  const hasDefinedFirstElement = (array) => !!(array && array.length && array[0]);
11578
11608
  const talks = getTgMapConfig().talks;
11579
- return new TalksMap($map, options, hasDefinedFirstElement(talks.layerIds) ? talks.layerIds : [talks.layerId || 'bing']);
11609
+ return new TalksMap($map, options, hasDefinedFirstElement(talks.layerIds) ? talks.layerIds : [talks.layerId || 'bing'], talks.overrideLayerAttribution);
11580
11610
  }
11581
11611
  default:
11582
11612
  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',
@@ -11087,6 +11099,7 @@ function createTalksBaseLayerImpl(layerId, { id = layerId, visible = true, } = {
11087
11099
  spatialReference: { projection: 'EPSG:3857' },
11088
11100
  });
11089
11101
  case 'baidu':
11102
+ // 废弃, https的网站上瓦片url也会自动变成https, 然后会报证书错误
11090
11103
  return new maptalks.TileLayer(id, {
11091
11104
  visible,
11092
11105
  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 +11111,19 @@ function createTalksBaseLayerImpl(layerId, { id = layerId, visible = true, } = {
11098
11111
  maxZoom: 20,
11099
11112
  attribution: '&copy; <a target="_blank" href="http://map.baidu.com">Baidu</a>',
11100
11113
  });
11114
+ case 'baidu-https':
11115
+ // gemini提供的瓦片地址
11116
+ return new maptalks.TileLayer(id, {
11117
+ visible,
11118
+ urlTemplate: `https://maponline{s}.bdimg.com/tile/?qt=vtile&x={x}&y={y}&z={z}&styles=pl&type=sate&scaler=${TILE_LAYER_BAIDU_SCALER}`,
11119
+ subdomains: ['0', '1', '2', '3'],
11120
+ spatialReference: {
11121
+ projection: 'BAIDU',
11122
+ },
11123
+ minZoom: 3,
11124
+ maxZoom: 20,
11125
+ attribution: '&copy; <a target="_blank" href="http://map.baidu.com">Baidu</a>',
11126
+ });
11101
11127
  case 'baidu-detail':
11102
11128
  // https://maptalks.org/examples/cn/tilelayer-projection/baidu/#tilelayer-projection_baidu
11103
11129
  return new maptalks.TileLayer(id, {
@@ -11222,6 +11248,7 @@ const MAP_ATTRIBUTION_TG = { content: 'TG' };
11222
11248
  class TalksMap extends BaseMap {
11223
11249
  mapOptions;
11224
11250
  baseLayoutIds;
11251
+ overrideLayerAttribution;
11225
11252
  map;
11226
11253
  attributionControl;
11227
11254
  baseLayerGroup;
@@ -11241,10 +11268,13 @@ class TalksMap extends BaseMap {
11241
11268
  * 最多8项, 前四项对应{@link MapType.BUILD_IN_MAP_TYPES}的四个值(普通、卫星、混合、地形)的亮色版, 后四项对应暗色版
11242
11269
  * @see computeBaseLayerId
11243
11270
  */
11244
- baseLayoutIds) {
11271
+ baseLayoutIds,
11272
+ /** 复写图层内部定义的attribution */
11273
+ overrideLayerAttribution) {
11245
11274
  super(element);
11246
11275
  this.mapOptions = mapOptions;
11247
11276
  this.baseLayoutIds = baseLayoutIds;
11277
+ this.overrideLayerAttribution = overrideLayerAttribution;
11248
11278
  this.mapStyleTheme = mapOptions.mapStyle?.talks?.theme ?? 'light';
11249
11279
  this.cachedBaseLayerId = this.computeBaseLayerId(mapOptions.buildInMapTypeId, this.mapStyleTheme);
11250
11280
  this.baseLayerGroup = new maptalks.GroupTileLayer('base', baseLayoutIds
@@ -11287,7 +11317,7 @@ class TalksMap extends BaseMap {
11287
11317
  return;
11288
11318
  // 更新cacheBaseLayerId, attribution, spatialReference, 但并没有更新minZoom/maxZoom, 因为感觉必要性不大
11289
11319
  this.cachedBaseLayerId = baseLayer.getId();
11290
- const layerAttribution = baseLayer.options.attribution;
11320
+ const layerAttribution = this.overrideLayerAttribution ?? baseLayer.options.attribution;
11291
11321
  this.attributionControl.setContent(MAP_ATTRIBUTION_TG.content + (layerAttribution ? ` - ${layerAttribution}` : ''));
11292
11322
  if (this.map.getSpatialReference().options.projection !== baseLayer.getSpatialReference().options.projection) {
11293
11323
  console.debug('setSpatialReference', this.map.getSpatialReference().options, '==>', baseLayer.getSpatialReference().options);
@@ -11537,7 +11567,7 @@ var TgMapFactory;
11537
11567
  case TgMapType.here:
11538
11568
  return new HereMap($map, options);
11539
11569
  case TgMapType.baiduFree:
11540
- return new TalksMap($map, options, ['baidu', 'amap-terrain', undefined, undefined, 'osm-dark']);
11570
+ return new TalksMap($map, options, ['baidu-https', 'amap-terrain', undefined, undefined, 'osm-dark']);
11541
11571
  case TgMapType.googleFree:
11542
11572
  return new TalksMap($map, options, ['google', 'osm-terrain', undefined, undefined, 'osm-dark']);
11543
11573
  case TgMapType.amap:
@@ -11549,7 +11579,7 @@ var TgMapFactory;
11549
11579
  case TgMapType.talks: {
11550
11580
  const hasDefinedFirstElement = (array) => !!(array && array.length && array[0]);
11551
11581
  const talks = getTgMapConfig().talks;
11552
- return new TalksMap($map, options, hasDefinedFirstElement(talks.layerIds) ? talks.layerIds : [talks.layerId || 'bing']);
11582
+ return new TalksMap($map, options, hasDefinedFirstElement(talks.layerIds) ? talks.layerIds : [talks.layerId || 'bing'], talks.overrideLayerAttribution);
11553
11583
  }
11554
11584
  default:
11555
11585
  assertNever(type);