index.vue 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096
  1. <template>
  2. <div style="width:100%;height:100%">
  3. <div style="width:100%;height:100%">
  4. <div id="map" ref="rootmap"><div id="popup"></div></div>
  5. <!-- <div id="textInfo" style="display:none">我是text文本信息</div> -->
  6. </div>
  7. <div class="iconSelect" v-if="iconSelect == 1">
  8. <el-checkbox-group v-model="checkList" @change="handleChange" >
  9. <el-checkbox v-for="item in dict.type.tl_static_type" :label="item.value" :key="item.value" style="margin-top:1rem">
  10. <!-- <img class="tipicon" src="../../assets/images/icons/video.png" /> -->
  11. <img class="tipicon" :src="imageMap[item.value]" />
  12. <span style="color:white">{{item.label}}</span>
  13. </el-checkbox>
  14. </el-checkbox-group>
  15. </div>
  16. <div class="iconSelect" v-if="iconSelect == 2">
  17. <el-checkbox-group v-model="checkList" @change="handleChange" >
  18. <el-checkbox v-for="item in dict.type.tl_dt_type" :label="item.raw.cssClass" :key="item.value" style="margin-top:1rem">
  19. <!-- <img class="tipicon" src="../../assets/images/icons/video.png" /> -->
  20. <img class="tipicon" :src="imageMap[item.raw.cssClass]" />
  21. <span style="color:white">{{item.label}}</span>
  22. </el-checkbox>
  23. </el-checkbox-group>
  24. </div>
  25. <div class="iconSelect" v-if="iconSelect == 3">
  26. <el-checkbox-group v-model="checkList" @change="handleChange" >
  27. <el-checkbox v-for="item in dict.type.tl_area_type" :label="item.raw.cssClass" :key="item.value" style="margin-top:1rem">
  28. <!-- <img class="tipicon" src="../../assets/images/icons/video.png" /> -->
  29. <img class="tipicon" :src="imageMap[item.raw.cssClass]" />
  30. <span style="color:white">{{item.label}}</span>
  31. </el-checkbox>
  32. </el-checkbox-group>
  33. </div>
  34. <div class='locationDiv' :style="locationStyle" v-show='isShow'>
  35. <div style="background:blue;height:4rem;width:100%;padding-top:0.8rem;padding-left:0.5rem">
  36. <span style='color:white;font-size:1.5rem;'>巡检点</span>
  37. </div>
  38. <div style="text-align:center;margin-top:0.5rem">
  39. <img :src='clickObj.imgsrc' style="width:20rem;height:20rem"/>
  40. <div>{{clickObj.name}}</div>
  41. </div>
  42. </div>
  43. <el-dialog
  44. title="视频播放"
  45. :visible.sync="dialogVisible"
  46. v-if="dialogVisible"
  47. width="50%"
  48. :before-close="handleClose"
  49. >
  50. <div style="width:100%;height:60rem;position:relative">
  51. <videodiv :cameracode="ccode" style="width:100%;height:100%;position:absolute;top:0;left:0"></videodiv>
  52. </div>
  53. <span slot="footer" class="dialog-footer">
  54. <el-button @click="handleClose()">关闭</el-button>
  55. <!-- <el-button type="primary" @click="dialogVisible = false">确 定</el-button> -->
  56. </span>
  57. </el-dialog>
  58. <el-dialog
  59. title="视频播放ckplayer"
  60. :visible.sync="dialogVisibleCk"
  61. v-if="dialogVisibleCk"
  62. width="50%"
  63. :before-close="handleCloseCk"
  64. >
  65. <div style="width:100%;height:60rem;position:relative">
  66. <div class="video" id="video" style="width:100%;height:100%;position:absolute;top:0;left:0"></div>
  67. <!-- <videodiv :cameracode="ccode" style="width:100%;height:100%;position:absolute;top:0;left:0"></videodiv> -->
  68. </div>
  69. <span slot="footer" class="dialog-footer">
  70. <el-button @click="handleCloseCk()">关闭</el-button>
  71. <!-- <el-button type="primary" @click="dialogVisible = false">确 定</el-button> -->
  72. </span>
  73. </el-dialog>
  74. </div>
  75. </template>
  76. <script>
  77. import "ol/ol.css";
  78. import Map from "ol/Map";
  79. // import TileLayer from "ol/layer/Tile";
  80. // import ImageLayer from "ol/layer/Image";
  81. import View from "ol/View";
  82. // import ol from "ol";
  83. import {getTopLeft, getWidth} from "ol/extent";
  84. // import ImageWMS from "ol/source/ImageWMS";
  85. import WMTS from "ol/source/WMTS";
  86. // import TileWMS from "ol/source/TileWMS";
  87. import WMTSTileGrid from "ol/tilegrid/WMTS";
  88. // ol.source.TileImage
  89. // ol.layer.Tile
  90. import {get as getProjection, transform} from "ol/proj";
  91. import {TileGrid} from "ol/tilegrid/TileGrid";
  92. import {TileImage} from "ol/source/TileImage";
  93. import {XYZ, Vector as SourceVec} from "ol/source";
  94. import {Tile,Vector as LayerVec} from "ol/layer";
  95. import { Polygon } from "ol/geom"
  96. import Overlay from 'ol/Overlay';
  97. import {Circle as CircleStyle, Fill, Stroke, Style, Icon, Text } from 'ol/style';
  98. import {Draw, Modify, Snap} from 'ol/interaction';
  99. // import {OSM, Vector as SourceVec} from 'ol/source';
  100. // import {Tile as TileLayer, Vector as LayerVec} from 'ol/layer';
  101. import {get,fromLonLat } from 'ol/proj';
  102. import { Feature } from "ol";
  103. // import {Vector as SourceVec} from "ol/source";
  104. // import {Feature} from "ol";
  105. import videodiv from "@/components/Videoplayer/index.vue"
  106. import { getResource } from "@/api/qdtl/data";
  107. import {LineString, Point} from "ol/geom";
  108. import { scale } from 'ol/coordinate';
  109. import { getLineData,getVideoHttp } from "@/api/qdtl/data";
  110. import {toStringHDMS} from 'ol/coordinate';
  111. // import {Icon, Stroke, Style} from "ol/style";
  112. // import {Vector as LayerVec} from "ol/layer";
  113. export default {
  114. props: {
  115. pointObj:{type:Object},
  116. isEdit:false,
  117. isLine:false,
  118. // lineLocations:{type:Array,default:[]},
  119. },
  120. dicts: ['tl_static_type','tl_area_type','tl_dt_type'],
  121. data() {
  122. return {
  123. locationStyle:'left:85.5rem;top:71.1rem',
  124. clickObj:{},
  125. iconSelectArea:true,
  126. isShow:false,
  127. iconSelect:0,
  128. checkList:[],
  129. map: null,
  130. typeSelect:'Point',
  131. source:null,
  132. draw:null,
  133. snap:null,
  134. locations:[],
  135. vector:null,
  136. pointArry:{},
  137. mapHashMap:{},
  138. deviceList:[],
  139. Base64:require('js-base64').Base64,
  140. areaList:[],
  141. dialogVisible:false,
  142. ccode:'',
  143. dialogVisibleCk:false,
  144. imgBg:require('../../assets/images/imgBg.jpg'),
  145. imgSrc:'require(../../assets/images/icons/',
  146. imgtype:'.png)',
  147. imageMap:{
  148. video:require('../../assets/images/icons/video.png'),
  149. location:require('../../assets/images/icons/location.png'),
  150. stop:require('../../assets/images/icons/stop.png'),
  151. work:require('../../assets/images/icons/work.png'),
  152. area:require('../../assets/images/icons/area.png'),
  153. bridge:require('../../assets/images/icons/bridge.png'),
  154. train:require('../../assets/images/icons/train.png'),
  155. rail:require('../../assets/images/icons/rail.png'),
  156. yjdw:require('../../assets/images/icons/yjdw.png'),
  157. device:require('../../assets/images/icons/device.png'),
  158. police:require('../../assets/images/icons/police.png'),
  159. wrj:require('../../assets/images/icons/wrj.png'),
  160. yxjl:require('../../assets/images/icons/yxjl.png'),
  161. },
  162. popup:null,
  163. element:null
  164. };
  165. },
  166. components:{
  167. videodiv
  168. },
  169. watch:{
  170. iconSelect(val, oldVal){//普通的watch监听
  171. this.checkList = [];
  172. for(var key in this.mapHashMap){
  173. this.mapHashMap[key].setVisible(false)
  174. }
  175. for(var index in this.deviceList){
  176. this.deviceList[index].setVisible(false)
  177. }
  178. for(var index in this.areaList){
  179. this.areaList[index].setVisible(false)
  180. }
  181. },
  182. },
  183. mounted() {
  184. this.initdev();
  185. this.initPoint();
  186. // this.getTrain(),
  187. this.getLineList();
  188. this.addQdStation();
  189. window.videosize = "1x1";
  190. // this.addpoint(point);
  191. var that = this
  192. if(this.isLine){
  193. this.getResource();
  194. }
  195. this.map.on("click", function (e) {
  196. // console.log(event.screenX+','+event.screenY)
  197. // that.addMarker(e.coordinate,'专家站点.png',0.2);
  198. var pixel = that.map.getEventPixel(e.originalEvent);
  199. var feature = that.map.forEachFeatureAtPixel(e.pixel, function (feature, layer) {
  200. return feature;
  201. });
  202. if (feature) { //这里说明我们点击的是点标记,
  203. let tadata = feature.get("tadata"); //我们可以通过给点标记传不同的值,来判断点击不同的点标记触发的事件。
  204. if (tadata) {
  205. if (tadata.sectionId == "line") {
  206. // alert("我是线:" + tadata.towerNumber)
  207. }
  208. if (tadata.sectionId == "point") {
  209. if(tadata.type == 'location'){
  210. var event = window.event;
  211. var x = event.screenX/10+5;
  212. var y = event.screenY/10-20;
  213. console.log(x+','+y);
  214. that.locationStyle='top:'+y+'rem;left:'+x+'rem'
  215. console.log(that.locationStyle);
  216. that.clickObj = tadata.data
  217. // console.log(tadata.pic);
  218. that.clickObj.imgsrc = 'http://58.221.168.61:9000/api'+tadata.data.pic
  219. that.isShow = true
  220. }
  221. if(tadata.type == 'video'){
  222. that.ccode = tadata.data.cameraIndexCode
  223. window.cameraid = that.ccode;
  224. that.dialogVisible = true
  225. setTimeout(() => {
  226. that.handleOpen()
  227. }, 1000);
  228. }
  229. if(tadata.type == 'wrj'){
  230. // that.ccode = tadata.data.cameraIndexCode
  231. // window.cameraid = that.ccode;
  232. // console.log(tadata.data);
  233. that.dialogVisibleCk = true
  234. setTimeout(() => {
  235. that.loadCkplayer(tadata.data.video)
  236. }, 1000);
  237. }
  238. if(that.isLine){
  239. if(tadata.type == 'selected'){
  240. var style = new Style({
  241. image: new Icon({
  242. color: "#eee",
  243. crossOrigin: "anonymous",
  244. src: require("../../assets/images/icons/location.png"), //本地的样式
  245. scale:0.6
  246. })
  247. })
  248. tadata.type = 'location'
  249. feature.setStyle(style);
  250. that.locationDelete(tadata.data);
  251. }else{
  252. var style = new Style({
  253. image: new Icon({
  254. color: "#eee",
  255. crossOrigin: "anonymous",
  256. src: require("../../assets/images/icons/location2.png"), //本地的样式
  257. scale:0.6
  258. })
  259. })
  260. tadata.data.sortNo = that.lineLocations.length + 1
  261. tadata.data.locationId = tadata.data.id
  262. that.lineLocations.push(tadata.data);
  263. tadata.type = 'selected'
  264. feature.setStyle(style);
  265. }
  266. }
  267. }
  268. //含有lnglat 参数的点标记触发事件
  269. }
  270. }
  271. });
  272. var view = this.map.getView();
  273. view.on('change:resolution', function (e) {
  274. });
  275. view.on('change:center', function (e) {
  276. });
  277. this.map.on('moveend', function (e) {
  278. });
  279. // this.map.on('pointermove', function (evt) {
  280. // if (evt.dragging) {
  281. // return;
  282. // }
  283. // const pixel = that.map.getEventPixel(evt.originalEvent);
  284. // var feature = that.map.forEachFeatureAtPixel(evt.pixel, function (feature, layer) {
  285. // return feature;
  286. // });
  287. // if (feature) { //这里说明我们点击的是点标记,
  288. // let tadata = feature.get("tadata"); //我们可以通过给点标记传不同的值,来判断点击不同的点标记触发的事件。
  289. // if (tadata) {
  290. // if (tadata.sectionId == "line") {
  291. // // alert("我是线:" + tadata.towerNumber)
  292. // }
  293. // if (tadata.sectionId == "point") {
  294. // // that.addText(evt.coordinate);
  295. // // console.log(tadata);
  296. // $(that.element).popover('dispose');
  297. // that.popup.setPosition(evt.coordinate);
  298. // if(tadata.data.pic){
  299. // // var src = 'http://58.221.168.61:9000/api/common/download/resource?resource=/profile/bx/1.jpg'
  300. // var src = 'http://58.221.168.61:9000/api'+tadata.data.pic
  301. // $(that.element).popover({
  302. // placement: 'top',
  303. // html: true,
  304. // content: '<div><div class="imgClass" style="width:10rem;height:10rem"><img style="width:10rem;height:10rem" src="'+src+'" class="imgClass"/></div><br/><span style="text-align:center">'+tadata.data.name+'</span></div>',
  305. // });
  306. // }else{
  307. // $(that.element).popover({
  308. // placement: 'top',
  309. // html: true,
  310. // content: '<div><img src="'+that.imgBg+'" style="width:5rem;height:5rem"/><br/><span style="text-align:center">'+tadata.data.name+'</span></div>',
  311. // });
  312. // }
  313. // $(that.element).popover('show');
  314. // // } else {
  315. // // $(element).popover('dispose');
  316. // // }
  317. // // popup = new OpenLayers.Popup.FramedCloud("Popup",
  318. // // new OpenLayers.LonLat(5.6, 50.6),
  319. // // null,
  320. // // '<div>Hello World! Put your html here</div>',
  321. // // null,
  322. // // false);
  323. // // this.map.addPopup(popup);
  324. // }else{
  325. // // console.log(1111111);
  326. // $(that.element).popover('dispose');
  327. // }
  328. // //含有lnglat 参数的点标记触发事件
  329. // }
  330. // }
  331. // })
  332. },
  333. methods: {
  334. addQdStation(){
  335. var station = [121.67994923828125,31.85240474572754]
  336. this.addMarkerQd(station,'station.png',0.6,'marker');
  337. var nqLine = [121.57008595703125,31.875750692993165]
  338. this.addMarker(nqLine,'宁启铁路二期.png',1,'marker');
  339. var ylLine = [121.54948659179688,32.08243099084473]
  340. this.addMarker(ylLine,'洋吕铁路在建.png',1,'marker');
  341. },
  342. locationDelete(data){
  343. for(var index in this.lineLocations){
  344. if(this.lineLocations[index].locationId == data.locationId){
  345. this.lineLocations.splice(index,1);
  346. }else if(this.lineLocations[index].sortNo > data.sortNo){
  347. this.lineLocations[index].sortNo = this.lineLocations[index].sortNo-1
  348. }
  349. }
  350. },
  351. loadCkplayer(url){
  352. url = 'rtmp://39.104.22.45:30498/rtp/34020001001320000001_34020001001320000001'
  353. console.log(url);
  354. url = this.Base64.encode(url);
  355. console.log(url);
  356. getVideoHttp(url).then(data=>{
  357. console.log(process.env.NODE_ENV)
  358. if(process.env.NODE_ENV === "production"){
  359. data.data = (data.data+"").replaceAll("http://58.221.168.61:9000/",process.env.VUE_APP_BASE_API)
  360. }
  361. console.log(data.data)
  362. var videoObject = {
  363. container: '.video', //“#”代表容器的ID,“.”或“”代表容器的class
  364. variable: 'player', //播放函数名称,该属性必需设置,值等于下面的new ckplayer()的对象
  365. autoplay:true,
  366. live:true,
  367. overspread:true,//是否让视频铺满播放器
  368. html5m3u8:true,//m3u8-hls形式播放视频
  369. // video: 'rtmp://58.200.131.2:1935/livetv/cctv1'//视频地址
  370. video:data.data//视频地址
  371. // video:'http://39.104.22.45:8089/rtp/34020001001320000001_34020001001320000001/hls.m3u8'
  372. };
  373. console.log(videoObject);
  374. window.player = new ckplayer(videoObject);
  375. })
  376. },
  377. getResource(){
  378. getResource({date:'2022-03-12'}).then(response =>{
  379. var selectLocation = [];
  380. var stationLocation = [];
  381. if(this.lineLocations != null){
  382. for(var index in this.lineLocations){
  383. var obj = this.lineLocations[index]
  384. obj.fence = obj.lnglat
  385. obj.name = obj.locationName
  386. selectLocation.push(obj)
  387. }
  388. }
  389. for(var i in response.data.staticLocation){
  390. var obj = response.data.staticLocation[i]
  391. obj.fence = obj.lnglat
  392. obj.name = obj.locationName
  393. obj.locationId = obj.id
  394. var isSelected = 0;
  395. for(var j in selectLocation){
  396. if(obj.id == selectLocation[j].locationId){
  397. isSelected = 1
  398. }
  399. }
  400. if(isSelected == 0){
  401. stationLocation.push(obj)
  402. }
  403. }
  404. this.addPoints(stationLocation,'location.png',0.6,'location');
  405. this.addPoints(selectLocation,'location2.png',0.6,'selected');
  406. })
  407. },
  408. // addText(location) {
  409. // var textInfo = new Overlay({
  410. // position: fromLonLat(location),
  411. // offset: [20, -20],
  412. // element: document.getElementById("textInfo")
  413. // });
  414. // this.map.addOverlay(textInfo);
  415. // },
  416. getTrain(){
  417. var trainArry = [[121.645366,31.856052],[121.636002,32.02354],[121.530258,32.086391]];
  418. for(var index in trainArry){
  419. this.addMarker(trainArry[index],'train.png',0.6,'marker');
  420. }
  421. },
  422. getLineList(){
  423. getLineData().then(data =>{
  424. for(var index in data.data){
  425. var obj = data.data[index]
  426. if(obj.configKey.indexOf('lined') > -1){
  427. var lineLocations ="["+obj.configValue+"]"
  428. var json = JSON.parse(lineLocations);
  429. this.addline(json,'nqtl');
  430. }else if(obj.configKey.indexOf('lineun') > -1){
  431. var lineLocations ="["+obj.configValue+"]"
  432. var json = JSON.parse(lineLocations);
  433. this.addline(json,'nqtl2');
  434. }
  435. }
  436. })
  437. },
  438. transpoints: function (points, type) {
  439. if (type == 0) {
  440. return points;
  441. } else {
  442. if (type == 1) {
  443. var pp = [];
  444. points.forEach(point => {
  445. pp.push(transform([parseFloat(point[0]),parseFloat(point[1])], "EPSG:3857", "EPSG:4326"));
  446. });
  447. return pp;
  448. } else {
  449. var pp = [];
  450. points.forEach(point => {
  451. pp.push(transform([parseFloat(point[0]),parseFloat(point[1])], "EPSG:4326", "EPSG:3857"));
  452. });
  453. return pp;
  454. }
  455. }
  456. },
  457. initdev: function () {
  458. function getWMTSLayer(url, layer) {
  459. let key = "98ec3e37b32974c2d58ea1a790640fe7"
  460. let projection = getProjection("EPSG:4326");
  461. let projectionExtent = projection.getExtent();
  462. let size = getWidth(projectionExtent) / 256;
  463. function getResolutions() {
  464. let resolutions = [];
  465. for (let z = 1; z < 19; ++z) {
  466. resolutions[z] = size / Math.pow(2, z);
  467. }
  468. return resolutions
  469. }
  470. return new Tile({
  471. source: new WMTS({
  472. url: url,
  473. layer: layer,
  474. style: "default",
  475. matrixSet: "c",
  476. format: "tiles",
  477. tileGrid: new WMTSTileGrid({
  478. origin: getTopLeft(projectionExtent),
  479. resolutions: getResolutions(),
  480. matrixIds: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
  481. }),
  482. }),
  483. })
  484. }
  485. var projection = getProjection("EPSG:4326");
  486. const satellite = new Tile({ // 卫星地图
  487. visible: false, // 显示或隐藏(用于切换地图图层(卫星切换街道))
  488. source: new XYZ({
  489. attributions: '',
  490. url: 'https://webst0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=6&x={x}&y={y}&z={z}&scl=1&ltype=10'
  491. })
  492. })
  493. const street = new Tile({ // 街道地图
  494. visible: true, // 显示或隐藏(用于切换地图图层(卫星切换街道))
  495. source: new XYZ({
  496. attributions: '',
  497. url: 'https://webst0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}'
  498. })
  499. })
  500. this.source = new SourceVec();
  501. const vector = new LayerVec({
  502. source: this.source,
  503. style: new Style({
  504. fill: new Fill({
  505. color: 'rgba(255, 255, 255, 0.2)',
  506. }),
  507. stroke: new Stroke({
  508. color: '#ffcc33',
  509. width: 2,
  510. }),
  511. image: new CircleStyle({
  512. radius: 7,
  513. fill: new Fill({
  514. color: '#ffcc33',
  515. }),
  516. }),
  517. }),
  518. });
  519. this.vector = vector;
  520. // 创建地图
  521. const map = new Map({
  522. target: 'map',
  523. layers: [ // 图层放置(类似有卫星图层,街道图层等)
  524. // satellite,
  525. getWMTSLayer(`${process.env.VUE_APP_MAP_URL}img_c/wmts?tk=98ec3e37b32974c2d58ea1a790640fe7`, 'img'),
  526. getWMTSLayer(`${process.env.VUE_APP_MAP_URL}cia_c/wmts?tk=98ec3e37b32974c2d58ea1a790640fe7`, 'cia'),
  527. // getWMTSLayer('https://gisserver.tianditu.gov.cn/TDTService/wfs?tk=98ec3e37b32974c2d58ea1a790640fe7', 'LRDL'),
  528. // satellite,street,
  529. //
  530. vector
  531. ],
  532. view: new View({
  533. zoom: 12, // 当前缩放
  534. // maxZoom: 16, // 最大缩放
  535. // minZoom: 8, // 最小缩放
  536. // projection: projection,
  537. projection: 'EPSG:4326',
  538. // center: this.transpoints([
  539. // [121.65523,31.892831]
  540. // ], 0)[0], // 中心坐标
  541. center:[121.65523,31.892831]
  542. })
  543. })
  544. street.setVisible(false)
  545. satellite.setVisible(true)
  546. const modify = new Modify({source: this.source});
  547. map.addInteraction(modify);
  548. this.map = map;
  549. if(this.isEdit){
  550. this.addInteractions();
  551. }
  552. var that = this;
  553. this.element = document.getElementById('popup');
  554. this.popup = new Overlay({
  555. element: this.element,
  556. positioning: 'bottom-center',
  557. stopEvent: false,
  558. });
  559. this.map.addOverlay(this.popup);
  560. },
  561. addInteractions() {
  562. var that = this
  563. let draw = new Draw({
  564. source: this.source,
  565. type: this.typeSelect,
  566. });
  567. draw.on('drawend',that.getLocation,this);
  568. draw.on('drawstar',that.removeDraw,this);
  569. // draw.on('drawstart',that.removeDraw,this);
  570. this.draw = draw;
  571. this.map.addInteraction(draw);
  572. let snap = new Snap({source: this.source});
  573. this.snap = snap;
  574. this.map.addInteraction(snap);
  575. },
  576. getLocation(evt){
  577. var feature = evt.feature;
  578. var geo = feature.getGeometry();
  579. var cor = geo.getCoordinates();
  580. this.locations = cor;
  581. },
  582. changeAddInteractions(evt) {
  583. this.map.removeInteraction(this.draw);
  584. this.map.removeInteraction(this.snap);
  585. this.addInteractions();
  586. },
  587. removeDraw(evt){
  588. if(this.locations.length > 0){
  589. this.vector.getSource().clear()
  590. }
  591. },
  592. removeLayer(id){
  593. var layers = this.pointArry[id];
  594. this.map.removeLayer(layers);
  595. },
  596. addMarker(lnglats,icon,size) {
  597. let tamarker = new Feature({
  598. tadata: {
  599. sectionId: "point",
  600. towerNumber: 22,
  601. }, //这里是用来传值用的,在接下来的一章里(事件)中我会讲到。
  602. geometry: new Point(lnglats) //这里是点坐标的位置,这里要注意fromLonLat
  603. });
  604. tamarker.setStyle(
  605. new Style({
  606. image: new Icon({
  607. color: "#eee",
  608. crossOrigin: "anonymous",
  609. src: require("../../assets/images/icons/" + icon), //本地的样式
  610. scale:size
  611. }),
  612. },
  613. )
  614. ); //这里是样式
  615. var markerta = new LayerVec({
  616. source: new SourceVec({
  617. features: [tamarker] //这里放的就是之前的那个点,如果要放置多个点直接push到这里面就行了
  618. }),
  619. zIndex:30
  620. });
  621. // this.pointArry[id]=markerta;
  622. this.map.addLayer(markerta); //这里是执行,执行之后点就出来了
  623. },
  624. addMarkerQd(lnglats,icon,size,id,data,type) {
  625. let tamarker = new Feature({
  626. tadata: {
  627. sectionId: "point",
  628. towerNumber: 22,
  629. data: data ,
  630. type: type
  631. }, //这里是用来传值用的,在接下来的一章里(事件)中我会讲到。
  632. geometry: new Point(lnglats) //这里是点坐标的位置,这里要注意fromLonLat
  633. });
  634. tamarker.setStyle(
  635. new Style({
  636. image: new Icon({
  637. color: "#eee",
  638. crossOrigin: "anonymous",
  639. src: require("../../assets/images/icons/" + icon), //本地的样式
  640. scale:size
  641. }),
  642. text: new Text({
  643. text: '启东站',
  644. font: '16px sans-serif',
  645. textAlign: "center",
  646. textBaseline: "middle",
  647. //font: 'verdana',
  648. fill: new Fill({
  649. color: "blue"
  650. }),
  651. backgroundFill: new Fill({
  652. color: "rgba(220,38,38,0.2)"
  653. }),
  654. stroke: new Stroke({
  655. color: "#ffffff"
  656. // width: 3
  657. }),
  658. // font: "10px sans-serif",
  659. // offsetX: parseInt(0, 10),
  660. offsetY: 25,
  661. placement: "point", //point 则自动计算面的中心k点然后标注 line 则根据面要素的边进行标注
  662. overflow: false //超出面的部分不显示
  663. })
  664. },
  665. )
  666. ); //这里是样式
  667. var markerta = new LayerVec({
  668. source: new SourceVec({
  669. features: [tamarker] //这里放的就是之前的那个点,如果要放置多个点直接push到这里面就行了
  670. }),
  671. zIndex:30
  672. });
  673. this.pointArry[id]=markerta;
  674. this.map.addLayer(markerta); //这里是执行,执行之后点就出来了
  675. },
  676. addMarkerVideo(lnglats,icon,size,id,data,type) {
  677. let tamarker = new Feature({
  678. tadata: {
  679. sectionId: "point",
  680. towerNumber: 22,
  681. data: data ,
  682. type: type
  683. }, //这里是用来传值用的,在接下来的一章里(事件)中我会讲到。
  684. geometry: new Point(lnglats) //这里是点坐标的位置,这里要注意fromLonLat
  685. });
  686. tamarker.setStyle(
  687. new Style({
  688. image: new Icon({
  689. color: "#eee",
  690. crossOrigin: "anonymous",
  691. src: require("../../assets/images/icons/" + icon), //本地的样式
  692. scale:size
  693. }),
  694. },
  695. )
  696. ); //这里是样式
  697. var markerta = new LayerVec({
  698. source: new SourceVec({
  699. features: [tamarker] //这里放的就是之前的那个点,如果要放置多个点直接push到这里面就行了
  700. }),
  701. zIndex:30
  702. });
  703. this.pointArry[id]=markerta;
  704. this.map.addLayer(markerta); //这里是执行,执行之后点就出来了
  705. },
  706. addText(lnglats,text,color,background) {
  707. let tamarker = new Feature({
  708. tadata: {
  709. sectionId: "point",
  710. towerNumber: 22,
  711. }, //这里是用来传值用的,在接下来的一章里(事件)中我会讲到。
  712. geometry: new Point(lnglats) //这里是点坐标的位置,这里要注意fromLonLat
  713. });
  714. tamarker.setStyle(
  715. new Style({
  716. text: new Text({
  717. text: text,
  718. font: '16px sans-serif',
  719. textAlign: "center",
  720. textBaseline: "middle",
  721. //font: 'verdana',
  722. fill: new Fill({
  723. color: color
  724. }),
  725. backgroundFill: new Fill({
  726. color: background
  727. }),
  728. stroke: new Stroke({
  729. color: "#ffffff"
  730. // width: 3
  731. }),
  732. // font: "10px sans-serif",
  733. // offsetX: parseInt(0, 10),
  734. offsetY: 25,
  735. placement: "point", //point 则自动计算面的中心k点然后标注 line 则根据面要素的边进行标注
  736. overflow: false //超出面的部分不显示
  737. })
  738. },
  739. )
  740. ); //这里是样式
  741. var markerta = new LayerVec({
  742. source: new SourceVec({
  743. features: [tamarker] //这里放的就是之前的那个点,如果要放置多个点直接push到这里面就行了
  744. }),
  745. zIndex:30
  746. });
  747. // this.pointArry[id]=markerta;
  748. this.map.addLayer(markerta); //这里是执行,执行之后点就出来了
  749. },
  750. addPoints(data,icon,size,type){
  751. var tamarkerArry =[]
  752. let tamarker = null
  753. for(var index in data){
  754. if(type === 'video'){
  755. tamarker = new Feature({
  756. tadata: {
  757. sectionId: "point",
  758. towerNumber: 22,
  759. data: data[index],
  760. type:type
  761. }, //这里是用来传值用的,在接下来的一章里(事件)中我会讲到。
  762. geometry: new Point([data[index].longitude, data[index].latitude]) //这里是点坐标的位置,这里要注意fromLonLat
  763. });
  764. }else {
  765. tamarker = new Feature({
  766. tadata: {
  767. sectionId: "point",
  768. towerNumber: 22,
  769. data:data[index],
  770. type:type
  771. }, //这里是用来传值用的,在接下来的一章里(事件)中我会讲到。
  772. geometry: new Point(data[index].fence.split(',')) //这里是点坐标的位置,这里要注意fromLonLat
  773. });
  774. }
  775. tamarker.setStyle(
  776. new Style({
  777. image: new Icon({
  778. color: "#eee",
  779. crossOrigin: "anonymous",
  780. src: require("../../assets/images/icons/" + icon), //本地的样式
  781. scale:size,
  782. anchor: [0.5, 60], //锚点
  783. anchorOrigin:'top-right', //锚点源
  784. anchorXUnits: 'fraction', //锚点X值单位
  785. anchorYUnits: 'pixels', //锚点Y值单位
  786. offsetOrigin: 'top-right', //偏移原点
  787. }),
  788. },)
  789. ); //这里是样式
  790. tamarkerArry.push(tamarker);
  791. }
  792. var markerta = new LayerVec({
  793. source: new SourceVec({
  794. features: tamarkerArry //这里放的就是之前的那个点,如果要放置多个点直接push到这里面就行了
  795. }),
  796. zIndex:300
  797. });
  798. // markerta.on('mouseover', markerta, function(evt) {
  799. // console.log(evt);
  800. // popup = new OpenLayers.Popup.FramedCloud("Popup",
  801. // new OpenLayers.LonLat(5.6, 50.6),
  802. // null,
  803. // '<div>Hello World! Put your html here</div>',
  804. // null,
  805. // false);
  806. // this.map.addPopup(popup);
  807. // });
  808. // //here add mouseout event
  809. // markerta.on('mouseout', markerta, function(evt) {popup.hide();});
  810. // this.pointArry.set(id,markerta);
  811. this.map.addLayer(markerta); //这里是执行,执行之后点就出来了
  812. markerta.setVisible(false);
  813. if(type == 'device'){
  814. this.deviceList.push(markerta);
  815. }else{
  816. this.mapHashMap[type]=markerta;
  817. }
  818. if(this.isLine){
  819. markerta.setVisible(true);
  820. }
  821. // markerta.setVisible(true)
  822. },
  823. addline: function(lnglats,type) {
  824. let line = new Feature({
  825. tadata: {
  826. sectionId: "line",
  827. towerNumber: 22
  828. },
  829. geometry: new LineString(lnglats)
  830. }); //这里要注意写fromLonLat,很重要
  831. var style =this.getStyle(type);
  832. line.setStyle(style);
  833. var linevectorLayer = new LayerVec({
  834. source: new SourceVec({
  835. features: [line] //要绘制多段线,直接push到这里面就行了
  836. })
  837. });
  838. if(type == 'device'){
  839. this.deviceList.push(linevectorLayer);
  840. linevectorLayer.setVisible(false)
  841. }
  842. // else{
  843. // this.mapHashMap[type]=linevectorLayer;
  844. // linevectorLayer.setVisible(false)
  845. // }
  846. this.map.addLayer(linevectorLayer); //这里是执行,执行之后点就出来了
  847. },
  848. addPolygon(item) {
  849. var polygon = new Feature({
  850. geometry: new Polygon(item),
  851. type: "polygon",
  852. });
  853. let style = [
  854. new Style({
  855. fill: new Fill({
  856. color: "rgba(5,96,187,0.2)",
  857. }),
  858. // 描边
  859. stroke: new Stroke({
  860. color:"#0560BB",
  861. width:3,
  862. lineDash:[10,20],
  863. lineCap:"butt"
  864. }),
  865. zIndex: 10,
  866. }),
  867. ];
  868. polygon.setStyle(style);
  869. var polygonLayer = new LayerVec({
  870. source: new SourceVec({
  871. features: [polygon]
  872. })
  873. });
  874. this.map.addLayer(polygonLayer);
  875. this.areaList.push(polygonLayer);
  876. polygonLayer.setVisible(false)
  877. },
  878. initPoint(){
  879. var pointObj = this.pointObj;
  880. if(pointObj){
  881. if(pointObj.type == 2){
  882. this.addMarker(pointObj.locations.split(','),'左侧-车站-高亮.png',0.2,'marker');
  883. }
  884. if(pointObj.type == 5){
  885. this.addMarker(pointObj.locations.split(','),'专家站点.png',0.2,'marker');
  886. }
  887. }
  888. },
  889. handleClose(){
  890. closevideo();
  891. this.dialogVisible = false
  892. },
  893. handleCloseCk(){
  894. this.dialogVisibleCk = false
  895. },
  896. handleOpen(){
  897. window.cameraid = this.ccode;
  898. startPreview(window.cameraid,-1);
  899. },
  900. handleChange(value){
  901. for(var key in this.mapHashMap){
  902. this.mapHashMap[key].setVisible(false)
  903. }
  904. for(var index in this.deviceList){
  905. this.deviceList[index].setVisible(false)
  906. }
  907. for(var index in this.areaList){
  908. this.areaList[index].setVisible(false)
  909. }
  910. console.log(this.deviceList);
  911. for(var index in value){
  912. if(value[index] == 'device'){
  913. for(var index in this.deviceList){
  914. this.deviceList[index].setVisible(true)
  915. }
  916. }else if(value[index] == 'area'){
  917. for(var index in this.areaList){
  918. this.areaList[index].setVisible(true)
  919. }
  920. }else{
  921. var mapkey = value[index]
  922. if(this.mapHashMap[mapkey]){
  923. this.mapHashMap[mapkey].setVisible(true)
  924. }
  925. }
  926. }
  927. },
  928. getStyle(type){
  929. var style = new Style({
  930. stroke: new Stroke({
  931. width: 3,
  932. color: "#008000"
  933. })
  934. })
  935. if(type == 'nqtl'){
  936. style =[
  937. new Style({
  938. stroke: new Stroke({
  939. color:"#000000",
  940. width:4,
  941. lineCap:"butt"
  942. }),
  943. zIndex:20
  944. }),
  945. new Style({
  946. stroke: new Stroke({
  947. color:"#ffffff",
  948. width:4,
  949. lineDash:[10,10],
  950. lineCap:"butt"
  951. }),
  952. zIndex:21
  953. })
  954. ]
  955. }else if(type == 'nqtl2'){
  956. style =[
  957. new Style({
  958. stroke: new Stroke({
  959. color:"#535353",
  960. width:4,
  961. lineCap:"butt"
  962. }),
  963. zIndex:20
  964. }),
  965. new Style({
  966. stroke: new Stroke({
  967. color:"#ffffff",
  968. width:4,
  969. lineDash:[10,10],
  970. lineCap:"butt"
  971. }),
  972. zIndex:21
  973. })
  974. ]
  975. }else if(type == 'device'){
  976. style =new Style({
  977. stroke: new Stroke({
  978. color:"#07DBFF",
  979. width:6,
  980. lineDash:[15,45],
  981. lineCap:"butt"
  982. }),
  983. zIndex:20
  984. })
  985. }
  986. return style;
  987. }
  988. }
  989. };
  990. </script>
  991. <style scoped>
  992. #map {
  993. height: 100%;
  994. }
  995. .iconSelect{
  996. position: absolute;
  997. top: 10rem;
  998. right: 5rem;
  999. width: 16rem;
  1000. min-height: 30rem;
  1001. background-color: transparent ;
  1002. padding-left:1rem
  1003. }
  1004. .tipicon{
  1005. width:3rem;
  1006. height:3rem;
  1007. vertical-align: middle;
  1008. }
  1009. img{
  1010. width:10rem;
  1011. height:10rem
  1012. }
  1013. .popover-body{
  1014. width:100px;
  1015. height:100px;
  1016. }
  1017. .imgClass{
  1018. width:10rem;
  1019. height:10rem
  1020. }
  1021. .locationDiv{
  1022. position: absolute;
  1023. /* top: 50rem;
  1024. right: 5rem; */
  1025. width: 24rem;
  1026. min-height: 24rem;
  1027. background-color: transparent ;
  1028. background:white
  1029. }
  1030. </style>