移动端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

382 行
14 KiB

  1. <template>
  2. <div>
  3. <p class="fuTitle">地块位置绘制</p>
  4. <div id="full-screen-acceptance" style="width: 100%;height:45vh;">
  5. <div :id=this.uuidMap style="width: 100%;height: 100%"></div>
  6. <div id='land-btn-wrap'>
  7. <el-row>
  8. <!--<el-button :id=this.drawingPolygonMap style="background-color:#D0EEFF;color:#1E88C7" @click="" type="primary">画图</el-button>-->
  9. <!--<input id="drawRemove" type="button" class="ant-btn ant-btn-red" value="取消"/>&nbsp;&nbsp;-->
  10. <!--<el-button :id=this.drawingPolygonMap style="background-color:#D0EEFF;color:#1E88C7" type="primary">重置图层</el-button>-->
  11. <input :id="this.drawingPolygonMap" class="ant-btn ant-btn-red" type="button" value="画图"/>&nbsp;&nbsp;
  12. <input :id="this.drawingResetMap" type="button" class="ant-btn ant-btn-red" value="重置图层"/>
  13. </el-row>
  14. </div>
  15. </div>
  16. <div id="info" style="display: none"></div>
  17. </div>
  18. </template>
  19. <script>
  20. import {getQueryLand} from "@/api/homesteadSurvey/zjdzd";
  21. import $ from "jquery";
  22. export default {
  23. components: {
  24. getQueryLand,
  25. },
  26. data() {
  27. return {
  28. closeMoule: null,
  29. uuidMap: this.guidProduct(),
  30. drawingPolygonMap: this.guidProduct(),
  31. drawingResetMap: this.guidProduct(),
  32. };
  33. },
  34. props: ['theGeom','message'],
  35. // created() {
  36. // // setTimeout(() => {
  37. // // this.drawingPaceCountryLine();
  38. // // }, 100);
  39. // },
  40. methods: {
  41. //地图加载
  42. formSubmit(){
  43. //父组件监听的名字必须是formSubmit
  44. // 子组件调用父组件的方法并传参
  45. if(this.closeMoule =="" || this.closeMoule == null){
  46. this.$emit('formSubmit', null);
  47. }else{
  48. this.$emit('formSubmit', JSON.stringify(this.closeMoule));
  49. }
  50. },
  51. guidProduct(){
  52. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  53. var r = Math.random() * 16 | 0,
  54. v = c == 'x' ? r : (r & 0x3 | 0x8);
  55. return v.toString(16);
  56. });
  57. },
  58. //地图查看
  59. drawingPaceCountryLine() {
  60. //加载地图编辑
  61. var that = this;
  62. var map;
  63. //var hc_land;
  64. var draw; // global so we can remove it later
  65. var vector_drawing;
  66. if (that.message != null && that.message != ""
  67. && that.message != undefined) {
  68. document.getElementById(that.uuidMap).innerHTML = '';
  69. var hc_land;
  70. var hc_landFuther;
  71. var draw; // global so we can remove it later
  72. var vector_drawing;
  73. var projection = new ol.proj.Projection({
  74. //地图投影类型
  75. code: "EPSG:3857",
  76. units: "degrees",
  77. //extent:extent
  78. });
  79. var aerial = new ol.layer.Tile({
  80. source: new ol.source.XYZ({
  81. url: "http://t0.tianditu.gov.cn/img_w/wmts?" +
  82. "SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles" +
  83. "&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=cc4aba6e967096098249efa069733067",
  84. }),
  85. isGroup: true,
  86. name: "卫星影像图",
  87. });
  88. var yingxzi = new ol.layer.Tile({
  89. source: new ol.source.XYZ({
  90. url: "https://t0.tianditu.gov.cn/DataServer?T=cia_w&x={x}&y={y}&l={z}&tk=cc4aba6e967096098249efa069733067",
  91. }),
  92. isGroup: true,
  93. name: "天地图文字标注--卫星影像图",
  94. });
  95. //加载地图
  96. map = new ol.Map({
  97. controls: ol.control.defaults({attribution: false, zoom: false, rotate: false}).extend([]), //隐藏放大缩小按钮
  98. layers: [aerial, yingxzi],
  99. projection: projection,
  100. target: that.uuidMap,
  101. view: new ol.View({
  102. //center: ol.proj.fromLonLat([115.452752, 31.789033]),
  103. zoom: 15,
  104. minZoom: 5, //地图缩小限制
  105. maxZoom: 18.3, //地图放大限制
  106. }),
  107. });
  108. //图层查询定位开始 ---------start
  109. if(this.message.substring(0,1) =="{"){
  110. // var theGeomMap =this.message.replace("Point", "MultiPolygon");
  111. // var pointLeft = theGeomMap.replace("[", "[[[[");
  112. // var pointRight = pointLeft.replace("]", "]]]]");
  113. hc_land = new ol.layer.Vector({
  114. title: "add Layer",
  115. source: new ol.source.Vector({
  116. projection: projection,
  117. features: new ol.format.GeoJSON().readFeatures("{\n" +
  118. " \"type\": \"Feature\",\n" +
  119. " \"geometry\":" + this.message + "}"),
  120. }),
  121. style: new ol.style.Style({
  122. fill: new ol.style.Fill({
  123. //矢量图层填充颜色,以及透明度
  124. color: "rgba(204, 255, 204,0.3)",
  125. }),
  126. stroke: new ol.style.Stroke({
  127. //边界样式
  128. color: "#47c68f",
  129. width: 3,
  130. }),
  131. }),
  132. });
  133. map.addLayer(hc_land);
  134. var maxXMap = hc_land.values_.source.featuresRtree_.rbush_.data.maxX;
  135. var maxYMap = hc_land.values_.source.featuresRtree_.rbush_.data.maxY;
  136. var minXMap = hc_land.values_.source.featuresRtree_.rbush_.data.minX;
  137. var minYMap = hc_land.values_.source.featuresRtree_.rbush_.data.minY;
  138. //定位查询位置
  139. var center = ol.extent.getCenter([maxXMap, maxYMap, minXMap, minYMap]); //获取边界区域的中心位置
  140. map.getView().animate({
  141. // 只设置需要的属性即可
  142. center: center, // 中心点
  143. zoom: 17.9, // 缩放级别
  144. rotation: undefined, // 缩放完成view视图旋转弧度
  145. duration: 1000, // 缩放持续时间,默认不需要设置
  146. });
  147. }
  148. // if(this.message.substring(0,1) =="["){
  149. // var zbNew = JSON.stringify({"type": "MultiPolygon", "coordinates": [[[this.message.replaceAll("\"","")]]]});
  150. // var leftJoin = zbNew.replace("\"[","[");
  151. // var rightJoin = leftJoin.replace("\"]","]");
  152. // hc_landFuther = new ol.layer.Vector({
  153. // title: "add Layer",
  154. // source: new ol.source.Vector({
  155. // projection: projection,
  156. // features: new ol.format.GeoJSON().readFeatures("{\n" +
  157. // " \"type\": \"Feature\",\n" +
  158. // " \"geometry\":" + rightJoin + "}"),
  159. // }),
  160. // style: new ol.style.Style({
  161. // fill: new ol.style.Fill({
  162. // //矢量图层填充颜色,以及透明度
  163. // color: "rgba(204, 255, 204,0.3)",
  164. // }),
  165. // stroke: new ol.style.Stroke({
  166. // //边界样式
  167. // color: "#47c68f",
  168. // width: 3,
  169. // }),
  170. // }),
  171. // });
  172. // map.addLayer(hc_landFuther);
  173. // var maxXMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.maxX;
  174. // var maxYMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.maxY;
  175. // var minXMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.minX;
  176. // var minYMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.minY;
  177. // //定位查询位置
  178. // var center = ol.extent.getCenter([maxXMap, maxYMap, minXMap, minYMap]); //获取边界区域的中心位置
  179. // map.getView().animate({
  180. // // 只设置需要的属性即可
  181. // center: center, // 中心点
  182. // zoom: 17.9, // 缩放级别
  183. // rotation: undefined, // 缩放完成view视图旋转弧度
  184. // duration: 1000, // 缩放持续时间,默认不需要设置
  185. // });
  186. // }
  187. //图层查询定位结束 ---------end
  188. //开始绘制地图
  189. $("#"+this.drawingPolygonMap).click(function () {
  190. map.removeLayer(hc_land);
  191. //map.removeLayer(hc_landFuther);
  192. map.removeLayer(vector_drawing);
  193. //that.closeMoule = null;
  194. map.removeInteraction(draw);
  195. //var source = new ol.source.Vector({wrapX: false});
  196. vector_drawing = new ol.layer.Vector({
  197. source: new ol.source.Vector(),
  198. });
  199. map.addLayer(vector_drawing);
  200. function addInteraction() {
  201. draw = new ol.interaction.Draw({
  202. source: vector_drawing.getSource(),
  203. type: "Polygon"
  204. });
  205. draw.on('drawend', function (evt) {
  206. var feature = evt.feature;
  207. var geometry = feature.getGeometry();
  208. var coordinate = geometry.getCoordinates();
  209. that.closeMoule = coordinate;
  210. that.formSubmit();
  211. });
  212. map.addInteraction(draw);
  213. }
  214. addInteraction();
  215. });
  216. //清除画图鼠标点击事件
  217. // $("#drawRemove").click(function () {
  218. // //map.addLayer(hc_land);
  219. // map.removeInteraction(draw);
  220. // //map.removeLayer(vector_drawing);
  221. // });
  222. //还原之前图层
  223. $("#"+this.drawingResetMap).click(function () {
  224. if(that.closeMoule !=null) {
  225. map.removeLayer(vector_drawing);
  226. //map.removeLayer(hc_landFuther);
  227. map.removeInteraction(draw);
  228. map.addLayer(hc_land);
  229. //map.addLayer(hc_landFuther);
  230. // that.closeMoule = null;
  231. that.formSubmit();
  232. }
  233. });
  234. } else{
  235. //this.closeMoule = null;
  236. document.getElementById(that.uuidMap).innerHTML = '';
  237. var projection = new ol.proj.Projection({
  238. //地图投影类型
  239. code: "EPSG:3857",
  240. units: "degrees",
  241. //extent:extent
  242. });
  243. var aerial = new ol.layer.Tile({
  244. source: new ol.source.XYZ({
  245. url: "http://t0.tianditu.gov.cn/img_w/wmts?" +
  246. "SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles" +
  247. "&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=cc4aba6e967096098249efa069733067",
  248. }),
  249. isGroup: true,
  250. name: "卫星影像图",
  251. });
  252. var yingxzi = new ol.layer.Tile({
  253. source: new ol.source.XYZ({
  254. url: "https://t0.tianditu.gov.cn/DataServer?T=cia_w&x={x}&y={y}&l={z}&tk=cc4aba6e967096098249efa069733067",
  255. }),
  256. isGroup: true,
  257. name: "天地图文字标注--卫星影像图",
  258. });
  259. //获取坐标是否存在
  260. var Zb;
  261. getQueryLand().then((response) => {
  262. if (response.code == 200) {
  263. let InsertCode = response.data;
  264. if (InsertCode != null) {
  265. var lat = InsertCode.lat;
  266. var lng = InsertCode.lng;
  267. if(lat !=null && lng !=null && lat !="" && lng !=""){
  268. Zb = [lng,lat];
  269. }else {
  270. Zb =[115.452752, 31.789033];
  271. }
  272. //加载地图
  273. map = new ol.Map({
  274. controls: ol.control.defaults({attribution: false, zoom: false, rotate: false}).extend([]), //隐藏放大缩小按钮
  275. layers: [aerial, yingxzi],
  276. projection: projection,
  277. logo: 'false',
  278. target: that.uuidMap,
  279. view: new ol.View({
  280. center: ol.proj.fromLonLat(Zb),
  281. //center: ol.proj.fromLonLat([115.452752, 31.789033]),
  282. zoom: 16.9,
  283. minZoom: 5, //地图缩小限制
  284. maxZoom: 18, //地图放大限制
  285. }),
  286. });
  287. }
  288. }
  289. });
  290. //图层查询定位结束 ---------end
  291. //开始绘制地图
  292. $("#"+this.drawingPolygonMap).click(function () {
  293. //that.closeMoule = null;
  294. map.removeInteraction(draw);
  295. //var source = new ol.source.Vector({wrapX: false});
  296. vector_drawing = new ol.layer.Vector({
  297. source: new ol.source.Vector(),
  298. });
  299. map.addLayer(vector_drawing);
  300. function addInteraction() {
  301. draw = new ol.interaction.Draw({
  302. source: vector_drawing.getSource(),
  303. type: "Polygon"
  304. });
  305. draw.on('drawend', function (evt) {
  306. var feature = evt.feature;
  307. var geometry = feature.getGeometry();
  308. var coordinate = geometry.getCoordinates();
  309. that.closeMoule = coordinate;
  310. that.formSubmit();
  311. });
  312. map.addInteraction(draw);
  313. }
  314. addInteraction();
  315. });
  316. //清除画图鼠标点击事件
  317. // $("#drawRemove").click(function () {
  318. // //map.addLayer(hc_land);
  319. // map.removeInteraction(draw);
  320. // //map.removeLayer(vector_drawing);
  321. // });
  322. //还原之前图层
  323. $("#"+this.drawingResetMap).click(function () {
  324. map.removeInteraction(draw);
  325. map.removeLayer(vector_drawing);
  326. //that.closeMoule = null;
  327. that.formSubmit();
  328. });
  329. }
  330. },
  331. },
  332. watch: {},
  333. };
  334. </script>
  335. <style scoped>
  336. #that.message {
  337. width: 100%;
  338. height: 100%;
  339. }
  340. .fuTitle {
  341. border-top: 1px solid #e9e9e9;
  342. text-align: center;
  343. padding: 10px 0px 0px 0px;
  344. font-size: 18px;
  345. color: #999;
  346. }
  347. .ant-btn-red {
  348. position: relative;
  349. display: inline-block;
  350. background: #D0EEFF;
  351. border: 1px solid #99D3F5;
  352. border-radius: 4px;
  353. padding: 4px 12px;
  354. overflow: hidden;
  355. color: #1E88C7;
  356. text-decoration: none;
  357. text-indent: 0;
  358. line-height: 20px;
  359. }
  360. #land-btn-wrap{
  361. position: relative;
  362. width: 25%;
  363. left: 75%;
  364. bottom: 100%;
  365. z-index: 2000;
  366. padding-top: 5%;
  367. }
  368. </style>