Map.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296
  1. import OLMap from 'ol/Map'
  2. import View from 'ol/View'
  3. import * as proj from 'ol/proj'
  4. import * as interaction from 'ol/interaction'
  5. import { Draw, Modify } from 'ol/interaction'
  6. import 'ol/ol.css'
  7. import './css/KMap.css'
  8. import * as Enum from './Enum'
  9. import Common from './Common'
  10. import VectorLayer from './VectorLayer'
  11. import * as Extent from 'ol/extent'
  12. import Overlay from 'ol/Overlay'
  13. import { GeoJSON, WKT } from 'ol/format'
  14. import WMTSLayer from './WMTSLayer'
  15. import XYZLayer from './XYZLayer'
  16. import config from "@/api/config.js";
  17. import { Circle, Fill, Stroke } from 'ol/style.js';
  18. import { LineString, Point } from 'ol/geom';
  19. import { Style, Text } from 'ol/style';
  20. import { Feature } from "ol";
  21. import { getArea } from "ol/sphere"
  22. import proj4 from "proj4"
  23. import { register } from "ol/proj/proj4"
  24. // 定义EPSG:38572投影系统
  25. proj4.defs("EPSG:38572", "+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs +type=crs");
  26. register(proj4);
  27. /**
  28. * @description KMap.Map 地图类
  29. */
  30. class Map {
  31. /**
  32. * @description 地图实例
  33. * @static
  34. * @memberof Map
  35. */
  36. // Instance = null
  37. /**
  38. * @description 信息窗体像素对象
  39. * @memberof Map
  40. */
  41. // infoWindowPixel = null
  42. /**
  43. * @description 鼠标移动事件弹窗UID
  44. * @memberof Map
  45. */
  46. // InfowindowmoveUID = -1
  47. /**
  48. * @description 鼠标点击事件弹窗UID
  49. * @memberof Map
  50. */
  51. // InfowindowclickUID = -1
  52. /**
  53. * @description 是否有鼠标移动弹窗
  54. * @memberof Map
  55. */
  56. // ClearMouseMoveInfoWindow = false
  57. /**
  58. * @description X方向缩放
  59. * @memberof Map
  60. */
  61. // scaleX = 1
  62. /**
  63. * @description Y方向缩放
  64. * @memberof Map
  65. */
  66. // scaleY = 1
  67. /**
  68. * @param {string} id DOM元素ID
  69. * @param {number} zoomLevel 地图层级
  70. * @param {number} lng 纬度
  71. * @param {number} lat 经度
  72. * @description Map初始化方法
  73. * @constructor
  74. */
  75. constructor(id, zoomLevel, lng, lat, projection, minZoom, maxZoom, mapType, dragPan = true, mouseWheelZoom = true) {
  76. this.mapType = mapType || "img";
  77. if (Map.Instance) {
  78. Map.Instance = false;
  79. }
  80. if (projection) {
  81. projection = proj.get(projection)
  82. }
  83. projection = projection || proj.get("EPSG:4326");
  84. const vm = this
  85. Map.Instance = this
  86. let lnglat = [lng, lat]
  87. if (projection.getCode() == "EPSG:3857") {
  88. lnglat = proj.fromLonLat(lnglat);
  89. }
  90. Common.checkLngLat(lng, lat)
  91. let view = new View({
  92. center: lnglat,
  93. zoom: zoomLevel,
  94. minZoom: minZoom || Common.ShowLevel[0],
  95. maxZoom: maxZoom || Common.ShowLevel[1],
  96. projection: projection,
  97. enableRotation: false
  98. })
  99. this.view = view
  100. this.map = new OLMap({
  101. interactions: interaction.defaults({
  102. dragPan,
  103. mouseWheelZoom
  104. }).extend([
  105. new interaction.DragRotateAndZoom()]),
  106. target: id,
  107. layers: [],//vm.baseLayer
  108. view: view,
  109. control: []
  110. })
  111. this.initBaseLayer(projection)
  112. //初始化业务图层
  113. this.initBusinessLayer()
  114. //初始化地图信息弹窗
  115. this.initInfoWindow()
  116. //初始化地图基础事件
  117. this.initMapBaseEvent()
  118. }
  119. /**
  120. * 初始化地图底图图层
  121. * @return {array}
  122. * @memberof Map
  123. */
  124. async initBaseLayer(projection) {
  125. if (this.mapType == "img") {
  126. const img_wmts = await VE_API.system.getCfg({ "k": "img_wmts_mkt", "resultType": "json" });
  127. const cva_wmts = await VE_API.system.getCfg({ "k": "cva_wmts_mkt", "resultType": "json" });
  128. this.tdtImgLayer = new WMTSLayer(img_wmts.data, projection, this);
  129. this.cva_torLayer = new WMTSLayer(cva_wmts.data, projection, this);
  130. } else {
  131. const img_wmts = await VE_API.system.getCfg({ "k": "vec_c_wmts", "resultType": "json" });
  132. const cva_wmts = await VE_API.system.getCfg({ "k": "cva_c_wmts", "resultType": "json" });
  133. this.tdtImgLayer = new WMTSLayer(img_wmts.data, projection, this);
  134. this.cva_torLayer = new WMTSLayer(cva_wmts.data, projection, this);
  135. }
  136. }
  137. addXYZLayer(url, options, zIndex) {
  138. let xyz = new XYZLayer(url, options, zIndex || 3);
  139. return xyz;
  140. }
  141. /**
  142. * @description 初始化业务图层
  143. * @memberof Map
  144. */
  145. initBusinessLayer() {
  146. const vm = this
  147. let map = vm.map
  148. //创建默认点标记图层
  149. vm.markerLayer = new VectorLayer("defaultMarkerLayer", 101)
  150. //创建默认线标记图层
  151. vm.polyLineLayer = new VectorLayer("defaultPolylineLayer", 101)
  152. //创建默认面图层
  153. vm.polygonLayer = new VectorLayer("defaultPolygonLayer", 1000, {
  154. style: vm.polygonStyle
  155. })
  156. //创建文本标记图层
  157. vm.labelLayer = new VectorLayer("defaultLabelLayer", 99)
  158. map.addLayer(vm.polygonLayer.layer)
  159. map.once('postrender', function (event) {
  160. map.addLayer(vm.markerLayer.layer)
  161. map.addLayer(vm.polyLineLayer.layer)
  162. map.addLayer(vm.labelLayer.layer)
  163. map.on('click', function (evt) {
  164. let coordinate = evt.coordinate;
  165. // let newPoints = proj.transform(coordinate, 'EPSG:3857', 'EPSG:4326');
  166. // debugger;
  167. })
  168. // map.addLayer(layer)
  169. })
  170. }
  171. initDraw(callback) {
  172. const vm = this
  173. this.draw = new Draw({
  174. type: 'MultiPolygon',
  175. source: this.polygonLayer.source,
  176. free: true,
  177. style: vm.drawStyleFunc
  178. })
  179. this.draw.setActive(false)
  180. this.map.addInteraction(this.draw);
  181. this.draw.on("drawend", callback)
  182. }
  183. startDraw() {
  184. this.draw.setActive(true)
  185. }
  186. modifyDraw(callback) {
  187. this.modify = new Modify({
  188. source: this.polygonLayer.source,
  189. pixelTolerance: 10, //设置吸附像素值
  190. })
  191. this.map.addInteraction(this.modify);
  192. this.modify.on("modifyend", callback)
  193. }
  194. drawStyleFunc(feature) {
  195. const styles = [];
  196. const type = feature.getGeometry().getType();
  197. const coord = feature.getGeometry().getCoordinates();
  198. for (let i = 0; i < coord.length - 1; i++) {
  199. if (i % 2) {
  200. styles.push(
  201. new Style({
  202. geometry: new Point(coord[i]),
  203. image: new Circle({
  204. radius: 4,
  205. fill: new Fill({
  206. color: '#2199F8'
  207. }),
  208. stroke: new Stroke({
  209. color: '#fff',
  210. width: 1
  211. })
  212. })
  213. })
  214. );
  215. } else {
  216. styles.push(
  217. new Style({
  218. geometry: new Point(coord[i]),
  219. image: new Circle({
  220. radius: 6,
  221. fill: new Fill({
  222. color: '#fff'
  223. }),
  224. })
  225. })
  226. );
  227. }
  228. }
  229. if (type === 'LineString') {
  230. for (let i = 0; i < coord.length - 1; i++) {
  231. styles.push(
  232. new Style({
  233. geometry: new LineString([coord[i], coord[i + 1]]),
  234. stroke: new Stroke({
  235. color: '#2199F8',
  236. width: 2
  237. })
  238. })
  239. );
  240. }
  241. }
  242. return styles;
  243. }
  244. polygonStyle(feature) {
  245. const styles = [];
  246. const coord = feature.getGeometry().getCoordinates()[0];
  247. for (let i = 0; i < coord[0].length - 1; i++) {
  248. if (i % 2) {
  249. styles.push(
  250. new Style({
  251. geometry: new Point(coord[0][i]),
  252. image: new Circle({
  253. radius: 4,
  254. fill: new Fill({
  255. color: '#2199F8'
  256. }),
  257. stroke: new Stroke({
  258. color: '#fff',
  259. width: 1
  260. })
  261. })
  262. })
  263. );
  264. } else {
  265. styles.push(
  266. new Style({
  267. geometry: new Point(coord[0][i]),
  268. image: new Circle({
  269. radius: 6,
  270. fill: new Fill({
  271. color: '#fff'
  272. })
  273. })
  274. })
  275. );
  276. }
  277. }
  278. let fillStyle = new Style({
  279. fill: new Fill({
  280. color: [0, 0, 0, 0.5]
  281. }),
  282. stroke: new Stroke({
  283. color: '#2199F8',
  284. width: 2
  285. })
  286. })
  287. let geom = feature.getGeometry().clone()
  288. geom.transform(proj.get("EPSG:4326"), proj.get("EPSG:38572"))
  289. let area = getArea(geom)
  290. area = (area + area / 2) / 1000;
  291. let areaValStyle = new Style({
  292. text: new Text({
  293. font: "16px sans-serif",
  294. text: area.toFixed(2) + "亩",
  295. // offsetX: 28,
  296. // offsetY: -100,
  297. fill: new Fill({ color: "#fff" }), // 字体颜色
  298. }),
  299. })
  300. styles.push(fillStyle,areaValStyle);
  301. return styles;
  302. }
  303. getLayerFeatures() {
  304. const vm = this
  305. let features = vm.polygonLayer.source.getFeatures()
  306. return features
  307. }
  308. // 传入geojson,回显到polygon
  309. setLayerPolygon(geometry) {
  310. const vm = this
  311. vm.polygonLayer.source.addFeatures(new GeoJSON().readFeatures(geometry))
  312. }
  313. setLayerWkt(wkt) {
  314. const vm = this
  315. const format = new WKT()
  316. const mapProjection = vm.map.getView().getProjection()
  317. // 读取WKT并指定投影参数
  318. let geometry = format.readGeometry(wkt, {
  319. dataProjection: 'EPSG:4326', // WKT数据的投影
  320. featureProjection: mapProjection // 地图使用的投影
  321. })
  322. let f = new Feature({ geometry: geometry })
  323. const extent = f.getGeometry().getExtent()
  324. vm.polygonLayer.source.addFeature(f)
  325. vm.map.getView().fit(extent, { padding: [20, 20, 20, 20] });
  326. }
  327. addLayer(layer) {
  328. const vm = this
  329. vm.map.addLayer(layer)
  330. }
  331. removeLayer(layer) {
  332. const vm = this
  333. vm.map.removeLayer(layer)
  334. }
  335. /**
  336. * @description 初始化信息弹窗
  337. * @memberof Map
  338. */
  339. initInfoWindow() {
  340. const vm = this
  341. //创建地图弹窗容器
  342. let infoWindowBoxClick = document.createElement("div")
  343. let infoWindowBoxMove = document.createElement("div")
  344. let mapTarget = vm.map.getTargetElement()
  345. infoWindowBoxClick.id = "infowindow-click"
  346. infoWindowBoxMove.id = "infowindow-move"
  347. infoWindowBoxClick.style.zIndex = 999
  348. infoWindowBoxMove.style.zIndex = 999
  349. mapTarget.appendChild(infoWindowBoxClick)
  350. mapTarget.appendChild(infoWindowBoxMove)
  351. vm.infoWindow_click = new Overlay({
  352. element: infoWindowBoxClick
  353. })
  354. vm.infoWindow_move = new Overlay({
  355. element: infoWindowBoxMove
  356. })
  357. //添加点击弹窗
  358. vm.map.addOverlay(vm.infoWindow_click)
  359. //添加悬停弹窗
  360. vm.map.addOverlay(vm.infoWindow_move)
  361. }
  362. /**
  363. * @description 初始化地图基础事件
  364. * @memberof Map
  365. */
  366. initMapBaseEvent() {
  367. const vm = this
  368. var allowTriggerEvent = function (pixel) {
  369. var infoWindowPixel = vm.infoWindowPixel
  370. if (infoWindowPixel == null) {
  371. return true
  372. }
  373. var x = pixel[0]
  374. var y = pixel[1]
  375. if (x >= infoWindowPixel[0] && x <= infoWindowPixel[2] &&
  376. y >= infoWindowPixel[1] && y <= infoWindowPixel[3]) {
  377. return false
  378. }
  379. return true
  380. }
  381. vm.map.on('click', function (event) {
  382. event.pixel[0] = (event.pixel[0] / vm.scaleX)
  383. event.pixel[1] = (event.pixel[1] / vm.scaleY)
  384. var clickFeature = vm.map.forEachFeatureAtPixel(event.pixel, function (feature) {
  385. if (!allowTriggerEvent(event.pixel)) return
  386. // 为点击到的feature发送自定义的click消息
  387. if (feature.dispatchEvent != undefined) {
  388. feature.dispatchEvent({ type: 'click', event: event })
  389. }
  390. return feature
  391. })
  392. //点击在地图空白处时清空弹窗
  393. if (clickFeature == undefined) {
  394. vm.clearInfoWindow()
  395. }
  396. })
  397. //为地图注册鼠标点击事件的监听
  398. vm.map.on('pointermove', function (event) {
  399. event.pixel[0] = (event.pixel[0] / vm.scaleX)
  400. event.pixel[1] = (event.pixel[1] / vm.scaleY)
  401. var mousemoveFeature = vm.map.forEachFeatureAtPixel(event.pixel, function (feature) {
  402. if (!allowTriggerEvent(event.pixel)) {
  403. return
  404. }
  405. // 为点击到的feature发送自定义的mousemove消息
  406. if (feature.dispatchEvent != undefined) {
  407. feature.dispatchEvent({ type: 'mousemove', event: event })
  408. }
  409. return feature
  410. })
  411. //悬停在地图空白处时清空悬停弹窗
  412. if (mousemoveFeature == undefined) {
  413. vm.clearMouseMoveInfoWindow()
  414. }
  415. //设置鼠标悬停到覆盖物上的样式
  416. var mapContainer = vm.getTarget()
  417. if (mousemoveFeature) {
  418. mapContainer.style.cursor = "pointer"
  419. }
  420. else {
  421. mapContainer.style.cursor = "default"
  422. }
  423. })
  424. }
  425. setScale(x, y) {
  426. const vm = this
  427. // var mapContainer = vm.getTarget()
  428. // mapContainer.style.overflow = 'hidden'
  429. // var mapContent = mapContainer.getElementsByClassName('ol-viewport')[0]
  430. // var scaleX = 1 / Number(x);
  431. // var scaleY = 1 / Number(y);
  432. vm.scaleX = Number(x)
  433. vm.scaleY = Number(y)
  434. // mapContent.style.transform = "scale("+scaleX+","+scaleY+")"
  435. }
  436. /**
  437. * @description 清除鼠标点击弹窗
  438. * @memberof Map
  439. */
  440. clearInfoWindow() {
  441. const vm = this
  442. vm.infoWindow_click.setPosition(undefined)
  443. vm.infoWindow_move.setPosition(undefined)
  444. vm.infoWindowPixel = null
  445. vm.InfowindowmoveUID = -1
  446. vm.InfowindowclickUID = -1
  447. }
  448. /**
  449. * @description 清除鼠标移动弹窗
  450. * @memberof Map
  451. */
  452. clearMouseMoveInfoWindow() {
  453. const vm = this
  454. if (vm.ClearMouseMoveInfoWindow) {
  455. vm.infoWindow_move.setPosition(undefined)
  456. vm.infoWindowPixel = null
  457. vm.InfowindowmoveUID = -1
  458. }
  459. }
  460. /**
  461. * @description 获取地图容器div
  462. * @returns 地图容器div
  463. * @memberof Map
  464. */
  465. getTarget() {
  466. let target = this.map.getTargetElement()
  467. return target
  468. }
  469. /**
  470. * @description 获取地图容器尺寸
  471. * @returns KMap.Size格式的尺寸
  472. * @memberof Map
  473. */
  474. getSize() {
  475. let size = this.map.getSize()
  476. console.log(Common)
  477. size = Common.MapSize2KMapSize(size)
  478. return size
  479. }
  480. /**
  481. * @description 获取地图投影EPSG类型
  482. * @returns 地图投影类型
  483. * @memberof Map
  484. */
  485. getProjection() {
  486. let projection = this.view.getProjection()
  487. return projection
  488. }
  489. /**
  490. * @description 获取地图中心
  491. * @returns 地图中心,KMap.LngLat对象格式
  492. * @memberof Map
  493. */
  494. getCenter() {
  495. let center = this.view.getCenter()
  496. center = proj.toLonLat(center)
  497. return Common.MapLngLat2KMapLngLat(center)
  498. }
  499. /**
  500. * @description 获取地图中心
  501. * @returns 地图中心,KMap.LngLat对象格式
  502. * @memberof Map
  503. */
  504. getCenter2() {
  505. let center = this.view.getCenter()
  506. center = proj.toLonLat(center)
  507. return center
  508. }
  509. /**
  510. * @description 设置地图中心
  511. * @param {KMap.LngLat} position 地图中心位置,KMap.LngLat对象格式,必填
  512. * @memberof Map
  513. */
  514. setCenter(position) {
  515. let centerlnglat = Common.KMapLngLat2MapLngLat(position)
  516. let center = proj.fromLonLat(centerlnglat)
  517. this.view.setCenter(center)
  518. }
  519. getView() {
  520. return this.view;
  521. }
  522. /**
  523. * @description 设置地图中心
  524. * @param {KMap.LngLat} position 地图中心位置,KMap.LngLat对象格式,必填
  525. * @memberof Map
  526. */
  527. setCenter2(position) {
  528. this.view.setCenter(position)
  529. }
  530. fitToView(center, zoom, dera) {
  531. this.view.fit(center, { duration: dera })
  532. }
  533. /**
  534. * @description 地图中心点平移至指定点位置
  535. * @param {KMap.LngLat} point 指定点经纬度坐标,KMap.LngLat对象格式,必填
  536. * @param {number} zoom 缩放级别,选填参数,不填则使用当前缩放级别
  537. * @memberof Map
  538. */
  539. panTo(point, zoom) {
  540. point = Common.KMapLngLat2MapLngLat(point)
  541. let center = proj.fromLonLat(point)
  542. if (zoom) {
  543. this.view.animate({ center: center }, { zoom: zoom })
  544. }
  545. else {
  546. this.view.animate({ center: center })
  547. }
  548. }
  549. /**
  550. * @description 地图放大一级显示
  551. * @memberof Map
  552. */
  553. zoomIn() {
  554. this.view.setZoom(this.getZoom() + 1)
  555. return this.getZoom()
  556. }
  557. /**
  558. * @description 地图缩小一级显示
  559. * @memberof Map
  560. */
  561. zoomOut() {
  562. this.view.setZoom(this.getZoom() - 1)
  563. return this.getZoom()
  564. }
  565. /**
  566. * @description 缩放到点标记图层范围
  567. * @param {number} duration 选填参数,动画时长(单位:毫秒),不填则使用默认的0毫秒
  568. * @memberof Map
  569. */
  570. zoomToMarkerLayer(duration) {
  571. const vm = this
  572. duration = (duration != undefined) ? duration : 0
  573. let markers = vm.markerLayer.getSource().getFeatures()
  574. let coordinateArray = new Array()
  575. for (let i = 0; i < markers.length; i++) {
  576. coordinateArray.push(markers[i].getGeometry().getCoordinates())
  577. }
  578. let extentBound = new Extent.boundingExtent(coordinateArray)
  579. this.view.fit(extentBound, {
  580. duration: duration
  581. })
  582. this.view.fit(vm.markerLayer.getSource().getExtent(), {
  583. duration: duration
  584. })
  585. }
  586. /**
  587. * @description 缩放到点标记集合范围
  588. * @param {Array} markerArray 点标记集合,必填
  589. * @param {number} duration 选填参数,动画时长(单位:毫秒),不填则使用默认的0毫秒
  590. * @memberof Map
  591. */
  592. zoomToMarkerArray(markerArray, duration) {
  593. duration = (duration != undefined) ? duration : 0
  594. let coordinateArray = new Array()
  595. for (let i = 0; i < markerArray.length; i++) {
  596. coordinateArray.push(markerArray[i].Marker.getGeometry().getCoordinates())
  597. }
  598. let extentBound = new Extent.boundingExtent(coordinateArray)
  599. this.view.fit(extentBound, {
  600. duration: duration
  601. })
  602. }
  603. /**
  604. * @description 缩放到文本标记图层范围
  605. * @param {number} duration 选填参数,动画时长(单位:毫秒),不填则使用默认的0毫秒
  606. * @memberof Map
  607. */
  608. zoomToLabelLayer(duration) {
  609. const vm = this;
  610. duration = (duration != undefined) ? duration : 0
  611. this.view.fit(vm.labelLayer.getSource().getExtent(), {
  612. duration: duration
  613. })
  614. }
  615. /**
  616. * @description 缩放到文本标记集合范围
  617. * @param {Array} labelArray 文本标记集合,必填
  618. * @param {number} duration 选填参数,动画时长(单位:毫秒),不填则使用默认的0毫秒
  619. * @memberof Map
  620. */
  621. zoomToLabelArray(labelArray, duration) {
  622. duration = (duration != undefined) ? duration : 0
  623. let coordinateArray = new Array()
  624. for (let i = 0; i < labelArray.length; i++) {
  625. coordinateArray.push(labelArray[i].Label.getGeometry().getCoordinates())
  626. }
  627. let extentBound = new Extent.boundingExtent(coordinateArray)
  628. this.view.fit(extentBound, {
  629. duration: duration
  630. })
  631. }
  632. /**
  633. * @description 缩放到线图层范围
  634. * @param {number} duration 选填参数,动画时长(单位:毫秒),不填则使用默认的0毫秒
  635. * @memberof Map
  636. */
  637. zoomToPolylineLayer(duration) {
  638. const vm = this
  639. duration = (duration != undefined) ? duration : 0
  640. this.view.fit(vm.polyLineLayer.getSource().getExtent(), {
  641. duration: duration
  642. })
  643. }
  644. /**
  645. * @description 缩放到线标记集合范围
  646. * @param {Array} lineArray 线标记集合,必填
  647. * @param {number} duration 选填参数,动画时长(单位:毫秒),不填则使用默认的0毫秒
  648. * @memberof Map
  649. */
  650. zoomToPolylineArray(lineArray, duration) {
  651. duration = (duration != undefined) ? duration : 0
  652. let coordinateArray = new Array()
  653. for (let i = 0; i < lineArray.length; i++) {
  654. let coordinates = lineArray[i].polyline.getGeometry().getCoordinates()
  655. for (let z = 0; z < coordinates.length; z++) {
  656. coordinateArray.push(coordinates[z])
  657. }
  658. }
  659. let extentBound = new Extent.boundingExtent(coordinateArray)
  660. this.view.fit(extentBound, {
  661. duration: duration
  662. })
  663. }
  664. /**
  665. * @description 缩放到经纬度数组范围
  666. * @param {Array} lngLatArray KMap.LngLat格式的经纬度坐标数组,必填
  667. * @param {number} duration 选填参数,动画时长(单位:毫秒),不填则使用默认的0毫秒
  668. * @memberof Map
  669. */
  670. zoomToLngLatArray(lngLatArray, duration) {
  671. duration = (duration != undefined) ? duration : 0
  672. let coordinateArray = new Array()
  673. for (let i = 0; i < lngLatArray.length; i++) {
  674. let point = Common.KMapLngLat2MapLngLat(lngLatArray[i])
  675. coordinateArray.push(proj.fromLonLat(point))
  676. }
  677. let extentBound = new Extent.boundingExtent(coordinateArray)
  678. this.view.fit(extentBound, {
  679. duration: duration
  680. })
  681. }
  682. /**
  683. * @description 调整地图视角到能够显示所有覆盖物的合适矩形范围
  684. * @param {number} duration 选填参数,动画时长(单位:毫秒),不填则使用默认的0毫秒
  685. * @memberof Map
  686. */
  687. setFitView(duration) {
  688. const vm = this
  689. //获取所有元素坐标点集合
  690. let LonLatArray = new Array()
  691. let markers = vm.markerLayer.getSource().getFeatures()
  692. let labels = vm.labelLayer.getSource().getFeatures()
  693. let polylines = vm.polyLineLayer.getSource().getFeatures()
  694. let features = [markers, labels, polylines]
  695. for (let i = 0; i < features.length; i++) {
  696. for (let z = 0; z < features[i].length; z++) {
  697. let featureLonLats = features[i][z].getGeometry().getCoordinates()
  698. if (features[i] != polylines) {
  699. LonLatArray.push(featureLonLats)
  700. }
  701. else {
  702. for (let m = 0; m < featureLonLats.length; m++) {
  703. LonLatArray.push(featureLonLats[m])
  704. }
  705. }
  706. }
  707. }
  708. //地图视角切换到坐标点集合的矩形范围
  709. duration = (duration != undefined) ? duration : 0
  710. let extentBound = new Extent.boundingExtent(LonLatArray)
  711. this.view.fit(extentBound, {
  712. duration: duration
  713. })
  714. }
  715. /**
  716. * @description 获取地图分辨率
  717. * @returns {number} 地图分辨率
  718. * @memberof Map
  719. */
  720. getResolution() {
  721. let resolution = this.view.getResolution()
  722. return resolution
  723. }
  724. /**
  725. * @description 获取地图当前缩放值
  726. * @returns {number} 地图缩放级别
  727. * @memberof Map
  728. */
  729. getZoom() {
  730. let zoom = this.view.getZoom()
  731. return zoom
  732. }
  733. /**
  734. * @description 设置地图当前缩放值
  735. * @param {number}zoom 缩放值,必填
  736. * @memberof Map
  737. */
  738. setZoom(zoom) {
  739. this.view.setZoom(zoom)
  740. }
  741. /**
  742. * @description 获取地图最大缩放值
  743. * @returns {number} 最大缩放值
  744. * @memberof Map
  745. */
  746. getMaxZoom() {
  747. let maxZoom = this.view.getMaxZoom()
  748. return maxZoom
  749. }
  750. /**
  751. * @description 设置地图最大缩放值
  752. * @param {number} zoom 最大缩放值,必填
  753. * @memberof Map
  754. */
  755. setMaxZoom(zoom) {
  756. this.view.setMaxZoom(zoom)
  757. }
  758. /**
  759. * @description 获取地图最小缩放值
  760. * @returns {number} 最小缩放值
  761. * @memberof Map
  762. */
  763. getMinZoom() {
  764. let minZoom = this.view.getMinZoom()
  765. return minZoom
  766. }
  767. /**
  768. * @description 设置地图最小缩放值
  769. * @param {number} zoom 最小缩放值,必填
  770. * @memberof Map
  771. */
  772. setMinZoom(zoom) {
  773. this.view.setMinZoom(zoom)
  774. }
  775. /**
  776. * @description 设置地图中心和缩放级别
  777. * @param {number} zoom 缩放级别,必填
  778. * @param {KMap.LngLat} center 地图中心 KMap.LngLat对象格式,必填
  779. * @param {boolean} animate 选填,是否使用缓冲动画,默认为false
  780. * @memberof Map
  781. */
  782. setZoomAndCenter(zoom, center, animate) {
  783. let centerlnglat = Common.KMapLngLat2MapLngLat(center)
  784. center = proj.fromLonLat(centerlnglat)
  785. if (animate) {
  786. this.view.animate({ center: center, zoom: zoom })
  787. }
  788. else {
  789. this.view.setCenter(center)
  790. this.view.setZoom(zoom)
  791. }
  792. }
  793. /**
  794. * @description 获取地图经纬度矩形范围
  795. * @returns {KMap.Bounds} 地图经纬度矩形范围,KMap.Bounds格式
  796. * @memberof Map
  797. */
  798. getBounds() {
  799. const vm = this;
  800. let bounds = vm.view.calculateExtent(vm.map.getSize())
  801. let southWest = proj.toLonLat([bounds[0], bounds[1]])
  802. let northEast = proj.toLonLat([bounds[2], bounds[3]])
  803. bounds = [southWest[0], southWest[1], northEast[0], northEast[1]]
  804. let mapBound = Common.MapBounds2KMapBounds(bounds)//将OL的Bounds格式转换成KMap的Bounds格式
  805. return mapBound
  806. }
  807. /**
  808. * @description 设置地图经纬度矩形范围
  809. * @param {KMap.Bounds} bound 地图经纬度矩形范围,KMap.Bounds格式,必填
  810. * @memberof Map
  811. */
  812. setBounds(bound) {
  813. let lnglatArray = new Array()
  814. let mapBound = Common.KMapBounds2MapBounds(bound)//将KMap的Bounds格式转换成OL的Bounds格式
  815. lnglatArray.push(proj.fromLonLat([mapBound[0], mapBound[1]]))
  816. lnglatArray.push(proj.fromLonLat([mapBound[2], mapBound[3]]))
  817. let bounds = new Extent.boundingExtent(lnglatArray)
  818. this.view.fit(bounds) //地图视角切换到矩阵范围
  819. }
  820. /**
  821. * @description 设置地图经纬度矩形范围
  822. * @param {[minLng,minLat,maxLng,maxLat]} bound 地图经纬度矩形范围,KMap.Bounds格式,必填
  823. * @memberof Map
  824. */
  825. fitBounds(bound) {
  826. let lnglatArray = new Array();
  827. lnglatArray.push(proj.fromLonLat([bound[0], bound[1]]))
  828. lnglatArray.push(proj.fromLonLat([bound[2], bound[3]]))
  829. let bounds = new Extent.boundingExtent(lnglatArray)
  830. this.view.fit(bounds) //地图视角切换到矩阵范围
  831. }
  832. fit(geometryOrExtent, padding) {
  833. this.view.fit(geometryOrExtent, { duration: 500, padding })
  834. }
  835. /**
  836. * @description 平面地图像素坐标转经纬度坐标
  837. * @param {KMap.Pixel} pixel 平面地图像素坐标,格式为KMap.Pixel对象,必填
  838. * @returns {KMap.LngLat} 经纬度坐标,格式为KMap.LngLat对象
  839. * @memberof Map
  840. */
  841. pixelToLngLat(pixel) {
  842. pixel = Common.KMapPixel2MapPixel(pixel)
  843. let lnglat = new proj.toLonLat(pixel)
  844. return Common.MapLngLat2KMapLngLat(lnglat)
  845. }
  846. /**
  847. * @description 经纬度坐标转平面地图像素坐标
  848. * @param {KMap.LngLat} lnglat 经纬度坐标,格式为KMap.LngLat对象,必填
  849. * @returns {KMap.Pixel} 地图像素坐标,格式为KMap.Pixel对象
  850. * @memberof Map
  851. */
  852. lnglatToPixel(lnglat) {
  853. lnglat = Common.KMapLngLat2MapLngLat(lnglat)
  854. let pixel = proj.fromLonLat(lnglat)
  855. return Common.MapPixel2KMapPixel(pixel)
  856. }
  857. /**
  858. * @description 地图容器屏幕坐标转经纬度坐标
  859. * @param {KMap.Pixel} pixel 地图容器像素,格式为KMap.Pixel对象,必填
  860. * @returns {KMap.LngLat} 返回KMap.LngLat格式的经纬度
  861. * @memberof Map
  862. */
  863. containerToLngLat(pixel) {
  864. pixel = Common.KMapPixel2MapPixel(pixel)
  865. let lnglat = this.map.getCoordinateFromPixel(pixel)
  866. lnglat = proj.toLonLat(lnglat)
  867. lnglat = Common.MapLngLat2KMapLngLat(lnglat)
  868. return lnglat
  869. }
  870. /**
  871. * @description 经纬度坐标转地图容器屏幕坐标
  872. * @param {KMap.LngLat} lnglat 经纬度坐标,KMap.LngLat格式的经纬度,必填
  873. * @returns {KMap.Pixel} 返回地图容器像素,格式为KMap.Pixel对象
  874. * @memberof Map
  875. */
  876. lngLatToContainer(lnglat) {
  877. lnglat = Common.KMapLngLat2MapLngLat(lnglat)
  878. let coordinate = proj.fromLonLat(lnglat)
  879. let container = this.map.getPixelFromCoordinate(coordinate)
  880. return Common.MapPixel2KMapPixel(container)
  881. }
  882. /**
  883. * @description 获取地图顺时针旋转角度
  884. * @returns {number} 顺时针旋转角度(弧度)
  885. * @memberof Map
  886. */
  887. getRotation() {
  888. let rotation = this.view.getRotation()
  889. return rotation
  890. }
  891. /**
  892. * @description 设置地图顺时针旋转角度
  893. * @param {number} rotation 顺时针旋转角度(弧度),必填
  894. * @memberof Map
  895. */
  896. setRotation(rotation) {
  897. this.view.setRotation(rotation)
  898. }
  899. /**
  900. * @description 获取地图插件集合
  901. * @returns {Array} 地图插件集合数组
  902. * @memberof Map
  903. */
  904. getControls() {
  905. let controls = this.map.getControls().array_
  906. return controls
  907. }
  908. /**
  909. * @description 添加插件
  910. * @param {ol.control} control OL原生control对象
  911. * @memberof Map
  912. */
  913. addControl(control) {
  914. let state = true
  915. let controls = this.map.getControls().array_
  916. for (let i = 0; i < controls.length; i++) {
  917. if (control == controls[i]) {
  918. state = false
  919. break
  920. }
  921. }
  922. if (state) {
  923. this.map.addControl(control)
  924. }
  925. }
  926. /**
  927. * @description 删除插件
  928. * @param {ol.control} control 插件,必填
  929. * @memberof Map
  930. */
  931. removeControl(control) {
  932. let controls = this.map.getControls().array_
  933. for (let i = 0; i < controls.length; i++) {
  934. if (control == controls[i]) {
  935. this.map.removeControl(controls[i])
  936. return
  937. }
  938. }
  939. }
  940. /**
  941. * @description 清空默认插件 注意如果要清除默认插件需要在加载其他插件前调用此函数
  942. * @memberof Map
  943. */
  944. removeOriginControls() {
  945. let controls = this.map.getControls().array_
  946. for (let i = 0; i < controls.length; i++) {
  947. this.map.removeControl(controls[i])
  948. }
  949. }
  950. /**
  951. * @description 获取地图指针样式
  952. * @memberof Map
  953. */
  954. getDefaultCursor() {
  955. let mapContainer = this.map.getTargetElement()
  956. let cursor = mapContainer.style.cursor
  957. return cursor
  958. }
  959. /**
  960. * @description 设置地图指针样式
  961. * @param {String} cursorStyle 鼠标样式("default"默认指针,"pointer"小手,"move"移动指针, "text"文本指针,"wait"等待状态,"help"帮助),必填
  962. * @memberof Map
  963. */
  964. setDefaultCursor(cursorStyle) {
  965. let mapContainer = this.map.getTargetElement()
  966. if (cursorStyle != undefined) {
  967. mapContainer.style.cursor = cursorStyle
  968. }
  969. else {
  970. mapContainer.style.cursor = "default"
  971. }
  972. }
  973. /**
  974. * @description 设置鼠标悬停在元素上时的样式
  975. * @param {String} cursorStyle 鼠标样式("default"默认指针,"pointer"小手,"move"移动指针, "text"文本指针,"wait"等待状态,"help"帮助),必填
  976. * @memberof Map
  977. */
  978. setFeatureCursor(cursorStyle) {
  979. cursorStyle = (cursorStyle == undefined) ? "default" : cursorStyle
  980. let mapContainer = this.map.getTargetElement()
  981. let defaultCursor = mapContainer.style.cursor
  982. this.map.on("pointermove", function (e) {
  983. let features = this.map.forEachFeatureAtPixel(e.pixel, function (feature) { return feature })
  984. if (features) {
  985. mapContainer.style.cursor = cursorStyle
  986. }
  987. else {
  988. mapContainer.style.cursor = defaultCursor
  989. }
  990. })
  991. }
  992. /**
  993. * @description 获取地图显示元素种类
  994. * @returns {Array} 地图显示元素种类集合
  995. * @memberof Map
  996. */
  997. getFeatures() {
  998. const vm = this
  999. let features = new Array()
  1000. if (vm.baseLayer.getVisible() == true) {
  1001. features.push("Tile")
  1002. }
  1003. if (vm.markerLayer.getVisible() == true) {
  1004. features.push("Marker")
  1005. }
  1006. if (vm.labelLayer.getVisible() == true) {
  1007. features.push("Label")
  1008. }
  1009. if (vm.polyLineLayer.getVisible() == true) {
  1010. features.push("PolyLine")
  1011. }
  1012. return features
  1013. }
  1014. /**
  1015. * @description 设置地图显示元素种类
  1016. * @param {JSON} param param 地图元素显示参数,JSON对象,必填
  1017. * param.marker true/false,点标记是否显示,选填
  1018. * param.label true/false,文本标记是否显示,选填
  1019. * param.polyline true/false,线标记是否显示,选填
  1020. * @memberof Map
  1021. */
  1022. setFeatures(param) {
  1023. const vm = this
  1024. if (param.marker == true || param.marker == false) {
  1025. vm.markerLayer.setVisible(param.marker)
  1026. }
  1027. if (param.label == true || param.label == false) {
  1028. vm.labelLayer.setVisible(param.label)
  1029. }
  1030. if (param.polyline == true || param.polyline == false) {
  1031. vm.polyLineLayer.setVisible(param.polyline)
  1032. }
  1033. }
  1034. /**
  1035. * @description 获取地图状态(双击缩放/拖拽/滚动鼠标中间缩放)
  1036. * @returns {JSON} 地图状态
  1037. * {"DoubleClickZoom": true, "DragAndDrop": true, "MouseWheelZoom": true}
  1038. * @memberof Map
  1039. */
  1040. getStates() {
  1041. let interactions = this.map.getInteractions().array_
  1042. let DoubleClickZoom, DragAndDrop, MouseWheelZoom
  1043. for (let i = 0; i < interactions.length; i++) {
  1044. if (i == 1) DoubleClickZoom = interactions[i].getActive()
  1045. if (i == 2) DragAndDrop = interactions[i].getActive()
  1046. if (i == 7) MouseWheelZoom = interactions[i].getActive()
  1047. }
  1048. let states = {
  1049. "DoubleClickZoom": DoubleClickZoom,
  1050. "DragAndDrop": DragAndDrop,
  1051. "MouseWheelZoom": MouseWheelZoom
  1052. }
  1053. return states
  1054. }
  1055. /**
  1056. * @description 设置地图状态(双击缩放/拖拽/滚动鼠标中间缩放)
  1057. * @param {JSON} param 地图状态 JSON对象,必填
  1058. * param.DoubleClickZoom true/false(双击缩放地图),选填
  1059. * param.DragAndDrop true/false(地图拖拽),选填
  1060. * param.MouseWheelZoom true/false(滚动鼠标中间缩放地图),选填
  1061. * @memberof Map
  1062. */
  1063. setStates(param) {
  1064. let interactions = this.map.getInteractions().array_
  1065. if (param.DoubleClickZoom == true || param.DoubleClickZoom == false)
  1066. interactions[1].setActive(param.DoubleClickZoom)
  1067. if (param.DragAndDrop == true || param.DragAndDrop == false)
  1068. interactions[2].setActive(param.DragAndDrop)
  1069. if (param.MouseWheelZoom == true || param.MouseWheelZoom == false)
  1070. interactions[7].setActive(param.MouseWheelZoom)
  1071. }
  1072. /**
  1073. * @description 清空地图所有元素
  1074. * @memberof Map
  1075. */
  1076. clearMap() {
  1077. const vm = this
  1078. //清空图层元素
  1079. vm.markerLayer.getSource().clear()
  1080. vm.labelLayer.getSource().clear()
  1081. vm.polyLineLayer.getSource().clear()
  1082. vm.polygonLayer.getSource().clear()
  1083. //清空地图弹窗
  1084. vm.clearInfoWindow()
  1085. }
  1086. /**
  1087. * @description 清除地图对象并清空地图容器(建议少使用此API,容易造成报错)
  1088. * @memberof Map
  1089. */
  1090. destroy() {
  1091. //清空地图对象
  1092. // this.map.destroy()
  1093. //清空地图容器
  1094. let target = this.map.getTargetElement()
  1095. target.innerHTML = ""
  1096. Common.UseBaiDuOnlineLayer = false;
  1097. Common.UseGaoDeOnlineLayer = false;
  1098. Common.UseWGS84OnlineLayer = false;
  1099. }
  1100. /**
  1101. * @description 获取地图图层数组
  1102. * @return {Array} 地图图层数组
  1103. * @memberof Map
  1104. */
  1105. getLayers() {
  1106. let layers = this.map.getLayers().array_
  1107. return layers
  1108. }
  1109. /**
  1110. * @description 设置地图各个图层显示/隐藏
  1111. * @param {JSON} param 地图图层显示参数,JSON对象,必填
  1112. * param.Marker true/false,点标记图层显示/隐藏,选填
  1113. * param.Label true/false,文本标记图层显示/隐藏,选填
  1114. * param.PolyLine true/false,线标记图层显示/隐藏,选填
  1115. * @memberof Map
  1116. */
  1117. setLayers(param) {
  1118. const vm = this
  1119. if (param.Marker == true || param.Marker == false) {
  1120. vm.markerLayer.setVisible(param.Marker)
  1121. }
  1122. if (param.Label == true || param.Label == false) {
  1123. vm.labelLayer.setVisible(param.Label)
  1124. }
  1125. if (param.PolyLine == true || param.PolyLine == false) {
  1126. vm.polyLineLayer.setVisible(param.PolyLine)
  1127. }
  1128. }
  1129. /**
  1130. * @description 获取地图各个图层index值
  1131. * @returns {JSON} JSON对象
  1132. * {"markerLayer": 0, "labelLayer": 0, "polyLineLayer": 0}
  1133. * @memberof Map
  1134. */
  1135. getLayersIndex() {
  1136. const vm = this
  1137. let index = {}
  1138. index.markerLayer = vm.markerLayer.getZIndex()
  1139. index.labelLayer = vm.labelLayer.getZIndex()
  1140. index.polyLineLayer = vm.polyLineLayer.getZIndex()
  1141. return index
  1142. }
  1143. /**
  1144. * @description 设置地图各个图层index值,index值大的图层显示在上方,值相同时后加载的图层显示在上方
  1145. * @param {JSON} param 图层索引JSON对象,必填
  1146. * param.marker 点标记图层index值,选填
  1147. * param.label 文字标记图层index值,选填
  1148. * param.polyLine 线标记图层index值,选填
  1149. * @memberof Map
  1150. */
  1151. setLayersIndex(param) {
  1152. const vm = this
  1153. let markerIndex = (param.marker) ? param.marker : vm.markerLayer.getZIndex()
  1154. let labelIndex = (param.label) ? param.label : vm.labelLayer.getZIndex()
  1155. let polyLineIndex = (param.polyLine) ? param.polyLine : vm.polyLineLayer.getZIndex()
  1156. vm.markerLayer.setZIndex(markerIndex)
  1157. vm.labelLayer.setZIndex(labelIndex)
  1158. vm.polyLineLayer.setZIndex(polyLineIndex)
  1159. }
  1160. /**
  1161. * @description 注册地图事件
  1162. * @param {String} eventName 地图操作事件类型,必填
  1163. * "click":单击地图,双击将触发两次;"singleclick":单击地图;"dblclick":双击地图;"movestart":开始移动地图;
  1164. * "moveend":移动地图结束;"postrender":渲染地图后;"pointerdrag":拖动指针时;"mousemove":移动指针时
  1165. * @param {funciton} callback 操作事件触发时调用的函数,必填
  1166. * @memberof Map
  1167. */
  1168. on(eventName, callback) {
  1169. if (eventName == "mousemove") {
  1170. eventName = "pointermove"
  1171. }
  1172. if (eventName == "load") {
  1173. eventName = "postrender"
  1174. }
  1175. this.map.on(eventName, callback)
  1176. }
  1177. /**
  1178. * @description 注册地图事件(事件仅执行一次)
  1179. * @param {Strig} eventName 地图操作事件类型,必填
  1180. * "click":单击地图,双击将触发两次;"singleclick":单击地图;"dblclick":双击地图;"movestart":开始移动地图;
  1181. * "moveend":移动地图结束;"postrender":渲染地图后;"pointerdrag":拖动指针时;"mousemove":移动指针时
  1182. * @param {function} callback 操作事件触发时调用的函数,必填
  1183. * @memberof Map
  1184. */
  1185. once(eventName, callback) {
  1186. if (eventName == "mousemove") {
  1187. eventName = "pointermove"
  1188. }
  1189. if (eventName == "load") {
  1190. eventName = "postrender"
  1191. }
  1192. this.map.once(eventName, callback)
  1193. }
  1194. /**
  1195. * @description 取消地图绑定事件
  1196. * @param {Strig} eventName 地图操作事件类型,必填
  1197. * "click":单击地图,双击将触发两次;"singleclick":单击地图;"dblclick":双击地图;"movestart":开始移动地图;
  1198. * "moveend":移动地图结束;"postrender":渲染地图后;"pointerdrag":拖动指针时;"mousemove":移动指针时
  1199. * @param {function} callback 操作事件触发时调用的函数,必填
  1200. * @memberof Map
  1201. */
  1202. off(eventName, callback) {
  1203. if (eventName == "mousemove") {
  1204. eventName = "pointermove"
  1205. }
  1206. if (eventName == "load") {
  1207. eventName = "postrender"
  1208. }
  1209. this.map.un(eventName, callback)
  1210. }
  1211. setMarkerLayerZoomInfo(minZoom, maxZoom) {
  1212. this.markerLayer.setMaxZoom(maxZoom);
  1213. this.markerLayer.setMinZoom(minZoom);
  1214. }
  1215. setPolylineLayerZoomInfo(minZoom, maxZoom) {
  1216. this.polylineLayer.setMaxZoom(maxZoom);
  1217. this.polylineLayer.setMinZoom(minZoom);
  1218. }
  1219. setPolygonLayerZoomInfo(minZoom, maxZoom) {
  1220. this.polygonLayer.setMaxZoom(maxZoom);
  1221. this.polygonLayer.setMinZoom(minZoom);
  1222. }
  1223. }
  1224. export default Map