Map.js 35 KB

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