Map.js 36 KB

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