tg-map-core 4.1.0 → 4.1.2

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.
@@ -758,20 +758,22 @@ const HERE_SUPPORTED_VERSIONS = ['3.0'];
758
758
  const defaultConfig = {
759
759
  baidu: {
760
760
  version: '3.0',
761
- // 在build时会被静态替换, 导致使用者不能无法设置它
761
+ // import.meta.env是Vite的功能, 在打包时会被静态替换, 故使用者无法设置它
762
+ // 若使用Rollup打包, 默认不会做任何处理, 原样输出, 所以使用者如果用的Vite, 就可以设置它, 如果用的Vue Cli, 默认就会报错
763
+ // 为了让使用者可以任意选择打包工具, 这里不使用import.meta.env, 改成填充默认的空字符串
762
764
  // @see https://cn.vitejs.dev/guide/build.html#library-mode:~:text=%E6%A8%A1%E5%BC%8F%E4%B8%8B%EF%BC%8C%E6%89%80%E6%9C%89-,import.meta.env.*,-%E7%94%A8%E6%B3%95%E5%9C%A8%E6%9E%84
763
765
  // @see @vite_process_env_detail
764
- key: undefined.VITE_APP_DEV_KEY_BAIDU,
766
+ key: '', // import.meta.env.VITE_APP_DEV_KEY_BAIDU,
765
767
  },
766
768
  google: {
767
769
  version: 'quarterly',
768
- key: undefined.VITE_APP_DEV_KEY_GOOGLE,
770
+ key: '', // import.meta.env.VITE_APP_DEV_KEY_GOOGLE,
769
771
  language: 'en-us',
770
772
  libraries: ['places', 'visualization'],
771
773
  },
772
774
  here: {
773
775
  version: HERE_SUPPORTED_VERSIONS[0],
774
- key: undefined.VITE_APP_DEV_KEY_HERE,
776
+ key: '', // import.meta.env.VITE_APP_DEV_KEY_HERE,
775
777
  },
776
778
  baiduFree: {},
777
779
  amap: {},
@@ -1403,45 +1405,6 @@ class TalksZoomControl extends EmptyControl {
1403
1405
  }
1404
1406
  }
1405
1407
 
1406
- /**
1407
- * Google地图官方提供的载入方式, 使用{@link google.map.importLibrary}动态载入依赖
1408
- *
1409
- * 实验性的特性, 实测当前只有`3.52`版支持
1410
- *
1411
- * @see https://developers.google.com/maps/documentation/javascript/load-maps-js-api#dynamic-library-import
1412
- */
1413
- function initGoogleMapDynamicLibraryImport(args) {
1414
- let promise;
1415
- let script;
1416
- let arg;
1417
- const googleTitle = 'The Google Maps JavaScript API';
1418
- const googleName = 'google';
1419
- const importMethod = 'importLibrary';
1420
- const callbackId = '__ib__';
1421
- const dom = document;
1422
- const global = window;
1423
- const google = global[googleName] || (global[googleName] = {});
1424
- const googleMaps = google.maps || (google.maps = {});
1425
- const libraries = new Set();
1426
- const url = new URLSearchParams();
1427
- // eslint-disable-next-line no-async-promise-executor
1428
- const loader = () => promise || (promise = new Promise(async (resolve, reject) => {
1429
- await (script = dom.createElement('script'));
1430
- url.set('libraries', [...libraries] + '');
1431
- for (arg in args)
1432
- url.set(arg.replace(/[A-Z]/g, t => '_' + t[0].toLowerCase()), args[arg]);
1433
- url.set('callback', googleName + '.maps.' + callbackId);
1434
- script.src = `https://maps.${googleName}apis.com/maps/api/js?` + url;
1435
- googleMaps[callbackId] = resolve;
1436
- // eslint-disable-next-line no-return-assign
1437
- script.onerror = () => promise = reject(Error(googleTitle + ' could not load.'));
1438
- script.nonce = dom.querySelector('script[nonce]')?.nonce || '';
1439
- dom.head.append(script);
1440
- }));
1441
- googleMaps[importMethod]
1442
- ? console.warn(googleTitle + ' only loads once. Ignoring:', args)
1443
- : googleMaps[importMethod] = (library, ...rest) => libraries.add(library) && loader().then(() => googleMaps[importMethod](library, ...rest));
1444
- }
1445
1408
  let _LATLNG_ZERO;
1446
1409
  let _BOUNDS_ZERO;
