Jelajahi Sumber

地图修改

DR/4DAGE 4 tahun lalu
induk
melakukan
33c7ca061b
7 mengubah file dengan 100 tambahan dan 153 penghapusan
  1. TEMPAT SAMPAH
      public/zzdemo/img/blue.png
  2. TEMPAT SAMPAH
      public/zzdemo/img/blue@2x.png
  3. TEMPAT SAMPAH
      public/zzdemo/img/red.png
  4. TEMPAT SAMPAH
      public/zzdemo/img/red@2x.png
  5. 5 25
      public/zzdemo/index.html
  6. 59 117
      public/zzdemo/main.js
  7. 36 11
      public/zzdemo/utils.js

TEMPAT SAMPAH
public/zzdemo/img/blue.png


TEMPAT SAMPAH
public/zzdemo/img/blue@2x.png


TEMPAT SAMPAH
public/zzdemo/img/red.png


TEMPAT SAMPAH
public/zzdemo/img/red@2x.png


+ 5 - 25
public/zzdemo/index.html

@@ -43,18 +43,6 @@
             left: 70%;
             z-index: 100;
         }
-        #sample{
-            position: absolute;
-            bottom: 5%;
-            right: 5%;
-            z-index: 100;
-           
-        }
-        #bu4{
-            position: absolute;
-            left: 40%;
-            z-index: 100; 
-        }
     </style>
     <script src="./jquery.min.js"></script>
     <script src="./imgtogif.js"></script>
@@ -69,20 +57,12 @@
 <body>
     <div id="global-container" style="height: 100%;">
         <img id="imgId1" style=" position:absolute;z-index: 100;width: 100px;height: 100px;left: -15%;"/>
+        <!-- <button id="bu" >蓝色</button>
+        <button id="bu1" >黄色</button>
+        <button id="bu2" >红色</button>
+        <button id="bu3">启动</button> -->
     </div>
-   <!-- <div id="global-container" style="height: 100%;">
-        <img src="img/sample.png" id="sample" style="display: none;"/> 
-        <img id="imgId1" style=" position:absolute;z-index: 100;width: 100px;height: 100px;left: -15%;"/>
-        <img id="imgId2" style=" position:absolute;z-index: 100;width: 100px;height: 100px;left: -15%;"/>
-        <img id="imgId3" style=" position:absolute;z-index: 100;width: 100px;height: 100px;left: -15%;"/>
-        <img id="imgId4" style=" position:absolute;z-index: 100;width: 100px;height: 100px;left: -15%;"/> 
-         <button id="bu" style="display: none;">切换地图</button>
-        <button id="bu1" style="display: none;">切换时间</button>
-        <button id="bu2" style="display: none;">启动</button>
-        <button id="bu3" style="display: none;">暂停</button>
-        <button id="bu4" style="display: none;">切换时间1</button>
-    </div> 
-     -->
+         
     <script src="./main.js"></script>
 </body>
 

+ 59 - 117
public/zzdemo/main.js

@@ -5,6 +5,7 @@ let chinaLineResource=undefined;
 let currentDatas=[];
 let currentDataIndex=0;
 let yellowMapLayer=undefined;
+let redMapLayer=undefined;
 let currentPosition=[];
 let xxgcxy=[]; //信息工程学院
 let chxy=[]; //测绘学院
@@ -12,6 +13,7 @@ let dzjsxy=[];//电子技术学院
 let ygyxy=[];//外国语学院
 let roadInterval;
 let onTimeInterval;
