|
@@ -9,6 +9,9 @@ import isEmpty from 'lodash/isEmpty';
|
|
|
//import loadjscssfile from './loadScript';
|
|
|
import APILoader from './APILoader';
|
|
|
|
|
|
+//const xdebug = console.log;
|
|
|
+var xdebug = function xdebug() {};
|
|
|
+
|
|
|
export var loadApi = function loadApi() {
|
|
|
var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '0325e3d6d69cd56de4980b4f28906fd8';
|
|
|
|
|
@@ -65,9 +68,9 @@ export var loadMap = function loadMap(key) {
|
|
|
/**
|
|
|
* [加载插件](https://lbs.amap.com/api/javascript-api/guide/abc/plugins)
|
|
|
* 加载完成后,可以调用:
|
|
|
- * var toolbar = new AMap.ToolBar();
|
|
|
+ * var toolbar = new window.AMap.ToolBar();
|
|
|
* map.addControl(toolbar);
|
|
|
- * @param {string} name 插件名或插件数组,如:AMap.ToolBar,['AMap.ToolBar','AMap.Driving']
|
|
|
+ * @param {string} name 插件名或插件数组,如:window.AMap.ToolBar,['AMap.ToolBar','AMap.Driving']
|
|
|
*/
|
|
|
export var loadPlugin = function loadPlugin(name) {
|
|
|
return new Promise(function (resolve, reject) {
|
|
@@ -83,33 +86,14 @@ export var loadPlugin = function loadPlugin(name) {
|
|
|
};
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
-// Map
|
|
|
+// 工具方法
|
|
|
////////////////////////////////////////////////////////////
|
|
|
-export var createMap = function createMap(AMap, dom, options, events) {
|
|
|
- var __func__ = 'createMap';
|
|
|
- if (!AMap) {
|
|
|
- console.log(__func__, 'fail! no AMap!');
|
|
|
- return null;
|
|
|
- }
|
|
|
- if (!dom) {
|
|
|
- console.log(__func__, 'fail! no dom!');
|
|
|
- return null;
|
|
|
- }
|
|
|
- var map = new AMap.Map(dom, _extends({}, options || {}));
|
|
|
- forOwn(events, function (value, key) {
|
|
|
- console.log(__func__, 'event on ' + key);
|
|
|
- map.on(key, value);
|
|
|
- });
|
|
|
- console.log(__func__, 'ok!');
|
|
|
- return map;
|
|
|
-};
|
|
|
-
|
|
|
-export var commonUpdate = function commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators) {
|
|
|
+var commonUpdate = function commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators) {
|
|
|
var __func__ = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 'commonUpdate';
|
|
|
|
|
|
// const __func__ = 'commonUpdate';
|
|
|
if (!entity) {
|
|
|
- console.log(__func__, 'fail! no entity!');
|
|
|
+ xdebug(__func__, 'fail! no entity!');
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -181,11 +165,11 @@ export var commonUpdate = function commonUpdate(entity, newOptions, newEvents, o
|
|
|
func(value);
|
|
|
} else {
|
|
|
// ignore properties can not set.
|
|
|
- console.log(__func__, 'warning! no setter! can not update ' + key);
|
|
|
+ xdebug(__func__, 'warning! no setter! can not update ' + key);
|
|
|
}
|
|
|
} else {
|
|
|
// key removed, not support!
|
|
|
- console.log(__func__, 'warning! remove prop not support! key=' + key);
|
|
|
+ xdebug(__func__, 'warning! remove prop not support! key=' + key);
|
|
|
}
|
|
|
});
|
|
|
forOwn(events, function (value, key) {
|
|
@@ -198,7 +182,7 @@ export var commonUpdate = function commonUpdate(entity, newOptions, newEvents, o
|
|
|
}
|
|
|
});
|
|
|
if (!isEmpty(props) || !isEmpty(events)) {
|
|
|
- console.log(__func__, 'update:', props, events
|
|
|
+ xdebug(__func__, 'update:', props, events
|
|
|
// newOptions,
|
|
|
// newEvents,
|
|
|
// oldOptions,
|
|
@@ -208,6 +192,28 @@ export var commonUpdate = function commonUpdate(entity, newOptions, newEvents, o
|
|
|
return true;
|
|
|
};
|
|
|
|
|
|
+////////////////////////////////////////////////////////////
|
|
|
+// Map
|
|
|
+////////////////////////////////////////////////////////////
|
|
|
+export var createMap = function createMap(dom, options, events) {
|
|
|
+ var __func__ = 'createMap';
|
|
|
+ if (!window.AMap) {
|
|
|
+ xdebug(__func__, 'fail! no window.AMap!');
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (!dom) {
|
|
|
+ xdebug(__func__, 'fail! no dom!');
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ var map = new window.AMap.Map(dom, _extends({}, options || {}));
|
|
|
+ forOwn(events, function (value, key) {
|
|
|
+ xdebug(__func__, 'event on ' + key);
|
|
|
+ map.on(key, value);
|
|
|
+ });
|
|
|
+ xdebug(__func__, 'ok!');
|
|
|
+ return map;
|
|
|
+};
|
|
|
+
|
|
|
export var updateMap = function updateMap(map, newOptions, newEvents, oldOptions, oldEvents) {
|
|
|
var operators = {
|
|
|
view: null,
|
|
@@ -286,18 +292,18 @@ export var updateMap = function updateMap(map, newOptions, newEvents, oldOptions
|
|
|
* @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
|
|
|
* @param {*} events
|
|
|
*/
|
|
|
-export var createMarker = function createMarker(AMap, options, events) {
|
|
|
+export var createMarker = function createMarker(options, events) {
|
|
|
var __func__ = 'createMarker';
|
|
|
- if (!AMap) {
|
|
|
- console.log(__func__, 'fail! no AMap!');
|
|
|
+ if (!window.AMap) {
|
|
|
+ xdebug(__func__, 'fail! no window.AMap!');
|
|
|
return null;
|
|
|
}
|
|
|
if (!options) {
|
|
|
- console.log(__func__, 'fail! no options!');
|
|
|
+ xdebug(__func__, 'fail! no options!');
|
|
|
return null;
|
|
|
}
|
|
|
if (!options.map) {
|
|
|
- console.log(__func__, 'fail! no options.map!');
|
|
|
+ xdebug(__func__, 'fail! no options.map!');
|
|
|
return null;
|
|
|
}
|
|
|
// let marker = new AMap.Marker({
|
|
@@ -305,11 +311,11 @@ export var createMarker = function createMarker(AMap, options, events) {
|
|
|
// position: [116.405467, 39.907761]
|
|
|
// });
|
|
|
// marker.setMap(map);
|
|
|
- var entity = new AMap.Marker(options);
|
|
|
+ var entity = new window.AMap.Marker(options);
|
|
|
forOwn(events, function (value, key) {
|
|
|
entity.on(key, value);
|
|
|
});
|
|
|
- console.log(__func__, 'ok!');
|
|
|
+ xdebug(__func__, 'ok!');
|
|
|
return entity;
|
|
|
};
|
|
|
|
|
@@ -374,7 +380,7 @@ export var updateMarker = function updateMarker(entity, newOptions, newEvents, o
|
|
|
};
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
-// MassMarks, warning! is a layer!
|
|
|
+// Traffic layer, warning! is a layer!
|
|
|
////////////////////////////////////////////////////////////
|
|
|
/**
|
|
|
*
|
|
@@ -383,14 +389,10 @@ export var updateMarker = function updateMarker(entity, newOptions, newEvents, o
|
|
|
* @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
|
|
|
* @param {*} events
|
|
|
*/
|
|
|
-var createMassMarks = function createMassMarks(AMap, options, events) {
|
|
|
- var __func__ = 'createMassMarks';
|
|
|
- if (!AMap) {
|
|
|
- console.log(__func__, 'fail! no AMap!');
|
|
|
- return null;
|
|
|
- }
|
|
|
- if (!options) {
|
|
|
- console.log(__func__, 'fail! no options!');
|
|
|
+var createTraffic = function createTraffic(options, events) {
|
|
|
+ var __func__ = 'createTraffic';
|
|
|
+ if (!window.AMap || !options || !options.map) {
|
|
|
+ xdebug(__func__, 'fail! parameters!', 'window.AMap:' + !!window.AMap, 'options:' + !!options, 'options.map:' + !!(options && options.map));
|
|
|
return null;
|
|
|
}
|
|
|
|
|
@@ -398,14 +400,64 @@ var createMassMarks = function createMassMarks(AMap, options, events) {
|
|
|
data = options.data,
|
|
|
restOpts = _objectWithoutProperties(options, ['map', 'data']);
|
|
|
|
|
|
- var entity = new AMap.MassMarks(data, restOpts);
|
|
|
+ var entity = new window.AMap.TileLayer.Traffic(data, restOpts);
|
|
|
forOwn(events, function (value, key) {
|
|
|
entity.on(key, value);
|
|
|
});
|
|
|
- if (map) {
|
|
|
- entity.setMap(map);
|
|
|
+ entity.setMap(map);
|
|
|
+ xdebug(__func__, 'ok!');
|
|
|
+ return entity;
|
|
|
+};
|
|
|
+
|
|
|
+export { createTraffic };
|
|
|
+export var updateTraffic = function updateTraffic(entity, newOptions, newEvents, oldOptions, oldEvents) {
|
|
|
+ var operators = {
|
|
|
+ map: function map(v) {
|
|
|
+ return entity.setMap(v);
|
|
|
+ },
|
|
|
+ zIndex: function zIndex(v) {
|
|
|
+ return entity.setzIndex(v);
|
|
|
+ },
|
|
|
+ opacity: function opacity(v) {
|
|
|
+ return entity.setOpacity(v);
|
|
|
+ },
|
|
|
+ zooms: null,
|
|
|
+ detectRetina: null,
|
|
|
+ autoRefresh: null,
|
|
|
+ interval: null
|
|
|
+ };
|
|
|
+
|
|
|
+ return commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators, 'updateTraffic');
|
|
|
+};
|
|
|
+
|
|
|
+////////////////////////////////////////////////////////////
|
|
|
+// MassMarks, warning! is a layer!
|
|
|
+////////////////////////////////////////////////////////////
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @param {*} AMap
|
|
|
+ * @param {*} map
|
|
|
+ * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
|
|
|
+ * @param {*} events
|
|
|
+ */
|
|
|
+var createMassMarks = function createMassMarks(options, events) {
|
|
|
+ var __func__ = 'createMassMarks';
|
|
|
+ if (!window.AMap || !options || !options.map) {
|
|
|
+ xdebug(__func__, 'fail! parameters!', 'window.AMap:' + !!window.AMap, 'options:' + !!options, 'options.map:' + !!(options && options.map));
|
|
|
+ return null;
|
|
|
}
|
|
|
- console.log(__func__, 'ok!');
|
|
|
+
|
|
|
+ var map = options.map,
|
|
|
+ data = options.data,
|
|
|
+ style = options.style,
|
|
|
+ restOpts = _objectWithoutProperties(options, ['map', 'data', 'style']);
|
|
|
+
|
|
|
+ var entity = new window.AMap.MassMarks(data || [], _extends({}, restOpts, { style: style || [] }));
|
|
|
+ forOwn(events, function (value, key) {
|
|
|
+ entity.on(key, value);
|
|
|
+ });
|
|
|
+ entity.setMap(map);
|
|
|
+ xdebug(__func__, 'ok!', map, 'layers:', map.getLayers());
|
|
|
return entity;
|
|
|
};
|
|
|
|
|
@@ -425,12 +477,14 @@ export var updateMassMarks = function updateMassMarks(entity, newOptions, newEve
|
|
|
return entity.setStyle(v);
|
|
|
},
|
|
|
map: function map(v) {
|
|
|
- return entity.setMap(v);
|
|
|
+ xdebug('updateMassMarks', 'setMap', v, 'layers:', v && v.getLayers());
|
|
|
+ entity.setMap(v);
|
|
|
},
|
|
|
data: function data(v) {
|
|
|
- return entity.setData(v);
|
|
|
+ entity.setData(v);
|
|
|
}
|
|
|
};
|
|
|
+ xdebug('updateMassMarks', 'mapOld:', oldOptions && oldOptions.map && oldOptions.map.getLayers(), 'mapNew:', newOptions && newOptions.map && newOptions.map.getLayers());
|
|
|
|
|
|
return commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators, 'updateMassMarks');
|
|
|
};
|
|
@@ -445,25 +499,17 @@ export var updateMassMarks = function updateMassMarks(entity, newOptions, newEve
|
|
|
* @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
|
|
|
* @param {*} events
|
|
|
*/
|
|
|
-export var createPolygon = function createPolygon(AMap, options, events) {
|
|
|
+export var createPolygon = function createPolygon(options, events) {
|
|
|
var __func__ = 'createPolygon';
|
|
|
- if (!AMap) {
|
|
|
- console.log(__func__, 'fail! no AMap!');
|
|
|
- return null;
|
|
|
- }
|
|
|
- if (!options) {
|
|
|
- console.log(__func__, 'fail! no options!');
|
|
|
+ if (!window.AMap || !options || !options.map) {
|
|
|
+ xdebug(__func__, 'fail! parameters!', 'window.AMap:' + !!window.AMap, 'options:' + !!options, 'options.map:' + !!(options && options.map));
|
|
|
return null;
|
|
|
}
|
|
|
- if (!options.map) {
|
|
|
- console.log(__func__, 'fail! no options.map!');
|
|
|
- return null;
|
|
|
- }
|
|
|
- var entity = new AMap.Polygon(options);
|
|
|
+ var entity = new window.AMap.Polygon(options);
|
|
|
forOwn(events, function (value, key) {
|
|
|
entity.on(key, value);
|
|
|
});
|
|
|
- console.log(__func__, 'ok!');
|
|
|
+ xdebug(__func__, 'ok!');
|
|
|
return entity;
|
|
|
};
|
|
|
|
|
@@ -509,25 +555,17 @@ export var updatePolygon = function updatePolygon(entity, newOptions, newEvents,
|
|
|
* @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
|
|
|
* @param {*} events
|
|
|
*/
|
|
|
-export var createPolyline = function createPolyline(AMap, options, events) {
|
|
|
+export var createPolyline = function createPolyline(options, events) {
|
|
|
var __func__ = 'createPolyline';
|
|
|
- if (!AMap) {
|
|
|
- console.log(__func__, 'fail! no AMap!');
|
|
|
- return null;
|
|
|
- }
|
|
|
- if (!options) {
|
|
|
- console.log(__func__, 'fail! no options!');
|
|
|
- return null;
|
|
|
- }
|
|
|
- if (!options.map) {
|
|
|
- console.log(__func__, 'fail! no options.map!');
|
|
|
+ if (!window.AMap || !options || !options.map) {
|
|
|
+ xdebug(__func__, 'fail! parameters!', 'window.AMap:' + !!window.AMap, 'options:' + !!options, 'options.map:' + !!(options && options.map));
|
|
|
return null;
|
|
|
}
|
|
|
- var entity = new AMap.Polyline(options);
|
|
|
+ var entity = new window.AMap.Polyline(options);
|
|
|
forOwn(events, function (value, key) {
|
|
|
entity.on(key, value);
|
|
|
});
|
|
|
- console.log(__func__, 'ok!');
|
|
|
+ xdebug(__func__, 'ok!');
|
|
|
return entity;
|
|
|
};
|
|
|
|
|
@@ -578,17 +616,17 @@ export var updatePolyline = function updatePolyline(entity, newOptions, newEvent
|
|
|
* @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
|
|
|
* @param {*} events
|
|
|
*/
|
|
|
-export var createInfoWindow = function createInfoWindow(AMap, options, events) {
|
|
|
+export var createInfoWindow = function createInfoWindow(options, events) {
|
|
|
var __func__ = 'createInfoWindow';
|
|
|
- if (!AMap || !options || !options.map) {
|
|
|
- console.log(__func__, 'fail! parameters!', 'AMap:' + !!AMap, 'options:' + !!options, 'options.map:' + !!(options && options.map));
|
|
|
+ if (!window.AMap || !options || !options.map) {
|
|
|
+ xdebug(__func__, 'fail! parameters!', 'window.AMap:' + !!window.AMap, 'options:' + !!options, 'options.map:' + !!(options && options.map));
|
|
|
return null;
|
|
|
}
|
|
|
- var entity = new AMap.InfoWindow(options);
|
|
|
+ var entity = new window.AMap.InfoWindow(options);
|
|
|
forOwn(events, function (value, key) {
|
|
|
entity.on(key, value);
|
|
|
});
|
|
|
- console.log(__func__, 'ok!');
|
|
|
+ xdebug(__func__, 'ok!');
|
|
|
return entity;
|
|
|
};
|
|
|
|