1447
1410
  const GoogleConst = {
@@ -5250,15 +5213,6 @@ function loadMap({ type, config }) {
5250
5213
  }
5251
5214
  switch (type) {
5252
5215
  case exports.TgMapType.google:
5253
- if (undefined.VITE_FALSE) {
5254
- // 测试新的动态载入方式
5255
- initGoogleMapDynamicLibraryImport({
5256
- key: config.key,
5257
- v: '3.52',
5258
- // v: config.version,
5259
- });
5260
- return google.maps.importLibrary('core');
5261
- }
5262
5216
  // TODO: 修改语言后, 要重新载入
5263
5217
  return loadJsonp(`https://maps.googleapis.com/maps/api/js?key=${config.key}&language=${config.language}&v=${config.version}&libraries=${config.libraries.join(',')}`);
5264
5218
  case exports.TgMapType.baidu:
@@ -737,20 +737,22 @@ const HERE_SUPPORTED_VERSIONS = ['3.0'];
737
737
  const defaultConfig = {
738
738
  baidu: {
739
739
  version: '3.0',
740
- // 在build时会被静态替换, 导致使用者不能无法设置它
740
+ // import.meta.env是Vite的功能, 在打包时会被静态替换, 故使用者无法设置它
741
+ // 若使用Rollup打包, 默认不会做任何处理, 原样输出, 所以使用者如果用的Vite, 就可以设置它, 如果用的Vue Cli, 默认就会报错
742
+ // 为了让使用者可以任意选择打包工具, 这里不使用import.meta.env, 改成填充默认的空字符串
741
743
  // @see https://cn.vitejs.dev/guide/build.html#library-mode:~:text=%E6%A8%A1%E5%BC%8F%E4%B8%8B%EF%BC%8C%E6%89%80%E6%9C%89-,import.meta.env.*,-%E7%94%A8%E6%B3%95%E5%9C%A8%E6%9E%84
742
744
  // @see @vite_process_env_detail
743
- key: import.meta.env.VITE_APP_DEV_KEY_BAIDU,
745
+ key: '', // import.meta.env.VITE_APP_DEV_KEY_BAIDU,
744
746
  },
745
747
  google: {
746
748
  version: 'quarterly',
747
- key: import.meta.env.VITE_APP_DEV_KEY_GOOGLE,
749
+ key: '', // import.meta.env.VITE_APP_DEV_KEY_GOOGLE,
748
750
  language: 'en-us',
749
751
  libraries: ['places', 'visualization'],
750
752
  },
751
753
  here: {
752
754
  version: HERE_SUPPORTED_VERSIONS[0],
753
- key: import.meta.env.VITE_APP_DEV_KEY_HERE,
755
+ key: '', // import.meta.env.VITE_APP_DEV_KEY_HERE,
754
756
  },
755
757
  baiduFree: {},
756
758
  amap: {},
@@ -1382,45 +1384,6 @@ class TalksZoomControl extends EmptyControl {
1382
1384
  }
1383
1385
  }
1384
1386
 
1385
- /**
1386
- * Google地图官方提供的载入方式, 使用{@link google.map.importLibrary}动态载入依赖
1387
- *
1388
- * 实验性的特性, 实测当前只有`3.52`版支持
1389
- *
1390
- * @see https://developers.google.com/maps/documentation/javascript/load-maps-js-api#dynamic-library-import
1391
- */
1392
- function initGoogleMapDynamicLibraryImport(args) {
1393
- let promise;
1394
- let script;
1395
- let arg;
1396
- const googleTitle = 'The Google Maps JavaScript API';
1397
- const googleName = 'google';
1398
- const importMethod = 'importLibrary';
1399
- const callbackId = '__ib__';
1400
- const dom = document;
1401
- const global = window;
1402
- const google = global[googleName] || (global[googleName] = {});
1403
- const googleMaps = google.maps || (google.maps = {});
1404
- const libraries = new Set();
1405
- const url = new URLSearchParams();
1406
- // eslint-disable-next-line no-async-promise-executor
1407
- const loader = () => promise || (promise = new Promise(async (resolve, reject) => {
1408
- await (script = dom.createElement('script'));
1409
- url.set('libraries', [...libraries] + '');
1410
- for (arg in args)
1411
- url.set(arg.replace(/[A-Z]/g, t => '_' + t[0].toLowerCase()), args[arg]);
1412
- url.set('callback', googleName + '.maps.' + callbackId);
1413
- script.src = `https://maps.${googleName}apis.com/maps/api/js?` + url;
1414
- googleMaps[callbackId] = resolve;
1415
- // eslint-disable-next-line no-return-assign
1416
- script.onerror = () => promise = reject(Error(googleTitle + ' could not load.'));
1417
- script.nonce = dom.querySelector('script[nonce]')?.nonce || '';
1418
- dom.head.append(script);
1419
- }));
1420
- googleMaps[importMethod]
1421
- ? console.warn(googleTitle + ' only loads once. Ignoring:', args)
1422
- : googleMaps[importMethod] = (library, ...rest) => libraries.add(library) && loader().then(() => googleMaps[importMethod](library, ...rest));
1423
- }
1424
1387
  let _LATLNG_ZERO;
1425
1388
  let _BOUNDS_ZERO;
1426
1389
  const GoogleConst = {
@@ -5229,15 +5192,6 @@ function loadMap({ type, config }) {
5229
5192
  }
5230
5193
  switch (type) {
5231
5194
  case TgMapType.google:
5232
- if (import.meta.env.VITE_FALSE) {
5233
- // 测试新的动态载入方式
5234
- initGoogleMapDynamicLibraryImport({
5235
- key: config.key,
5236
- v: '3.52',
5237
- // v: config.version,
5238
- });
5239
- return google.maps.importLibrary('core');
5240
- }
5241
5195
  // TODO: 修改语言后, 要重新载入
5242
5196
  return loadJsonp(`https://maps.googleapis.com/maps/api/js?key=${config.key}&language=${config.language}&v=${config.version}&libraries=${config.libraries.join(',')}`);
5243
5197
  case TgMapType.baidu: