Administrator 2 년 전
부모
커밋
54f1a42078

+ 28 - 0
src/main/java/com/sysu/admin/api/cfg/CfgController.java

@@ -0,0 +1,28 @@
+package com.sysu.admin.api.cfg;
+
+import com.alibaba.fastjson.JSON;
+import com.sysu.admin.support.system.config.SConfigService;
+import com.xiesx.fastboot.base.result.BaseResult;
+import com.xiesx.fastboot.base.result.R;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
+
+@RequestMapping("/api/cfg")
+@RestController
+public class CfgController {
+
+    @Autowired
+    SConfigService mSConfigService;
+
+    @RequestMapping(value = "/get")
+    @ResponseBody
+    public BaseResult get(@RequestBody String data){
+        String key = JSON.parseObject(data).get("key").toString();
+        String sldXmlJson = mSConfigService.getV(key);
+        return R.succ("success",sldXmlJson);
+    }
+
+}

+ 22 - 7
src/main/java/com/sysu/admin/api/crop/CropController.java

@@ -4,8 +4,11 @@ import com.alibaba.fastjson.JSON;
 import com.google.common.collect.Lists;
 import com.sysu.admin.controller.crop.CropLand;
 import com.sysu.admin.controller.crop.CropLandService;
+import com.sysu.admin.controller.crop.images.CropImage;
+import com.sysu.admin.controller.crop.images.CropImageService;
 import com.sysu.admin.support.base.BaseComponent;
 import com.sysu.admin.support.shiro.ShiroService;
+import com.sysu.admin.support.system.config.ConfigContext;
 import com.sysu.admin.support.system.config.SConfigService;
 import com.sysu.admin.utils.TextUtil;
 import com.sysu.admin.utils.shape.GeoCastUtil;
