AllotNsMap.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import Layer from 'ol/layer/Vector'
  2. import Source from 'ol/source/Vector'
  3. import Select from 'ol/interaction/Select.js';
  4. import {singleClick} from 'ol/events/condition'
  5. import * as olEvents from 'ol/events';
  6. import config from "@/api/config.js"
  7. import * as KMap from '@/utils/ol-map/KMap';
  8. import Style from "ol/style/Style";
  9. import Photo from "ol-ext/style/Photo";
  10. import {base_img_url2} from "../../api/config";
  11. import Stroke from "ol/style/Stroke";
  12. import * as util from "@/common/ol_common.js"
  13. import {newAreaFeature, newAreaPoint, newPolymerFeature, newPoint} from "../zhgl/map";
  14. /**
  15. * @description 智能巡园地图层对象
  16. */
  17. class AllotNsMap {
  18. constructor(){
  19. let that = this
  20. this.vectorStyle = new KMap.VectorStyle()
  21. let pointSimpleStyle = this.vectorStyle.getPointSimpleStyle(8,"#999999","#d5d5d0","1")
  22. this.areaLayer = new KMap.VectorLayer("areaLayer",999,{style:(f)=> that.vectorStyle.getPolygonStyle("#ffffff10", "#ffffff",3)})
  23. this.areaPointLayer = new KMap.VectorLayer("areaPointLayer",1002,{style:(f)=> that.vectorStyle.getPointTextStyle(f.get("name"), "#120046","#FFFFFF",2, 30)})
  24. this.treeLayer = new KMap.VectorLayer("treeLayer",1001,{style:pointSimpleStyle})
  25. this.treeFeatures = []
  26. }
  27. initMap(location, target) {
  28. let level = 18
  29. let coordinate = util.wktCastGeom(location).getFirstCoordinate()
  30. this.kmap = new KMap.Map(target,level,coordinate[0], coordinate[1],null,10,22);
  31. let xyz = config.base_img_url + 'map/lby/{z}/{x}/{y}.png';
  32. this.kmap.addXYZLayer(xyz,{minZoom:15,maxZoom:22});
  33. let xyz2 = config.base_img_url3 + 'map/lby/{z}/{x}/{y}.png';
  34. this.kmap.addXYZLayer(xyz2,{minZoom:12,maxZoom:22});
  35. this.kmap.addLayer(this.areaLayer.layer)
  36. this.kmap.addLayer(this.treeLayer.layer)
  37. this.kmap.addLayer(this.areaPointLayer.layer)
  38. }
  39. initArea(organId, callback){
  40. let that = this
  41. this.areaLayer.refresh()
  42. VE_API.area.list({organId}).then(({data,code})=>{
  43. for(let item of data){
  44. that.areaLayer.addFeature(newAreaFeature(item))
  45. that.areaPointLayer.addFeature(newAreaPoint(item))
  46. }
  47. callback && callback()
  48. })
  49. }
  50. initTree(organId, callback){
  51. let that = this
  52. this.treeLayer.refresh()
  53. that.treeFeatures = []
  54. VE_API.tree.treeList({organId,areaId:-1}).then(({data,code})=>{
  55. for(let item of data){
  56. let point = newPoint(item);
  57. that.treeFeatures.push(point)
  58. that.treeLayer.addFeature(point)
  59. }
  60. callback && callback()
  61. })
  62. }
  63. addToggleTreeSelect(listener){
  64. let that = this
  65. let selectStyle = this.vectorStyle.getPointSimpleStyle(8,"#cc3f2e","#e18b7c","2")
  66. this.treeLayer.addToggleSelect(function({deselected,selected, preventDefault}){
  67. if(selected.length > 0){
  68. listener && listener(selected[0],deselected[0])
  69. }
  70. preventDefault()
  71. },this.kmap.map, selectStyle)
  72. that.treeLayer.toggleSelect.setActive(false)
  73. }
  74. addToggleAreaSelect(listener){
  75. let that = this
  76. this.areaLayer.addToggleSelect(function({deselected,selected,preventDefault}){
  77. if(selected.length > 0){
  78. that.treeLayer.source.forEachFeature((f)=>{
  79. if(f.get("areaId") == selected[0].get("id")){
  80. that.treeLayer.toggleSelect.getFeatures().remove(f)
  81. }
  82. })
  83. that.treeLayer.source.forEachFeature((f)=>{
  84. if(f.get("areaId") == selected[0].get("id")){
  85. that.treeLayer.toggleSelect.getFeatures().push(f)
  86. }
  87. })
  88. }
  89. if(deselected.length > 0){
  90. that.treeLayer.source.forEachFeature((f)=>{
  91. if(f.get("areaId") == deselected[0].get("id")){
  92. that.treeLayer.toggleSelect.getFeatures().remove(f)
  93. }
  94. })
  95. }
  96. listener && listener(selected[0],deselected[0])
  97. preventDefault()
  98. },this.kmap.map)
  99. that.areaLayer.toggleSelect.setActive(false)
  100. }
  101. setTreeStyle(style){
  102. this.treeLayer.layer.setStyle(style)
  103. this.treeLayer.layer.changed()
  104. }
  105. fit(geomOrExtent){
  106. this.kmap.fit(geomOrExtent)
  107. }
  108. }
  109. export default AllotNsMap