Map.js 36 KB

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