Administrator 2 年 前
コミット
743a688c35

+ 13 - 0
pom.xml

@@ -139,6 +139,19 @@
 			<artifactId>GeoLib</artifactId>
 			<version>1.0</version>
 		</dependency>
+		<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-spatial -->
+		<dependency>
+			<groupId>org.hibernate</groupId>
+			<artifactId>hibernate-spatial</artifactId>
+			<version>5.6.10.Final</version>
+		</dependency>
+		<!-- https://mvnrepository.com/artifact/net.postgis/postgis-jdbc -->
+		<dependency>
+			<groupId>net.postgis</groupId>
+			<artifactId>postgis-jdbc</artifactId>
+			<version>2.5.1</version>
+		</dependency>
+
 
 
 		<dependency>

+ 2 - 2
src/main/java/com/sysu/admin/MarkApplication.java

@@ -21,8 +21,8 @@ import lombok.extern.slf4j.Slf4j;
  */
 @Slf4j
 @EnableJpaAuditing
-@EnableJpaPlusDataSourceRepositories
-@SpringBootApplication(exclude = {ValidationAutoConfiguration.class, DataSourceAutoConfiguration.class})
+@EnableJpaPlusRepositories
+@SpringBootApplication(exclude = {ValidationAutoConfiguration.class})
 public class MarkApplication extends SpringBootServletInitializer {
 
     public static void main(String[] args) {

+ 8 - 2
src/main/java/com/sysu/admin/controller/geo/CityLand.java

@@ -1,11 +1,13 @@
 package com.sysu.admin.controller.geo;
 
+import com.alibaba.fastjson.annotation.JSONField;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
 import lombok.experimental.FieldNameConstants;
 import org.hibernate.annotations.DynamicInsert;
 import org.hibernate.annotations.DynamicUpdate;
+import org.locationtech.jts.geom.MultiPolygon;
 
 import javax.persistence.*;
 
@@ -28,8 +30,12 @@ public class CityLand {
     @Column(name = "gridcode")
     private Long gridcode;
 
-    @Column(name = "geom")
-    private String geom;
+    @JSONField(serialize = false)
+    @Column(columnDefinition = "geom")
+    private MultiPolygon geom;
+
+    @Transient
+    private String wkt;
 
 
 }

+ 1 - 1
src/main/java/com/sysu/admin/controller/geo/CityLandRepository.java

@@ -9,7 +9,7 @@ import java.util.List;
 public interface CityLandRepository extends JpaPlusRepository<CityLand, Long> {
 
 
-    @Query(value = "SELECT \"id\",ST_AsEWKT(\"geom\") as \"geom\",\"gridcode\" FROM \"gdcityland30\" where St_within(st_geomfromtext(?1,4526), geom) limit 1", nativeQuery = true)
+    @Query(value = "SELECT * FROM \"gdcityland30\" where St_within(st_geomfromtext(?1,4526), geom) limit 1", nativeQuery = true)
     CityLand findIdByPoint(String pointWKT);
 
 }

+ 2 - 2
src/main/java/com/sysu/admin/controller/geo/CityLandService.java

@@ -1,6 +1,5 @@
 package com.sysu.admin.controller.geo;
 
-import com.sysu.admin.support.base.BaseService;
 import com.xiesx.fastboot.core.jpa.annotation.TargetDataSource;
 import com.xiesx.fastboot.core.jpa.cfg.DataSourceEnum;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -14,7 +13,8 @@ public class CityLandService {
 
     @TargetDataSource(DataSourceEnum.slave)
     public CityLand findByPoint(double x, double y){
-        return cityLandRepository.findIdByPoint("Point("+x+" "+y+")");
+        CityLand cityLand = cityLandRepository.findIdByPoint("Point("+x+" "+y+")");
+        return cityLand;
     }
 
 }

+ 3 - 0
src/main/java/com/sysu/admin/controller/geo/PostGisInfoController.java

@@ -8,6 +8,7 @@ import com.xiesx.fastboot.base.result.R;
 import org.geotools.data.postgis.TWKBReader;
 import org.geotools.geojson.feature.FeatureJSON;
 import org.geotools.geometry.jts.WKBReader;
+import org.geotools.geometry.jts.WKTReader2;
 import org.geotools.geometry.jts.WKTWriter2;
 import org.locationtech.jts.geom.Coordinate;
 import org.locationtech.jts.geom.Geometry;
@@ -37,6 +38,8 @@ public class PostGisInfoController {
     @RequestMapping("/getInfo")
     public BaseResult getInfo(String layerName, Double x, Double y){
         CityLand cityLand = cityLandService.findByPoint(x,y);
+        WKTWriter2 wktReader2 = new WKTWriter2();
+        cityLand.setWkt(wktReader2.write(cityLand.getGeom()));
         return R.succ(cityLand);
     }
 

+ 0 - 2
src/main/java/com/sysu/admin/controller/geo/qyz/QyzController.java

@@ -1,10 +1,8 @@
 package com.sysu.admin.controller.geo.qyz;
 
-import com.sysu.admin.utils.shape.GeoServerCQLECQL;
 import com.sysu.admin.utils.shape.postgis.PostGisUtil;
 import com.xiesx.fastboot.base.result.BaseResult;
 import com.xiesx.fastboot.base.result.R;
-import org.geotools.geometry.jts.WKTReader2;
 import org.geotools.geometry.jts.WKTWriter2;
 import org.locationtech.jts.geom.Geometry;
 import org.opengis.feature.simple.SimpleFeature;

+ 29 - 5
src/main/resources/application-adm.yml

@@ -8,10 +8,34 @@ logging:
   
 spring:
   datasource:
-    driver-class-name: com.mysql.jdbc.Driver
-    url: jdbc:mysql://127.0.0.1:3306/change_det?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&autoReconnect=true&useSSL=false&serverTimezone=Asia/Shanghai
-    username: change_det
-    password: change_det2021
+    write:
+      driver-class-name: com.mysql.jdbc.Driver
+      jdbc-url: jdbc:mysql://127.0.0.1:3306/sysu-emap?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&autoReconnect=true&useSSL=false&serverTimezone=Asia/Shanghai
+      username: sysu-emap
+      password: sysu-emap-2020
+      pool-name: HikariPool-1
+      connection-timeout: 60000
+      validation-timeout: 3000
+      idle-timeout: 60000
+      login-timeout: 5
+      max-lifetime: 60000
+      maximum-pool-size: 10
+      minimum-idle: 10
+      read-only: false
+    read:
+      driver-class-name: org.postgresql.Driver
+      jdbc-url: jdbc:postgresql://127.0.0.1:39543/sysu-emap
+      username: postgres
+      password: postgres
+      pool-name: HikariPool-2
+      connection-timeout: 60000
+      validation-timeout: 3000
+      idle-timeout: 60000
+      login-timeout: 5
+      max-lifetime: 60000
+      maximum-pool-size: 2
+      minimum-idle: 2
+      read-only: true
     druid:
       # 日志
       filter:
@@ -66,6 +90,6 @@ postgis:
 geoserver:
   user: admin
   password: geoserver
-  url:
+  url: http://change.zylfsm.com
   port:
   path: geoserver

+ 11 - 38
src/main/resources/application-dev.yml

@@ -9,52 +9,25 @@ logging:
 spring:
   jpa:
     show-sql: true
-    database-platform: org.hibernate.dialect.MySQL8Dialect
+    database-platform: org.hibernate.spatial.dialect.postgis.PostgisDialect
   datasource:
-    driver-class-name: com.mysql.jdbc.Driver
-    url: jdbc:mysql://127.0.0.1:3307/zedu-admin?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&autoReconnect=true&useSSL=false&serverTimezone=Asia/Shanghai
-    username: zedu-admin
-    password: zedu-admin
-    write:
-      driver-class-name: com.mysql.jdbc.Driver
-      jdbc-url: jdbc:mysql://127.0.0.1:3307/sysu_emap?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&autoReconnect=true&useSSL=false&serverTimezone=Asia/Shanghai
-      username: root
-      password: shuhao7572
-      pool-name: HikariPool-1
-      connection-timeout: 60000
-      validation-timeout: 3000
-      idle-timeout: 60000
-      login-timeout: 5
-      max-lifetime: 60000
-      maximum-pool-size: 10
-      minimum-idle: 10
-      read-only: false
-    read:
-      driver-class-name: org.postgresql.Driver
-      jdbc-url: jdbc:postgresql://127.0.0.1:5432/sysu-emap
-      username: postgres
-      password: postgres
-      pool-name: HikariPool-2
-      connection-timeout: 60000
-      validation-timeout: 3000
-      idle-timeout: 60000
-      login-timeout: 5
-      max-lifetime: 60000
-      maximum-pool-size: 2
-      minimum-idle: 2
-      read-only: true
+    driver-class-name: org.postgis.DriverWrapper
+    url: jdbc:postgresql_postGIS://101.35.200.5:39543/sysu-emap
+    username: postgres
+    password: postgres
+    pool-name: HikariPool-1
 
 
 postgis:
   url: localhost
-  port: 5432
+  port: 39543
   database: sysu-emap
   user: postgres
   password: postgres
 geoserver:
-  user: postgres
-  password: root
-  url: http://localhost
-  port: 8080
+  user: admin
+  password: geoserver
+  url: http://change.zylfsm.com
+  port:
   path: geoserver
 

+ 1 - 1
src/main/resources/log4j2-adm.xml

@@ -52,7 +52,7 @@
 
 	<Loggers>
 		<!-- 默认DEBUG -->
-		<Root level="DEBUG">
+		<Root level="WARN">
 			<AppenderRef ref="console" />
 			<AppenderRef ref="all" />
 			<AppenderRef ref="error" />

+ 10 - 3
src/main/webapp/WEB-INF/jsp/comm/admin2.jsp

@@ -59,14 +59,15 @@
                 view1 = new ol.View({
                     center: [113.0978, 23.6697],
                     projection: projection,
-                    zoom: 9
+                    zoom: 10
                 })
 
                 map = new ol.Map({
                     view: view1,
                     target: target
                 });
-                geoServerContext = new GeoServerContext({currentMap: map,currentView: view1,projection: projection})
+                geoServerContext = new GeoServerContext({currentMap: map,currentView: view1,projection: projection},
+                "${geoserver}")
 
 
                 //初始化鼠标位置控件
@@ -189,7 +190,13 @@
             <div class="timeline-box no-events">
                 <div class="cx-time-main" id="cxTime"></div>
             </div>
-            <!-- 左边层 -->
+
+            <div id="popup" class="ol-popup">
+                <a href="#" id="popup-closer" class="ol-popup-closer"></a>
+                <div id="popup-title" class="popup-title"></div>
+                <div id="popup-content" class="popup-context" ></div>
+            </div>
+
         </div>
         <!-- 底部地图 -->
         <!-- 背景层 -->

+ 78 - 0
src/main/webapp/static/css/admin2.css

@@ -260,6 +260,84 @@
 }
 
 
+.ol-popup {
+    display: none;
+    position: absolute;
+    background-color: #147ae850;
+    -moz-box-shadow: 0 1px 4px rgba(0,0,0,0.2);
+    -webkit-filter: drop-shadow(0 1px 4px rgba(0,0,0,0.2));
+    filter: drop-shadow(0 1px 4px rgba(0,0,0,0.2));
+    bottom: 12px;
+    left: -50px;
+    width: 400px;
+    border: 1px #5AEEF5 solid;
+    border-radius: 3px;
+}
+.ol-popup:after, .ol-popup:before {
+    top: 100%;
+    border: solid transparent;
+    content: " ";
+    height: 0;
+    width: 0;
+    position: absolute;
+    pointer-events: none;
+}
+.ol-popup:after {
+    border-top-color: #5AEEF5;
+    border-width: 10px;
+    left: 48px;
+    margin-left: -10px;
+}
+.ol-popup:before {
+    border-top-color: #5AEEF5;
+    border-width: 11px;
+    left: 48px;
+    margin-left: -11px;
+}
+.popup-title{
+    line-height: 30px;
+    background-color: transparent;
+    font-weight: bold;
+    color: #5AEEF5;
+    border-bottom:1px solid #5AEEF5;
+    padding-top: 4px;
+    padding-bottom: 4px;
+    margin-left: 10px;
+    margin-right: 10px;
+}
+
+.popup-context{
+    padding-top: 4px;
+    padding-bottom: 4px;
+    margin-left: 10px;
+    margin-right: 10px;
+    color: whitesmoke;
+    line-height: 30px;
+}
+.popup-context .lab{
+    text-align: left;
+    float: left;
+}
+.popup-context .val{
+    text-align: right;
+    float: right;
+}
+
+.ol-popup-closer {
+    text-decoration: none;
+    position: absolute;
+    top: -3px;
+    right: 0px;
+    border-bottom:1px solid #5AEEF5;
+    border-left:1px solid #5AEEF5;
+    border-radius: 50%;
+    background-color: transparent;
+}
+.ol-popup-closer:after {
+    content: "✖";
+    color: whitesmoke;
+}
+
 
 
 

+ 1 - 1
src/main/webapp/static/js/tools/openLayers.js

@@ -89,7 +89,7 @@ function Popup(option){
     //'bottom-left', 'bottom-center', 'bottom-right', 'center-left', 'center-center', 'center-right', 'top-left', 'top-center', and 'top-right'
     this.overlay = new ol.Overlay({
         element: this.container,
-        positioning: 'center-left',
+        positioning: 'top-center',
     });
     map.addOverlay(this.overlay);
 }

+ 54 - 6
src/main/webapp/static/package/cityland.js

@@ -3,6 +3,7 @@ function CityLandAction(context, id){
     this.id = id
     this.selected = {}
     this.tempVectorLayer = null
+    this.popup = null
     this.obj = new CityLand({
         url : context.local_wmts_path,
         projection: context.projection
@@ -14,8 +15,13 @@ CityLandAction.prototype = {
     startStatus : false,
     createStatus : false,
     create(){
+        let that = this
         this.obj.getTileLayer()
         this.tempVectorLayer = this.loadTempVectorLayer()
+        this.popup = new Popup({map: this.context.currentMap,
+            close(){
+                that.tempVectorLayer.getSource().clear()
+            }});
         this.createStatus = true;
     },
     start(){
@@ -38,6 +44,8 @@ CityLandAction.prototype = {
         console.log("tempVectorLayer cleared")
         this.context.clicks[this.id] = null
         console.log("remove click")
+        this.popup._close()
+        console.log("close popup")
         this.startStatus = false;
     },
     click(event, that){
@@ -48,12 +56,29 @@ CityLandAction.prototype = {
         that.clickLock = true
         let layerName = that.obj.wmsData.params.LAYER.substring(that.obj.wmsData.params.LAYER.indexOf(":") + 1)
         that.context.getInfo(layerName, event.coordinate, function(res){
-            let feature = new ol.Feature({
-                geometry: that.context.wkt.readGeometry(res.data.geom.substring(res.data.geom.indexOf(";") +1 )).transform("EPSG:4526","EPSG:4326")
-            });
-            that.tempVectorLayer.getSource().clear()
-            that.tempVectorLayer.getSource().addFeature(feature)
-            that.clickLock = false
+            try {
+                console.log(res.data)
+                let geometry = that.context.wkt.readGeometry(res.data.wkt)
+                let area = geometry.getArea()
+                area = (area + area / 2) / 1000
+                res.data["area"] = area.toFixed(2)
+                let feature = new ol.Feature({
+                    geometry: geometry.transform("EPSG:4526","EPSG:4326")
+                });
+                for(let key in res.data){
+                    if(key != "wkt"){
+                        feature.set(key, res.data[key])
+                    }
+                }
+                that.tempVectorLayer.getSource().clear()
+                that.tempVectorLayer.getSource().addFeature(feature)
+                that.popup.show(ol.extent.getCenter(feature.getGeometry().getExtent()), that.getInfoHtml(feature))
+            }catch (e){
+                console.log(e)
+            }finally {
+                that.clickLock = false
+            }
+
         },function(){
             that.clickLock = false
         })
@@ -77,6 +102,27 @@ CityLandAction.prototype = {
             },
         });
     },
+    landType:{
+        0:"其他",
+        1:"湿地",
+        2:"耕地",
+        3:"种植",
+        4:"林地",
+        5:"草地",
+        6:"水域",
+    },getInfoHtml(feature){
+        let html = ""
+        let data = {
+            "地块类别":this.landType[feature.get("gridcode")],
+            "地块图斑编号":feature.get("id"),
+            "地块面积(亩)":feature.get("area"),
+            "地块周长(米)":"10000",
+        }
+        for(let key in data){
+            html += "<div class='layui-row'><div class='lab' >"+key+"</div><div class='val' >"+data[key]+"</div></div>"
+        }
+        return html
+    }
 
 }
 
@@ -138,6 +184,8 @@ CityLand.prototype = {
         this.layerData.layer = new ol.layer.Tile({
             source: this.layerData.source,
             zIndex: 2,
+            minZoom: 8,
+            maxZoom: 14
         });
     }
 }

+ 3 - 4
src/main/webapp/static/package/geo_server_context.js

@@ -1,6 +1,6 @@
-function GeoServerContext(opt){
-    this.local_wms_path = "http://localhost:8080/geoserver/wuhan/wms"
-    this.local_wmts_path = "http://localhost:8080/geoserver/gwc/service/wmts"
+function GeoServerContext(opt,geoserver_path){
+    this.local_wms_path = geoserver_path+"/wuhan/wms"
+    this.local_wmts_path = geoserver_path+"/gwc/service/wmts"
     this.actions = {}
     this.clicks = {}
     this.currentMap = opt.currentMap || window.map
@@ -59,7 +59,6 @@ GeoServerContext.prototype = {
             success : function(res){
                 let html = ""
                 let data = JSON.parse(res.msg)
-
                 for(let item of data){
                     html += '<div class="cutline-item">'
                     html += '<div class="item-color" style="background-color: '+item.fill+'"></div>'