Map.js 36 KB

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