dtable-ui-component 6.0.29-beta14 → 6.0.29-beta15

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.
@@ -334,23 +334,27 @@ class MapEditor extends _react.Component {
334
334
  componentDidMount() {
335
335
  if (this.mapType === _mapEditorUtils.MAP_TYPES.B_MAP) {
336
336
  if (!window.BMap) {
337
- window.renderBaiduMap = () => this.renderBaiduMap();
338
- (0, _mapEditorUtils.loadMapSource)(this.mapType, this.mapKey);
337
+ (0, _mapEditorUtils.loadMapSource)(this.mapType, this.mapKey).then(() => {
338
+ this.renderBaiduMap();
339
+ });
339
340
  } else {
340
341
  this.renderBaiduMap();
341
342
  }
342
343
  return;
343
344
  } else if (this.mapType === _mapEditorUtils.MAP_TYPES.G_MAP) {
344
345
  if (!window.google) {
345
- window.renderGoogleMap = () => this.renderGoogleMap();
346
- (0, _mapEditorUtils.loadMapSource)(this.mapType, this.mapKey);
346
+ (0, _mapEditorUtils.loadMapSource)(this.mapType, this.mapKey).then(() => {
347
+ this.renderGoogleMap();
348
+ });
347
349
  } else {
348
350
  this.renderGoogleMap();
349
351
  }
350
352
  return;
351
353
  } else if (this.mapType === _mapEditorUtils.MAP_TYPES.M_MAP) {
352
354
  if (!window.minemap) {
353
- (0, _mapEditorUtils.loadMapSource)(this.mapType, this.mapKey, this.loadMineMapCallBack);
355
+ (0, _mapEditorUtils.loadMapSource)(this.mapType, this.mapKey).then(() => {
356
+ this.loadMineMapCallBack();
357
+ });
354
358
  } else {
355
359
  this.renderMineMap();
356
360
  }
@@ -95,26 +95,53 @@ const getMapInfo = function () {
95
95
  };
96
96
  };
97
97
  exports.getMapInfo = getMapInfo;
98
- const loadMapSource = (mapType, mapKey, callback) => {
99
- if (!mapType || !mapKey) return;
100
- let scriptUrl = '';
101
- let script = document.createElement('script');
102
- script.type = 'text/javascript';
103
- if (mapType === MAP_TYPES.B_MAP) {
104
- scriptUrl = "https://api.map.baidu.com/api?v=3.0&ak=".concat(mapKey, "}&callback=renderBaiduMap");
105
- } else if (mapType === MAP_TYPES.G_MAP) {
106
- scriptUrl = "https://maps.googleapis.com/maps/api/js?key=".concat(mapKey, "&callback=renderGoogleMap&libraries=&v=weekly");
107
- } else {
108
- scriptUrl = 'https://minemap.minedata.cn/minemapapi/v2.1.1/minemap.js';
109
- let link = document.createElement('link');
110
- link.rel = 'stylesheet';
111
- link.type = 'text/css';
112
- link.href = 'https://minemap.minedata.cn/minemapapi/v2.1.1/minemap.css';
113
- document.head.appendChild(link);
114
- }
115
- script.src = scriptUrl;
116
- document.body.appendChild(script);
117
- if (callback) callback();
98
+ const isImplementedOnload = script => {
99
+ script = script || document.createElement('script');
100
+ if ('onload' in script) return true;
101
+ script.setAttribute('onload', '');
102
+ return typeof script['onload'] === 'function'; // ff true ie false .
103
+ };
104
+ const loadMapSource = (mapType, mapKey) => {
105
+ return new Promise((resolve, reject) => {
106
+ if (!mapType || !mapKey) {
107
+ reject();
108
+ return;
109
+ }
110
+ let scriptUrl = '';
111
+ let script = document.createElement('script');
112
+ script.type = 'text/javascript';
113
+ if (mapType === MAP_TYPES.B_MAP) {
114
+ scriptUrl = "https://api.map.baidu.com/api?v=3.0&ak=".concat(mapKey);
115
+ } else if (mapType === MAP_TYPES.G_MAP) {
116
+ scriptUrl = "https://maps.googleapis.com/maps/api/js?key=".concat(mapKey, "&libraries=&v=weekly");
117
+ } else {
118
+ scriptUrl = 'https://minemap.minedata.cn/minemapapi/v2.1.1/minemap.js';
119
+ let link = document.createElement('link');
120
+ link.rel = 'stylesheet';
121
+ link.type = 'text/css';
122
+ link.href = 'https://minemap.minedata.cn/minemapapi/v2.1.1/minemap.css';
123
+ document.head.appendChild(link);
124
+ }
125
+ script.src = scriptUrl;
126
+ script.onerror = err => {
127
+ reject(err);
128
+ };
129
+ if (isImplementedOnload(script)) {
130
+ // Firefox, Safari, Chrome, and Opera
131
+ script.onload = res => {
132
+ resolve(res);
133
+ };
134
+ } else {
135
+ // IE
136
+ script.onreadystatechange = () => {
137
+ if (script.readyState === 'loaded' || script.readyState === 'complete') {
138
+ script.onreadystatechange = null;
139
+ resolve();
140
+ }
141
+ };
142
+ }
143
+ document.body.appendChild(script);
144
+ });
118
145
  };
119
146
  exports.loadMapSource = loadMapSource;
120
147
  const locateCurrentPosition = (map, mapType, callback) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dtable-ui-component",
3
- "version": "6.0.29-beta14",
3
+ "version": "6.0.29-beta15",
4
4
  "main": "./lib/index.js",
5
5
  "dependencies": {
6
6
  "@seafile/react-image-lightbox": "4.0.2",