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

831 行
34 KiB

  1. <template>
  2. <div>
  3. <p class="fuTitle">地块位置绘制</p>
  4. <div id="full-screen-acceptance" style="width: 100%;height:45vh;position:relative;">
  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="this.positioningMap" 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 id="info" style="display: none"></div>
  16. </div>
  17. </template>
  18. <script>
  19. import {getQueryLand} from "@/api/homesteadSurvey/zjdzd";
  20. import {getGeoServerConfigKey} from "@/api/system/config";
  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. positioningMap: this.guidProduct(),
  33. newZb: null,
  34. newGeom: null,
  35. mapData: null,
  36. //地图服务地址
  37. mapGeoServerUrl:"",
  38. };
  39. },
  40. props: ['theGeom','message'],
  41. // created() {
  42. // // setTimeout(() => {
  43. // // this.drawingPaceCountryDarw();
  44. // // }, 100);
  45. // },
  46. methods: {
  47. //地图加载
  48. formSubmit(){
  49. //父组件监听的名字必须是formSubmit
  50. // 子组件调用父组件的方法并传参
  51. if(this.closeMoule =="" || this.closeMoule == null){
  52. this.$emit('formSubmit', null);
  53. }else{
  54. this.$emit('formSubmit', JSON.stringify(this.closeMoule));
  55. }
  56. },
  57. guidProduct(){
  58. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  59. var r = Math.random() * 16 | 0,
  60. v = c == 'x' ? r : (r & 0x3 | 0x8);
  61. return v.toString(16);
  62. });
  63. },
  64. //地图查看
  65. drawingPaceCountryDarw() {
  66. /* console.log(this.message);*/
  67. //加载地图编辑
  68. var that = this;
  69. var map;
  70. //var hc_land;
  71. var draw; // global so we can remove it later
  72. var vector_drawing;
  73. console.log(that.message);
  74. // if(that.$cookies.get("item").backMapZjdAData.theGeom !=null && that.$cookies.get("item").backMapZjdAData.theGeom !=""
  75. // && that.$cookies.get("item").backMapZjdAData.theGeom.substring(0,1) =="["){
  76. // console.log(that.$cookies.get("item"));
  77. // that.message = that.$cookies.get("item").backMapZjdAData.theGeom;
  78. // }
  79. getGeoServerConfigKey().then(response => {
  80. that.mapGeoServerUrl = response.msg;
  81. if (that.message != null && that.message != ""
  82. && that.message != undefined) {
  83. document.getElementById(that.uuidMap).innerHTML = '';
  84. var hc_land;
  85. var hc_landFuther;
  86. var draw; // global so we can remove it later
  87. var vector_drawing;
  88. var projection = new ol.proj.Projection({
  89. //地图投影类型
  90. code: "EPSG:3857",
  91. units: "degrees",
  92. //extent:extent
  93. });
  94. var aerial = new ol.layer.Tile({
  95. source: new ol.source.XYZ({
  96. url: "http://t{0-7}.tianditu.com/img_w/wmts?" +
  97. "SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles" +
  98. "&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=cc4aba6e967096098249efa069733067",
  99. }),
  100. isGroup: true,
  101. name: "卫星影像图",
  102. });
  103. var yingxzi = new ol.layer.Tile({
  104. source: new ol.source.XYZ({
  105. url: "http://t{0-7}.tianditu.com/DataServer?T=cia_w&x={x}&y={y}&l={z}&tk=cc4aba6e967096098249efa069733067",
  106. }),
  107. isGroup: true,
  108. name: "天地图文字标注--卫星影像图",
  109. });
  110. //加载地图
  111. map = new ol.Map({
  112. controls: ol.control.defaults({attribution: false, zoom: false, rotate: false}).extend([]), //隐藏放大缩小按钮
  113. layers: [aerial, yingxzi],
  114. projection: projection,
  115. target: that.uuidMap,
  116. view: new ol.View({
  117. //center: ol.proj.fromLonLat([115.452752, 31.789033]),
  118. zoom: 15,
  119. minZoom: 5, //地图缩小限制
  120. maxZoom: 18.3, //地图放大限制
  121. }),
  122. });
  123. that.mapData= that.message;
  124. var zjdTc;
  125. var zrzTc;
  126. var fsssTc;
  127. map.removeLayer(zrzTc);
  128. map.removeLayer(zjdTc);
  129. map.removeLayer(fsssTc);
  130. //宅基地图层查询开始 ------------------start
  131. var cql_filter_all = "dept_id='" + that.$cookies.get("item").deptId + "'" + "and zjddm='" + that.$cookies.get("item").zjddm + "'";
  132. zjdTc= new ol.layer.Tile({
  133. source: new ol.source.TileWMS({
  134. url: that.mapGeoServerUrl +"/geoserver/zjd_dc/wms",
  135. params: {
  136. LAYERS: 'zjd_dc:t_house_survey_zjdzd',
  137. TILED: true,
  138. cql_filter: cql_filter_all,
  139. SRID: 3857,
  140. },
  141. }),
  142. });
  143. map.addLayer(zjdTc);
  144. //宅基地图层查询开始 ------------------start
  145. //自然幢图层查询开始 ------------------start
  146. zrzTc= new ol.layer.Tile({
  147. source: new ol.source.TileWMS({
  148. url: that.mapGeoServerUrl+"/geoserver/zjd_dc/wms",
  149. params: {
  150. LAYERS: 'zjd_dc:t_house_survey_zrz',
  151. TILED: true,
  152. cql_filter: cql_filter_all,
  153. SRID: 3857,
  154. },
  155. }),
  156. });
  157. map.addLayer(zrzTc);
  158. //自然幢图层查询结束 ------------------end
  159. //附属设施图层查询开始 ------------------start
  160. fsssTc= new ol.layer.Tile({
  161. source: new ol.source.TileWMS({
  162. url: that.mapGeoServerUrl+"/geoserver/zjd_dc/wms",
  163. params: {
  164. LAYERS: 'zjd_dc:t_house_survey_fsss',
  165. TILED: true,
  166. cql_filter: cql_filter_all,
  167. SRID: 3857,
  168. },
  169. }),
  170. });
  171. map.addLayer(fsssTc);
  172. //附属设施图层查询结束 ------------------end
  173. //图层查询定位开始 ---------start
  174. if(this.message.substring(0,1) =="{"){
  175. //that.newHt ="1";
  176. // var theGeomMap =this.message.replace("Point", "MultiPolygon");
  177. // var pointLeft = theGeomMap.replace("[", "[[[[");
  178. // var pointRight = pointLeft.replace("]", "]]]]");
  179. hc_land = new ol.layer.Vector({
  180. title: "add Layer",
  181. source: new ol.source.Vector({
  182. projection: projection,
  183. features: new ol.format.GeoJSON().readFeatures("{\n" +
  184. " \"type\": \"Feature\",\n" +
  185. " \"geometry\":" + this.message + "}"),
  186. }),
  187. style: new ol.style.Style({
  188. fill: new ol.style.Fill({
  189. //矢量图层填充颜色,以及透明度
  190. color: "rgba(204, 255, 204,0.3)",
  191. }),
  192. stroke: new ol.style.Stroke({
  193. //边界样式
  194. color: "#47c68f",
  195. width: 3,
  196. }),
  197. }),
  198. });
  199. map.addLayer(hc_land);
  200. var maxXMap = hc_land.values_.source.featuresRtree_.rbush_.data.maxX;
  201. var maxYMap = hc_land.values_.source.featuresRtree_.rbush_.data.maxY;
  202. var minXMap = hc_land.values_.source.featuresRtree_.rbush_.data.minX;
  203. var minYMap = hc_land.values_.source.featuresRtree_.rbush_.data.minY;
  204. //定位查询位置
  205. var center = ol.extent.getCenter([maxXMap, maxYMap, minXMap, minYMap]); //获取边界区域的中心位置
  206. map.getView().animate({
  207. // 只设置需要的属性即可
  208. center: center, // 中心点
  209. zoom: 17.9, // 缩放级别
  210. rotation: undefined, // 缩放完成view视图旋转弧度
  211. duration: 1000, // 缩放持续时间,默认不需要设置
  212. });
  213. // let resolution = map.getView().getResolutionForExtent([maxXMap, maxYMap, minXMap, minYMap],map.getSize());
  214. // map.getView().fit([maxXMap, maxYMap, minXMap, minYMap]);
  215. // map.getView().setResolution(resolution);
  216. } else if(this.message.substring(0,1) =="["){
  217. //that.newHt ="1";
  218. var zbNew = JSON.stringify({"type": "MultiPolygon", "coordinates": [this.message.replaceAll("\"","")]});
  219. var leftJoin = zbNew.replace("\"[","[");
  220. var rightJoin = leftJoin.replace("\"]","]");
  221. hc_land = new ol.layer.Vector({
  222. title: "add Layer",
  223. source: new ol.source.Vector({
  224. projection: projection,
  225. features: new ol.format.GeoJSON().readFeatures("{\n" +
  226. " \"type\": \"Feature\",\n" +
  227. " \"geometry\":" + rightJoin + "}"),
  228. }),
  229. style: new ol.style.Style({
  230. fill: new ol.style.Fill({
  231. //矢量图层填充颜色,以及透明度
  232. color: "rgba(204, 255, 204,0.3)",
  233. }),
  234. stroke: new ol.style.Stroke({
  235. //边界样式
  236. color: "#47c68f",
  237. width: 3,
  238. }),
  239. }),
  240. });
  241. map.addLayer(hc_land);
  242. var maxXMap = hc_land.values_.source.featuresRtree_.rbush_.data.maxX;
  243. var maxYMap = hc_land.values_.source.featuresRtree_.rbush_.data.maxY;
  244. var minXMap = hc_land.values_.source.featuresRtree_.rbush_.data.minX;
  245. var minYMap = hc_land.values_.source.featuresRtree_.rbush_.data.minY;
  246. //定位查询位置
  247. var center = ol.extent.getCenter([maxXMap, maxYMap, minXMap, minYMap]); //获取边界区域的中心位置
  248. map.getView().animate({
  249. // 只设置需要的属性即可
  250. center: center, // 中心点
  251. zoom: 16.9, // 缩放级别
  252. rotation: undefined, // 缩放完成view视图旋转弧度
  253. duration: 1000, // 缩放持续时间,默认不需要设置
  254. });
  255. // let resolution = map.getView().getResolutionForExtent([maxXMap, maxYMap, minXMap, minYMap],map.getSize());
  256. // map.getView().fit([maxXMap, maxYMap, minXMap, minYMap]);
  257. // map.getView().setResolution(resolution);
  258. } else {
  259. }
  260. //图层查询定位结束 ---------end
  261. //开始绘制地图
  262. $("#"+this.drawingPolygonMap).click(function () {
  263. that.newGeom = 1;
  264. map.removeLayer(hc_land);
  265. map.removeLayer(vector_drawing);
  266. //that.closeMoule = null;
  267. map.removeInteraction(draw);
  268. //var source = new ol.source.Vector({wrapX: false});
  269. vector_drawing = new ol.layer.Vector({
  270. source: new ol.source.Vector(),
  271. });
  272. map.addLayer(vector_drawing);
  273. function addInteraction() {
  274. draw = new ol.interaction.Draw({
  275. source: vector_drawing.getSource(),
  276. type: "Polygon"
  277. });
  278. draw.on('drawend', function (evt) {
  279. var feature = evt.feature;
  280. var geometry = feature.getGeometry();
  281. var coordinate = geometry.getCoordinates();
  282. if(coordinate !="" && coordinate !=null){
  283. //map.addLayer(vector_drawing);
  284. map.removeInteraction(draw);
  285. }
  286. that.closeMoule = coordinate;
  287. that.formSubmit();
  288. });
  289. map.addInteraction(draw);
  290. }
  291. addInteraction();
  292. });
  293. //清除画图鼠标点击事件
  294. // $("#drawRemove").click(function () {
  295. // //map.addLayer(hc_land);
  296. // map.removeInteraction(draw);
  297. // //map.removeLayer(vector_drawing);
  298. // });
  299. //还原之前图层
  300. $("#"+this.drawingResetMap).click(function () {
  301. that.newGeom = 2;
  302. if(that.closeMoule !=null) {
  303. map.addLayer(hc_land);
  304. map.removeInteraction(draw);
  305. map.removeLayer(vector_drawing);
  306. that.formSubmit();
  307. }
  308. });
  309. //定位当前绘制图层
  310. $("#"+this.positioningMap).click(function () {
  311. //图层查询定位开始 ---------start
  312. console.log(that.message);
  313. console.log(that.closeMoule);
  314. console.log(that.newGeom);
  315. // var dwmap;
  316. // if(that.closeMoule != null && that.closeMoule !=""){
  317. // dwmap = JSON.stringify(that.closeMoule);
  318. // }else {
  319. // console.log(that.newGeom);
  320. // dwmap = JSON.stringify(that.newGeom);
  321. // }
  322. var deMap = JSON.stringify(that.closeMoule);
  323. if(that.newGeom == 1){
  324. if(deMap.substring(0,1) =="{"){
  325. //that.newHt ="1";
  326. // var theGeomMap =this.message.replace("Point", "MultiPolygon");
  327. // var pointLeft = theGeomMap.replace("[", "[[[[");
  328. // var pointRight = pointLeft.replace("]", "]]]]");
  329. hc_landFuther = new ol.layer.Vector({
  330. title: "add Layer",
  331. source: new ol.source.Vector({
  332. projection: projection,
  333. features: new ol.format.GeoJSON().readFeatures("{\n" +
  334. " \"type\": \"Feature\",\n" +
  335. " \"geometry\":" + deMap + "}"),
  336. }),
  337. style: new ol.style.Style({
  338. fill: new ol.style.Fill({
  339. //矢量图层填充颜色,以及透明度
  340. color: "rgba(204, 255, 204,0.3)",
  341. }),
  342. stroke: new ol.style.Stroke({
  343. //边界样式
  344. color: "#47c68f",
  345. width: 3,
  346. }),
  347. }),
  348. });
  349. //map.addLayer(hc_land);
  350. var maxXMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.maxX;
  351. var maxYMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.maxY;
  352. var minXMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.minX;
  353. var minYMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.minY;
  354. //定位查询位置
  355. var center = ol.extent.getCenter([maxXMap, maxYMap, minXMap, minYMap]); //获取边界区域的中心位置
  356. map.getView().animate({
  357. // 只设置需要的属性即可
  358. center: center, // 中心点
  359. zoom: 17.9, // 缩放级别
  360. rotation: undefined, // 缩放完成view视图旋转弧度
  361. duration: 1000, // 缩放持续时间,默认不需要设置
  362. });
  363. // let resolution = map.getView().getResolutionForExtent([maxXMap, maxYMap, minXMap, minYMap],map.getSize());
  364. // map.getView().fit([maxXMap, maxYMap, minXMap, minYMap]);
  365. // map.getView().setResolution(resolution);
  366. } else if(deMap.substring(0,1) =="[") {
  367. //that.newHt ="1";
  368. var zbNew = JSON.stringify({"type": "MultiPolygon", "coordinates": [deMap.replaceAll("\"", "")]});
  369. var leftJoin = zbNew.replace("\"[", "[");
  370. var rightJoin = leftJoin.replace("\"]", "]");
  371. hc_landFuther = new ol.layer.Vector({
  372. title: "add Layer",
  373. source: new ol.source.Vector({
  374. projection: projection,
  375. features: new ol.format.GeoJSON().readFeatures("{\n" +
  376. " \"type\": \"Feature\",\n" +
  377. " \"geometry\":" + rightJoin + "}"),
  378. }),
  379. style: new ol.style.Style({
  380. fill: new ol.style.Fill({
  381. //矢量图层填充颜色,以及透明度
  382. color: "rgba(204, 255, 204,0.3)",
  383. }),
  384. stroke: new ol.style.Stroke({
  385. //边界样式
  386. color: "#47c68f",
  387. width: 3,
  388. }),
  389. }),
  390. });
  391. //map.addLayer(hc_land);
  392. var maxXMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.maxX;
  393. var maxYMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.maxY;
  394. var minXMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.minX;
  395. var minYMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.minY;
  396. //定位查询位置
  397. var center = ol.extent.getCenter([maxXMap, maxYMap, minXMap, minYMap]); //获取边界区域的中心位置
  398. map.getView().animate({
  399. // 只设置需要的属性即可
  400. center: center, // 中心点
  401. zoom: 16.9, // 缩放级别
  402. rotation: undefined, // 缩放完成view视图旋转弧度
  403. duration: 1000, // 缩放持续时间,默认不需要设置
  404. });
  405. }
  406. } else {
  407. console.log(that.mapData);
  408. if(that.mapData.substring(0,1) =="{"){
  409. //that.newHt ="1";
  410. // var theGeomMap =this.message.replace("Point", "MultiPolygon");
  411. // var pointLeft = theGeomMap.replace("[", "[[[[");
  412. // var pointRight = pointLeft.replace("]", "]]]]");
  413. hc_landFuther = new ol.layer.Vector({
  414. title: "add Layer",
  415. source: new ol.source.Vector({
  416. projection: projection,
  417. features: new ol.format.GeoJSON().readFeatures("{\n" +
  418. " \"type\": \"Feature\",\n" +
  419. " \"geometry\":" + that.mapData + "}"),
  420. }),
  421. style: new ol.style.Style({
  422. fill: new ol.style.Fill({
  423. //矢量图层填充颜色,以及透明度
  424. color: "rgba(204, 255, 204,0.3)",
  425. }),
  426. stroke: new ol.style.Stroke({
  427. //边界样式
  428. color: "#47c68f",
  429. width: 3,
  430. }),
  431. }),
  432. });
  433. //map.addLayer(hc_land);
  434. var maxXMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.maxX;
  435. var maxYMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.maxY;
  436. var minXMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.minX;
  437. var minYMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.minY;
  438. //定位查询位置
  439. var center = ol.extent.getCenter([maxXMap, maxYMap, minXMap, minYMap]); //获取边界区域的中心位置
  440. map.getView().animate({
  441. // 只设置需要的属性即可
  442. center: center, // 中心点
  443. zoom: 17.9, // 缩放级别
  444. rotation: undefined, // 缩放完成view视图旋转弧度
  445. duration: 1000, // 缩放持续时间,默认不需要设置
  446. });
  447. // let resolution = map.getView().getResolutionForExtent([maxXMap, maxYMap, minXMap, minYMap],map.getSize());
  448. // map.getView().fit([maxXMap, maxYMap, minXMap, minYMap]);
  449. // map.getView().setResolution(resolution);
  450. } else if(that.mapData.substring(0,1) =="[") {
  451. //that.newHt ="1";
  452. var zbNew = JSON.stringify({"type": "MultiPolygon", "coordinates": [that.mapData.replaceAll("\"", "")]});
  453. var leftJoin = zbNew.replace("\"[", "[");
  454. var rightJoin = leftJoin.replace("\"]", "]");
  455. hc_landFuther = new ol.layer.Vector({
  456. title: "add Layer",
  457. source: new ol.source.Vector({
  458. projection: projection,
  459. features: new ol.format.GeoJSON().readFeatures("{\n" +
  460. " \"type\": \"Feature\",\n" +
  461. " \"geometry\":" + rightJoin + "}"),
  462. }),
  463. style: new ol.style.Style({
  464. fill: new ol.style.Fill({
  465. //矢量图层填充颜色,以及透明度
  466. color: "rgba(204, 255, 204,0.3)",
  467. }),
  468. stroke: new ol.style.Stroke({
  469. //边界样式
  470. color: "#47c68f",
  471. width: 3,
  472. }),
  473. }),
  474. });
  475. //map.addLayer(hc_land);
  476. var maxXMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.maxX;
  477. var maxYMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.maxY;
  478. var minXMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.minX;
  479. var minYMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.minY;
  480. //定位查询位置
  481. var center = ol.extent.getCenter([maxXMap, maxYMap, minXMap, minYMap]); //获取边界区域的中心位置
  482. map.getView().animate({
  483. // 只设置需要的属性即可
  484. center: center, // 中心点
  485. zoom: 16.9, // 缩放级别
  486. rotation: undefined, // 缩放完成view视图旋转弧度
  487. duration: 1000, // 缩放持续时间,默认不需要设置
  488. });
  489. }
  490. }
  491. });
  492. } else{
  493. //this.closeMoule = null;
  494. document.getElementById(that.uuidMap).innerHTML = '';
  495. var projection = new ol.proj.Projection({
  496. //地图投影类型
  497. code: "EPSG:3857",
  498. units: "degrees",
  499. //extent:extent
  500. });
  501. var aerial = new ol.layer.Tile({
  502. source: new ol.source.XYZ({
  503. url: "http://t{0-7}.tianditu.com/img_w/wmts?" +
  504. "SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles" +
  505. "&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=cc4aba6e967096098249efa069733067",
  506. }),
  507. isGroup: true,
  508. name: "卫星影像图",
  509. });
  510. var yingxzi = new ol.layer.Tile({
  511. source: new ol.source.XYZ({
  512. url: "http://t{0-7}.tianditu.com/DataServer?T=cia_w&x={x}&y={y}&l={z}&tk=cc4aba6e967096098249efa069733067",
  513. }),
  514. isGroup: true,
  515. name: "天地图文字标注--卫星影像图",
  516. });
  517. //加载地图
  518. map = new ol.Map({
  519. controls: ol.control.defaults({attribution: false, zoom: false, rotate: false}).extend([]), //隐藏放大缩小按钮
  520. layers: [aerial, yingxzi],
  521. projection: projection,
  522. logo: 'false',
  523. target: that.uuidMap,
  524. view: new ol.View({
  525. //center: ol.proj.fromLonLat(Zb),
  526. //center: ol.proj.fromLonLat([115.452752, 31.789033]),
  527. zoom: 16.9,
  528. minZoom: 5, //地图缩小限制
  529. maxZoom: 18, //地图放大限制
  530. }),
  531. });
  532. //获取坐标是否存在
  533. //var Zb;
  534. //村边界查询开始 ------------------------------start
  535. var cql_filter = "dept_id='" + that.$cookies.get("item").deptId + "'";
  536. var cunTc= new ol.layer.Tile({
  537. source: new ol.source.TileWMS({
  538. url: that.mapGeoServerUrl +"/geoserver/zjd_dc/wms",
  539. params: {
  540. LAYERS: 'zjd_dc:t_house_survey_border_village',
  541. TILED: true,
  542. cql_filter: cql_filter,
  543. SRID: 3857,
  544. },
  545. }),
  546. });
  547. //定位查询位置
  548. let param_dw = {
  549. srsName: "EPSG:3857",
  550. service: "WFS",
  551. version: "1.0.0",
  552. request: "GetFeature",
  553. typename: "zjd_dc:t_house_survey_border_village",
  554. //featureNS: 'nsgk_hc',//命名空间 URI
  555. cql_filter: cql_filter,
  556. //featurePrefix: 'nationalwater',//工作区名称
  557. //featureTypes: ['nationalwater:01fir'],//查询图层,可以是同一个工作区下多个图层,逗号隔开
  558. outputFormat: "application/json",
  559. //filter: ol.format.filter.equalTo(t,e,r)//前者是属性名,后者是对应值
  560. };
  561. let url_dw = that.mapGeoServerUrl +"/geoserver/zjd_dc/wfs"; //wfsurl;
  562. url_dw = url_dw + "?";
  563. for (let key in param_dw) {
  564. url_dw = url_dw + key + "=" + param_dw[key] + "&";
  565. }
  566. url_dw = url_dw.substr(0, url_dw.length - 1);
  567. fetch(url_dw, {
  568. method: "POST", // *GET, POST, PUT, DELETE, etc.
  569. })
  570. .then((res) => {
  571. var geojsonmap = res.json();
  572. return geojsonmap;
  573. })
  574. .then((data) => {
  575. console.log(data);
  576. let resolution = map.getView().getResolutionForExtent(data.bbox,map.getSize());
  577. map.getView().fit(data.bbox);
  578. map.getView().setResolution(resolution);
  579. // var datamap = data.bbox;
  580. // var center = ol.extent.getCenter(datamap);
  581. // map.getView().animate({
  582. // // 只设置需要的属性即可
  583. // center: center, // 中心点
  584. // rotation: undefined, // 缩放完成view视图旋转弧度
  585. // });
  586. })
  587. .catch((error) => {
  588. console.log("【异常】", error);
  589. });
  590. map.addLayer(cunTc);
  591. //村边界查询开始 ------------------------------end
  592. //宅基地图层查询开始 ------------------start
  593. //var cql_filter_all = "dept_id='" + that.$cookies.get("item").deptId + "'";
  594. var zjdTc= new ol.layer.Tile({
  595. source: new ol.source.TileWMS({
  596. url: that.mapGeoServerUrl+"/geoserver/zjd_dc/wms",
  597. params: {
  598. LAYERS: 'zjd_dc:t_house_survey_zjdzd',
  599. TILED: true,
  600. cql_filter: cql_filter,
  601. SRID: 3857,
  602. },
  603. }),
  604. });
  605. map.addLayer(zjdTc);
  606. //宅基地图层查询开始 ------------------start
  607. // getQueryLand().then((response) => {
  608. // if (response.code == 200) {
  609. // let InsertCode = response.data;
  610. // if (InsertCode != null) {
  611. // var lat = InsertCode.lat;
  612. // var lng = InsertCode.lng;
  613. // if(lat !=null && lng !=null && lat !="" && lng !=""){
  614. // Zb = [lng,lat];
  615. // }else {
  616. // Zb =[115.452752, 31.789033];
  617. // }
  618. // //加载地图
  619. // map = new ol.Map({
  620. // controls: ol.control.defaults({attribution: false, zoom: false, rotate: false}).extend([]), //隐藏放大缩小按钮
  621. // layers: [aerial, yingxzi],
  622. // projection: projection,
  623. // logo: 'false',
  624. // target: that.uuidMap,
  625. // view: new ol.View({
  626. // center: ol.proj.fromLonLat(Zb),
  627. // //center: ol.proj.fromLonLat([115.452752, 31.789033]),
  628. // zoom: 16.9,
  629. // minZoom: 5, //地图缩小限制
  630. // maxZoom: 18, //地图放大限制
  631. // }),
  632. // });
  633. // }
  634. // }
  635. // });
  636. //图层查询定位结束 ---------end
  637. //开始绘制地图
  638. $("#"+this.drawingPolygonMap).click(function () {
  639. //that.closeMoule = null;
  640. map.removeInteraction(draw);
  641. //var source = new ol.source.Vector({wrapX: false});
  642. vector_drawing = new ol.layer.Vector({
  643. source: new ol.source.Vector(),
  644. });
  645. map.addLayer(vector_drawing);
  646. function addInteraction() {
  647. draw = new ol.interaction.Draw({
  648. source: vector_drawing.getSource(),
  649. type: "Polygon"
  650. });
  651. draw.on('drawend', function (evt) {
  652. var feature = evt.feature;
  653. var geometry = feature.getGeometry();
  654. var coordinate = geometry.getCoordinates();
  655. that.newZb = JSON.stringify(coordinate);
  656. if(coordinate !="" && coordinate !=null){
  657. //map.addLayer(vector_drawing);
  658. map.removeInteraction(draw);
  659. }
  660. that.closeMoule = coordinate;
  661. that.formSubmit();
  662. });
  663. map.addInteraction(draw);
  664. }
  665. addInteraction();
  666. });
  667. //清除画图鼠标点击事件
  668. // $("#drawRemove").click(function () {
  669. // //map.addLayer(hc_land);
  670. // map.removeInteraction(draw);
  671. // //map.removeLayer(vector_drawing);
  672. // });
  673. //还原之前图层
  674. $("#"+this.drawingResetMap).click(function () {
  675. map.removeInteraction(draw);
  676. map.removeLayer(vector_drawing);
  677. //that.closeMoule = null;
  678. that.formSubmit();
  679. });
  680. //定位当前绘制图层
  681. $("#"+this.positioningMap).click(function () {
  682. console.log(that.newZb);
  683. //图层查询定位开始 ---------start
  684. //if(){}
  685. //map.removeLayer(hc_landFuther);
  686. if(that.newZb.substring(0,1) =="{"){
  687. //that.newHt ="1";
  688. // var theGeomMap =this.message.replace("Point", "MultiPolygon");
  689. // var pointLeft = theGeomMap.replace("[", "[[[[");
  690. // var pointRight = pointLeft.replace("]", "]]]]");
  691. hc_landFuther = new ol.layer.Vector({
  692. title: "add Layer",
  693. source: new ol.source.Vector({
  694. projection: projection,
  695. features: new ol.format.GeoJSON().readFeatures("{\n" +
  696. " \"type\": \"Feature\",\n" +
  697. " \"geometry\":" + that.newZb + "}"),
  698. }),
  699. style: new ol.style.Style({
  700. fill: new ol.style.Fill({
  701. //矢量图层填充颜色,以及透明度
  702. color: "rgba(204, 255, 204,0.3)",
  703. }),
  704. stroke: new ol.style.Stroke({
  705. //边界样式
  706. color: "#47c68f",
  707. width: 3,
  708. }),
  709. }),
  710. });
  711. //map.addLayer(hc_landFuther);
  712. var maxXMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.maxX;
  713. var maxYMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.maxY;
  714. var minXMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.minX;
  715. var minYMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.minY;
  716. //定位查询位置
  717. var center = ol.extent.getCenter([maxXMap, maxYMap, minXMap, minYMap]); //获取边界区域的中心位置
  718. map.getView().animate({
  719. // 只设置需要的属性即可
  720. center: center, // 中心点
  721. zoom: 17.9, // 缩放级别
  722. rotation: undefined, // 缩放完成view视图旋转弧度
  723. duration: 1000, // 缩放持续时间,默认不需要设置
  724. });
  725. // let resolution = map.getView().getResolutionForExtent([maxXMap, maxYMap, minXMap, minYMap],map.getSize());
  726. // map.getView().fit([maxXMap, maxYMap, minXMap, minYMap]);
  727. // map.getView().setResolution(resolution);
  728. } else if(that.newZb.substring(0,1) =="["){
  729. //that.newHt ="1";
  730. var zbNew = JSON.stringify({"type": "MultiPolygon", "coordinates": [that.newZb.replaceAll("\"","")]});
  731. var leftJoin = zbNew.replace("\"[","[");
  732. var rightJoin = leftJoin.replace("\"]","]");
  733. hc_landFuther = new ol.layer.Vector({
  734. title: "add Layer",
  735. source: new ol.source.Vector({
  736. projection: projection,
  737. features: new ol.format.GeoJSON().readFeatures("{\n" +
  738. " \"type\": \"Feature\",\n" +
  739. " \"geometry\":" + rightJoin + "}"),
  740. }),
  741. style: new ol.style.Style({
  742. fill: new ol.style.Fill({
  743. //矢量图层填充颜色,以及透明度
  744. color: "rgba(204, 255, 204,0.3)",
  745. }),
  746. stroke: new ol.style.Stroke({
  747. //边界样式
  748. color: "#47c68f",
  749. width: 3,
  750. }),
  751. }),
  752. });
  753. //map.addLayer(hc_landFuther);
  754. var maxXMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.maxX;
  755. var maxYMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.maxY;
  756. var minXMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.minX;
  757. var minYMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.minY;
  758. //定位查询位置
  759. var center = ol.extent.getCenter([maxXMap, maxYMap, minXMap, minYMap]); //获取边界区域的中心位置
  760. map.getView().animate({
  761. // 只设置需要的属性即可
  762. center: center, // 中心点
  763. zoom: 16.9, // 缩放级别
  764. rotation: undefined, // 缩放完成view视图旋转弧度
  765. duration: 1000, // 缩放持续时间,默认不需要设置
  766. });
  767. // let resolution = map.getView().getResolutionForExtent([maxXMap, maxYMap, minXMap, minYMap],map.getSize());
  768. // map.getView().fit([maxXMap, maxYMap, minXMap, minYMap]);
  769. // map.getView().setResolution(resolution);
  770. } else {
  771. }
  772. //图层查询定位结束 ---------end
  773. });
  774. }
  775. });
  776. },
  777. },
  778. watch: {},
  779. };
  780. </script>
  781. <style scoped>
  782. #that.message {
  783. width: 100%;
  784. height: 100%;
  785. }
  786. .fuTitle {
  787. border-top: 1px solid #e9e9e9;
  788. text-align: center;
  789. padding: 10px 0px 0px 0px;
  790. font-size: 36px;
  791. color: #999;
  792. }
  793. .ant-btn-red {
  794. position: relative;
  795. display: inline-block;
  796. background: #D0EEFF;
  797. border: 1px solid #99D3F5;
  798. border-radius: 4px;
  799. padding: 4px 12px;
  800. overflow: hidden;
  801. color: #1E88C7;
  802. text-decoration: none;
  803. text-indent: 0;
  804. line-height: 20px;
  805. }
  806. #land-btn-wrap{
  807. position: absolute;
  808. right: 3%;
  809. top: 5%;
  810. z-index: 2000;
  811. }
  812. </style>