analysisMap.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import config from "@/api/config.js";
  2. import * as KMap from "@/utils/ol-map/KMap";
  3. import * as util from "@/common/ol_common.js";
  4. import {
  5. newAreaFeature,
  6. newAreaPoint,
  7. newPoint,
  8. newPolymerFeature,
  9. } from "../../zhgl/map";
  10. import { base_img_url2 } from "../../../api/config";
  11. import Stroke from "ol/style/Stroke";
  12. import Style from "ol/style/Style";
  13. import Photo from "ol-ext/style/Photo";
  14. /**
  15. * @description 农事分析详情地图
  16. */
  17. class analysisMap {
  18. getRadius(zoom) {
  19. if (zoom >= 20) {
  20. return 70;
  21. }
  22. if (zoom >= 19) {
  23. return 30;
  24. }
  25. if (zoom >= 18) {
  26. return 15;
  27. }
  28. if (zoom >= 17) {
  29. return 10;
  30. }
  31. return 5;
  32. }
  33. constructor() {
  34. let that = this;
  35. let vectorStyle = new KMap.VectorStyle();
  36. this.areaLayer = new KMap.VectorLayer("areaLayer", 999, {
  37. style: (f) =>
  38. vectorStyle.getPolygonStyle(f.get("color") + "10", f.get("color"), 3),
  39. });
  40. this.subAreaLayer = new KMap.VectorLayer("subAreaLayer", 999, {
  41. style: (f) => vectorStyle.getPolygonStyle("#fba50410", "#fba504", 1),
  42. });
  43. this.areaPointLayer = new KMap.VectorLayer("areaPointLayer", 1000, {
  44. style: (f) =>
  45. vectorStyle.getPointTextStyle(
  46. f.get("name"),
  47. "#120046",
  48. "#FFFFFF",
  49. 2,
  50. 30
  51. ),
  52. });
  53. this.treeLayer = new KMap.VectorLayer("treeLayer", 999);
  54. this.imgStyleCache = {};
  55. this.imgTreeLayer = new KMap.VectorLayer("imgTreeLayer", 999, {
  56. minZoom: 15,
  57. maxZoom: 22,
  58. style: (feature) => {
  59. let zoom = that.kmap.view.getZoom();
  60. let r = that.getRadius(zoom);
  61. let img = feature.get("img");
  62. let k = img + r;
  63. if (img && img != "") {
  64. let style = that.imgStyleCache[k];
  65. if (!style) {
  66. style = new Style({
  67. image: new Photo({
  68. src: base_img_url2 + img,
  69. radius: r,
  70. shadow: 0,
  71. crop: true,
  72. kind: "circle",
  73. onload: function () {
  74. that.imgTreeLayer.layer.changed();
  75. },
  76. displacement: [0, 30 + 15],
  77. stroke: new Stroke({
  78. width: 3,
  79. color: "#fdfcfc",
  80. }),
  81. }),
  82. });
  83. that.imgStyleCache[k] = style;
  84. }
  85. return style;
  86. } else {
  87. return vectorStyle.getPointSimpleStyle(
  88. 10,
  89. "#00000000",
  90. "#00000000",
  91. 1
  92. );
  93. }
  94. },
  95. });
  96. this.imgTreeLayer.layer.setVisible(false);
  97. this.subAreaLayer.layer.setVisible(true);
  98. }
  99. initMap(location, target) {
  100. let level = 18;
  101. let coordinate = util.wktCastGeom(location).getFirstCoordinate();
  102. this.kmap = new KMap.Map(
  103. target,
  104. level,
  105. coordinate[0],
  106. coordinate[1],
  107. null,
  108. 10,
  109. 22
  110. );
  111. let xyz = config.base_img_url + "map/lby/{z}/{x}/{y}.png";
  112. this.kmap.addXYZLayer(xyz, { minZoom: 15, maxZoom: 22 });
  113. let xyz2 = config.base_img_url3 + "map/lby/{z}/{x}/{y}.png";
  114. this.kmap.addXYZLayer(xyz2, { minZoom: 12, maxZoom: 22 });
  115. this.kmap.addLayer(this.areaLayer.layer);
  116. this.kmap.addLayer(this.subAreaLayer.layer);
  117. this.kmap.addLayer(this.treeLayer.layer);
  118. this.kmap.addLayer(this.areaPointLayer.layer);
  119. this.kmap.addLayer(this.imgTreeLayer.layer);
  120. }
  121. initArea(organId) {
  122. let that = this;
  123. this.areaLayer.refresh();
  124. VE_API.area.list({ organId }).then(({ data, code }) => {
  125. for (let item of data) {
  126. that.areaLayer.addFeature(newAreaFeature(item));
  127. that.areaPointLayer.addFeature(newAreaPoint(item));
  128. }
  129. });
  130. }
  131. initSubArea(organId) {
  132. let that = this;
  133. this.subAreaLayer.refresh();
  134. VE_API.sub_area.list({ organId }).then(({ data, code }) => {
  135. for (let item of data) {
  136. that.subAreaLayer.addFeature(newPolymerFeature(item));
  137. }
  138. });
  139. }
  140. initTree(organId) {
  141. let that = this;
  142. this.treeLayer.refresh();
  143. this.imgTreeLayer.refresh();
  144. VE_API.tree
  145. .treeListAndGrowData({ organId, areaId: -1 })
  146. .then(({ data, code }) => {
  147. for (let item of data) {
  148. let point = newPoint(item);
  149. that.treeLayer.addFeature(point);
  150. that.imgTreeLayer.addFeature(point);
  151. }
  152. });
  153. }
  154. addSingleSelect(listener) {
  155. this.treeLayer.addSingleSelect(function (e) {
  156. if (e.selected.length > 0) {
  157. listener(e.selected[0]);
  158. }
  159. }, this.kmap.map);
  160. }
  161. setTreeStyle(style) {
  162. this.treeLayer.layer.setStyle(style);
  163. this.treeLayer.layer.changed();
  164. }
  165. fit(geomOrExtent) {
  166. this.kmap.fit(geomOrExtent);
  167. }
  168. openCloseImg() {
  169. this.imgTreeLayer.layer.setVisible(!this.imgTreeLayer.layer.getVisible());
  170. }
  171. openClosePolymer() {
  172. this.subAreaLayer.layer.setVisible(!this.subAreaLayer.layer.getVisible());
  173. }
  174. }
  175. export default analysisMap;