移动端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

637 linhas
22 KiB

  1. <template>
  2. <div>
  3. <!-- <p class="fuTitle">地块位置绘制</p>-->
  4. <div id="full-screen-acceptance" style="width: 100%;height:71vh;">
  5. <div :id=this.uuidMap style="width: 100%;height: 100%"></div>
  6. <div id='land-btn-wrap'>
  7. <!--<el-button :id=this.drawingPolygonMap style="background-color:#D0EEFF;color:#1E88C7" @click="" type="primary">画图</el-button>-->
  8. <!--<input id="drawRemove" type="button" class="ant-btn ant-btn-red" value="取消"/>&nbsp;&nbsp;-->
  9. <!--<el-button :id=this.drawingPolygonMap style="background-color:#D0EEFF;color:#1E88C7" type="primary">重置图层</el-button>-->
  10. <input :id="locationMap" type="button" class="ant-btn ant-btn-red" value="定位"/>&nbsp;&nbsp;
  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. </div>
  14. </div>
  15. <div style="font-size: 13px; padding-top: 5px;">备注:绿色地块表示该地块,蓝色表示本账套已标记的其他地块</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. import { getConfigKey } from "@/api/system/config";
  23. export default {
  24. components: {
  25. getQueryLand,
  26. },
  27. data() {
  28. return {
  29. closeMoule: null,
  30. uuidMap: this.guidProduct(),
  31. drawingPolygonMap: this.guidProduct(),
  32. drawingResetMap: this.guidProduct(),
  33. locationMap: this.guidProduct(),
  34. mapGeoServerUrl: "", // geoserver地址
  35. villageBorderLayerName: "", // 乡镇边界图层名称
  36. };
  37. },
  38. props: ['theGeom','message', 'resourceId', 'resourceList'],
  39. created() {
  40. // 获取geoserver的地址
  41. this.getGeoServerUrl();
  42. // 获取村边界的图层名称
  43. this.getVillageBorderLayerName();
  44. },
  45. methods: {
  46. // 获取geoserver的地址
  47. getGeoServerUrl() {
  48. getConfigKey("system.geoServer.url").then(response => {
  49. this.mapGeoServerUrl = response.msg;
  50. });
  51. },
  52. // 获取村边界的图层名称
  53. getVillageBorderLayerName() {
  54. getConfigKey("geoserver.layer.villageBorder").then(response => {
  55. this.villageBorderLayerName = response.msg;
  56. });
  57. },
  58. //地图加载
  59. formSubmit(){
  60. //父组件监听的名字必须是formSubmit
  61. // 子组件调用父组件的方法并传参
  62. if(this.closeMoule =="" || this.closeMoule == null){
  63. this.$emit('formSubmit', null);
  64. }else{
  65. this.$emit('formSubmit', JSON.stringify(this.closeMoule));
  66. }
  67. },
  68. guidProduct(){
  69. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  70. var r = Math.random() * 16 | 0,
  71. v = c == 'x' ? r : (r & 0x3 | 0x8);
  72. return v.toString(16);
  73. });
  74. },
  75. getCurrentLocation(callback) {
  76. // 1. 首先尝试Android宿主端
  77. if(window._Native_object) // Android层注入全局对象
  78. {
  79. console.log('使用Native获取定位');
  80. let coord = window._Native_object.GetLocation(null);
  81. console.log('Native坐标: ' + coord);
  82. if(coord)
  83. {
  84. let arr = coord.split(',');
  85. let res = {
  86. code: 200,
  87. data: {
  88. lng: arr[0],
  89. lat: arr[1],
  90. },
  91. };
  92. callback(res);
  93. return;
  94. }
  95. }
  96. // 2. 再尝试浏览器
  97. if (navigator.geolocation) {
  98. console.log('使用浏览器获取定位');
  99. navigator.geolocation.getCurrentPosition(
  100. (position) => {
  101. const { latitude, longitude } = position.coords;
  102. let res = {
  103. code: 200,
  104. data: {
  105. lng: longitude,
  106. lat: latitude,
  107. },
  108. };
  109. callback(res);
  110. },
  111. (error) => {
  112. console.log('定位失败: ' + error.message);
  113. getQueryLand().then(callback);
  114. },
  115. { enableHighAccuracy: true, timeout: 5000 }
  116. );
  117. return;
  118. }
  119. // 最后使用地区坐标
  120. console.log('使用地区坐标定位');
  121. getQueryLand().then(callback);
  122. },
  123. getDeptLocation(callback) {
  124. getQueryLand().then((response) => {
  125. if (response.code == 200) {
  126. let InsertCode = response.data;
  127. if (InsertCode != null) {
  128. var lat = InsertCode.lat;
  129. var lng = InsertCode.lng;
  130. if(lat !=null && lng !=null && lat !="" && lng !=""){
  131. callback(response);
  132. return;
  133. }
  134. }
  135. }
  136. this.getCurrentLocation(callback);
  137. });
  138. },
  139. //地图查看
  140. drawingPaceCountryLine() {
  141. //加载地图编辑
  142. var that = this;
  143. var map;
  144. //var hc_land;
  145. var draw; // global so we can remove it later
  146. var vector_drawing;
  147. var mark_layer = null;
  148. function addMark(lng, lat) {
  149. if(!mark_layer)
  150. {
  151. mark_layer = new ol.layer.Vector({
  152. source: new ol.source.Vector(),
  153. });
  154. map.addLayer(mark_layer);
  155. }
  156. else
  157. mark_layer.getSource().clear();
  158. let newFeature = new ol.Feature({
  159. geometry: new ol.geom.Point(ol.proj.fromLonLat([lng, lat])), //几何信息
  160. //name: "标注点",
  161. });
  162. newFeature.setStyle(new ol.style.Style({
  163. image: new ol.style.Icon({
  164. //设置图标偏移
  165. anchor: [0.5, 0.5],
  166. //标注样式的起点位置
  167. anchorOrigin: "top-right",
  168. //X方向单位:分数
  169. anchorXUnits: "fraction",
  170. //Y方向单位:像素
  171. anchorYUnits: "fraction",
  172. //偏移起点位置的方向
  173. offsetOrigin: "top-right",
  174. //透明度
  175. opacity: 0.9,
  176. //图片路径
  177. src: require('../../assets/images/location/mark.png'),
  178. }),
  179. zIndex: 9999,
  180. }));
  181. mark_layer.getSource().addFeature(newFeature);
  182. }
  183. if (that.message != null && that.message != ""
  184. && that.message != undefined) {
  185. document.getElementById(that.uuidMap).innerHTML = '';
  186. var hc_land;
  187. var hc_landFuther;
  188. var draw; // global so we can remove it later
  189. var vector_drawing;
  190. var projection = new ol.proj.Projection({
  191. //地图投影类型
  192. code: "EPSG:3857",
  193. units: "degrees",
  194. //extent:extent
  195. });
  196. var aerial = new ol.layer.Tile({
  197. source: new ol.source.XYZ({
  198. url: "http://t0.tianditu.gov.cn/img_w/wmts?" +
  199. "SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles" +
  200. "&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=c78ca1c13e82e1cdd64ef9d8cdbbb237",
  201. }),
  202. isGroup: true,
  203. name: "卫星影像图",
  204. });
  205. var yingxzi = new ol.layer.Tile({
  206. source: new ol.source.XYZ({
  207. url: "https://t0.tianditu.gov.cn/DataServer?T=cia_w&x={x}&y={y}&l={z}&tk=c78ca1c13e82e1cdd64ef9d8cdbbb237",
  208. }),
  209. isGroup: true,
  210. name: "天地图文字标注--卫星影像图",
  211. });
  212. //加载地图
  213. map = new ol.Map({
  214. controls: ol.control.defaults({attribution: false, zoom: false, rotate: false}).extend([]), //隐藏放大缩小按钮
  215. layers: [aerial, yingxzi],
  216. projection: projection,
  217. target: that.uuidMap,
  218. view: new ol.View({
  219. //center: ol.proj.fromLonLat([115.452752, 31.789033]),
  220. zoom: 15,
  221. minZoom: 5, //地图缩小限制
  222. maxZoom: 18.3, //地图放大限制
  223. }),
  224. });
  225. // 添加村边界
  226. let mapBorder = new ol.layer.Image({
  227. source: new ol.source.ImageWMS({
  228. url: this.mapGeoServerUrl + '/wms',
  229. params: {
  230. LAYERS: this.villageBorderLayerName,
  231. cql_filter: "dept_id = '" + this.$store.state.user.loginDeptId + "'",
  232. SRID: 3857,
  233. },
  234. }),
  235. name: 'villageBorderLayer'
  236. });
  237. map.addLayer(mapBorder);
  238. // 添加已经存在的资源图层
  239. let vectorSource = new ol.source.Vector();
  240. for (let resource of this.resourceList) {
  241. if (resource.theGeom && resource.id !== this.resourceId) {
  242. let feature = new ol.Feature({
  243. geometry: new ol.geom.MultiPolygon(JSON.parse(resource.theGeom).coordinates),
  244. // permanentName: permanent.name
  245. });
  246. vectorSource.addFeature(feature);
  247. }
  248. }
  249. let resourceLayer = new ol.layer.Vector({
  250. source: vectorSource,
  251. style: (feature, resolution) => {
  252. return new ol.style.Style({
  253. fill: new ol.style.Fill({
  254. //矢量图层填充颜色,以及透明度
  255. color: "rgba(0, 218, 255, 0.3)",
  256. }),
  257. stroke: new ol.style.Stroke({
  258. //边界样式
  259. color: "#00DAFF",
  260. width: 3,
  261. }),
  262. })
  263. }
  264. });
  265. map.addLayer(resourceLayer);
  266. //图层查询定位开始 ---------start
  267. if(this.message.substring(0,1) =="{"){
  268. // var theGeomMap =this.message.replace("Point", "MultiPolygon");
  269. // var pointLeft = theGeomMap.replace("[", "[[[[");
  270. // var pointRight = pointLeft.replace("]", "]]]]");
  271. hc_land = new ol.layer.Vector({
  272. title: "add Layer",
  273. source: new ol.source.Vector({
  274. projection: projection,
  275. features: new ol.format.GeoJSON().readFeatures("{\n" +
  276. " \"type\": \"Feature\",\n" +
  277. " \"geometry\":" + this.message + "}"),
  278. }),
  279. style: new ol.style.Style({
  280. fill: new ol.style.Fill({
  281. //矢量图层填充颜色,以及透明度
  282. color: "rgba(204, 255, 204,0.3)",
  283. }),
  284. stroke: new ol.style.Stroke({
  285. //边界样式
  286. color: "#47c68f",
  287. width: 3,
  288. }),
  289. }),
  290. });
  291. map.addLayer(hc_land);
  292. var maxXMap = hc_land.values_.source.featuresRtree_.rbush_.data.maxX;
  293. var maxYMap = hc_land.values_.source.featuresRtree_.rbush_.data.maxY;
  294. var minXMap = hc_land.values_.source.featuresRtree_.rbush_.data.minX;
  295. var minYMap = hc_land.values_.source.featuresRtree_.rbush_.data.minY;
  296. //定位查询位置
  297. var center = ol.extent.getCenter([maxXMap, maxYMap, minXMap, minYMap]); //获取边界区域的中心位置
  298. map.getView().animate({
  299. // 只设置需要的属性即可
  300. center: center, // 中心点
  301. zoom: 17.9, // 缩放级别
  302. rotation: undefined, // 缩放完成view视图旋转弧度
  303. duration: 1000, // 缩放持续时间,默认不需要设置
  304. });
  305. }
  306. // if(this.message.substring(0,1) =="["){
  307. // var zbNew = JSON.stringify({"type": "MultiPolygon", "coordinates": [[[this.message.replaceAll("\"","")]]]});
  308. // var leftJoin = zbNew.replace("\"[","[");
  309. // var rightJoin = leftJoin.replace("\"]","]");
  310. // hc_landFuther = new ol.layer.Vector({
  311. // title: "add Layer",
  312. // source: new ol.source.Vector({
  313. // projection: projection,
  314. // features: new ol.format.GeoJSON().readFeatures("{\n" +
  315. // " \"type\": \"Feature\",\n" +
  316. // " \"geometry\":" + rightJoin + "}"),
  317. // }),
  318. // style: new ol.style.Style({
  319. // fill: new ol.style.Fill({
  320. // //矢量图层填充颜色,以及透明度
  321. // color: "rgba(204, 255, 204,0.3)",
  322. // }),
  323. // stroke: new ol.style.Stroke({
  324. // //边界样式
  325. // color: "#47c68f",
  326. // width: 3,
  327. // }),
  328. // }),
  329. // });
  330. // map.addLayer(hc_landFuther);
  331. // var maxXMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.maxX;
  332. // var maxYMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.maxY;
  333. // var minXMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.minX;
  334. // var minYMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.minY;
  335. // //定位查询位置
  336. // var center = ol.extent.getCenter([maxXMap, maxYMap, minXMap, minYMap]); //获取边界区域的中心位置
  337. // map.getView().animate({
  338. // // 只设置需要的属性即可
  339. // center: center, // 中心点
  340. // zoom: 17.9, // 缩放级别
  341. // rotation: undefined, // 缩放完成view视图旋转弧度
  342. // duration: 1000, // 缩放持续时间,默认不需要设置
  343. // });
  344. // }
  345. //图层查询定位结束 ---------end
  346. //开始绘制地图
  347. $("#"+this.drawingPolygonMap).click(function () {
  348. map.removeLayer(hc_land);
  349. //map.removeLayer(hc_landFuther);
  350. map.removeLayer(vector_drawing);
  351. //that.closeMoule = null;
  352. map.removeInteraction(draw);
  353. //var source = new ol.source.Vector({wrapX: false});
  354. vector_drawing = new ol.layer.Vector({
  355. source: new ol.source.Vector(),
  356. });
  357. map.addLayer(vector_drawing);
  358. function addInteraction() {
  359. draw = new ol.interaction.Draw({
  360. source: vector_drawing.getSource(),
  361. type: "Polygon"
  362. });
  363. draw.on('drawend', function (evt) {
  364. var feature = evt.feature;
  365. var geometry = feature.getGeometry();
  366. var coordinate = geometry.getCoordinates();
  367. that.closeMoule = coordinate;
  368. that.formSubmit();
  369. });
  370. map.addInteraction(draw);
  371. }
  372. addInteraction();
  373. });
  374. //清除画图鼠标点击事件
  375. // $("#drawRemove").click(function () {
  376. // //map.addLayer(hc_land);
  377. // map.removeInteraction(draw);
  378. // //map.removeLayer(vector_drawing);
  379. // });
  380. //还原之前图层
  381. $("#"+this.drawingResetMap).click(function () {
  382. if(that.closeMoule !=null) {
  383. map.removeLayer(vector_drawing);
  384. //map.removeLayer(hc_landFuther);
  385. map.removeInteraction(draw);
  386. map.addLayer(hc_land);
  387. //map.addLayer(hc_landFuther);
  388. // that.closeMoule = null;
  389. that.formSubmit();
  390. }
  391. });
  392. $("#" + this.locationMap).click(function () {
  393. that.getCurrentLocation(res => {
  394. if (res.code == 200) {
  395. let lat = res.data.lat;
  396. let lng = res.data.lng;
  397. if(lat && lng){
  398. Zb = [lng,lat];
  399. }else {
  400. Zb =[115.452752, 31.789033];
  401. }
  402. addMark(lng,lat);
  403. map.getView().animate({
  404. // 只设置需要的属性即可
  405. center: ol.proj.fromLonLat(Zb), // 中心点
  406. zoom: 18, // 缩放级别
  407. rotation: undefined, // 缩放完成view视图旋转弧度
  408. duration: 1000, // 缩放持续时间,默认不需要设置
  409. });
  410. }
  411. });
  412. });
  413. } else{
  414. //this.closeMoule = null;
  415. document.getElementById(that.uuidMap).innerHTML = '';
  416. var projection = new ol.proj.Projection({
  417. //地图投影类型
  418. code: "EPSG:3857",
  419. units: "degrees",
  420. //extent:extent
  421. });
  422. var aerial = new ol.layer.Tile({
  423. source: new ol.source.XYZ({
  424. url: "http://t0.tianditu.gov.cn/img_w/wmts?" +
  425. "SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles" +
  426. "&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=c78ca1c13e82e1cdd64ef9d8cdbbb237",
  427. }),
  428. isGroup: true,
  429. name: "卫星影像图",
  430. });
  431. var yingxzi = new ol.layer.Tile({
  432. source: new ol.source.XYZ({
  433. url: "https://t0.tianditu.gov.cn/DataServer?T=cia_w&x={x}&y={y}&l={z}&tk=c78ca1c13e82e1cdd64ef9d8cdbbb237",
  434. }),
  435. isGroup: true,
  436. name: "天地图文字标注--卫星影像图",
  437. });
  438. //获取坐标是否存在
  439. var Zb;
  440. this.getDeptLocation((response) => {
  441. if (response.code == 200) {
  442. let InsertCode = response.data;
  443. if (InsertCode != null) {
  444. var lat = InsertCode.lat;
  445. var lng = InsertCode.lng;
  446. if(lat !=null && lng !=null && lat !="" && lng !=""){
  447. Zb = [lng,lat];
  448. }else {
  449. Zb =[115.452752, 31.789033];
  450. }
  451. //加载地图
  452. map = new ol.Map({
  453. controls: ol.control.defaults({attribution: false, zoom: false, rotate: false}).extend([]), //隐藏放大缩小按钮
  454. layers: [aerial, yingxzi],
  455. projection: projection,
  456. logo: 'false',
  457. target: that.uuidMap,
  458. view: new ol.View({
  459. center: ol.proj.fromLonLat(Zb),
  460. //center: ol.proj.fromLonLat([115.452752, 31.789033]),
  461. zoom: 16.9,
  462. minZoom: 5, //地图缩小限制
  463. maxZoom: 18, //地图放大限制
  464. }),
  465. });
  466. // 添加村边界
  467. let mapBorder = new ol.layer.Image({
  468. source: new ol.source.ImageWMS({
  469. url: this.mapGeoServerUrl + '/wms',
  470. params: {
  471. LAYERS: this.villageBorderLayerName,
  472. cql_filter: "dept_id = '" + this.$store.state.user.loginDeptId + "'",
  473. SRID: 3857,
  474. },
  475. }),
  476. name: 'villageBorderLayer'
  477. });
  478. map.addLayer(mapBorder);
  479. // 添加已经存在的资源图层
  480. let vectorSource = new ol.source.Vector();
  481. for (let resource of this.resourceList) {
  482. if (resource.theGeom && resource.id !== this.resourceId) {
  483. let feature = new ol.Feature({
  484. geometry: new ol.geom.MultiPolygon(JSON.parse(resource.theGeom).coordinates),
  485. // permanentName: permanent.name
  486. });
  487. vectorSource.addFeature(feature);
  488. }
  489. }
  490. let resourceLayer = new ol.layer.Vector({
  491. source: vectorSource,
  492. style: (feature, resolution) => {
  493. return new ol.style.Style({
  494. fill: new ol.style.Fill({
  495. //矢量图层填充颜色,以及透明度
  496. color: "rgba(0, 218, 255, 0.3)",
  497. }),
  498. stroke: new ol.style.Stroke({
  499. //边界样式
  500. color: "#00DAFF",
  501. width: 3,
  502. }),
  503. })
  504. }
  505. });
  506. map.addLayer(resourceLayer);
  507. }
  508. }
  509. });
  510. //图层查询定位结束 ---------end
  511. //开始绘制地图
  512. $("#"+this.drawingPolygonMap).click(function () {
  513. //that.closeMoule = null;
  514. map.removeInteraction(draw);
  515. //var source = new ol.source.Vector({wrapX: false});
  516. vector_drawing = new ol.layer.Vector({
  517. source: new ol.source.Vector(),
  518. });
  519. map.addLayer(vector_drawing);
  520. function addInteraction() {
  521. draw = new ol.interaction.Draw({
  522. source: vector_drawing.getSource(),
  523. type: "Polygon"
  524. });
  525. draw.on('drawend', function (evt) {
  526. var feature = evt.feature;
  527. var geometry = feature.getGeometry();
  528. var coordinate = geometry.getCoordinates();
  529. that.closeMoule = coordinate;
  530. that.formSubmit();
  531. });
  532. map.addInteraction(draw);
  533. }
  534. addInteraction();
  535. });
  536. //清除画图鼠标点击事件
  537. // $("#drawRemove").click(function () {
  538. // //map.addLayer(hc_land);
  539. // map.removeInteraction(draw);
  540. // //map.removeLayer(vector_drawing);
  541. // });
  542. //还原之前图层
  543. $("#"+this.drawingResetMap).click(function () {
  544. map.removeInteraction(draw);
  545. map.removeLayer(vector_drawing);
  546. //that.closeMoule = null;
  547. that.formSubmit();
  548. });
  549. $("#" + this.locationMap).click(function () {
  550. that.getCurrentLocation(res => {
  551. if (res.code == 200) {
  552. let lat = res.data.lat;
  553. let lng = res.data.lng;
  554. if(lat && lng){
  555. Zb = [lng,lat];
  556. }else {
  557. Zb =[115.452752, 31.789033];
  558. }
  559. addMark(lng,lat);
  560. map.getView().animate({
  561. // 只设置需要的属性即可
  562. center: ol.proj.fromLonLat(Zb), // 中心点
  563. zoom: 18, // 缩放级别
  564. rotation: undefined, // 缩放完成view视图旋转弧度
  565. duration: 1000, // 缩放持续时间,默认不需要设置
  566. });
  567. }
  568. });
  569. });
  570. }
  571. },
  572. },
  573. watch: {},
  574. };
  575. </script>
  576. <style scoped>
  577. #that.message {
  578. width: 100%;
  579. height: 100%;
  580. }
  581. .fuTitle {
  582. border-top: 1px solid #e9e9e9;
  583. text-align: center;
  584. padding: 10px 0px 0px 0px;
  585. font-size: 18px;
  586. color: #999;
  587. }
  588. .ant-btn-red {
  589. position: relative;
  590. display: inline-block;
  591. background: #D0EEFF;
  592. border: 1px solid #99D3F5;
  593. border-radius: 4px;
  594. padding: 4px 12px;
  595. overflow: hidden;
  596. color: #1E88C7;
  597. text-decoration: none;
  598. text-indent: 0;
  599. line-height: 30px;
  600. font-size: 28px;
  601. margin: 5px 0 5px;
  602. }
  603. #land-btn-wrap{
  604. position: relative;
  605. width: 25%;
  606. left: 75%;
  607. bottom: 100%;
  608. z-index: 2000;
  609. padding-top: 5%;
  610. }
  611. </style>