移动端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

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