@@ -34,6 +37,10 @@ public class CropController extends BaseComponent {
     SConfigService mSConfigService;
     @Autowired
     ShiroService mShiroService;
+    @Autowired
+    ConfigContext configContext;
+    @Autowired
+    CropImageService cropImageService;
 
     @RequestMapping("/list")
     public BaseResult list(@RequestBody String data) throws FactoryException, TransformException {
@@ -60,18 +67,24 @@ public class CropController extends BaseComponent {
         CropVo vo = JSON.parseObject(json, CropVo.class);
         CropLand bean = cityLandService.findOne(vo.getId());
         BeanUtils.copyProperties(vo, bean, CopyUtils.nullNames(vo));
-        saveFile(fay, "fay");
-        saveFile(center, "center");
-        saveFile(near, "near");
-
+        CropImage fayImage = vo.getFay();
+        fayImage.setType(0);
+        CropImage centerImage = vo.getCenter();
+        centerImage.setType(1);
+        CropImage nearImage = vo.getNear();
+        nearImage.setType(2);
+        fayImage.setFilename(saveFile(fay, "fay","test"));
+        centerImage.setFilename(saveFile(center, "center","test"));
+        nearImage.setFilename(saveFile(near, "near","test"));
+        cityLandService.saveCropAndImages(bean, new CropImage[]{fayImage, centerImage, nearImage});
         return R.succ();
     }
 
-    public String saveFile(MultipartFile file, String sign){
+    public String saveFile(MultipartFile file, String sign, String username){
         if(file != null){
-            String imageDirPath =  mSConfigService.getV("imageDirPath");
+            String imageDirPath = configContext.getImageDirPath();
             String hz = TextUtil.rightSubstring(".",file.getOriginalFilename());
-            String newFileName = System.currentTimeMillis() + "_" + mShiroService.getPrincipalId()+"_"+sign+"." + hz;
+            String newFileName = System.currentTimeMillis() + "_" + username+"_"+sign+"." + hz;
             try {
                 //复制到零时文件
                 File target = new File(imageDirPath + newFileName);
@@ -84,4 +97,6 @@ public class CropController extends BaseComponent {
         return "";
     }
 
+
+
 }

+ 4 - 0
src/main/java/com/sysu/admin/api/crop/CropVo.java

@@ -4,6 +4,8 @@ import com.sysu.admin.controller.crop.images.CropImage;
 import lombok.Data;
 import lombok.experimental.FieldNameConstants;
 
+import javax.persistence.Column;
+
 @Data
 @FieldNameConstants(innerTypeName = "FIELDS")
 public class CropVo {
@@ -17,5 +19,7 @@ public class CropVo {
     private CropImage fay;
     private CropImage center;
     private CropImage near;
+    private Double pickLongitude;
+    private Double pickLatitude;
 
 }

+ 8 - 1
src/main/java/com/sysu/admin/controller/crop/CropLand.java

@@ -1,6 +1,7 @@
 package com.sysu.admin.controller.crop;
 
 import com.alibaba.fastjson.annotation.JSONField;
+import com.sysu.admin.controller.crop.images.CropImage;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
@@ -8,7 +9,6 @@ import lombok.experimental.FieldNameConstants;
 import org.hibernate.annotations.DynamicInsert;
 import org.hibernate.annotations.DynamicUpdate;
 import org.locationtech.jts.geom.MultiPolygon;
-
 import javax.persistence.*;
 import java.util.Date;
 
@@ -96,5 +96,12 @@ public class CropLand {
     @Column
     private Integer status;
 
+    @Transient
+    private CropImage fay;
+    @Transient
+    private CropImage center;
+    @Transient
+    private CropImage near;
+
 
 }

+ 0 - 3
src/main/java/com/sysu/admin/controller/crop/CropLandRepository.java

@@ -19,8 +19,5 @@ public interface CropLandRepository extends JpaPlusRepository<CropLand, Long> {
             ");",nativeQuery = true)
     List<CropLand> findByBuffer(String pointWKT, Double degree);
 
-    @Query(value = "update \"p_crop\" set status = ?2 where id = ?1", nativeQuery = true)
-    @Modifying
-    int updateStatus(Long id, Integer status);
 
 }

+ 14 - 0
src/main/java/com/sysu/admin/controller/crop/CropLandService.java

@@ -1,8 +1,11 @@
 package com.sysu.admin.controller.crop;
 
+import com.sysu.admin.controller.crop.images.CropImage;
+import com.sysu.admin.controller.crop.images.CropImageService;
 import com.sysu.admin.controller.geo.land.LandTaskStatus;
 import com.sysu.admin.support.base.BaseService;
 import com.xiesx.fastboot.core.jpa.JpaPlusRepository;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.transaction.Transactional;
@@ -12,6 +15,8 @@ import java.util.List;
 @Service
 public class CropLandService extends BaseService<CropLand, Long> {
 
+    @Autowired
+    CropImageService cropImageService;
 
     public List<CropLand> findByBuffer(Double[] point, Integer meter){
         double degree = meter / (2 * Math.PI * 6371004) * 360;
@@ -33,6 +38,15 @@ public class CropLandService extends BaseService<CropLand, Long> {
         mCropLandRepository.save(bean);
     }
 
+    @Transactional
+    public void saveCropAndImages(CropLand bean, CropImage[] cropImages){
+        for(CropImage cropImage: cropImages){
+            cropImage.setCropId(bean.getId());
+            cropImageService.save(cropImage);
+        }
+        mCropLandRepository.save(bean);
+    }
+
     @Override
     public JpaPlusRepository<CropLand, Long> r() {
         return mCropLandRepository;

+ 7 - 1
src/main/java/com/sysu/admin/controller/crop/images/CropImage.java

@@ -22,7 +22,7 @@ import java.util.Date;
 @Accessors(chain = true)
 @EqualsAndHashCode(callSuper = false)
 @FieldNameConstants(innerTypeName = "FIELDS")
-@Table(name = "p_field_point_image")
+@Table(name = "p_crop_image")
 @Entity
 @EntityListeners(AuditingEntityListener.class)
 @DynamicInsert
@@ -44,6 +44,12 @@ public class CropImage extends JpaPlusEntity<CropImage> {
     private String filename;
 
     /**
+     * 类型 是远景0还是中景1 还是近景色2
+     */
+    @Column
+    private Integer type;
+
+    /**
      * 创建时间
      */
     @CreatedDate

+ 1 - 0
src/main/java/com/sysu/admin/controller/crop/images/CropImageService.java

@@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
 @Service
 public class CropImageService extends BaseService<CropImage, Long> {
 
+
     @Override
     public JpaPlusRepository<CropImage, Long> r() {
         return mCropImageRepository;

+ 10 - 0
src/main/java/com/sysu/admin/controller/geo/CropLandController.java

@@ -9,6 +9,7 @@ import com.sysu.admin.utils.shape.GeoCastUtil;
 import com.xiesx.fastboot.base.result.BaseResult;
 import com.xiesx.fastboot.base.result.R;
 import com.xiesx.fastboot.utils.CopyUtils;
+import org.locationtech.jts.geom.MultiPolygon;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -52,6 +53,15 @@ public class CropLandController {
         return R.succ(bean);
     }
 
+    @RequestMapping("/addTest")
+    @ResponseBody
+    public BaseResult addTest(String wkt){
+        CropLand bean = new CropLand().setGeom((MultiPolygon)GeoCastUtil.wktToGeom(wkt))
+                .setGridcode(2L).setStatus(LandTaskStatus.unpublished.ordinal());
+        cityLandService.save(bean);
+        return R.succ();
+    }
+
 }
 
 

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

@@ -18,6 +18,7 @@ public class SldStyleController extends ServiceContext {
     @ResponseBody
     public BaseResult sign(String styleName){
         String sldXmlJson =  mSConfigService.getV(styleName);
+        System.out.println(sldXmlJson);
         return R.succ(sldXmlJson);
     }
 

+ 19 - 0
src/main/java/com/sysu/admin/support/system/config/ConfigContext.java

@@ -0,0 +1,19 @@
+package com.sysu.admin.support.system.config;
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+@Component
+@ConfigurationProperties("config")
+public class ConfigContext {
+
+    private String imageDirPath;
+
+    public String getImageDirPath() {
+        return imageDirPath;
+    }
+
+    public void setImageDirPath(String imageDirPath) {
+        this.imageDirPath = imageDirPath;
+    }
+}

+ 1 - 1
src/main/resources/application-adm.yml

@@ -56,7 +56,7 @@ spring:
   jpa:
     database-platform: org.hibernate.spatial.dialect.postgis.PostgisDialect
     show-sql: false
-
+config.image-dir-path: /www/wwwroot/emap.sysuimars.com/images/
 postgis:
   url: localhost
   port: 39543

+ 1 - 1
src/main/resources/application-dev.yml

@@ -17,7 +17,7 @@ spring:
     password: postgres
     pool-name: HikariPool-1
 
-
+config.image-dir-path: E:/zcjy/workspace3/sysu_emap/src/main/webapp/images/
 postgis:
   url: 101.35.200.5
   port: 39543

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

@@ -60,9 +60,9 @@
                 var target = "map"
 
                 view1 = new ol.View({
-                    center: [112.9986, 23.6789],
+                    center: [113.348406, 23.166332],
                     projection: projection,
-                    zoom: 12
+                    zoom: 14
                 })
 
                 map = new ol.Map({

+ 59 - 14
src/main/webapp/static/package/cityland.js

@@ -17,6 +17,8 @@ CityLandAction.prototype = {
         let that = this
         this.obj.getTileLayer()
         this.tempVectorLayer = this.loadTempVectorLayer()
+        this.drawMultiPolygon = new DrawMultiPolygon({vector: this.tempVectorLayer, map: this.context.currentMap,wkt: this.context.wkt})
+
         this.popup = new Popup({map: this.context.currentMap,
             close(){
                 that.tempVectorLayer.getSource().clear()
@@ -45,6 +47,7 @@ CityLandAction.prototype = {
             return
         }
         this.context.clicks[this.id] = this
+        this.drawMultiPolygon.show()
         this.context.currentMap.addLayer(this.obj.layerData.layer)
         this.context.getSldStyleSign(this.obj.wmsData.params.STYLE)
         this.startStatus = true;
@@ -56,6 +59,8 @@ CityLandAction.prototype = {
         }
         this.tempVectorLayer.getSource().clear()
         this.context.currentMap.removeLayer(this.obj.layerData.layer)
+        console.log("drawMultiPolygon close")
+        this.drawMultiPolygon.close()
         console.log("tempVectorLayer cleared")
         this.context.clicks[this.id] = null
         console.log("remove click")
@@ -183,18 +188,6 @@ CityLandAction.prototype = {
         }
         return html
     },
-    // selectPoint(that){
-    //     document.body.style.cursor = "crosshair";
-    //     that.popup.showOrHide(false)
-    //     this.context.clicks["selectPoint"] = {
-    //         click(event, action){
-    //             $("#point").val(event.coordinate[0].toFixed(7)+","+event.coordinate[1].toFixed(7))
-    //             that.context.clicks["selectPoint"] = undefined
-    //             document.body.style.cursor = "default";
-    //             that.popup.showOrHide(true)
-    //         }
-    //     }
-    // },
     saveTask(that, feature){
         layui.tool.submit("/crop/save",{"status":1,"id":feature.get("id")},function(res){
             if(res.code == 0){
@@ -202,7 +195,6 @@ CityLandAction.prototype = {
             }
         })
     }
-
 }
 
 function CityLand(opt){
@@ -272,4 +264,57 @@ CityLand.prototype = {
             maxZoom: 30
         });
     }
-}
+}
+
+
+function DrawMultiPolygon(option){
+    this.vector = option.vector
+    this.map = option.map
+    this.wkt = option.wkt
+    let that = this
+    let html = "<a href='javascript:void(0)' id='drawMultiPolygon' style='color: white;position: absolute;top: 0px;right: 100px;z-index: 10' >绘制多边形</a>";
+    $(document.body).append(html)
+    this.initDraw()
+    $("#drawMultiPolygon").on("click",function(){
+        that.vector.getSource().clear()
+        that.draw.setActive(true)
+    })
+
+}
+
+DrawMultiPolygon.prototype = {
+    initDraw(){
+        let that = this
+        that.draw = new ol.interaction.Draw({
+            source : that.vector.getSource(),
+            type: "MultiPolygon",
+            freehand: false,//自由绘制
+            stopClick: true
+        })
+        that.draw.setActive(false)
+        that.draw.on("drawend", function(e){
+            that.draw.setActive(false)
+            that.submit(e.feature)
+        })
+        that.map.addInteraction(that.draw)
+    },
+    show(){
+        $("#drawMultiPolygon").show()
+    },
+    close(){
+        this.draw.setActive(false)
+        $("#drawMultiPolygon").hide()
+    },
+    submit(feature){
+        let geometry = feature.getGeometry()
+        layui.tool.post("/crop/addTest",{"wkt":this.wkt.writeGeometry(geometry)})
+    }
+}
+
+
+
+
+
+
+
+

+ 1 - 1
src/main/webapp/static/package/geo_server_context.js

@@ -107,6 +107,7 @@ function TipLayer(option){
     for(let feature of this.features){
         let point = new ol.geom.Point(ol.extent.getCenter(feature.getGeometry().getExtent()))
         let pointFeature = new ol.Feature({geometry:point})
+        pointFeature.setId(feature.getId().substring(feature.getId().indexOf(".") + 1))
         let keys = feature.getKeys();
         for(let key of keys){
             if(key === "geometry"){
@@ -115,7 +116,6 @@ function TipLayer(option){
             pointFeature.set(key,feature.get(key))
         }
         this.source.addFeature(pointFeature)
-        console.log(pointFeature.getKeys())
     }
     this.vector = new ol.layer.Vector({
         style: this.style,

+ 1 - 2
src/main/webapp/static/package/style.js

@@ -8,10 +8,9 @@ let globalStyle = {
         });
     },
     pointStyle(f){
-        console.log(f.get("id"))
         return new ol.style.Style({
             text:new ol.style.Text({
-                text:f.get("id")+"",
+                text:f.getId(),
                 stroke: new ol.style.Stroke({
                     color: 'rgba(239,236,236)',
                     width: 1,

+ 0 - 11
src/main/webapp/static/package/task_action.js

@@ -72,17 +72,6 @@ TaskLandAction.prototype = {
         this.popup._close()
         console.log("close popup")
         this.startStatus = false;
-    },
-    addFieldPointOfTempLayer(TaskLand){
-        let geometry = this.context.wkt.readGeometry(TaskLand.wkt)
-        let extent = ol.extent.getCenter(geometry.getExtent());
-        let point = new ol.Feature({
-            geometry: new ol.geom.Point(extent)
-        });
-        point.set("isPoint",1)
-        point.set("id",TaskLand.id)
-        let source = this.tempVectorLayer.getSource();
-        source.addFeature(point)
     }
     ,
     landType:{