api.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. 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; };
  2. 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; }
  3. import forOwn from 'lodash/forOwn';
  4. import isEqual from 'lodash/isEqual';
  5. import isNil from 'lodash/isNil';
  6. import isEmpty from 'lodash/isEmpty';
  7. //import loadjscssfile from './loadScript';
  8. import APILoader from './APILoader';
  9. var xdebug = console.log;
  10. // const xdebug = () => {};
  11. export var loadApi = function loadApi() {
  12. var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '0325e3d6d69cd56de4980b4f28906fd8';
  13. return new APILoader({
  14. key: key,
  15. useAMapUI: true,
  16. version: '1.4.7',
  17. protocol: 'https'
  18. }).load();
  19. };
  20. export var loadMap = function loadMap(key) {
  21. return new Promise(function (resolve, reject) {
  22. if (window.AMap) {
  23. resolve(window.AMap);
  24. }
  25. loadApi(key).then(function (ret) {
  26. if (window.AMap) {
  27. resolve(window.AMap);
  28. } else {
  29. reject(new Error('window.AMap不存在!'));
  30. }
  31. }).catch(function (error) {
  32. reject(new Error('加载地图错误!' + error.message));
  33. });
  34. });
  35. };
  36. // export const loadApiV1 = async (key = '0325e3d6d69cd56de4980b4f28906fd8') => {
  37. // return await loadjscssfile(
  38. // 'https://webapi.amap.com/maps?v=1.4.7&key=' + key,
  39. // 'js'
  40. // );
  41. // };
  42. // export const loadMapV1 = key => {
  43. // return new Promise((resolve, reject) => {
  44. // if (window.AMap) {
  45. // resolve(window.AMap);
  46. // }
  47. // loadApi(key)
  48. // .then(ret => {
  49. // if (window.AMap) {
  50. // resolve(window.AMap);
  51. // } else {
  52. // reject(new Error('window.AMap不存在!'));
  53. // }
  54. // })
  55. // .catch(error => {
  56. // reject(new Error('加载地图错误!' + error.message));
  57. // });
  58. // });
  59. // };
  60. /**
  61. * [加载插件](https://lbs.amap.com/api/javascript-api/guide/abc/plugins)
  62. * 加载完成后,可以调用:
  63. * var toolbar = new window.AMap.ToolBar();
  64. * map.addControl(toolbar);
  65. * @param {string} name 插件名或插件数组,如:window.AMap.ToolBar,['AMap.ToolBar','AMap.Driving']
  66. */
  67. export var loadPlugin = function loadPlugin(name) {
  68. return new Promise(function (resolve, reject) {
  69. if (window.AMap) {
  70. window.AMap.plugin(name, function () {
  71. resolve(true);
  72. });
  73. //是否有加载失败的情况,如果加载失败,怎么reject?
  74. } else {
  75. reject(new Error('地图还未加载!'));
  76. }
  77. });
  78. };
  79. ////////////////////////////////////////////////////////////
  80. // 工具方法
  81. ////////////////////////////////////////////////////////////
  82. var commonUpdate = function commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators) {
  83. var __func__ = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 'commonUpdate';
  84. // const __func__ = 'commonUpdate';
  85. if (!entity) {
  86. xdebug(__func__, 'fail! no entity!');
  87. return false;
  88. }
  89. // 找到改变的属性集合,包含添加,删除及修改的属性,删除的置为null
  90. var props = {};
  91. if (newOptions != oldOptions) {
  92. oldOptions && forOwn(oldOptions, function (value, key) {
  93. // 找到改变的旧属性,用新属性取代
  94. var newValue = newOptions && newOptions[key];
  95. if (!isEqual(newValue, value)) {
  96. if (!(isNil(newValue) && isNil(value))) props[key] = newValue;
  97. }
  98. });
  99. newOptions && forOwn(newOptions, function (value, key) {
  100. // 找到新加的属性,添加进去
  101. var oldValue = oldOptions && oldOptions[key];
  102. if (isNil(oldValue) && !isNil(value)) {
  103. props[key] = value;
  104. }
  105. });
  106. }
  107. // 找到改变的事件集合,包含添加,删除及修改的事件处理函数,删除的置为null
  108. var events = {};
  109. if (newEvents != oldEvents) {
  110. oldEvents && forOwn(oldEvents, function (value, key) {
  111. // 找到改变的旧属性,用新属性取代
  112. var newValue = newEvents && newEvents[key];
  113. if (!isEqual(newValue, value)) {
  114. if (!(isNil(newValue) && isNil(value))) events[key] = newValue;
  115. }
  116. });
  117. newEvents && forOwn(newEvents, function (value, key) {
  118. // 找到新加的属性,添加进去
  119. var oldValue = oldEvents && oldEvents[key];
  120. if (isNil(oldValue) && !isNil(value)) {
  121. events[key] = value;
  122. }
  123. });
  124. }
  125. // let operators = {
  126. // map: v => entity.setMap(v),
  127. // position: v => entity.setPosition(v),
  128. // offset: v => entity.setOffset(v),
  129. // icon: v => entity.setIcon(v),
  130. // content: v => entity.setContent(v),
  131. // topWhenClick: null,
  132. // bubble: null,
  133. // draggable: v => entity.setDraggable(v),
  134. // raiseOnDrag: null,
  135. // cursor: v => entity.setCursor(v),
  136. // visible: null,
  137. // zIndex: v => entity.setzIndex(v),
  138. // angle: v => entity.setAngle(v),
  139. // autoRotation: null,
  140. // animation: v => entity.setAnimation(v),
  141. // shadow: v => entity.setShadow(v),
  142. // title: v => entity.setTitle(v),
  143. // clickable: v => entity.setClickable(v),
  144. // shape: v => entity.setShape(v),
  145. // extData: v => entity.setExtData(v),
  146. // label: v => entity.setLabel(v)
  147. // };
  148. forOwn(props, function (value, key) {
  149. if (value) {
  150. var func = operators[key];
  151. if (func) {
  152. func(value);
  153. } else {
  154. // ignore properties can not set.
  155. xdebug(__func__, 'warning! no setter! can not update ' + key);
  156. }
  157. } else {
  158. // key removed, not support!
  159. xdebug(__func__, 'warning! remove prop not support! key=' + key);
  160. }
  161. });
  162. forOwn(events, function (value, key) {
  163. var oldFunc = oldEvents && oldEvents[key];
  164. if (oldFunc) {
  165. entity.off(key, oldFunc);
  166. }
  167. if (value) {
  168. entity.on(key, value);
  169. }
  170. });
  171. if (!isEmpty(props) || !isEmpty(events)) {
  172. xdebug(__func__, 'update:', props, events
  173. // newOptions,
  174. // newEvents,
  175. // oldOptions,
  176. // oldEvents
  177. );
  178. }
  179. return true;
  180. };
  181. ////////////////////////////////////////////////////////////
  182. // Map
  183. ////////////////////////////////////////////////////////////
  184. export var createMap = function createMap(dom, options, events) {
  185. var __func__ = 'createMap';
  186. if (!window.AMap) {
  187. xdebug(__func__, 'fail! no window.AMap!');
  188. return null;
  189. }
  190. if (!dom) {
  191. xdebug(__func__, 'fail! no dom!');
  192. return null;
  193. }
  194. var map = new window.AMap.Map(dom, _extends({}, options || {}));
  195. forOwn(events, function (value, key) {
  196. xdebug(__func__, 'event on ' + key);
  197. map.on(key, value);
  198. });
  199. xdebug(__func__, 'ok!');
  200. return map;
  201. };
  202. export var updateMap = function updateMap(map, newOptions, newEvents, oldOptions, oldEvents) {
  203. var operators = {
  204. view: null,
  205. layers: function layers(v) {
  206. return map.setLayers(v);
  207. },
  208. zoom: function zoom(v) {
  209. return map.setZoom(v);
  210. },
  211. center: function center(v) {
  212. return map.setCenter(v);
  213. },
  214. labelzIndex: function labelzIndex(v) {
  215. return map.setlabelzIndex(v);
  216. },
  217. zooms: null,
  218. lang: function lang(v) {
  219. return map.setLang(v);
  220. },
  221. defaultCursor: function defaultCursor(v) {
  222. return map.setDefaultCursor(v);
  223. },
  224. crs: null,
  225. animateEnable: null,
  226. isHotspot: function isHotspot(v) {
  227. return map.setStatus({ isHotspot: v });
  228. },
  229. defaultLayer: function defaultLayer(v) {
  230. return map.setDefaultLayer(v);
  231. },
  232. rotateEnable: null,
  233. resizeEnable: null,
  234. showIndoorMap: null,
  235. indoorMap: null,
  236. expandZoomRange: null,
  237. dragEnable: function dragEnable(v) {
  238. return map.setStatus({ dragEnable: v });
  239. },
  240. zoomEnable: null,
  241. doubleClickZoom: function doubleClickZoom(v) {
  242. return map.setStatus({ doubleClickZoom: v });
  243. },
  244. keyboardEnable: function keyboardEnable(v) {
  245. return map.setStatus({ keyboardEnable: v });
  246. },
  247. jogEnable: null,
  248. scrollWheel: null,
  249. touchZoom: null,
  250. touchZoomCenter: null,
  251. mapStyle: function mapStyle(v) {
  252. return map.setMapStyle(v);
  253. },
  254. features: function features(v) {
  255. return map.setFeatures(v);
  256. },
  257. showBuildingBlock: null,
  258. viewMode: null,
  259. pitch: function pitch(v) {
  260. return map.setPitch(v);
  261. },
  262. pitchEnable: null,
  263. buildAnimation: null,
  264. skyColor: null,
  265. preloadMode: null
  266. };
  267. return commonUpdate(map, newOptions, newEvents, oldOptions, oldEvents, operators, 'updateMap');
  268. };
  269. ////////////////////////////////////////////////////////////
  270. // Marker
  271. ////////////////////////////////////////////////////////////
  272. /**
  273. *
  274. * @param {*} AMap
  275. * @param {*} map
  276. * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
  277. * @param {*} events
  278. */
  279. export var createMarker = function createMarker(options, events) {
  280. var __func__ = 'createMarker';
  281. if (!window.AMap) {
  282. xdebug(__func__, 'fail! no window.AMap!');
  283. return null;
  284. }
  285. if (!options) {
  286. xdebug(__func__, 'fail! no options!');
  287. return null;
  288. }
  289. if (!options.map) {
  290. xdebug(__func__, 'fail! no options.map!');
  291. return null;
  292. }
  293. // let marker = new AMap.Marker({
  294. // icon: "https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
  295. // position: [116.405467, 39.907761]
  296. // });
  297. // marker.setMap(map);
  298. var entity = new window.AMap.Marker(options);
  299. forOwn(events, function (value, key) {
  300. entity.on(key, value);
  301. });
  302. xdebug(__func__, 'ok!');
  303. return entity;
  304. };
  305. export var updateMarker = function updateMarker(entity, newOptions, newEvents, oldOptions, oldEvents) {
  306. var operators = {
  307. map: function map(v) {
  308. return entity.setMap(v);
  309. },
  310. position: function position(v) {
  311. return entity.setPosition(v);
  312. },
  313. offset: function offset(v) {
  314. return entity.setOffset(v);
  315. },
  316. icon: function icon(v) {
  317. return entity.setIcon(v);
  318. },
  319. content: function content(v) {
  320. return entity.setContent(v);
  321. },
  322. topWhenClick: null,
  323. bubble: null,
  324. draggable: function draggable(v) {
  325. return entity.setDraggable(v);
  326. },
  327. raiseOnDrag: null,
  328. cursor: function cursor(v) {
  329. return entity.setCursor(v);
  330. },
  331. visible: null,
  332. zIndex: function zIndex(v) {
  333. return entity.setzIndex(v);
  334. },
  335. angle: function angle(v) {
  336. return entity.setAngle(v);
  337. },
  338. autoRotation: null,
  339. animation: function animation(v) {
  340. return entity.setAnimation(v);
  341. },
  342. shadow: function shadow(v) {
  343. return entity.setShadow(v);
  344. },
  345. title: function title(v) {
  346. return entity.setTitle(v);
  347. },
  348. clickable: function clickable(v) {
  349. return entity.setClickable(v);
  350. },
  351. shape: function shape(v) {
  352. return entity.setShape(v);
  353. },
  354. extData: function extData(v) {
  355. return entity.setExtData(v);
  356. },
  357. label: function label(v) {
  358. return entity.setLabel(v);
  359. }
  360. };
  361. return commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators, 'updateMarker');
  362. };
  363. ////////////////////////////////////////////////////////////
  364. // Traffic layer, warning! is a layer!
  365. ////////////////////////////////////////////////////////////
  366. /**
  367. *
  368. * @param {*} AMap
  369. * @param {*} map
  370. * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
  371. * @param {*} events
  372. */
  373. var createTraffic = function createTraffic(options, events) {
  374. var __func__ = 'createTraffic';
  375. if (!window.AMap || !options || !options.map) {
  376. xdebug(__func__, 'fail! parameters!', 'window.AMap:' + !!window.AMap, 'options:' + !!options, 'options.map:' + !!(options && options.map));
  377. return null;
  378. }
  379. var map = options.map,
  380. restOpts = _objectWithoutProperties(options, ['map']);
  381. var entity = new window.AMap.TileLayer.Traffic(restOpts);
  382. forOwn(events, function (value, key) {
  383. entity.on(key, value);
  384. });
  385. entity.setMap(map);
  386. xdebug(__func__, 'ok!');
  387. return entity;
  388. };
  389. export { createTraffic };
  390. export var updateTraffic = function updateTraffic(entity, newOptions, newEvents, oldOptions, oldEvents) {
  391. var operators = {
  392. map: function map(v) {
  393. return entity.setMap(v);
  394. },
  395. zIndex: function zIndex(v) {
  396. return entity.setzIndex(v);
  397. },
  398. opacity: function opacity(v) {
  399. return entity.setOpacity(v);
  400. },
  401. zooms: null,
  402. detectRetina: null,
  403. autoRefresh: null,
  404. interval: null,
  405. tileUrl: function tileUrl(v) {
  406. return entity.setTileUrl(v);
  407. } // not in options.
  408. };
  409. return commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators, 'updateTraffic');
  410. };
  411. ////////////////////////////////////////////////////////////
  412. // MassMarks, warning! is a layer!
  413. ////////////////////////////////////////////////////////////
  414. /**
  415. *
  416. * @param {*} AMap
  417. * @param {*} map
  418. * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
  419. * @param {*} events
  420. */
  421. var createMassMarks = function createMassMarks(options, events) {
  422. var __func__ = 'createMassMarks';
  423. if (!window.AMap || !options || !options.map) {
  424. xdebug(__func__, 'fail! parameters!', 'window.AMap:' + !!window.AMap, 'options:' + !!options, 'options.map:' + !!(options && options.map));
  425. return null;
  426. }
  427. var map = options.map,
  428. data = options.data,
  429. style = options.style,
  430. restOpts = _objectWithoutProperties(options, ['map', 'data', 'style']);
  431. var entity = new window.AMap.MassMarks(data || [], _extends({}, restOpts, { style: style || [] }));
  432. forOwn(events, function (value, key) {
  433. entity.on(key, value);
  434. });
  435. entity.setMap(map);
  436. xdebug(__func__, 'ok!', map, 'layers:', map.getLayers());
  437. return entity;
  438. };
  439. export { createMassMarks };
  440. export var updateMassMarks = function updateMassMarks(entity, newOptions, newEvents, oldOptions, oldEvents) {
  441. var operators = {
  442. zIndex: function zIndex(v) {
  443. return entity.setzIndex(v);
  444. },
  445. opacity: null,
  446. zooms: null,
  447. cursor: function cursor(v) {
  448. return entity.setCursor(v);
  449. },
  450. alwaysRender: null,
  451. style: function style(v) {
  452. return entity.setStyle(v);
  453. },
  454. map: function map(v) {
  455. xdebug('updateMassMarks', 'setMap', v, 'layers:', v && v.getLayers());
  456. entity.setMap(v);
  457. },
  458. data: function data(v) {
  459. entity.setData(v);
  460. }
  461. };
  462. xdebug('updateMassMarks', 'mapOld:', oldOptions && oldOptions.map && oldOptions.map.getLayers(), 'mapNew:', newOptions && newOptions.map && newOptions.map.getLayers());
  463. return commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators, 'updateMassMarks');
  464. };
  465. // ////////////////////////////////////////////////////////////
  466. // // Traffic, warning! is a layer!
  467. // ////////////////////////////////////////////////////////////
  468. // /**
  469. // *
  470. // * @param {*} window.AMap
  471. // * @param {*} map
  472. // * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
  473. // * @param {*} events
  474. // */
  475. // export const createTraffic = (options, events) => {
  476. // const __func__ = 'createTraffic';
  477. // if (!window.AMap || !options || !options.map) {
  478. // xdebug(__func__, 'fail! parameters!', 'window.AMap:'+!!window.AMap, 'options:'+!!options, 'options.map:'+!!(options&&options.map));
  479. // return null;
  480. // }
  481. // let {map, data, style, ...restOpts} = options;
  482. // // let entity = new window.AMap.TileLayer.Traffic(data, restOpts);
  483. // let entity = new window.AMap.Traffic(data||[], {...restOpts, style: style||[]});
  484. // forOwn(events, (value, key) => {
  485. // entity.on(key, value);
  486. // });
  487. // entity.setMap(map);
  488. // xdebug(__func__, 'ok!', map, 'layers:', map.getLayers());
  489. // return entity;
  490. // };
  491. // export const updateTraffic = (
  492. // entity,
  493. // newOptions,
  494. // newEvents,
  495. // oldOptions,
  496. // oldEvents
  497. // ) => {
  498. // let operators = {
  499. // map: v => entity.setMap(v),
  500. // zIndex: v => entity.setzIndex(v),
  501. // opacity: v => entity.setOpacity(v),
  502. // zooms: null,
  503. // detectRetina: null,
  504. // autoRefresh: null,
  505. // interval: null,
  506. // tileUrl: v => entity.setTileUrl(v), // not in options.
  507. // };
  508. // xdebug('updateTraffic', 'mapOld:', (oldOptions && oldOptions.map && oldOptions.map.getLayers()), 'mapNew:', (newOptions && newOptions.map && newOptions.map.getLayers()));
  509. // return commonUpdate (
  510. // entity,
  511. // newOptions,
  512. // newEvents,
  513. // oldOptions,
  514. // oldEvents,
  515. // operators,
  516. // 'updateTraffic'
  517. // )
  518. // };
  519. ////////////////////////////////////////////////////////////
  520. // Polygon
  521. ////////////////////////////////////////////////////////////
  522. /**
  523. *
  524. * @param {*} AMap
  525. * @param {*} map
  526. * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
  527. * @param {*} events
  528. */
  529. export var createPolygon = function createPolygon(options, events) {
  530. var __func__ = 'createPolygon';
  531. if (!window.AMap || !options || !options.map) {
  532. xdebug(__func__, 'fail! parameters!', 'window.AMap:' + !!window.AMap, 'options:' + !!options, 'options.map:' + !!(options && options.map));
  533. return null;
  534. }
  535. var entity = new window.AMap.Polygon(options);
  536. forOwn(events, function (value, key) {
  537. entity.on(key, value);
  538. });
  539. xdebug(__func__, 'ok!');
  540. return entity;
  541. };
  542. export var updatePolygon = function updatePolygon(entity, newOptions, newEvents, oldOptions, oldEvents) {
  543. var operators = {
  544. map: function map(v) {
  545. return entity.setMap(v);
  546. },
  547. zIndex: function zIndex(v) {
  548. return entity.setzIndex(v);
  549. },
  550. path: function path(v) {
  551. return entity.setPath(v);
  552. },
  553. bubble: null,
  554. cursor: null,
  555. strokeColor: null,
  556. strokeOpacity: null,
  557. strokeWeight: null,
  558. fillColor: null,
  559. fillOpacity: null,
  560. draggable: null,
  561. extData: function extData(v) {
  562. return entity.setExtData(v);
  563. },
  564. strokeStyle: null,
  565. strokeDasharray: null,
  566. options: function options(v) {
  567. return entity.setOptions(v);
  568. }
  569. };
  570. return commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators, 'updatePolygon');
  571. };
  572. ////////////////////////////////////////////////////////////
  573. // Polyline
  574. ////////////////////////////////////////////////////////////
  575. /**
  576. *
  577. * @param {*} AMap
  578. * @param {*} map
  579. * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
  580. * @param {*} events
  581. */
  582. export var createPolyline = function createPolyline(options, events) {
  583. var __func__ = 'createPolyline';
  584. if (!window.AMap || !options || !options.map) {
  585. xdebug(__func__, 'fail! parameters!', 'window.AMap:' + !!window.AMap, 'options:' + !!options, 'options.map:' + !!(options && options.map));
  586. return null;
  587. }
  588. var entity = new window.AMap.Polyline(options);
  589. forOwn(events, function (value, key) {
  590. entity.on(key, value);
  591. });
  592. xdebug(__func__, 'ok!');
  593. return entity;
  594. };
  595. export var updatePolyline = function updatePolyline(entity, newOptions, newEvents, oldOptions, oldEvents) {
  596. var operators = {
  597. map: function map(v) {
  598. return entity.setMap(v);
  599. },
  600. zIndex: function zIndex(v) {
  601. return entity.setzIndex(v);
  602. },
  603. bubble: null,
  604. cursor: null,
  605. gedodesic: null,
  606. isOutline: null,
  607. borderWeight: null,
  608. outlineColor: null,
  609. path: function path(v) {
  610. return entity.setPath(v);
  611. },
  612. strokeColor: null,
  613. strokeOpacity: null,
  614. strokeWeight: null,
  615. strokeStyle: null,
  616. strokeDasharray: null,
  617. lineJoin: null,
  618. lineCap: null,
  619. draggable: null,
  620. extData: function extData(v) {
  621. return entity.setExtData(v);
  622. },
  623. showDir: null,
  624. options: function options(v) {
  625. return entity.setOptions(v);
  626. }
  627. };
  628. return commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators, 'updatePolyline');
  629. };
  630. ////////////////////////////////////////////////////////////
  631. // InfoWindow
  632. ////////////////////////////////////////////////////////////
  633. /**
  634. *
  635. * @param {*} AMap
  636. * @param {*} map
  637. * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
  638. * @param {*} events
  639. */
  640. export var createInfoWindow = function createInfoWindow(options, events) {
  641. var __func__ = 'createInfoWindow';
  642. if (!window.AMap || !options || !options.map) {
  643. xdebug(__func__, 'fail! parameters!', 'window.AMap:' + !!window.AMap, 'options:' + !!options, 'options.map:' + !!(options && options.map));
  644. return null;
  645. }
  646. var entity = new window.AMap.InfoWindow(options);
  647. forOwn(events, function (value, key) {
  648. entity.on(key, value);
  649. });
  650. xdebug(__func__, 'ok!');
  651. return entity;
  652. };
  653. export var updateInfoWindow = function updateInfoWindow(entity, newOptions, newEvents, oldOptions, oldEvents) {
  654. var operators = {
  655. isCustom: null,
  656. autoMove: null,
  657. closeWhenClickMap: null,
  658. content: function content(v) {
  659. return entity.setContent(v);
  660. },
  661. size: function size(v) {
  662. return entity.setSize(v);
  663. },
  664. offset: null,
  665. position: function position(v) {
  666. return entity.setPosition(v);
  667. },
  668. showShadow: null
  669. };
  670. return commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators, 'updateInfoWindow');
  671. };