+
 const viewer=new Cesium.Viewer("global-container",{
         shouldAnimate: true,
         infoBox: false, //是否显示点击要素之后显示的信息
@@ -68,11 +70,10 @@ function changeLocation(){
     chxy.length>0&&changeImgLocation(chxy[chxy.length-1].position[0],chxy[chxy.length-1].position[1],2)
     dzjsxy.length>0&&changeImgLocation(dzjsxy[dzjsxy.length-1].position[0],dzjsxy[dzjsxy.length-1].position[1],3)
     ygyxy.length>0&&changeImgLocation(ygyxy[ygyxy.length-1].position[0],ygyxy[ygyxy.length-1].position[1],4)
-    
-    xxgcxy.length>0&&changeFontLocation(xxgcxy[xxgcxy.length-1].position[0],xxgcxy[xxgcxy.length-1].position[1],xxgcxy[xxgcxy.length-1].imgUrl,1)
-    chxy.length>0&&changeFontLocation(chxy[chxy.length-1].position[0],chxy[chxy.length-1].position[1],xxgcxy[xxgcxy.length-1].imgUrl,1)
-    dzjsxy.length>0&&changeFontLocation(dzjsxy[dzjsxy.length-1].position[0],dzjsxy[dzjsxy.length-1].position[1],xxgcxy[xxgcxy.length-1].imgUrl,1)
-    ygyxy.length>0&&changeFontLocation(ygyxy[ygyxy.length-1].position[0],ygyxy[ygyxy.length-1].position[1],xxgcxy[xxgcxy.length-1].imgUrl,1)
+    xxgcxy.length>0&&changeFontLocation(xxgcxy[xxgcxy.length-1].position[0],xxgcxy[xxgcxy.length-1].position[1],xxgcxy[xxgcxy.length-1].imgUrl,1,StyleClass)
+    chxy.length>0&&changeFontLocation(chxy[chxy.length-1].position[0],chxy[chxy.length-1].position[1],xxgcxy[xxgcxy.length-1].imgUrl,1,StyleClass)
+    dzjsxy.length>0&&changeFontLocation(dzjsxy[dzjsxy.length-1].position[0],dzjsxy[dzjsxy.length-1].position[1],xxgcxy[xxgcxy.length-1].imgUrl,1,StyleClass)
+    ygyxy.length>0&&changeFontLocation(ygyxy[ygyxy.length-1].position[0],ygyxy[ygyxy.length-1].position[1],xxgcxy[xxgcxy.length-1].imgUrl,1,StyleClass)
 }
 /**
  * 动态箭头生成函数
@@ -157,7 +158,6 @@ function showData(result){
     chxy=[];
     dzjsxy=[];
     ygyxy=[];
-    console.log(result);
   //  showPoints(result);
     showTifAndRoad(result);
 }
@@ -165,16 +165,16 @@ function showData(result){
 //添加地图基础数据
 function addMapInit(){
 
-   let url="http://192.168.0.95:8081/geoserver/gwc/service/wmts";
+   let url="http://120.24.176.22:8080/geoserver/gwc/service/wmts";
 
    let matrixIds = ['EPSG:4326:0', 'EPSG:4326:1', 'EPSG:4326:2', 'EPSG:4326:3', 'EPSG:4326:4', 'EPSG:4326:5', 'EPSG:4326:6', 'EPSG:4326:7', 'EPSG:4326:8', 'EPSG:4326:9', 'EPSG:4326:10',
    'EPSG:4326:11', 'EPSG:4326:12', 'EPSG:4326:13', 'EPSG:4326:14', 'EPSG:4326:15', 'EPSG:4326:16', 'EPSG:4326:17', 'EPSG:4326:18', 'EPSG:4326:19', 'EPSG:4326:20', 'EPSG:4326:21'];
   
-  //1.新建ImageryProvider
+  //1.新建ImageryProvider yellow
   let wmtsImageryProvider = new Cesium.WebMapTileServiceImageryProvider({
     url: url,
-    layer: "cite:globaldem21",
-    style: 'zz',
+    layer: "xiaoshibianqian:dem-yellow",
+    style: '',
     format: 'image/png',
     tileMatrixSetID: 'EPSG:4326',
     tileMatrixLabels: matrixIds,
@@ -185,15 +185,33 @@ function addMapInit(){
   });
  yellowMapLayer=new Cesium.ImageryLayer(wmtsImageryProvider);
    viewer.imageryLayers.add(yellowMapLayer);
+    //1.新建ImageryProvider yellow
+  let wmtsImageryProviderred = new Cesium.WebMapTileServiceImageryProvider({
+    url: url,
+    layer: "xiaoshibianqian:dem-red",
+    style: '',
+    format: 'image/png',
+    tileMatrixSetID: 'EPSG:4326',
+    tileMatrixLabels: matrixIds,
+    tilingScheme: new Cesium.GeographicTilingScheme({
+      numberOfLevelZeroTilesX: 2,
+      numberOfLevelZeroTilesY: 1
+    })
+  });
+   redMapLayer=new Cesium.ImageryLayer(wmtsImageryProviderred);
+viewer.imageryLayers.add(redMapLayer);
+
+yellowMapLayer.show=false;
+redMapLayer.show=false;
     Cesium.GeoJsonDataSource.load("./china1.json").then(ds=>{
         viewer.dataSources.add(ds);
         chinaLineResource=ds;
         ds.entities.values.map(entity => {
-            entity.polyline.material=new Cesium.Color(200/255, 169/255,145/255);
+            entity.polyline.material=new Cesium.Color(255/255, 255/255,255/255);
 			entity.polyline.width=1;
         });
     });
-  
+
     $.ajax({
         type: 'GET',
 		url: "./data.json",
@@ -247,8 +265,6 @@ function clearMap(){
 }
 //特定时间
 function onAtimeShow(time){
-    console.log(datas);
-    console.log("time--------------------------------------",time)
     let index=0;
     for(let i=0;i<datas.length;i++){
         if(datas[i].time==time){
@@ -308,7 +324,8 @@ function showTifAndRoad(result,index){
 }
 
 function showTifAndRoadPrivate(result,i,index){
-    changeFontLocation(result[i].position[0],result[i].position[1],result[i].imgUrl,index)
+
+    changeFontLocation(result[i].position[0],result[i].position[1],result[i].imgUrl,index,StyleClass)
     changeImgLocation(result[i].position[0],result[i].position[1],result[i].type);
     if(result[i].type==1){
         xxgcxy.push(result[i])
@@ -430,117 +447,42 @@ function pauseShow(){
     }
 }
 
-function changeStyle(){
-    yellowMapLayer.show=!yellowMapLayer.show;
-    !yellowMapLayer.show&&chinaLineResource.entities.values.map(entity => {
-        entity.polyline.material=new Cesium.Color(255/255,255/255,255/255,0.8);
-    });
-    yellowMapLayer.show&&chinaLineResource.entities.values.map(entity => {
-        entity.polyline.material=new Cesium.Color(200/255, 169/255,145/255);
-    });
-    yellowMapLayer.show&&pointsSource.entities.values.map(p=>{
-        p.billboard.color=Cesium.Color.YELLOW;
-    });
-    !yellowMapLayer.show&&pointsSource.entities.values.map(p=>{
-        p.billboard.color=Cesium.Color.WHITE;
-    });
+function changeStyle(type){
+    StyleClass=type;
+    if(type==RED){
+        redMapLayer.show=true;
+        yellowMapLayer.show=false;
+        chinaLineResource&&chinaLineResource.entities.values.map(entity => {
+            entity.polyline.material=new Cesium.Color(255/255,0,0,0.8);
+        });
+    }else if(type==YELLOW){
+        yellowMapLayer.show=true;
+        redMapLayer.show=false;
+        chinaLineResource&&chinaLineResource.entities.values.map(entity => {
+            entity.polyline.material=new Cesium.Color(200/255, 169/255,145/255);
+        });
+    }else {
+        yellowMapLayer.show=false;
+        redMapLayer.show=false;
+        chinaLineResource&&chinaLineResource.entities.values.map(entity => {
+            entity.polyline.material=new Cesium.Color(255/255,255/255,255/255,0.8);
+        });
+    }
 }
 
 
-// /**
-//  * 按时间展示点
-//  * @param {*} result 
-//  */
-//  function showPoints(result){
-//     let start,stop;
-//     start = Cesium.JulianDate.fromDate(new Date());
-//      // 结束时间
-//       stop = Cesium.JulianDate.addSeconds(start, 4*result.length, new Cesium.JulianDate());
-//     // 设置时钟开始时间
-//     viewer.clock.startTime = start.clone();
-//     // 设置时钟当前时间
-//     viewer.clock.currentTime = start.clone();
-//     // 设置时钟停止时间
-//     viewer.clock.stopTime  = stop.clone();
-//     // 时间轴
-//     viewer.clock.currentTime =start;
-//     viewer.clock.clockRange = Cesium.ClockRange.LOOP_STOP; 
-//     for(let i=0;i<result.length;i++){
-//         html2canvas(result[i].imgUrl).then(canvas=>{
-//             // 结束时间
-//             if(i==0){
-//                 stop= Cesium.JulianDate.addSeconds(start, 4, new Cesium.JulianDate());
-//             }else{
-//                 start = stop;
-//                 stop= Cesium.JulianDate.addSeconds(start,4,new Cesium.JulianDate());
-//             }
-//             let entity=new Cesium.Entity({
-//                 position:Cesium.Cartesian3.fromDegrees(result[i].position[0],result[i].position[1],1000),
-//                 availability:new Cesium.TimeIntervalCollection([new Cesium.TimeInterval({
-//                     start : start,
-//                     stop : stop
-//                 })]),
-//                 billboard:{
-//                 // image:result[i].imgUrl,
-//                 image:canvas,
-//                     //scale:0.2,
-//                     scale:1,
-//                     pixelOffset:new Cesium.Cartesian2(0,-20),
-//                 }
-//             });
-//             pointsSource.entities.add(entity);
-//             if(i+1<result.length&&result[i].time==result[i+1].time){
-//                 i++;
-//                     let nextEntity=new Cesium.Entity({
-//                         position:Cesium.Cartesian3.fromDegrees(result[i].position[0],result[i].position[1],1000),
-//                         availability:new Cesium.TimeIntervalCollection([new Cesium.TimeInterval({
-//                             start : start,
-//                             stop : stop
-//                         })]),
-//                         billboard:{
-//                             image:result[i].imgUrl,
-//                             scale:0.2,
-//                             pixelOffset:new Cesium.Cartesian2(0,-20)
-//                         }
-//                     });
-//                     pointsSource.entities.add(nextEntity);
-                
-//             }
-//         });
-
-       
-       
-//      }
-// }
 
 addMapInit();
 getGif();//动态图
 ontimeShow()
 // document.getElementById("bu").addEventListener("click",()=>{
-//     changeStyle();
+//     changeStyle(Style.BLUE);
 // });
-
 // document.getElementById("bu1").addEventListener("click",()=>{
-//     let i=0;
-//     onAtimeShow(times[i]);
-//     i++;
-//    setInterval(()=>{
-//     onAtimeShow(times[i]);//时间轴:点击某个年份的方法
-//     i++;
-// },4000)
-   
+//     changeStyle(Style.YELLOW);
 // });
-// document.getElementById("bu4").addEventListener("click",()=>{
-//     let time='1970.1';
-    
-//     onAtimeShowPause(time);//时间轴:点击某个年份的方法
-//  });
-// // document.getElementById("bu2").addEventListener("click",()=>{
-// //     console.log("times",times);
-// //     ontimeShow(); //时间轴:启动和复位
-// //  });
- 
-//  document.getElementById("bu3").addEventListener("click",()=>{
-//     pauseShow(); //时间轴:暂停和继续
-//  });
+// document.getElementById("bu2").addEventListener("click",()=>{
+//     changeStyle(Style.RED);
+// });
+
  

+ 36 - 11
public/zzdemo/utils.js

@@ -1,4 +1,9 @@
 /* eslint-disable */
+let BLUE=1;
+let YELLOW=2;
+let  RED=3;
+
+window.StyleClass=BLUE;
 /**
  * 改变动态图图片位置
  * @param {*} lon 
@@ -133,12 +138,27 @@ function sortByATime(data,time){
 /**
  * 地图展示文字
  */
-function changeFontLocation(lon,lat,imgUrl,index){
-    console.log("index",index)
-    let dom=createDiv({
-        fontImg:imgUrl,
-        proImg:"./img/yellow@2x.png"
-    })
+function changeFontLocation(lon,lat,imgUrl,index,t){
+   let  dom;
+    if(t==RED){
+         dom=createDiv({
+            fontImg:imgUrl,
+            proImg:"./img/red@2x.png",
+            style:RED
+        })
+    }else if(t==YELLOW){
+         dom=createDiv({
+            fontImg:imgUrl,
+            proImg:"./img/yellow@2x.png",
+            style:YELLOW
+        })
+    } else{
+        dom=createDiv({
+           fontImg:imgUrl,
+           proImg:"./img/blue@2x.png",
+           style:BLUE
+       })
+   }
     let root=document.getElementById("global-container");
     let childs=root.childNodes;
     //不知道为什么删不掉,运行3次才能删
@@ -164,9 +184,6 @@ function changeFontLocation(lon,lat,imgUrl,index){
             })
           }
     root.appendChild(dom);
-    childs.forEach(child=>{
-        console.log("fff",child)
-    })
    
     let pixel= Cesium.SceneTransforms.wgs84ToWindowCoordinates(viewer.scene,Cesium.Cartesian3.fromDegrees(lon,lat)); 
      dom.style.left=pixel.x-0.4*dom.width+"px";
@@ -189,9 +206,17 @@ function createDiv(options={}) {
     let lineImgHeight=lineImgNode.naturalHeight;
     let fontImgWidth=fontImgNode.naturalWidth;
     let fontImgHeight=fontImgNode.naturalHeight;
-    let  partentStyle=" z-index: 110;border-radius: 25px;border: 2px solid #f0e006; padding: 20px; position: absolute;left:"+lineImgWidth+"px";
+    let border="";
+    if(options.style==BLUE){
+        border= "border:2px solid #39C4F6;"
+    }else if(options.style==YELLOW){
+        border= "border:2px solid #f0e006;"
+    }else if(options.style==RED){
+        border= "border:2px solid #FF0000;"
+    }
+    let  partentStyle=" z-index: 110;border-radius: 25px;"+border+" padding: 20px; position: absolute;left:"+lineImgWidth+"px";
     parentNode.setAttribute('style',partentStyle);
-    let cloneStyle="z-index: 110;background-color:darkslategray;opacity: 0.5; border-radius: 25px;border: 2px solid #f0e006; padding: 20px; position: absolute;left:"+lineImgWidth+"px";
+    let cloneStyle="z-index: 110;background-color:darkslategray;opacity: 0.5; border-radius: 25px;"+border+" padding: 20px; position: absolute;left:"+lineImgWidth+"px";
     let cloneNode=parentNode.cloneNode(true);
     cloneNode.setAttribute('style',cloneStyle);
     rootNode.appendChild(cloneNode);