f6af96256a9029e0e0be1513d3ac9b228af8cced.svn-base 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. <!--地图主组件-->
  2. <template>
  3. <div id="mapContent" style="height:100%;">
  4. <!-- 地图容器 -->
  5. <div id="mapNode1" style="width:100%;height:100%;"></div>
  6. <!-- 名称弹窗 -->
  7. <div id="popup" class="ol-popup" style="display:none;">
  8. <!-- <a href="#" id="popup-closer" class="ol-popup-closer"></a>-->
  9. <div id="popup-content"></div>
  10. </div>
  11. <!-- 底图切换 -->
  12. <div id="baseMapContainer" style="color:#2C9EFF;box-shadow: 0 1px 6px 0 rgba(32, 33, 36, .28);position: absolute;right: 10px;top: 106px;width: 700px;display: flex;align-items: center;font-size:14px;background:white;">
  13. <img src="./assets/basemap.png" style="margin-left: 15px;">
  14. <el-select v-model="radio4" placeholder="请选择" @change="baseMapChange">
  15. <el-option
  16. v-for="item in mapOptions"
  17. :key="item.value"
  18. :label="item.label"
  19. :value="item.value">
  20. </el-option>
  21. </el-select>
  22. <span class="demonstration">日期</span>
  23. <el-select v-model="currentDate" @change="changeDate">
  24. <el-option
  25. v-for="(item,index) in dateOptions"
  26. :value="item.year+''">{{item.year}}
  27. </el-option>
  28. </el-select>
  29. <span class="demonstration">批次</span>
  30. <el-select v-model="currentBatch" @change="changeBatch">
  31. <el-option
  32. v-for="(item,index) in batchOption"
  33. :value="item.batch+''">{{item.label}}
  34. </el-option>
  35. </el-select>
  36. </div>
  37. <proPblmDetail v-if="proPblmVisible" :proPblmId="proPblmId" :title="proTitle" @closeDialog="closeDialog"></proPblmDetail>
  38. </div>
  39. </template>
  40. <script>
  41. import "ol/ol.css";
  42. import { getAdData,getCurrentAdData} from "../../api/duChaAPI.js";
  43. import {
  44. getYear,
  45. getBatch,
  46. } from "../../api/homeMainView.js";
  47. import {mapConfig} from './config/mapConfig.js'
  48. import {initProGraphic,pointMoveHandler,pointClickHandler} from '../zongHeXinXiOl/js/initProLayer.js'
  49. import {baseMapChangeHandler} from './js/baseMapChange.js' //底图切换
  50. import proPblmDetail from "../../views/home/proPblmDetail"
  51. import {xzqChange} from './js/xzqChange.js' //切换行政区
  52. export default {
  53. components: {
  54. proPblmDetail
  55. },
  56. data() {
  57. return {
  58. proPblmVisible:false,
  59. proPblmId:"",
  60. proTitle:"",
  61. dateOptions:[],
  62. currentDate:(new Date()).getFullYear()+'',
  63. batchOption:[],
  64. currentBatch:"",
  65. loading:true,
  66. radio4:'图层',//底图切换radiobutton
  67. mapObject:null,
  68. viewObject:null,
  69. fullExtent:'',
  70. initOptions:null,//各图层option
  71. popupDelay:'',//延时弹出
  72. currentRsCode:'1111111',
  73. currentStatus:'',
  74. currentLocation:'',
  75. zoomnext:'',
  76. currentExtent:'',
  77. timeInterval_people:'',//定时刷新人员
  78. currentChangeGraphicLayerId:'',//当前graphic类型变化的图层id
  79. currentChangeGraphicId:'',
  80. tileInfo:'',//高德切片信息
  81. biaojiFlag:false,
  82. showBiaojiTable:false,
  83. currentAdCode:'',
  84. leftLayersAddedList:[],//左侧图层已经添加列表 为一张图查询做支撑
  85. showSearchOneMapToolTip:false,//一张图查询开关
  86. showSearchOneMap:false,//一张图空间查询结果
  87. mapPointObj:null,
  88. bufferDistance1:10,//缓冲距离
  89. showRealTimeData:false,//水利一张图实时数据查询列表
  90. currentZoom:0,//当前底图level
  91. mapOptions:[
  92. // {
  93. // value: '影像',
  94. // label: '影像'
  95. // }, {
  96. // value: '谷歌',
  97. // label: '谷歌'
  98. // }, {
  99. // value: '高德',
  100. // label: '高德'
  101. // }
  102. ],
  103. menu_overlay:null,
  104. longLat:[],
  105. center:[],//地图 全国范围的center
  106. zoom:0,
  107. };
  108. },
  109. computed: {
  110. userId: function () {
  111. return localStorage.getItem("userid") ?localStorage.getItem("userid") : "1098101939614724096";
  112. }
  113. },
  114. watch: {},
  115. //生命周期 - 创建完成(可以访问当前this实例)
  116. created() {
  117. this.initYear();
  118. this.initBatch();
  119. },
  120. //生命周期 - 挂载完成(可以访问DOM元素)
  121. mounted() {
  122. var _self = this;
  123. if(mapConfig.provinceBaseLayer[localStorage.getItem('currentRlcode')]!=null){
  124. this.initOptions = mapConfig.provinceBaseLayer[localStorage.getItem('currentRlcode')].layer;
  125. this.center = mapConfig.provinceBaseLayer[localStorage.getItem('currentRlcode')].mapExtent.center;
  126. this.zoom = mapConfig.provinceBaseLayer[localStorage.getItem('currentRlcode')].mapExtent.zoom;
  127. }else{
  128. this.initOptions = (mapConfig.wkid == '3857' || mapConfig.wkid =='102100')?mapConfig.baseLayerOptions_ol_M:mapConfig.baseLayerOptions_ol;
  129. var mapArr = (mapConfig.wkid == '3857' || mapConfig.wkid =='102100')?[this.initOptions[0],this.initOptions[1]]:[this.initOptions[0],this.initOptions[1],this.initOptions[2]];
  130. this.initOptions = mapArr;
  131. this.center = (mapConfig.wkid == '3857' || mapConfig.wkid =='102100')?mapConfig.mapExtent_M.center:mapConfig.mapExtent.center;
  132. this.zoom = (mapConfig.wkid == '3857' || mapConfig.wkid =='102100')?mapConfig.mapExtent_M.zoom:mapConfig.mapExtent.zoom;
  133. }
  134. this.initOptions.forEach(item=>{
  135. _self.mapOptions.push({
  136. value:item.id,
  137. label:item.name
  138. })
  139. })
  140. this.initMap();
  141. },
  142. beforeCreate() {}, //生命周期 - 创建之前
  143. beforeMount() {}, //生命周期 - 挂载之前
  144. beforeUpdate() {}, //生命周期 - 更新之前
  145. updated() {}, //生命周期 - 更新之后
  146. beforeDestroy() {}, //生命周期 - 销毁之前
  147. destroyed() {}, //生命周期 - 销毁完成
  148. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  149. methods: {
  150. getAdData:function(){
  151. var adCode = localStorage.getItem('areacode') ? localStorage.getItem('areacode'): '000000000000';
  152. var _self = this;
  153. getAdData(adCode).then((response)=>{
  154. _self.nextLevelXzq = response.data;
  155. if(_self.nextLevelXzq.length){
  156. let item = _self.nextLevelXzq[0];
  157. if(item.adCode!=localStorage.getItem('currentRlcode')){
  158. getCurrentAdData(localStorage.getItem('currentRlcode')).then((response)=>{
  159. if(response.data){
  160. xzqChange(this,_self.mapObject,response.data,this.fullExtent);
  161. }
  162. });
  163. }else{
  164. xzqChange(this,_self.mapObject,item,this.fullExtent);
  165. }
  166. }
  167. });
  168. },
  169. closeDialog(){
  170. this.proPblmVisible = false;
  171. this.proPblmId = "";
  172. },
  173. changeDate(val){
  174. var _self = this;
  175. initProGraphic(_self);
  176. },
  177. changeBatch(val){
  178. var _self = this;
  179. initProGraphic(_self);
  180. },
  181. initYear(){
  182. var _self = this;
  183. _self.dateOptions = [];
  184. getYear().then((res) => {
  185. if(res!=null && res.data.length>0){
  186. _self.dateOptions = res.data;
  187. }
  188. });
  189. },
  190. initBatch(){
  191. var _self = this;
  192. _self.batchOption = [];
  193. getBatch().then((res) => {
  194. if(res!=null && res.data.length>0){
  195. _self.batchOption = res.data;
  196. for(var i = 0;i<_self.batchOption.length;i++){
  197. _self.batchOption[i].label = _self.batchOption[i].batch+'';
  198. }
  199. _self.batchOption.push({label:'全部',batch:''});
  200. }
  201. });
  202. },
  203. initMap(){//初始化地图
  204. var _self = this;
  205. var ol = _self.$ol;
  206. var resolutions =null;
  207. var matrixIds = null;
  208. var projection = null;
  209. var projectionExtent = null;
  210. var tileGrid = null;
  211. var origin = null;
  212. var fullExtent = [];
  213. var view = new ol.View({
  214. center:_self.center,
  215. zoom:_self.zoom,
  216. maxZoom:18,
  217. minZoom:0
  218. });
  219. if(localStorage.getItem('currentRlcode')=="430000000000"){
  220. resolutions = mapConfig.resolutions;
  221. matrixIds = mapConfig.matrixIds;
  222. projection = ol.proj.get("EPSG:4326");
  223. projectionExtent = projection.getExtent();
  224. // 水利一张图 湖南底图
  225. tileGrid = new ol.tilegrid.TileGrid({
  226. origin: ol.extent.getTopLeft(projectionExtent), //原点(左上角)
  227. resolutions: resolutions, //分辨率数组
  228. matrixIds: matrixIds //矩阵标识列表,与地图级数保持一致
  229. });
  230. }
  231. if(localStorage.getItem('currentRlcode')=="330000000000"){
  232. resolutions = mapConfig.resolutions_zhejiang;
  233. projection = ol.proj.get('EPSG:4490');
  234. origin = [-180.0, 90.0];
  235. fullExtent = [
  236. 118.02252237300922,
  237. 27.029697618000057,
  238. 123.2499368190001,
  239. 31.182560451903395
  240. ];
  241. tileGrid = new ol.tilegrid.TileGrid({
  242. tileSize: 256,
  243. origin: origin,
  244. resolutions: resolutions
  245. });
  246. view = new ol.View({
  247. center:_self.center,
  248. resolutions: resolutions,
  249. zoom:_self.zoom,
  250. projection: projection,
  251. extent: fullExtent
  252. });
  253. }
  254. var layers = [];
  255. _self.initOptions.forEach((item)=>{//所有底图
  256. if(item.type == 'supermap'){
  257. var lyr = new ol.layer.Tile({
  258. id:item.id,
  259. source: new ol.source.XYZ({
  260. projection:'EPSG:4326',
  261. tileGrid: tileGrid,
  262. tileUrlFunction: function (tileCoord) {
  263. var z = tileCoord[0];
  264. var x = tileCoord[1];
  265. var y = -tileCoord[2]-1;
  266. return item.urlTemplate+"&FORMAT=image/png&tilecol="+x+"&tilerow="+y+"&tilematrix="+z;
  267. },
  268. wrapX: true,
  269. }),
  270. name: item.name,
  271. visible:item.visible
  272. });
  273. layers.push(lyr)
  274. }else if(item.type == 'tdtLayer'){
  275. var lyr = new ol.layer.Tile({
  276. id:item.id,
  277. source: new ol.source.XYZ({
  278. projection:(mapConfig.wkid == '3857' || mapConfig.wkid =='102100')? 'EPSG:3857': 'EPSG:4326',
  279. crossOrigin: 'anonymous',
  280. url: item.urlTemplate
  281. }),
  282. name: item.name,
  283. visible:item.visible
  284. });
  285. layers.push(lyr)
  286. }else if(item.type == 'mapServer'){
  287. var lyr = new ol.layer.Image({
  288. source: new ol.source.ImageArcGISRest({
  289. ratio: 1,
  290. params: {},
  291. url: item.urlTemplate
  292. }),
  293. id:item.id,
  294. name: item.name,
  295. visible:item.visible
  296. })
  297. layers.push(lyr);
  298. }else if(item.type == 'wp'){
  299. var lyr = new ol.layer.Tile({
  300. source: new ol.source.XYZ({
  301. tileGrid: tileGrid,
  302. projection: projection,
  303. url:item.urlTemplate
  304. }),
  305. id:item.id,
  306. name: item.name,
  307. visible:item.visible
  308. })
  309. layers.push(lyr);
  310. }else if(item.type == "xjbt"){
  311. var resolutions = new Array(17);
  312. var matrixIds = new Array(17);
  313. for (var z = 0; z < 17; ++z) {
  314. resolutions[z] = 156543.033928041 / Math.pow(2, z);
  315. matrixIds[z] = z;
  316. }
  317. var layer = new ol.layer.Tile({
  318. source: new ol.source.WMTS({
  319. url: item.urlTemplate,
  320. layer: 'AD_R_20210419',
  321. matrixSet: 'GoogleMapsCompatible_AD_R_20210419',
  322. format: 'image/png',
  323. tileGrid: new ol.tilegrid.WMTS({
  324. origin: [-2.0037508342787E7,2.0037508342787E7],
  325. extent:[-2.0037508342789244E7, -2.0037508342789203E7 ,2.0037508342789244E7, 2.003750834278921E7],
  326. resolutions: resolutions,
  327. matrixIds: matrixIds
  328. })
  329. })
  330. })
  331. layers.push(layer);
  332. }
  333. })
  334. this.$nextTick(() => {
  335. });
  336. _self.mapObject = new ol.Map({
  337. layers:layers,
  338. view:view,
  339. target:'mapNode1'
  340. });
  341. _self.mapObject.on('click',_self.mapClickHandle);//点击事件
  342. _self.mapObject.on('pointermove',_self.pointMoveHandle);//地图移动事件
  343. initProGraphic(_self);
  344. _self.getAdData();
  345. },
  346. //地图点击事件
  347. mapClickHandle(e){
  348. var _self = this;
  349. var features = _self.mapObject.getFeaturesAtPixel(e.pixel);
  350. if(features){
  351. if(features[0].getProperties().layerId){
  352. pointClickHandler(_self,features[0].getProperties());
  353. }
  354. }
  355. },
  356. //鼠标移动事件
  357. pointMoveHandle(e){
  358. var _self = this;
  359. var overlay = _self.mapObject.getOverlayById('overlayId');
  360. if(overlay){
  361. if(document.getElementById('popup')){
  362. document.getElementById('popup').style.display = 'none'
  363. }
  364. }
  365. var features = _self.mapObject.getFeaturesAtPixel(e.pixel);
  366. if(features){
  367. if(features[0].getProperties().layerId){
  368. pointMoveHandler(_self,features[0].getProperties(),e);
  369. }
  370. }
  371. },
  372. // 底图切换处理方法
  373. baseMapChange(val){//底图切换
  374. baseMapChangeHandler(this.mapObject,val);
  375. }
  376. },
  377. }
  378. </script>
  379. <style>
  380. /*@import url(); 引入公共css类*/
  381. .ol-popup {
  382. position: absolute;
  383. background-color: white;
  384. -webkit-filter: drop-shadow(0 1px 4px rgba(0,0,0,0.2));
  385. filter: drop-shadow(0 1px 4px rgba(0,0,0,0.2));
  386. padding: 10px;
  387. border-radius: 10px;
  388. border: 1px solid #cccccc;
  389. bottom: 12px;
  390. left: -49px;
  391. min-width: 80px;
  392. text-align: center;
  393. z-index: 100;
  394. }
  395. .ol-popup:after, .ol-popup:before {
  396. top: 100%;
  397. border: solid transparent;
  398. content: " ";
  399. height: 0;
  400. width: 0;
  401. position: absolute;
  402. pointer-events: none;
  403. }
  404. .ol-popup:after {
  405. border-top-color: white;
  406. border-width: 10px;
  407. left: 48px;
  408. margin-left: -10px;
  409. }
  410. .ol-popup:before {
  411. border-top-color: #cccccc;
  412. border-width: 11px;
  413. left: 48px;
  414. margin-left: -11px;
  415. }
  416. .ol-popup-closer {
  417. text-decoration: none;
  418. position: absolute;
  419. top: 2px;
  420. right: 8px;
  421. }
  422. .ol-popup-closer:after {
  423. content: "✖";
  424. }
  425. #baseMapContainer .el-input__inner{
  426. color:#2C9EFF;
  427. font-size: 14px;
  428. border: 0px !important;
  429. }
  430. #mapContent .el-select .el-input .el-select__caret{
  431. color:#2C9EFF;
  432. }
  433. .rightMenuClass{
  434. left: 3px;
  435. position: absolute;
  436. background-color: #ffffffad;
  437. width: 90px;
  438. border: 1px solid #8c8b8b;
  439. box-shadow: 0 2px 15px 2px rgba(0, 0, 0, 0.6);
  440. border-radius: 13px;
  441. padding: 10px;
  442. border-top-left-radius: 0px;
  443. }
  444. .rightMenuClass p{
  445. padding: 3px 3px;
  446. margin: 0px 2px;
  447. line-height: 17px;
  448. width: 84px;
  449. color: rgb(101, 101, 101);
  450. cursor: pointer;
  451. /* border-bottom: 1px solid #bbb; */
  452. }
  453. </style>