api.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  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:', entity, 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. setTimeout(function () {
  318. return entity.setIcon(v);
  319. }, 0);
  320. }, // 这里有一个bug,在某些时候页面更改icon时,界面上并不生效.
  321. content: function content(v) {
  322. return entity.setContent(v);
  323. },
  324. topWhenClick: null,
  325. bubble: null,
  326. draggable: function draggable(v) {
  327. return entity.setDraggable(v);
  328. },
  329. raiseOnDrag: null,
  330. cursor: function cursor(v) {
  331. return entity.setCursor(v);
  332. },
  333. visible: null,
  334. zIndex: function zIndex(v) {
  335. return entity.setzIndex(v);
  336. },
  337. angle: function angle(v) {
  338. return entity.setAngle(v);
  339. },
  340. autoRotation: null,
  341. animation: function animation(v) {
  342. return entity.setAnimation(v);
  343. },
  344. shadow: function shadow(v) {
  345. return entity.setShadow(v);
  346. },
  347. title: function title(v) {
  348. return entity.setTitle(v);
  349. },
  350. clickable: function clickable(v) {
  351. return entity.setClickable(v);
  352. },
  353. shape: function shape(v) {
  354. return entity.setShape(v);
  355. },
  356. extData: function extData(v) {
  357. return entity.setExtData(v);
  358. },
  359. label: function label(v) {
  360. return entity.setLabel(v);
  361. }
  362. };
  363. return commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators, 'updateMarker');
  364. };
  365. ////////////////////////////////////////////////////////////
  366. // Traffic layer, warning! is a layer!
  367. ////////////////////////////////////////////////////////////
  368. /**
  369. *
  370. * @param {*} AMap
  371. * @param {*} map
  372. * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
  373. * @param {*} events
  374. */
  375. var createTraffic = function createTraffic(options, events) {
  376. var __func__ = 'createTraffic';
  377. if (!window.AMap || !options || !options.map) {
  378. xdebug(__func__, 'fail! parameters!', 'window.AMap:' + !!window.AMap, 'options:' + !!options, 'options.map:' + !!(options && options.map));
  379. return null;
  380. }
  381. var map = options.map,
  382. restOpts = _objectWithoutProperties(options, ['map']);
  383. var entity = new window.AMap.TileLayer.Traffic(restOpts);
  384. forOwn(events, function (value, key) {
  385. entity.on(key, value);
  386. });
  387. entity.setMap(map);
  388. xdebug(__func__, 'ok!');
  389. return entity;
  390. };
  391. export { createTraffic };
  392. export var updateTraffic = function updateTraffic(entity, newOptions, newEvents, oldOptions, oldEvents) {
  393. var operators = {
  394. map: function map(v) {
  395. return entity.setMap(v);
  396. },
  397. zIndex: function zIndex(v) {
  398. return entity.setzIndex(v);
  399. },
  400. opacity: function opacity(v) {
  401. return entity.setOpacity(v);
  402. },
  403. zooms: null,
  404. detectRetina: null,
  405. autoRefresh: null,
  406. interval: null,
  407. tileUrl: function tileUrl(v) {
  408. return entity.setTileUrl(v);
  409. } // not in options.
  410. };
  411. return commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators, 'updateTraffic');
  412. };
  413. ////////////////////////////////////////////////////////////
  414. // MassMarks, warning! is a layer!
  415. ////////////////////////////////////////////////////////////
  416. /**
  417. *
  418. * @param {*} AMap
  419. * @param {*} map
  420. * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
  421. * @param {*} events
  422. */
  423. var createMassMarks = function createMassMarks(options, events) {
  424. var __func__ = 'createMassMarks';
  425. if (!window.AMap || !options || !options.map) {
  426. xdebug(__func__, 'fail! parameters!', 'window.AMap:' + !!window.AMap, 'options:' + !!options, 'options.map:' + !!(options && options.map));
  427. return null;
  428. }
  429. var map = options.map,
  430. data = options.data,
  431. style = options.style,
  432. restOpts = _objectWithoutProperties(options, ['map', 'data', 'style']);
  433. var entity = new window.AMap.MassMarks(data || [], _extends({}, restOpts, { style: style || [] }));
  434. forOwn(events, function (value, key) {
  435. entity.on(key, value);
  436. });
  437. entity.setMap(map);
  438. xdebug(__func__, 'ok!', map, 'layers:', map.getLayers());
  439. return entity;
  440. };
  441. export { createMassMarks };
  442. export var updateMassMarks = function updateMassMarks(entity, newOptions, newEvents, oldOptions, oldEvents) {
  443. var operators = {
  444. zIndex: function zIndex(v) {
  445. return entity.setzIndex(v);
  446. },
  447. opacity: null,
  448. zooms: null,
  449. cursor: function cursor(v) {
  450. return entity.setCursor(v);
  451. },
  452. alwaysRender: null,
  453. style: function style(v) {
  454. return entity.setStyle(v);
  455. },
  456. map: function map(v) {
  457. xdebug('updateMassMarks', 'setMap', v, 'layers:', v && v.getLayers());
  458. entity.setMap(v);
  459. },
  460. data: function data(v) {
  461. entity.setData(v);
  462. }
  463. };
  464. xdebug('updateMassMarks', 'mapOld:', oldOptions && oldOptions.map && oldOptions.map.getLayers(), 'mapNew:', newOptions && newOptions.map && newOptions.map.getLayers());
  465. return commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators, 'updateMassMarks');
  466. };
  467. // ////////////////////////////////////////////////////////////
  468. // // Traffic, warning! is a layer!
  469. // ////////////////////////////////////////////////////////////
  470. // /**
  471. // *
  472. // * @param {*} window.AMap
  473. // * @param {*} map
  474. // * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
  475. // * @param {*} events
  476. // */
  477. // export const createTraffic = (options, events) => {
  478. // const __func__ = 'createTraffic';
  479. // if (!window.AMap || !options || !options.map) {
  480. // xdebug(__func__, 'fail! parameters!', 'window.AMap:'+!!window.AMap, 'options:'+!!options, 'options.map:'+!!(options&&options.map));
  481. // return null;
  482. // }
  483. // let {map, data, style, ...restOpts} = options;
  484. // // let entity = new window.AMap.TileLayer.Traffic(data, restOpts);
  485. // let entity = new window.AMap.Traffic(data||[], {...restOpts, style: style||[]});
  486. // forOwn(events, (value, key) => {
  487. // entity.on(key, value);
  488. // });
  489. // entity.setMap(map);
  490. // xdebug(__func__, 'ok!', map, 'layers:', map.getLayers());
  491. // return entity;
  492. // };
  493. // export const updateTraffic = (
  494. // entity,
  495. // newOptions,
  496. // newEvents,
  497. // oldOptions,
  498. // oldEvents
  499. // ) => {
  500. // let operators = {
  501. // map: v => entity.setMap(v),
  502. // zIndex: v => entity.setzIndex(v),
  503. // opacity: v => entity.setOpacity(v),
  504. // zooms: null,
  505. // detectRetina: null,
  506. // autoRefresh: null,
  507. // interval: null,
  508. // tileUrl: v => entity.setTileUrl(v), // not in options.
  509. // };
  510. // xdebug('updateTraffic', 'mapOld:', (oldOptions && oldOptions.map && oldOptions.map.getLayers()), 'mapNew:', (newOptions && newOptions.map && newOptions.map.getLayers()));
  511. // return commonUpdate (
  512. // entity,
  513. // newOptions,
  514. // newEvents,
  515. // oldOptions,
  516. // oldEvents,
  517. // operators,
  518. // 'updateTraffic'
  519. // )
  520. // };
  521. ////////////////////////////////////////////////////////////
  522. // Polygon
  523. ////////////////////////////////////////////////////////////
  524. /**
  525. *
  526. * @param {*} AMap
  527. * @param {*} map
  528. * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
  529. * @param {*} events
  530. */
  531. export var createPolygon = function createPolygon(options, events) {
  532. var __func__ = 'createPolygon';
  533. if (!window.AMap || !options || !options.map) {
  534. xdebug(__func__, 'fail! parameters!', 'window.AMap:' + !!window.AMap, 'options:' + !!options, 'options.map:' + !!(options && options.map));
  535. return null;
  536. }
  537. var entity = new window.AMap.Polygon(options);
  538. forOwn(events, function (value, key) {
  539. entity.on(key, value);
  540. });
  541. xdebug(__func__, 'ok!');
  542. return entity;
  543. };
  544. export var updatePolygon = function updatePolygon(entity, newOptions, newEvents, oldOptions, oldEvents) {
  545. var operators = {
  546. map: function map(v) {
  547. return entity.setMap(v);
  548. },
  549. zIndex: function zIndex(v) {
  550. return entity.setzIndex(v);
  551. },
  552. path: function path(v) {
  553. return entity.setPath(v);
  554. },
  555. bubble: null,
  556. cursor: null,
  557. strokeColor: null,
  558. strokeOpacity: null,
  559. strokeWeight: null,
  560. fillColor: null,
  561. fillOpacity: null,
  562. draggable: null,
  563. extData: function extData(v) {
  564. return entity.setExtData(v);
  565. },
  566. strokeStyle: null,
  567. strokeDasharray: null,
  568. options: function options(v) {
  569. return entity.setOptions(v);
  570. }
  571. };
  572. return commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators, 'updatePolygon');
  573. };
  574. ////////////////////////////////////////////////////////////
  575. // Polyline
  576. ////////////////////////////////////////////////////////////
  577. /**
  578. *
  579. * @param {*} AMap
  580. * @param {*} map
  581. * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
  582. * @param {*} events
  583. */
  584. export var createPolyline = function createPolyline(options, events) {
  585. var __func__ = 'createPolyline';
  586. if (!window.AMap || !options || !options.map) {
  587. xdebug(__func__, 'fail! parameters!', 'window.AMap:' + !!window.AMap, 'options:' + !!options, 'options.map:' + !!(options && options.map));
  588. return null;
  589. }
  590. var entity = new window.AMap.Polyline(options);
  591. forOwn(events, function (value, key) {
  592. entity.on(key, value);
  593. });
  594. xdebug(__func__, 'ok!');
  595. return entity;
  596. };
  597. export var updatePolyline = function updatePolyline(entity, newOptions, newEvents, oldOptions, oldEvents) {
  598. var operators = {
  599. map: function map(v) {
  600. return entity.setMap(v);
  601. },
  602. zIndex: function zIndex(v) {
  603. return entity.setzIndex(v);
  604. },
  605. bubble: null,
  606. cursor: null,
  607. gedodesic: null,
  608. isOutline: null,
  609. borderWeight: null,
  610. outlineColor: null,
  611. path: function path(v) {
  612. return entity.setPath(v);
  613. },
  614. strokeColor: null,
  615. strokeOpacity: null,
  616. strokeWeight: null,
  617. strokeStyle: null,
  618. strokeDasharray: null,
  619. lineJoin: null,
  620. lineCap: null,
  621. draggable: null,
  622. extData: function extData(v) {
  623. return entity.setExtData(v);
  624. },
  625. showDir: null,
  626. options: function options(v) {
  627. return entity.setOptions(v);
  628. }
  629. };
  630. return commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators, 'updatePolyline');
  631. };
  632. ////////////////////////////////////////////////////////////
  633. // InfoWindow
  634. ////////////////////////////////////////////////////////////
  635. /**
  636. *
  637. * @param {*} AMap
  638. * @param {*} map
  639. * @param {*} options 如果有dom用来显示,则其中的content字段即被填充为dom,不再用独立参数表示dom
  640. * @param {*} events
  641. */
  642. export var createInfoWindow = function createInfoWindow(options, events) {
  643. var __func__ = 'createInfoWindow';
  644. if (!window.AMap || !options || !options.map) {
  645. xdebug(__func__, 'fail! parameters!', 'window.AMap:' + !!window.AMap, 'options:' + !!options, 'options.map:' + !!(options && options.map));
  646. return null;
  647. }
  648. var entity = new window.AMap.InfoWindow(options);
  649. forOwn(events, function (value, key) {
  650. entity.on(key, value);
  651. });
  652. xdebug(__func__, 'ok!');
  653. return entity;
  654. };
  655. export var updateInfoWindow = function updateInfoWindow(entity, newOptions, newEvents, oldOptions, oldEvents) {
  656. var operators = {
  657. isCustom: null,
  658. autoMove: null,
  659. closeWhenClickMap: null,
  660. content: function content(v) {
  661. return entity.setContent(v);
  662. },
  663. size: function size(v) {
  664. return entity.setSize(v);
  665. },
  666. offset: null,
  667. position: function position(v) {
  668. return entity.setPosition(v);
  669. },
  670. showShadow: null
  671. };
  672. return commonUpdate(entity, newOptions, newEvents, oldOptions, oldEvents, operators, 'updateInfoWindow');
  673. };