Administrator %!s(int64=2) %!d(string=hai) anos
pai
achega
07d4aba4d8

+ 8 - 0
pom.xml

@@ -111,6 +111,14 @@
 			<groupId>javax.servlet</groupId>
 			<artifactId>jstl</artifactId>
 		</dependency>
+		<!-- https://mvnrepository.com/artifact/org.apache.velocity/velocity-engine-core -->
+		<dependency>
+			<groupId>org.apache.velocity</groupId>
+			<artifactId>velocity-engine-core</artifactId>
+			<version>2.3</version>
+			<scope>test</scope>
+		</dependency>
+
 		<!-- ==========================shiro========================== -->
 		<!-- https://mvnrepository.com/artifact/org.apache.shiro/shiro-spring -->
 		<dependency>

+ 1 - 1
src/main/java/com/sysu/admin/api/crop/ApiLandController.java

@@ -87,7 +87,7 @@ public class ApiLandController extends BaseComponent {
         PaginationResult result  = landService.list(commonVo.getSure(), commonVo.getDistrict(),commonVo.getTown(), paginationVo, commonVo.getCrop_type(), commonVo.getParcel_type());
         ((List<Land>)result.data()).stream().forEach(land -> {
             land.setCropTypeName(CropAreaStat.castName(land.getCrop_type()));
-            land.setParcelTypeName(LandAreaStat.castName(land.getParcelType()));
+            land.setParcelTypeName(LandAreaStat.castName(land.getParcel_type()));
             //计算总产量
             land.setZongChan(land.getDanChan() * land.getArea());
             land.setGeojson(GeoCastUtil.gjson.toString(land.getGeom()));

+ 1 - 1
src/main/java/com/sysu/admin/controller/aland/Land.java

@@ -145,7 +145,7 @@ crop_sure -- 作物可信度
     @Column
     private Integer majority;
     @Column
-    private Integer parcelType;
+    private Integer parcel_type;
     @Transient
     private String parcelTypeName;
 

+ 2 - 2
src/main/java/com/sysu/admin/controller/aland/LandAreaStat.java

@@ -23,8 +23,8 @@ public class LandAreaStat {
     /**
      * 0其它 1水田  2水浇地  3旱地  4果园
      */
-    static  String[] name2s = {"其他","水田","水浇地","旱地","果园"};
-    static  String[] colors = {"#696969","#228B22","#8FAFE3","#EEB554","#D365A1"};
+    static String[] name2s = {"其他","水田","水浇地","旱地","果园"};
+    static String[] colors = {"#696969","#228B22","#8FAFE3","#EEB554","#D365A1"};
 
     public static String castName(Integer id){
         if(id != null){

+ 36 - 0
src/main/resources/styleModel.vm

@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<StyledLayerDescriptor version="1.0.0"
+  xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd"
+  xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
+  xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+  <NamedLayer>
+    <Name>${name}</Name>
+    <UserStyle>
+      <Title>A gold polygon style</Title>
+      <FeatureTypeStyle>
+		#foreach( $item in $rules )
+        <Rule>
+          <Title>${item.title}</Title>
+          <ogc:Filter>
+            <ogc:PropertyIsEqualTo>
+              <ogc:PropertyName>${item.field}</ogc:PropertyName>
+              <ogc:Literal>${item.value}</ogc:Literal>
+            </ogc:PropertyIsEqualTo>
+          </ogc:Filter>
+          <PolygonSymbolizer>
+            <Fill>
+              <CssParameter name="fill">${item.color}</CssParameter>
+              <CssParameter name="fill-opacity">0.6</CssParameter>
+            </Fill>
+            <Stroke>
+            	<CssParameter name="stroke">${item.color}</CssParameter>
+            	<CssParameter name="stroke-width">1.5</CssParameter>
+          	</Stroke>
+          </PolygonSymbolizer>
+        </Rule>
+		#end
+      </FeatureTypeStyle>
+    </UserStyle>
+  </NamedLayer>
+</StyledLayerDescriptor>

+ 52 - 2
src/test/java/com/sysu/admin/api/crop/CropControllerTest.java

@@ -1,7 +1,57 @@
 package com.sysu.admin.api.crop;
 
+import com.sysu.admin.controller.aland.StatItemData;
 import junit.framework.TestCase;
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.io.VelocityWriter;
+import org.apache.velocity.runtime.RuntimeConstants;
+import org.apache.velocity.runtime.VelocimacroFactory;
+import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
+import org.junit.Test;
 
-public class CropControllerTest extends TestCase {
+import java.io.*;
+import java.nio.charset.Charset;
+import java.util.HashMap;
+import java.util.Map;
 
-}
+public class CropControllerTest {
+
+    @Test
+    public void runVelocityModel() throws IOException {
+        VelocityEngine ve = new VelocityEngine();
+        ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
+        ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
+        ve.setProperty(RuntimeConstants.INPUT_ENCODING, Charset.forName("GBK"));
+        ve.init();
+        Template t = ve.getTemplate("styleModel.vm");
+        VelocityContext context = new VelocityContext();
+
+        for(String key : StatItemData.typeMap.keySet()){
+            String field =  StatItemData.typeMap.get(key)[1];
+            String[] names = StatItemData.get(key,"Names");
+            String[] colors = StatItemData.get(key,"Colors");
+            Map<String, String>[] rules = new HashMap[names.length];
+            for(int i=0;i<names.length;i++){
+                Map<String, String> item = new HashMap<>();
+                item.put("title",names[i]);
+                item.put("field",field);
+                item.put("value",i+"");
+                item.put("color",colors[i]);
+                rules[i] = item;
+            }
+            context.put("name","leizhou_land_"+key+"_type");
+            context.put("rules",rules);
+            File tempFile = new File("E:/FFout","leizhou_land_"+key+"_type");
+            FileOutputStream fs=new FileOutputStream(tempFile);
+            OutputStreamWriter fileWriter=new OutputStreamWriter(fs, Charset.forName("UTF-8"));
+            t.merge(context, fileWriter);
+            fileWriter.flush();
+            fileWriter.close();
+        }
+
+
+    }
+
+}