Map.js 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361
  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. return f
  385. }
  386. addLayer(layer){
  387. const vm = this
  388. vm.map.addLayer(layer)
  389. }
  390. removeLayer(layer){
  391. const vm = this
  392. vm.map.removeLayer(layer)
  393. }
  394. /**
  395. * @description 初始化信息弹窗
  396. * @memberof Map
  397. */
  398. initInfoWindow(){
  399. const vm = this
  400. //创建地图弹窗容器
  401. let infoWindowBoxClick = document.createElement("div")
  402. let infoWindowBoxMove = document.createElement("div")
  403. let mapTarget = vm.map.getTargetElement()
  404. infoWindowBoxClick.id = "infowindow-click"
  405. infoWindowBoxMove.id = "infowindow-move"
  406. infoWindowBoxClick.style.zIndex = 999
  407. infoWindowBoxMove.style.zIndex = 999
  408. mapTarget.appendChild(infoWindowBoxClick)
  409. mapTarget.appendChild(infoWindowBoxMove)
  410. vm.infoWindow_click = new Overlay({
  411. element: infoWindowBoxClick
  412. })
  413. vm.infoWindow_move = new Overlay({
  414. element: infoWindowBoxMove
  415. })
  416. //添加点击弹窗
  417. vm.map.addOverlay(vm.infoWindow_click)
  418. //添加悬停弹窗
  419. vm.map.addOverlay(vm.infoWindow_move)
  420. }
  421. /**
  422. * @description 初始化地图基础事件
  423. * @memberof Map
  424. */
  425. initMapBaseEvent(){
  426. const vm = this
  427. var allowTriggerEvent = function(pixel) {
  428. var infoWindowPixel = vm.infoWindowPixel
  429. if(infoWindowPixel == null){
  430. return true
  431. }
  432. var x = pixel[0]
  433. var y = pixel[1]
  434. if(x>=infoWindowPixel[0] && x<=infoWindowPixel[2] &&
  435. y>=infoWindowPixel[1] && y<=infoWindowPixel[3]) {
  436. return false
  437. }
  438. return true
  439. }
  440. vm.map.on('click',function(event){
  441. event.pixel[0] = (event.pixel[0] / vm.scaleX)
  442. event.pixel[1] = (event.pixel[1] / vm.scaleY)
  443. var clickFeature = vm.map.forEachFeatureAtPixel(event.pixel, function(feature){
  444. if(!allowTriggerEvent(event.pixel)) return
  445. // 为点击到的feature发送自定义的click消息
  446. if(feature.dispatchEvent != undefined){
  447. feature.dispatchEvent({type: 'click', event: event})
  448. }
  449. return feature
  450. })
  451. //点击在地图空白处时清空弹窗
  452. if(clickFeature == undefined){
  453. vm.clearInfoWindow()
  454. }
  455. })
  456. //为地图注册鼠标点击事件的监听
  457. vm.map.on('pointermove', function(event) {
  458. event.pixel[0] = (event.pixel[0] / vm.scaleX)
  459. event.pixel[1] = (event.pixel[1] / vm.scaleY)
  460. var mousemoveFeature = vm.map.forEachFeatureAtPixel(event.pixel, function(feature){
  461. if(!allowTriggerEvent(event.pixel)){
  462. return
  463. }
  464. // 为点击到的feature发送自定义的mousemove消息
  465. if(feature.dispatchEvent != undefined){
  466. feature.dispatchEvent({type: 'mousemove', event: event})
  467. }
  468. return feature
  469. })
  470. //悬停在地图空白处时清空悬停弹窗
  471. if(mousemoveFeature == undefined)
  472. {
  473. vm.clearMouseMoveInfoWindow()
  474. }
  475. //设置鼠标悬停到覆盖物上的样式
  476. let mapContainer = vm.getTarget()
  477. if(mousemoveFeature) {
  478. mapContainer.style.cursor = "pointer"
  479. }
  480. else {
  481. mapContainer.style.cursor = this.defaultCursor
  482. }
  483. })
  484. }
  485. setScale(x, y) {
  486. const vm = this
  487. // var mapContainer = vm.getTarget()
  488. // mapContainer.style.overflow = 'hidden'
  489. // var mapContent = mapContainer.getElementsByClassName('ol-viewport')[0]
  490. // var scaleX = 1 / Number(x);
  491. // var scaleY = 1 / Number(y);
  492. vm.scaleX = Number(x)
  493. vm.scaleY = Number(y)
  494. // mapContent.style.transform = "scale("+scaleX+","+scaleY+")"
  495. }
  496. /**
  497. * @description 清除鼠标点击弹窗
  498. * @memberof Map
  499. */
  500. clearInfoWindow() {
  501. const vm = this
  502. vm.infoWindow_click.setPosition(undefined)
  503. vm.infoWindow_move.setPosition(undefined)
  504. vm.infoWindowPixel = null
  505. vm.InfowindowmoveUID = -1
  506. vm.InfowindowclickUID = -1
  507. }
  508. /**
  509. * @description 清除鼠标移动弹窗
  510. * @memberof Map
  511. */
  512. clearMouseMoveInfoWindow() {
  513. const vm = this
  514. if(vm.ClearMouseMoveInfoWindow) {
  515. vm.infoWindow_move.setPosition(undefined)
  516. vm.infoWindowPixel = null
  517. vm.InfowindowmoveUID = -1
  518. }
  519. }
  520. /**
  521. * @description 获取地图容器div
  522. * @returns 地图容器div
  523. * @memberof Map
  524. */
  525. getTarget() {
  526. let target = this.map.getTargetElement()
  527. return target
  528. }
  529. /**
  530. * @description 获取地图容器尺寸
  531. * @returns KMap.Size格式的尺寸
  532. * @memberof Map
  533. */
  534. getSize() {
  535. let size = this.map.getSize()
  536. console.log(Common)
  537. size = Common.MapSize2KMapSize(size)
  538. return size
  539. }
  540. /**
  541. * @description 获取地图投影EPSG类型
  542. * @returns 地图投影类型
  543. * @memberof Map
  544. */
  545. getProjection() {
  546. let projection = this.view.getProjection()
  547. return projection
  548. }
  549. /**
  550. * @description 获取地图中心
  551. * @returns 地图中心,KMap.LngLat对象格式
  552. * @memberof Map
  553. */
  554. getCenter() {
  555. let center = this.view.getCenter()
  556. center = proj.toLonLat(center)
  557. return Common.MapLngLat2KMapLngLat(center)
  558. }
  559. /**
  560. * @description 获取地图中心
  561. * @returns 地图中心,KMap.LngLat对象格式
  562. * @memberof Map
  563. */
  564. getCenter2() {
  565. let center = this.view.getCenter()
  566. center = proj.toLonLat(center)
  567. return center
  568. }
  569. /**
  570. * @description 设置地图中心
  571. * @param {KMap.LngLat} position 地图中心位置,KMap.LngLat对象格式,必填
  572. * @memberof Map
  573. */
  574. setCenter(position) {
  575. let centerlnglat = Common.KMapLngLat2MapLngLat(position)
  576. let center = proj.fromLonLat(centerlnglat)
  577. this.view.setCenter(center)
  578. }
  579. getView(){
  580. return this.view;
  581. }
  582. /**
  583. * @description 设置地图中心
  584. * @param {KMap.LngLat} position 地图中心位置,KMap.LngLat对象格式,必填
  585. * @memberof Map
  586. */
  587. setCenter2(position) {
  588. this.view.setCenter(position)
  589. }
  590. fitToView(center,zoom,dera) {
  591. this.view.fit(center,{duration: dera})
  592. }
  593. /**
  594. * @description 地图中心点平移至指定点位置
  595. * @param {KMap.LngLat} point 指定点经纬度坐标,KMap.LngLat对象格式,必填
  596. * @param {number} zoom 缩放级别,选填参数,不填则使用当前缩放级别
  597. * @memberof Map
  598. */
  599. panTo(point,zoom) {
  600. point = Common.KMapLngLat2MapLngLat(point)
  601. let center = proj.fromLonLat(point)
  602. if(zoom) {
  603. this.view.animate({center:center},{zoom:zoom})
  604. }
  605. else {
  606. this.view.animate({center:center})
  607. }
  608. }
  609. /**
  610. * @description 地图放大一级显示
  611. * @memberof Map
  612. */
  613. zoomIn() {
  614. this.view.setZoom( this.getZoom() + 1 )
  615. return this.getZoom()
  616. }
  617. /**
  618. * @description 地图缩小一级显示
  619. * @memberof Map
  620. */
  621. zoomOut() {
  622. this.view.setZoom( this.getZoom() - 1)
  623. return this.getZoom()
  624. }
  625. /**
  626. * @description 缩放到点标记图层范围
  627. * @param {number} duration 选填参数,动画时长(单位:毫秒),不填则使用默认的0毫秒
  628. * @memberof Map
  629. */
  630. zoomToMarkerLayer(duration) {
  631. const vm = this
  632. duration = (duration != undefined)? duration : 0
  633. let markers = vm.markerLayer.getSource().getFeatures()
  634. let coordinateArray = new Array()
  635. for(let i=0; i<markers.length; i++) {
  636. coordinateArray.push(markers[i].getGeometry().getCoordinates())
  637. }
  638. let extentBound = new Extent.boundingExtent(coordinateArray)
  639. this.view.fit(extentBound,{
  640. duration: duration
  641. })
  642. this.view.fit(vm.markerLayer.getSource().getExtent(),{
  643. duration: duration
  644. })
  645. }
  646. /**
  647. * @description 缩放到点标记集合范围
  648. * @param {Array} markerArray 点标记集合,必填
  649. * @param {number} duration 选填参数,动画时长(单位:毫秒),不填则使用默认的0毫秒
  650. * @memberof Map
  651. */
  652. zoomToMarkerArray(markerArray,duration) {
  653. duration = (duration != undefined)? duration : 0
  654. let coordinateArray = new Array()
  655. for(let i=0; i<markerArray.length; i++) {
  656. coordinateArray.push(markerArray[i].Marker.getGeometry().getCoordinates())
  657. }
  658. let extentBound = new Extent.boundingExtent(coordinateArray)
  659. this.view.fit(extentBound,{
  660. duration: duration
  661. })
  662. }
  663. /**
  664. * @description 缩放到文本标记图层范围
  665. * @param {number} duration 选填参数,动画时长(单位:毫秒),不填则使用默认的0毫秒
  666. * @memberof Map
  667. */
  668. zoomToLabelLayer(duration) {
  669. const vm = this;
  670. duration = (duration != undefined)? duration : 0
  671. this.view.fit(vm.labelLayer.getSource().getExtent(),{
  672. duration: duration
  673. })
  674. }
  675. /**
  676. * @description 缩放到文本标记集合范围
  677. * @param {Array} labelArray 文本标记集合,必填
  678. * @param {number} duration 选填参数,动画时长(单位:毫秒),不填则使用默认的0毫秒
  679. * @memberof Map
  680. */
  681. zoomToLabelArray(labelArray,duration) {
  682. duration = (duration != undefined)? duration : 0
  683. let coordinateArray = new Array()
  684. for(let i=0; i<labelArray.length; i++) {
  685. coordinateArray.push(labelArray[i].Label.getGeometry().getCoordinates())
  686. }
  687. let extentBound = new Extent.boundingExtent(coordinateArray)
  688. this.view.fit(extentBound,{
  689. duration: duration
  690. })
  691. }
  692. /**
  693. * @description 缩放到线图层范围
  694. * @param {number} duration 选填参数,动画时长(单位:毫秒),不填则使用默认的0毫秒
  695. * @memberof Map
  696. */
  697. zoomToPolylineLayer(duration) {
  698. const vm = this
  699. duration = (duration != undefined)? duration : 0
  700. this.view.fit(vm.polyLineLayer.getSource().getExtent(),{
  701. duration: duration
  702. })
  703. }
  704. /**
  705. * @description 缩放到线标记集合范围
  706. * @param {Array} lineArray 线标记集合,必填
  707. * @param {number} duration 选填参数,动画时长(单位:毫秒),不填则使用默认的0毫秒
  708. * @memberof Map
  709. */
  710. zoomToPolylineArray(lineArray,duration) {
  711. duration = (duration != undefined)? duration : 0
  712. let coordinateArray = new Array()
  713. for(let i=0; i<lineArray.length; i++) {
  714. let coordinates = lineArray[i].polyline.getGeometry().getCoordinates()
  715. for(let z=0; z<coordinates.length; z++) {
  716. coordinateArray.push(coordinates[z])
  717. }
  718. }
  719. let extentBound = new Extent.boundingExtent(coordinateArray)
  720. this.view.fit(extentBound,{
  721. duration: duration
  722. })
  723. }
  724. /**
  725. * @description 缩放到经纬度数组范围
  726. * @param {Array} lngLatArray KMap.LngLat格式的经纬度坐标数组,必填
  727. * @param {number} duration 选填参数,动画时长(单位:毫秒),不填则使用默认的0毫秒
  728. * @memberof Map
  729. */
  730. zoomToLngLatArray(lngLatArray,duration) {
  731. duration = (duration != undefined)? duration : 0
  732. let coordinateArray = new Array()
  733. for(let i=0; i<lngLatArray.length; i++) {
  734. let point = Common.KMapLngLat2MapLngLat(lngLatArray[i])
  735. coordinateArray.push(proj.fromLonLat(point))
  736. }
  737. let extentBound = new Extent.boundingExtent(coordinateArray)
  738. this.view.fit(extentBound,{
  739. duration: duration
  740. })
  741. }
  742. /**
  743. * @description 调整地图视角到能够显示所有覆盖物的合适矩形范围
  744. * @param {number} duration 选填参数,动画时长(单位:毫秒),不填则使用默认的0毫秒
  745. * @memberof Map
  746. */
  747. setFitView(duration) {
  748. const vm = this
  749. //获取所有元素坐标点集合
  750. let LonLatArray = new Array()
  751. let markers = vm.markerLayer.getSource().getFeatures()
  752. let labels = vm.labelLayer.getSource().getFeatures()
  753. let polylines = vm.polyLineLayer.getSource().getFeatures()
  754. let features = [markers,labels,polylines]
  755. for(let i=0; i<features.length; i++) {
  756. for(let z=0; z<features[i].length; z++) {
  757. let featureLonLats = features[i][z].getGeometry().getCoordinates()
  758. if(features[i] != polylines) {
  759. LonLatArray.push(featureLonLats)
  760. }
  761. else {
  762. for(let m=0; m<featureLonLats.length; m++) {
  763. LonLatArray.push(featureLonLats[m])
  764. }
  765. }
  766. }
  767. }
  768. //地图视角切换到坐标点集合的矩形范围
  769. duration = (duration != undefined)? duration : 0
  770. let extentBound = new Extent.boundingExtent(LonLatArray)
  771. this.view.fit(extentBound,{
  772. duration: duration
  773. })
  774. }
  775. /**
  776. * @description 获取地图分辨率
  777. * @returns {number} 地图分辨率
  778. * @memberof Map
  779. */
  780. getResolution() {
  781. let resolution = this.view.getResolution()
  782. return resolution
  783. }
  784. /**
  785. * @description 获取地图当前缩放值
  786. * @returns {number} 地图缩放级别
  787. * @memberof Map
  788. */
  789. getZoom() {
  790. let zoom = this.view.getZoom()
  791. return zoom
  792. }
  793. /**
  794. * @description 设置地图当前缩放值
  795. * @param {number}zoom 缩放值,必填
  796. * @memberof Map
  797. */
  798. setZoom(zoom) {
  799. this.view.setZoom(zoom)
  800. }
  801. /**
  802. * @description 获取地图最大缩放值
  803. * @returns {number} 最大缩放值
  804. * @memberof Map
  805. */
  806. getMaxZoom() {
  807. let maxZoom = this.view.getMaxZoom()
  808. return maxZoom
  809. }
  810. /**
  811. * @description 设置地图最大缩放值
  812. * @param {number} zoom 最大缩放值,必填
  813. * @memberof Map
  814. */
  815. setMaxZoom(zoom) {
  816. this.view.setMaxZoom(zoom)
  817. }
  818. /**
  819. * @description 获取地图最小缩放值
  820. * @returns {number} 最小缩放值
  821. * @memberof Map
  822. */
  823. getMinZoom () {
  824. let minZoom = this.view.getMinZoom()
  825. return minZoom
  826. }
  827. /**
  828. * @description 设置地图最小缩放值
  829. * @param {number} zoom 最小缩放值,必填
  830. * @memberof Map
  831. */
  832. setMinZoom(zoom) {
  833. this.view.setMinZoom(zoom)
  834. }
  835. /**
  836. * @description 设置地图中心和缩放级别
  837. * @param {number} zoom 缩放级别,必填
  838. * @param {KMap.LngLat} center 地图中心 KMap.LngLat对象格式,必填
  839. * @param {boolean} animate 选填,是否使用缓冲动画,默认为false
  840. * @memberof Map
  841. */
  842. setZoomAndCenter(zoom,center,animate) {
  843. let centerlnglat = Common.KMapLngLat2MapLngLat(center)
  844. center = proj.fromLonLat(centerlnglat)
  845. if(animate) {
  846. this.view.animate({center:center,zoom:zoom})
  847. }
  848. else {
  849. this.view.setCenter(center)
  850. this.view.setZoom(zoom)
  851. }
  852. }
  853. /**
  854. * @description 获取地图经纬度矩形范围
  855. * @returns {KMap.Bounds} 地图经纬度矩形范围,KMap.Bounds格式
  856. * @memberof Map
  857. */
  858. getBounds() {
  859. const vm = this;
  860. let bounds = vm.view.calculateExtent(vm.map.getSize())
  861. let southWest = proj.toLonLat([bounds[0],bounds[1]])
  862. let northEast = proj.toLonLat([bounds[2],bounds[3]])
  863. bounds = [southWest[0],southWest[1],northEast[0],northEast[1]]
  864. let mapBound = Common.MapBounds2KMapBounds(bounds)//将OL的Bounds格式转换成KMap的Bounds格式
  865. return mapBound
  866. }
  867. /**
  868. * @description 设置地图经纬度矩形范围
  869. * @param {KMap.Bounds} bound 地图经纬度矩形范围,KMap.Bounds格式,必填
  870. * @memberof Map
  871. */
  872. setBounds(bound) {
  873. let lnglatArray = new Array()
  874. let mapBound = Common.KMapBounds2MapBounds(bound)//将KMap的Bounds格式转换成OL的Bounds格式
  875. lnglatArray.push(proj.fromLonLat([mapBound[0],mapBound[1]]))
  876. lnglatArray.push(proj.fromLonLat([mapBound[2],mapBound[3]]))
  877. let bounds = new Extent.boundingExtent(lnglatArray)
  878. this.view.fit(bounds) //地图视角切换到矩阵范围
  879. }
  880. /**
  881. * @description 设置地图经纬度矩形范围
  882. * @param {[minLng,minLat,maxLng,maxLat]} bound 地图经纬度矩形范围,KMap.Bounds格式,必填
  883. * @memberof Map
  884. */
  885. fitBounds(bound) {
  886. let lnglatArray = new Array();
  887. lnglatArray.push(proj.fromLonLat([bound[0],bound[1]]))
  888. lnglatArray.push(proj.fromLonLat([bound[2],bound[3]]))
  889. let bounds = new Extent.boundingExtent(lnglatArray)
  890. this.view.fit(bounds) //地图视角切换到矩阵范围
  891. }
  892. fit(geometryOrExtent,options){
  893. this.view.fit(geometryOrExtent)
  894. }
  895. /**
  896. * @description 平面地图像素坐标转经纬度坐标
  897. * @param {KMap.Pixel} pixel 平面地图像素坐标,格式为KMap.Pixel对象,必填
  898. * @returns {KMap.LngLat} 经纬度坐标,格式为KMap.LngLat对象
  899. * @memberof Map
  900. */
  901. pixelToLngLat(pixel) {
  902. pixel = Common.KMapPixel2MapPixel(pixel)
  903. let lnglat = new proj.toLonLat(pixel)
  904. return Common.MapLngLat2KMapLngLat(lnglat)
  905. }
  906. /**
  907. * @description 经纬度坐标转平面地图像素坐标
  908. * @param {KMap.LngLat} lnglat 经纬度坐标,格式为KMap.LngLat对象,必填
  909. * @returns {KMap.Pixel} 地图像素坐标,格式为KMap.Pixel对象
  910. * @memberof Map
  911. */
  912. lnglatToPixel(lnglat) {
  913. lnglat = Common.KMapLngLat2MapLngLat(lnglat)
  914. let pixel = proj.fromLonLat(lnglat)
  915. return Common.MapPixel2KMapPixel(pixel)
  916. }
  917. /**
  918. * @description 地图容器屏幕坐标转经纬度坐标
  919. * @param {KMap.Pixel} pixel 地图容器像素,格式为KMap.Pixel对象,必填
  920. * @returns {KMap.LngLat} 返回KMap.LngLat格式的经纬度
  921. * @memberof Map
  922. */
  923. containerToLngLat(pixel) {
  924. pixel = Common.KMapPixel2MapPixel(pixel)
  925. let lnglat =this.map.getCoordinateFromPixel(pixel)
  926. lnglat = proj.toLonLat(lnglat)
  927. lnglat = Common.MapLngLat2KMapLngLat(lnglat)
  928. return lnglat
  929. }
  930. /**
  931. * @description 经纬度坐标转地图容器屏幕坐标
  932. * @param {KMap.LngLat} lnglat 经纬度坐标,KMap.LngLat格式的经纬度,必填
  933. * @returns {KMap.Pixel} 返回地图容器像素,格式为KMap.Pixel对象
  934. * @memberof Map
  935. */
  936. lngLatToContainer(lnglat) {
  937. lnglat = Common.KMapLngLat2MapLngLat(lnglat)
  938. let coordinate = proj.fromLonLat(lnglat)
  939. let container =this.map.getPixelFromCoordinate(coordinate)
  940. return Common.MapPixel2KMapPixel(container)
  941. }
  942. /**
  943. * @description 获取地图顺时针旋转角度
  944. * @returns {number} 顺时针旋转角度(弧度)
  945. * @memberof Map
  946. */
  947. getRotation() {
  948. let rotation = this.view.getRotation()
  949. return rotation
  950. }
  951. /**
  952. * @description 设置地图顺时针旋转角度
  953. * @param {number} rotation 顺时针旋转角度(弧度),必填
  954. * @memberof Map
  955. */
  956. setRotation(rotation) {
  957. this.view.setRotation(rotation)
  958. }
  959. /**
  960. * @description 获取地图插件集合
  961. * @returns {Array} 地图插件集合数组
  962. * @memberof Map
  963. */
  964. getControls() {
  965. let controls =this.map.getControls().array_
  966. return controls
  967. }
  968. /**
  969. * @description 添加插件
  970. * @param {ol.control} control OL原生control对象
  971. * @memberof Map
  972. */
  973. addControl(control) {
  974. let state = true
  975. let controls = this.map.getControls().array_
  976. for(let i=0; i<controls.length; i++) {
  977. if(control == controls[i]) {
  978. state = false
  979. break
  980. }
  981. }
  982. if(state){
  983. this.map.addControl(control)
  984. }
  985. }
  986. /**
  987. * @description 删除插件
  988. * @param {ol.control} control 插件,必填
  989. * @memberof Map
  990. */
  991. removeControl(control) {
  992. let controls = this.map.getControls().array_
  993. for(let i=0; i<controls.length; i++) {
  994. if(control == controls[i]) {
  995. this.map.removeControl(controls[i])
  996. return
  997. }
  998. }
  999. }
  1000. /**
  1001. * @description 清空默认插件 注意如果要清除默认插件需要在加载其他插件前调用此函数
  1002. * @memberof Map
  1003. */
  1004. removeOriginControls() {
  1005. let controls = this.map.getControls().array_
  1006. for(let i=0; i<controls.length; i++) {
  1007. this.map.removeControl(controls[i])
  1008. }
  1009. }
  1010. /**
  1011. * @description 获取地图指针样式
  1012. * @memberof Map
  1013. */
  1014. getDefaultCursor() {
  1015. let mapContainer = this.map.getTargetElement()
  1016. let cursor = mapContainer.style.cursor
  1017. return cursor
  1018. }
  1019. /**
  1020. * @description 设置地图指针样式
  1021. * @param {String} cursorStyle 鼠标样式("default"默认指针,"pointer"小手,"move"移动指针, "text"文本指针,"wait"等待状态,"help"帮助,"crosshair"十字指针),必填
  1022. * @memberof Map
  1023. */
  1024. setDefaultCursor(cursorStyle) {
  1025. this.defaultCursor = cursorStyle
  1026. let mapContainer = this.map.getTargetElement()
  1027. if(cursorStyle != undefined) {
  1028. mapContainer.style.cursor = cursorStyle
  1029. }
  1030. else {
  1031. mapContainer.style.cursor = "default"
  1032. }
  1033. }
  1034. /**
  1035. * @description 设置鼠标悬停在元素上时的样式
  1036. * @param {String} cursorStyle 鼠标样式("default"默认指针,"pointer"小手,"move"移动指针, "text"文本指针,"wait"等待状态,"help"帮助),必填
  1037. * @memberof Map
  1038. */
  1039. setFeatureCursor(cursorStyle) {
  1040. cursorStyle = (cursorStyle == undefined)? "default" : cursorStyle
  1041. let mapContainer = this.map.getTargetElement()
  1042. this.map.on("pointermove",function(e){
  1043. let features = this.map.forEachFeatureAtPixel(e.pixel,function(feature) { return feature })
  1044. if(features) {
  1045. mapContainer.style.cursor = cursorStyle
  1046. }
  1047. else {
  1048. mapContainer.style.cursor = this.defaultCursor
  1049. }
  1050. })
  1051. }
  1052. /**
  1053. * @description 获取地图显示元素种类
  1054. * @returns {Array} 地图显示元素种类集合
  1055. * @memberof Map
  1056. */
  1057. getFeatures() {
  1058. const vm = this
  1059. let features = new Array()
  1060. if(vm.baseLayer.getVisible() == true) {
  1061. features.push("Tile")
  1062. }
  1063. if(vm.markerLayer.getVisible() == true){
  1064. features.push("Marker")
  1065. }
  1066. if(vm.labelLayer.getVisible() == true){
  1067. features.push("Label")
  1068. }
  1069. if(vm.polyLineLayer.getVisible() == true){
  1070. features.push("PolyLine")
  1071. }
  1072. return features
  1073. }
  1074. /**
  1075. * @description 设置地图显示元素种类
  1076. * @param {JSON} param param 地图元素显示参数,JSON对象,必填
  1077. * param.marker true/false,点标记是否显示,选填
  1078. * param.label true/false,文本标记是否显示,选填
  1079. * param.polyline true/false,线标记是否显示,选填
  1080. * @memberof Map
  1081. */
  1082. setFeatures(param) {
  1083. const vm = this
  1084. if(param.marker == true || param.marker == false){
  1085. vm.markerLayer.setVisible(param.marker)
  1086. }
  1087. if(param.label == true || param.label == false){
  1088. vm.labelLayer.setVisible(param.label)
  1089. }
  1090. if(param.polyline == true || param.polyline == false){
  1091. vm.polyLineLayer.setVisible(param.polyline)
  1092. }
  1093. }
  1094. /**
  1095. * @description 获取地图状态(双击缩放/拖拽/滚动鼠标中间缩放)
  1096. * @returns {JSON} 地图状态
  1097. * {"DoubleClickZoom": true, "DragAndDrop": true, "MouseWheelZoom": true}
  1098. * @memberof Map
  1099. */
  1100. getStates() {
  1101. let interactions =this.map.getInteractions().array_
  1102. let DoubleClickZoom,DragAndDrop,MouseWheelZoom
  1103. for(let i=0; i<interactions.length; i++) {
  1104. if(i==1) DoubleClickZoom = interactions[i].getActive()
  1105. if(i==2) DragAndDrop = interactions[i].getActive()
  1106. if(i==7) MouseWheelZoom = interactions[i].getActive()
  1107. }
  1108. let states = {
  1109. "DoubleClickZoom": DoubleClickZoom,
  1110. "DragAndDrop": DragAndDrop,
  1111. "MouseWheelZoom": MouseWheelZoom
  1112. }
  1113. return states
  1114. }
  1115. /**
  1116. * @description 设置地图状态(双击缩放/拖拽/滚动鼠标中间缩放)
  1117. * @param {JSON} param 地图状态 JSON对象,必填
  1118. * param.DoubleClickZoom true/false(双击缩放地图),选填
  1119. * param.DragAndDrop true/false(地图拖拽),选填
  1120. * param.MouseWheelZoom true/false(滚动鼠标中间缩放地图),选填
  1121. * @memberof Map
  1122. */
  1123. setStates(param) {
  1124. let interactions =this.map.getInteractions().array_
  1125. if(param.DoubleClickZoom == true || param.DoubleClickZoom == false)
  1126. interactions[1].setActive(param.DoubleClickZoom)
  1127. if(param.DragAndDrop == true || param.DragAndDrop == false)
  1128. interactions[2].setActive(param.DragAndDrop)
  1129. if(param.MouseWheelZoom == true || param.MouseWheelZoom == false)
  1130. interactions[7].setActive(param.MouseWheelZoom)
  1131. }
  1132. /**
  1133. * @description 清空地图所有元素
  1134. * @memberof Map
  1135. */
  1136. clearMap() {
  1137. const vm = this
  1138. //清空图层元素
  1139. vm.markerLayer.getSource().clear()
  1140. vm.labelLayer.getSource().clear()
  1141. vm.polyLineLayer.getSource().clear()
  1142. vm.polygonLayer.getSource().clear()
  1143. //清空地图弹窗
  1144. vm.clearInfoWindow()
  1145. }
  1146. /**
  1147. * @description 清除地图对象并清空地图容器(建议少使用此API,容易造成报错)
  1148. * @memberof Map
  1149. */
  1150. destroy() {
  1151. //清空地图对象
  1152. // this.map.destroy()
  1153. //清空地图容器
  1154. let target =this.map.getTargetElement()
  1155. target.innerHTML = ""
  1156. Common.UseBaiDuOnlineLayer = false;
  1157. Common.UseGaoDeOnlineLayer = false;
  1158. Common.UseWGS84OnlineLayer = false;
  1159. }
  1160. /**
  1161. * @description 获取地图图层数组
  1162. * @return {Array} 地图图层数组
  1163. * @memberof Map
  1164. */
  1165. getLayers() {
  1166. let layers =this.map.getLayers().array_
  1167. return layers
  1168. }
  1169. /**
  1170. * @description 设置地图各个图层显示/隐藏
  1171. * @param {JSON} param 地图图层显示参数,JSON对象,必填
  1172. * param.Marker true/false,点标记图层显示/隐藏,选填
  1173. * param.Label true/false,文本标记图层显示/隐藏,选填
  1174. * param.PolyLine true/false,线标记图层显示/隐藏,选填
  1175. * @memberof Map
  1176. */
  1177. setLayers(param) {
  1178. const vm = this
  1179. if(param.Marker == true || param.Marker == false){
  1180. vm.markerLayer.setVisible(param.Marker)
  1181. }
  1182. if(param.Label == true || param.Label == false){
  1183. vm.labelLayer.setVisible(param.Label)
  1184. }
  1185. if(param.PolyLine == true || param.PolyLine == false){
  1186. vm.polyLineLayer.setVisible(param.PolyLine)
  1187. }
  1188. }
  1189. /**
  1190. * @description 获取地图各个图层index值
  1191. * @returns {JSON} JSON对象
  1192. * {"markerLayer": 0, "labelLayer": 0, "polyLineLayer": 0}
  1193. * @memberof Map
  1194. */
  1195. getLayersIndex() {
  1196. const vm = this
  1197. let index = {}
  1198. index.markerLayer = vm.markerLayer.getZIndex()
  1199. index.labelLayer = vm.labelLayer.getZIndex()
  1200. index.polyLineLayer = vm.polyLineLayer.getZIndex()
  1201. return index
  1202. }
  1203. /**
  1204. * @description 设置地图各个图层index值,index值大的图层显示在上方,值相同时后加载的图层显示在上方
  1205. * @param {JSON} param 图层索引JSON对象,必填
  1206. * param.marker 点标记图层index值,选填
  1207. * param.label 文字标记图层index值,选填
  1208. * param.polyLine 线标记图层index值,选填
  1209. * @memberof Map
  1210. */
  1211. setLayersIndex(param) {
  1212. const vm = this
  1213. let markerIndex = (param.marker)? param.marker : vm.markerLayer.getZIndex()
  1214. let labelIndex = (param.label)? param.label : vm.labelLayer.getZIndex()
  1215. let polyLineIndex = (param.polyLine)? param.polyLine : vm.polyLineLayer.getZIndex()
  1216. vm.markerLayer.setZIndex(markerIndex)
  1217. vm.labelLayer.setZIndex(labelIndex)
  1218. vm.polyLineLayer.setZIndex(polyLineIndex)
  1219. }
  1220. /**
  1221. * @description 注册地图事件
  1222. * @param {String} eventName 地图操作事件类型,必填
  1223. * "click":单击地图,双击将触发两次;"singleclick":单击地图;"dblclick":双击地图;"movestart":开始移动地图;
  1224. * "moveend":移动地图结束;"postrender":渲染地图后;"pointerdrag":拖动指针时;"mousemove":移动指针时
  1225. * @param {funciton} callback 操作事件触发时调用的函数,必填
  1226. * @memberof Map
  1227. */
  1228. on(eventName,callback) {
  1229. if(eventName == "mousemove"){
  1230. eventName = "pointermove"
  1231. }
  1232. if(eventName == "load"){
  1233. eventName = "postrender"
  1234. }
  1235. this.map.on(eventName,callback)
  1236. }
  1237. /**
  1238. * @description 注册地图事件(事件仅执行一次)
  1239. * @param {Strig} eventName 地图操作事件类型,必填
  1240. * "click":单击地图,双击将触发两次;"singleclick":单击地图;"dblclick":双击地图;"movestart":开始移动地图;
  1241. * "moveend":移动地图结束;"postrender":渲染地图后;"pointerdrag":拖动指针时;"mousemove":移动指针时
  1242. * @param {function} callback 操作事件触发时调用的函数,必填
  1243. * @memberof Map
  1244. */
  1245. once(eventName,callback) {
  1246. if(eventName == "mousemove"){
  1247. eventName = "pointermove"
  1248. }
  1249. if(eventName == "load"){
  1250. eventName = "postrender"
  1251. }
  1252. this.map.once(eventName,callback)
  1253. }
  1254. /**
  1255. * @description 取消地图绑定事件
  1256. * @param {Strig} eventName 地图操作事件类型,必填
  1257. * "click":单击地图,双击将触发两次;"singleclick":单击地图;"dblclick":双击地图;"movestart":开始移动地图;
  1258. * "moveend":移动地图结束;"postrender":渲染地图后;"pointerdrag":拖动指针时;"mousemove":移动指针时
  1259. * @param {function} callback 操作事件触发时调用的函数,必填
  1260. * @memberof Map
  1261. */
  1262. off(eventName,callback) {
  1263. if(eventName == "mousemove"){
  1264. eventName = "pointermove"
  1265. }
  1266. if(eventName == "load"){
  1267. eventName = "postrender"
  1268. }
  1269. this.map.un(eventName,callback)
  1270. }
  1271. setMarkerLayerZoomInfo(minZoom,maxZoom){
  1272. this.markerLayer.setMaxZoom(maxZoom);
  1273. this.markerLayer.setMinZoom(minZoom);
  1274. }
  1275. setPolylineLayerZoomInfo(minZoom,maxZoom){
  1276. this.polylineLayer.setMaxZoom(maxZoom);
  1277. this.polylineLayer.setMinZoom(minZoom);
  1278. }
  1279. setPolygonLayerZoomInfo(minZoom,maxZoom){
  1280. this.polygonLayer.setMaxZoom(maxZoom);
  1281. this.polygonLayer.setMinZoom(minZoom);
  1282. }
  1283. }
  1284. export default Map