移动端
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.
 
 

857 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. });
  552. //view.setResolution(view.getResolution() + Math.random() * 0.00000001);//随机数缩放实现刷新
  553. //获取坐标是否存在
  554. //var Zb;
  555. //村边界查询开始 ------------------------------start
  556. var cql_filter = "dept_id='" + that.$cookies.get("item").deptId + "'";
  557. console.log(cql_filter);
  558. var cunTc= new ol.layer.Image({
  559. source: new ol.source.ImageWMS({
  560. url: that.mapGeoServerUrl +"/geoserver/zjd_dc/wms",
  561. params: {
  562. LAYERS: 'zjd_dc:t_house_survey_border_village',
  563. TILED: true,
  564. cql_filter: cql_filter,
  565. SRID: 3857,
  566. },
  567. }),
  568. });
  569. //定位查询位置
  570. let param_dw = {
  571. srsName: "EPSG:3857",
  572. service: "WFS",
  573. version: "1.0.0",
  574. request: "GetFeature",
  575. typename: "zjd_dc:t_house_survey_border_village",
  576. //featureNS: 'nsgk_hc',//命名空间 URI
  577. cql_filter: cql_filter,
  578. //featurePrefix: 'nationalwater',//工作区名称
  579. //featureTypes: ['nationalwater:01fir'],//查询图层,可以是同一个工作区下多个图层,逗号隔开
  580. outputFormat: "application/json",
  581. //filter: ol.format.filter.equalTo(t,e,r)//前者是属性名,后者是对应值
  582. };
  583. let url_dw = that.mapGeoServerUrl +"/geoserver/zjd_dc/wfs"; //wfsurl;
  584. url_dw = url_dw + "?";
  585. for (let key in param_dw) {
  586. url_dw = url_dw + key + "=" + param_dw[key] + "&";
  587. }
  588. url_dw = url_dw.substr(0, url_dw.length - 1);
  589. fetch(url_dw, {
  590. method: "POST", // *GET, POST, PUT, DELETE, etc.
  591. })
  592. .then((res) => {
  593. var geojsonmap = res.json();
  594. return geojsonmap;
  595. })
  596. .then((data) => {
  597. console.log(data);
  598. let resolution = that.map.getView().getResolutionForExtent(data.bbox,that.map.getSize());
  599. resolution:resolution + Math.random() * 0.00000001,
  600. that.map.getView().fit(data.bbox);
  601. that.map.getView().setResolution(resolution);
  602. // var datamap = data.bbox;
  603. // var center = ol.extent.getCenter(datamap);
  604. // map.getView().animate({
  605. // // 只设置需要的属性即可
  606. // center: center, // 中心点
  607. // rotation: undefined, // 缩放完成view视图旋转弧度
  608. // });
  609. })
  610. .catch((error) => {
  611. console.log("【异常】", error);
  612. });
  613. that.map.addLayer(cunTc);
  614. //村边界查询开始 ------------------------------end
  615. //宅基地图层查询开始 ------------------start
  616. //var cql_filter_all = "dept_id='" + that.$cookies.get("item").deptId + "'";
  617. var zjdTc= new ol.layer.Image({
  618. source: new ol.source.ImageWMS({
  619. url: that.mapGeoServerUrl+"/geoserver/zjd_dc/wms",
  620. params: {
  621. LAYERS: 'zjd_dc:t_house_survey_zjdzd',
  622. TILED: true,
  623. cql_filter: cql_filter,
  624. SRID: 3857,
  625. },
  626. }),
  627. });
  628. that.map.addLayer(zjdTc);
  629. //宅基地图层查询开始 ------------------start
  630. // getQueryLand().then((response) => {
  631. // if (response.code == 200) {
  632. // let InsertCode = response.data;
  633. // if (InsertCode != null) {
  634. // var lat = InsertCode.lat;
  635. // var lng = InsertCode.lng;
  636. // if(lat !=null && lng !=null && lat !="" && lng !=""){
  637. // Zb = [lng,lat];
  638. // }else {
  639. // Zb =[115.452752, 31.789033];
  640. // }
  641. // //加载地图
  642. // map = new ol.Map({
  643. // controls: ol.control.defaults({attribution: false, zoom: false, rotate: false}).extend([]), //隐藏放大缩小按钮
  644. // layers: [aerial, yingxzi],
  645. // projection: projection,
  646. // logo: 'false',
  647. // target: that.uuidMap,
  648. // view: new ol.View({
  649. // center: ol.proj.fromLonLat(Zb),
  650. // //center: ol.proj.fromLonLat([115.452752, 31.789033]),
  651. // zoom: 16.9,
  652. // minZoom: 5, //地图缩小限制
  653. // maxZoom: 18, //地图放大限制
  654. // }),
  655. // });
  656. // }
  657. // }
  658. // });
  659. //图层查询定位结束 ---------end
  660. //开始绘制地图
  661. $("#"+this.drawingPolygonMap).click(function () {
  662. //that.closeMoule = null;
  663. that.map.removeInteraction(draw);
  664. //var source = new ol.source.Vector({wrapX: false});
  665. vector_drawing = new ol.layer.Vector({
  666. source: new ol.source.Vector(),
  667. });
  668. that.map.addLayer(vector_drawing);
  669. function addInteraction() {
  670. draw = new ol.interaction.Draw({
  671. source: vector_drawing.getSource(),
  672. type: "Polygon"
  673. });
  674. draw.on('drawend', function (evt) {
  675. var feature = evt.feature;
  676. var geometry = feature.getGeometry();
  677. var coordinate = geometry.getCoordinates();
  678. that.newZb = JSON.stringify(coordinate);
  679. if(coordinate !="" && coordinate !=null){
  680. //map.addLayer(vector_drawing);
  681. map.removeInteraction(draw);
  682. }
  683. that.closeMoule = coordinate;
  684. that.formSubmit();
  685. });
  686. that.map.addInteraction(draw);
  687. }
  688. addInteraction();
  689. });
  690. //清除画图鼠标点击事件
  691. // $("#drawRemove").click(function () {
  692. // //map.addLayer(hc_land);
  693. // map.removeInteraction(draw);
  694. // //map.removeLayer(vector_drawing);
  695. // });
  696. //还原之前图层
  697. $("#"+this.drawingResetMap).click(function () {
  698. that.map.removeInteraction(draw);
  699. that.map.removeLayer(vector_drawing);
  700. //that.closeMoule = null;
  701. that.formSubmit();
  702. });
  703. //定位当前绘制图层
  704. $("#"+this.positioningMap).click(function () {
  705. console.log(that.newZb);
  706. //图层查询定位开始 ---------start
  707. //if(){}
  708. //map.removeLayer(hc_landFuther);
  709. if(that.newZb.substring(0,1) =="{"){
  710. //that.newHt ="1";
  711. // var theGeomMap =this.message.replace("Point", "MultiPolygon");
  712. // var pointLeft = theGeomMap.replace("[", "[[[[");
  713. // var pointRight = pointLeft.replace("]", "]]]]");
  714. hc_landFuther = new ol.layer.Vector({
  715. title: "add Layer",
  716. source: new ol.source.Vector({
  717. projection: projection,
  718. features: new ol.format.GeoJSON().readFeatures("{\n" +
  719. " \"type\": \"Feature\",\n" +
  720. " \"geometry\":" + that.newZb + "}"),
  721. }),
  722. style: new ol.style.Style({
  723. fill: new ol.style.Fill({
  724. //矢量图层填充颜色,以及透明度
  725. color: "rgba(204, 255, 204,0.3)",
  726. }),
  727. stroke: new ol.style.Stroke({
  728. //边界样式
  729. color: "#CCFF66",
  730. width: 3,
  731. }),
  732. }),
  733. });
  734. //map.addLayer(hc_landFuther);
  735. var maxXMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.maxX;
  736. var maxYMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.maxY;
  737. var minXMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.minX;
  738. var minYMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.minY;
  739. //定位查询位置
  740. var center = ol.extent.getCenter([maxXMap, maxYMap, minXMap, minYMap]); //获取边界区域的中心位置
  741. that.map.getView().animate({
  742. // 只设置需要的属性即可
  743. center: center, // 中心点
  744. zoom: 17.9, // 缩放级别
  745. rotation: undefined, // 缩放完成view视图旋转弧度
  746. duration: 1000, // 缩放持续时间,默认不需要设置
  747. resolution:Math.random() * 0.00000001,
  748. });
  749. // let resolution = map.getView().getResolutionForExtent([maxXMap, maxYMap, minXMap, minYMap],map.getSize());
  750. // map.getView().fit([maxXMap, maxYMap, minXMap, minYMap]);
  751. // map.getView().setResolution(resolution);
  752. } else if(that.newZb.substring(0,1) =="["){
  753. //that.newHt ="1";
  754. var zbNew = JSON.stringify({"type": "MultiPolygon", "coordinates": [that.newZb.replaceAll("\"","")]});
  755. var leftJoin = zbNew.replace("\"[","[");
  756. var rightJoin = leftJoin.replace("\"]","]");
  757. hc_landFuther = new ol.layer.Vector({
  758. title: "add Layer",
  759. source: new ol.source.Vector({
  760. projection: projection,
  761. features: new ol.format.GeoJSON().readFeatures("{\n" +
  762. " \"type\": \"Feature\",\n" +
  763. " \"geometry\":" + rightJoin + "}"),
  764. }),
  765. style: new ol.style.Style({
  766. fill: new ol.style.Fill({
  767. //矢量图层填充颜色,以及透明度
  768. color: "rgba(204, 255, 204,0.3)",
  769. }),
  770. stroke: new ol.style.Stroke({
  771. //边界样式
  772. color: "#CCFF66",
  773. width: 3,
  774. }),
  775. }),
  776. });
  777. //map.addLayer(hc_landFuther);
  778. var maxXMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.maxX;
  779. var maxYMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.maxY;
  780. var minXMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.minX;
  781. var minYMap = hc_landFuther.values_.source.featuresRtree_.rbush_.data.minY;
  782. //定位查询位置
  783. var center = ol.extent.getCenter([maxXMap, maxYMap, minXMap, minYMap]); //获取边界区域的中心位置
  784. that.map.getView().animate({
  785. // 只设置需要的属性即可
  786. center: center, // 中心点
  787. zoom: 16.9, // 缩放级别
  788. rotation: undefined, // 缩放完成view视图旋转弧度
  789. duration: 1000, // 缩放持续时间,默认不需要设置
  790. resolution:Math.random() * 0.00000001,
  791. });
  792. // let resolution = map.getView().getResolutionForExtent([maxXMap, maxYMap, minXMap, minYMap],map.getSize());
  793. // map.getView().fit([maxXMap, maxYMap, minXMap, minYMap]);
  794. // map.getView().setResolution(resolution);
  795. } else {
  796. }
  797. //图层查询定位结束 ---------end
  798. });
  799. }
  800. });
  801. },
  802. },
  803. watch: {},
  804. };
  805. </script>
  806. <style scoped>
  807. #that.message {
  808. width: 100%;
  809. height: 100%;
  810. }
  811. .fuTitle {
  812. border-top: 1px solid #e9e9e9;
  813. text-align: center;
  814. padding: 10px 0px 0px 0px;
  815. font-size: 36px;
  816. color: #999;
  817. }
  818. .ant-btn-red {
  819. position: relative;
  820. display: inline-block;
  821. background: #D0EEFF;
  822. border: 1px solid #99D3F5;
  823. border-radius: 4px;
  824. padding: 4px 12px;
  825. overflow: hidden;
  826. color: #1E88C7;
  827. text-decoration: none;
  828. text-indent: 0;
  829. line-height: 20px;
  830. }
  831. #land-btn-wrap{
  832. position: absolute;
  833. right: 3%;
  834. top: 5%;
  835. z-index: 2000;
  836. }
  837. </style>