Map.js 36 KB

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