|
@@ -1,38 +1,24 @@
|
|
|
-'use strict';
|
|
|
+var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
|
|
|
|
|
-Object.defineProperty(exports, "__esModule", {
|
|
|
- value: true
|
|
|
-});
|
|
|
-exports.updatePolyline = exports.createPolyline = exports.updatePolygon = exports.createPolygon = exports.updateMassMarks = exports.createMassMarks = exports.updateMarker = exports.createMarker = exports.updateMap = exports.commonUpdate = exports.createMap = exports.loadPlugin = exports.loadMap = exports.loadApi = undefined;
|
|
|
+function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
|
|
|
|
|
|
-var _forOwn = require('lodash/forOwn');
|
|
|
-
|
|
|
-var _forOwn2 = babelHelpers.interopRequireDefault(_forOwn);
|
|
|
-
|
|
|
-var _isEqual = require('lodash/isEqual');
|
|
|
-
|
|
|
-var _isEqual2 = babelHelpers.interopRequireDefault(_isEqual);
|
|
|
-
|
|
|
-var _isNil = require('lodash/isNil');
|
|
|
-
|
|
|
-var _isNil2 = babelHelpers.interopRequireDefault(_isNil);
|
|
|
-
|
|
|
-var _APILoader = require('./APILoader');
|
|
|
-
|
|
|
-var _APILoader2 = babelHelpers.interopRequireDefault(_APILoader);
|
|
|
+import forOwn from 'lodash/forOwn';
|
|
|
+import isEqual from 'lodash/isEqual';
|
|
|
+import isNil from 'lodash/isNil';
|
|
|
+//import loadjscssfile from './loadScript';
|
|
|
+import APILoader from './APILoader';
|
|
|
|
|
|
-var loadApi = exports.loadApi = function loadApi() {
|
|
|
+export var loadApi = function loadApi() {
|
|
|
var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '0325e3d6d69cd56de4980b4f28906fd8';
|
|
|
|
|
|
- return new _APILoader2.default({
|
|
|
+ return new APILoader({
|
|
|
key: key,
|
|
|
useAMapUI: false,
|
|
|
version: '1.4.7',
|
|
|
protocol: 'https'
|
|
|
}).load();
|
|
|
};
|
|
|
-//import loadjscssfile from './loadScript';
|
|
|
-var loadMap = exports.loadMap = function loadMap(key) {
|
|
|
+export var loadMap = function loadMap(key) {
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
if (window.AMap) {
|
|
|
resolve(window.AMap);
|
|
@@ -82,7 +68,7 @@ var loadMap = exports.loadMap = function loadMap(key) {
|
|
|
* map.addControl(toolbar);
|
|
|
* @param {string} name 插件名或插件数组,如:AMap.ToolBar,['AMap.ToolBar','AMap.Driving']
|
|
|
*/
|
|
|
-var loadPlugin = exports.loadPlugin = function loadPlugin(name) {
|
|
|
+export var loadPlugin = function loadPlugin(name) {
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
if (window.AMap) {
|
|
|
window.AMap.plugin(name, function () {
|
|
@@ -98,7 +84,7 @@ var loadPlugin = exports.loadPlugin = function loadPlugin(name) {
|
|
|
////////////////////////////////////////////////////////////
|
|
|
// Map
|
|
|
////////////////////////////////////////////////////////////
|
|
|
-var createMap = exports.createMap = function createMap(AMap, dom, options, events) {
|
|
|
+export var createMap = function createMap(AMap, dom, options, events) {
|
|
|
var __func__ = 'createMap';
|
|
|
if (!AMap) {
|
|
|
console.log(__func__, 'fail! no AMap!');
|
|
@@ -108,8 +94,8 @@ var createMap = exports.createMap = function createMap(AMap, dom, options, event
|
|
|
console.log(__func__, 'fail! no dom!');
|
|
|
return null;
|
|
|
}
|
|
|
- var map = new AMap.Map(dom, babelHelpers.extends({}, options || {}));
|
|
|
- (0, _forOwn2.default)(events, function (value, key) {
|
|
|
+ var map = new AMap.Map(dom, _extends({}, options || {}));
|
|
|
+ forOwn(events, function (value, key) {
|
|
|
console.log(__func__, 'event on ' + key);
|
|
|
map.on(key, value);
|
|
|
});
|
|
@@ -117,7 +103,7 @@ var createMap = exports.createMap = function createMap(AMap, dom, options, event
|
|
|
return map;
|
|
|
};
|
|
|
|
|
|
-var commonUpdate = exports.commonUpdate = function commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators) {
|
|
|
+export var commonUpdate = function commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators) {
|
|
|
var __func__ = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 'commonUpdate';
|
|
|
|
|
|
// const __func__ = 'commonUpdate';
|
|
@@ -129,17 +115,17 @@ var commonUpdate = exports.commonUpdate = function commonUpdate(entity, newOptio
|
|
|
// 找到改变的属性集合,包含添加,删除及修改的属性,删除的置为null
|
|
|
var props = {};
|
|
|
if (newOptions != oldOptions) {
|
|
|
- oldOptions && (0, _forOwn2.default)(oldOptions, function (value, key) {
|
|
|
+ oldOptions && forOwn(oldOptions, function (value, key) {
|
|
|
// 找到改变的旧属性,用新属性取代
|
|
|
var newValue = newOptions && newOptions[key];
|
|
|
- if (!(0, _isEqual2.default)(newValue, value)) {
|
|
|
- if (!((0, _isNil2.default)(newValue) && (0, _isNil2.default)(value))) props[key] = newValue;
|
|
|
+ if (!isEqual(newValue, value)) {
|
|
|
+ if (!(isNil(newValue) && isNil(value))) props[key] = newValue;
|
|
|
}
|
|
|
});
|
|
|
- newOptions && (0, _forOwn2.default)(newOptions, function (value, key) {
|
|
|
+ newOptions && forOwn(newOptions, function (value, key) {
|
|
|
// 找到新加的属性,添加进去
|
|
|
var oldValue = oldOptions && oldOptions[key];
|
|
|
- if ((0, _isNil2.default)(oldValue) && !(0, _isNil2.default)(value)) {
|
|
|
+ if (isNil(oldValue) && !isNil(value)) {
|
|
|
props[key] = value;
|
|
|
}
|
|
|
});
|
|
@@ -147,17 +133,17 @@ var commonUpdate = exports.commonUpdate = function commonUpdate(entity, newOptio
|
|
|
// 找到改变的事件集合,包含添加,删除及修改的事件处理函数,删除的置为null
|
|
|
var events = {};
|
|
|
if (newEvents != oldEvents) {
|
|
|
- oldEvents && (0, _forOwn2.default)(oldEvents, function (value, key) {
|
|
|
+ oldEvents && forOwn(oldEvents, function (value, key) {
|
|
|
// 找到改变的旧属性,用新属性取代
|
|
|
var newValue = newEvents && newEvents[key];
|
|
|
- if (!(0, _isEqual2.default)(newValue, value)) {
|
|
|
- if (!((0, _isNil2.default)(newValue) && (0, _isNil2.default)(value))) events[key] = newValue;
|
|
|
+ if (!isEqual(newValue, value)) {
|
|
|
+ if (!(isNil(newValue) && isNil(value))) events[key] = newValue;
|
|
|
}
|
|
|
});
|
|
|
- newEvents && (0, _forOwn2.default)(newEvents, function (value, key) {
|
|
|
+ newEvents && forOwn(newEvents, function (value, key) {
|
|
|
// 找到新加的属性,添加进去
|
|
|
var oldValue = oldEvents && oldEvents[key];
|
|
|
- if ((0, _isNil2.default)(oldValue) && !(0, _isNil2.default)(value)) {
|
|
|
+ if (isNil(oldValue) && !isNil(value)) {
|
|
|
events[key] = value;
|
|
|
}
|
|
|
});
|
|
@@ -187,7 +173,7 @@ var commonUpdate = exports.commonUpdate = function commonUpdate(entity, newOptio
|
|
|
// label: v => entity.setLabel(v)
|
|
|
// };
|
|
|
|
|
|
- (0, _forOwn2.default)(props, function (value, key) {
|
|
|
+ forOwn(props, function (value, key) {
|
|
|
if (value) {
|
|
|
var func = operators[key];
|
|
|
if (func) {
|
|
@@ -201,7 +187,7 @@ var commonUpdate = exports.commonUpdate = function commonUpdate(entity, newOptio
|
|
|
console.log(__func__, 'warning! remove prop not support! key=' + key);
|
|
|
}
|
|
|
});
|
|
|
- (0, _forOwn2.default)(events, function (value, key) {
|
|
|
+ forOwn(events, function (value, key) {
|
|
|
var oldFunc = oldEvents && oldEvents[key];
|
|
|
if (oldFunc) {
|
|
|
entity.off(key, oldFunc);
|
|
@@ -219,7 +205,7 @@ var commonUpdate = exports.commonUpdate = function commonUpdate(entity, newOptio
|
|
|
return true;
|
|
|
};
|
|
|
|
|
|
-var updateMap = exports.updateMap = function updateMap(map, newOptions, newEvents, oldOptions, oldEvents) {
|
|
|
+export var updateMap = function updateMap(map, newOptions, newEvents, oldOptions, oldEvents) {
|
|
|
var operators = {
|
|
|
view: null,
|
|
|
layers: function layers(v) {
|
|
@@ -297,7 +283,7 @@ var updateMap = exports.updateMap = function updateMap(map, newOptions, newEvent
|
|
|
* @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
|
|
|
* @param {*} events
|
|
|
*/
|
|
|
-var createMarker = exports.createMarker = function createMarker(AMap, options, events) {
|
|
|
+export var createMarker = function createMarker(AMap, options, events) {
|
|
|
var __func__ = 'createMarker';
|
|
|
if (!AMap) {
|
|
|
console.log(__func__, 'fail! no AMap!');
|
|
@@ -317,14 +303,14 @@ var createMarker = exports.createMarker = function createMarker(AMap, options, e
|
|
|
// });
|
|
|
// marker.setMap(map);
|
|
|
var entity = new AMap.Marker(options);
|
|
|
- (0, _forOwn2.default)(events, function (value, key) {
|
|
|
+ forOwn(events, function (value, key) {
|
|
|
entity.on(key, value);
|
|
|
});
|
|
|
console.log(__func__, 'ok!');
|
|
|
return entity;
|
|
|
};
|
|
|
|
|
|
-var updateMarker = exports.updateMarker = function updateMarker(entity, newOptions, newEvents, oldOptions, oldEvents) {
|
|
|
+export var updateMarker = function updateMarker(entity, newOptions, newEvents, oldOptions, oldEvents) {
|
|
|
var operators = {
|
|
|
map: function map(v) {
|
|
|
return entity.setMap(v);
|
|
@@ -404,12 +390,13 @@ var createMassMarks = function createMassMarks(AMap, options, events) {
|
|
|
console.log(__func__, 'fail! no options!');
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
var map = options.map,
|
|
|
data = options.data,
|
|
|
- restOpts = babelHelpers.objectWithoutProperties(options, ['map', 'data']);
|
|
|
+ restOpts = _objectWithoutProperties(options, ['map', 'data']);
|
|
|
|
|
|
var entity = new AMap.MassMarks(data, restOpts);
|
|
|
- (0, _forOwn2.default)(events, function (value, key) {
|
|
|
+ forOwn(events, function (value, key) {
|
|
|
entity.on(key, value);
|
|
|
});
|
|
|
if (map) {
|
|
@@ -419,8 +406,8 @@ var createMassMarks = function createMassMarks(AMap, options, events) {
|
|
|
return entity;
|
|
|
};
|
|
|
|
|
|
-exports.createMassMarks = createMassMarks;
|
|
|
-var updateMassMarks = exports.updateMassMarks = function updateMassMarks(entity, newOptions, newEvents, oldOptions, oldEvents) {
|
|
|
+export { createMassMarks };
|
|
|
+export var updateMassMarks = function updateMassMarks(entity, newOptions, newEvents, oldOptions, oldEvents) {
|
|
|
var operators = {
|
|
|
zIndex: function zIndex(v) {
|
|
|
return entity.setzIndex(v);
|
|
@@ -455,7 +442,7 @@ var updateMassMarks = exports.updateMassMarks = function updateMassMarks(entity,
|
|
|
* @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
|
|
|
* @param {*} events
|
|
|
*/
|
|
|
-var createPolygon = exports.createPolygon = function createPolygon(AMap, options, events) {
|
|
|
+export var createPolygon = function createPolygon(AMap, options, events) {
|
|
|
var __func__ = 'createPolygon';
|
|
|
if (!AMap) {
|
|
|
console.log(__func__, 'fail! no AMap!');
|
|
@@ -470,14 +457,14 @@ var createPolygon = exports.createPolygon = function createPolygon(AMap, options
|
|
|
return null;
|
|
|
}
|
|
|
var entity = new AMap.Polygon(options);
|
|
|
- (0, _forOwn2.default)(events, function (value, key) {
|
|
|
+ forOwn(events, function (value, key) {
|
|
|
entity.on(key, value);
|
|
|
});
|
|
|
console.log(__func__, 'ok!');
|
|
|
return entity;
|
|
|
};
|
|
|
|
|
|
-var updatePolygon = exports.updatePolygon = function updatePolygon(entity, newOptions, newEvents, oldOptions, oldEvents) {
|
|
|
+export var updatePolygon = function updatePolygon(entity, newOptions, newEvents, oldOptions, oldEvents) {
|
|
|
var operators = {
|
|
|
map: function map(v) {
|
|
|
return entity.setMap(v);
|
|
@@ -519,7 +506,7 @@ var updatePolygon = exports.updatePolygon = function updatePolygon(entity, newOp
|
|
|
* @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
|
|
|
* @param {*} events
|
|
|
*/
|
|
|
-var createPolyline = exports.createPolyline = function createPolyline(AMap, options, events) {
|
|
|
+export var createPolyline = function createPolyline(AMap, options, events) {
|
|
|
var __func__ = 'createPolyline';
|
|
|
if (!AMap) {
|
|
|
console.log(__func__, 'fail! no AMap!');
|
|
@@ -534,14 +521,14 @@ var createPolyline = exports.createPolyline = function createPolyline(AMap, opti
|
|
|
return null;
|
|
|
}
|
|
|
var entity = new AMap.Polyline(options);
|
|
|
- (0, _forOwn2.default)(events, function (value, key) {
|
|
|
+ forOwn(events, function (value, key) {
|
|
|
entity.on(key, value);
|
|
|
});
|
|
|
console.log(__func__, 'ok!');
|
|
|
return entity;
|
|
|
};
|
|
|
|
|
|
-var updatePolyline = exports.updatePolyline = function updatePolyline(entity, newOptions, newEvents, oldOptions, oldEvents) {
|
|
|
+export var updatePolyline = function updatePolyline(entity, newOptions, newEvents, oldOptions, oldEvents) {
|
|
|
var operators = {
|
|
|
map: function map(v) {
|
|
|
return entity.setMap(v);
|