Parcourir la source

优化瓦片生成

zhouyuexiang il y a 1 an
Parent
commit
593b1e09af

+ 3 - 0
cql-service/src/main/java/cn/com/taiji/cql/model/GeoRequestParam.java

@@ -35,4 +35,7 @@ public class GeoRequestParam implements Serializable {
     private String styles;
 
     private String bbox;
+
+    private int x;
+    private int y;
 }

+ 1 - 0
cql-service/src/main/java/cn/com/taiji/cql/service/impl/SqlServiceImpl.java

@@ -71,6 +71,7 @@ public class SqlServiceImpl implements ISqlService {
                 resultSet = preparedStatement.executeQuery();
 
                 datas = getDatas(resultSet);
+                count= Long.valueOf(datas.size());
 
             }
         }catch (Exception exception){

+ 8 - 0
external-data.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<data>
+  <object-set>
+    <view path="geo.layer_style_view">
+      <column name="virtual_column_name" expr=""/>
+    </view>
+  </object-set>
+</data>

+ 25 - 0
tile-service/src/main/java/cn/com/taiji/tile/model/FeatureInfo.java

@@ -0,0 +1,25 @@
+package cn.com.taiji.tile.model;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.checkerframework.checker.units.qual.A;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author zzyx 2024/1/25
+ */
+@Data
+@ApiModel("点击要素信息")
+public class FeatureInfo {
+    private String totalFeatures;
+    @ApiModelProperty("要素信息集合")
+    private List<Map<String,Object>> features;
+    @ApiModelProperty("时间戳")
+    private String timeStamp;
+    @ApiModelProperty("总数")
+    private Integer numberReturned;
+
+}

+ 3 - 0
tile-service/src/main/java/cn/com/taiji/tile/service/ITileService.java

@@ -4,6 +4,7 @@ package cn.com.taiji.tile.service;
 import cn.com.taiji.common.model.LayerGroupDsView;
 import cn.com.taiji.common.model.LayerStyleView;
 import cn.com.taiji.cql.model.GeoRequestParam;
+import cn.com.taiji.tile.model.FeatureInfo;
 
 import java.util.List;
 import java.util.Map;
@@ -22,4 +23,6 @@ public interface ITileService {
      */
     List<?> queryElements(String bbox, Integer type, String layerName);
 
+    FeatureInfo getFeatureInfo(GeoRequestParam geoRequestParam, List<LayerGroupDsView> layerGroupDsViewList, Map<String, List<LayerStyleView>> dataMaps);
+
 }

+ 134 - 51
tile-service/src/main/java/cn/com/taiji/tile/service/impl/TileServiceImpl.java

@@ -6,10 +6,12 @@ import cn.com.taiji.common.model.LayerStyleView;
 import cn.com.taiji.cql.model.GeoRequestParam;
 import cn.com.taiji.cql.service.IECqlService;
 import cn.com.taiji.cql.service.ISqlService;
+import cn.com.taiji.tile.model.FeatureInfo;
 import cn.com.taiji.tile.model.POI;
 import cn.com.taiji.tile.service.ITileService;
 import cn.com.taiji.tile.style.ShapeStyle;
 import cn.com.taiji.tile.util.ShapeUtils;
+import cn.hutool.core.date.DateUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.geotools.data.jdbc.datasource.DBCPDataSourceFactory;
 import org.geotools.jdbc.JDBCDataStoreFactory;
@@ -22,8 +24,11 @@ import java.awt.image.BufferedImage;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 @Slf4j
 @Service
@@ -38,28 +43,21 @@ public class TileServiceImpl implements ITileService {
 
     @Override
     public byte[] tileData(GeoRequestParam requestParam, List<LayerGroupDsView> layerGroupDsViewList, Map<String, List<LayerStyleView>> dataMaps) {
-        BufferedImage image = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB);
-        Graphics2D g2 = image.createGraphics();
-        for (LayerGroupDsView layerGroupDsView : layerGroupDsViewList) {
-
-
+        ConcurrentHashMap<String, BufferedImage> biMap = new ConcurrentHashMap<>();
+        layerGroupDsViewList.parallelStream().forEach(layerGroupDsView -> {
+            long l = System.currentTimeMillis();
             //获取图层代码对应的样式
             List<LayerStyleView> layerStyleViewList = new ArrayList<LayerStyleView>();
-
             if (dataMaps.containsKey(layerGroupDsView.getLayerCode())) {
-
                 layerStyleViewList = dataMaps.get(layerGroupDsView.getLayerCode());
-
             }
-
-
             String host = layerGroupDsView.getHost().split(",")[0].split(":")[0];
             String port = layerGroupDsView.getHost().split(",")[0].split(":")[1];
 
             Map<String, Object> cqlDsParams = new HashMap<String, Object>();
             cqlDsParams.put(DBCPDataSourceFactory.DSTYPE.key, "DBCP");
             cqlDsParams.put(DBCPDataSourceFactory.DRIVERCLASS.key, "com.mysql.cj.jdbc.Driver");
-            cqlDsParams.put(DBCPDataSourceFactory.JDBC_URL.key, "jdbc:mysql://"+host+":"+port+"/"+layerGroupDsView.getDataBase()+"?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai");
+            cqlDsParams.put(DBCPDataSourceFactory.JDBC_URL.key, "jdbc:mysql://" + host + ":" + port + "/" + layerGroupDsView.getDataBase() + "?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai");
             cqlDsParams.put(DBCPDataSourceFactory.USERNAME.key, layerGroupDsView.getUserName());
             cqlDsParams.put(DBCPDataSourceFactory.PASSWORD.key, layerGroupDsView.getUserPassword());
             cqlDsParams.put(DBCPDataSourceFactory.MAXACTIVE.key, Integer.valueOf(10));
@@ -91,81 +89,60 @@ public class TileServiceImpl implements ITileService {
                 }
 
                 String bbox = requestParam.getBbox();
-                if(bbox !=null && !"".equals(bbox)){
+                if (bbox != null && !"".equals(bbox)) {
 
                     StringBuffer sbBbox = new StringBuffer();
                     sbBbox.append("(bbox (");
-                    sbBbox.append(layerGroupDsView.getBoxColumn()+",");
-                    sbBbox.append(requestParam.getBbox()+"))");
+                    sbBbox.append("location,");
+                    sbBbox.append(requestParam.getBbox() + "))");
 
-                    if(filterCqlStr.length() >0){
+                    if (filterCqlStr.length() > 0) {
 
-                        filterCqlStr.append(" and "+sbBbox.toString());
-                    }else{
+                        filterCqlStr.append(" and " + sbBbox.toString());
+                    } else {
 
                         filterCqlStr.append(sbBbox.toString());
 
                     }
 
                 }
-
                 if (layerDataRun != null && !"".equals(layerDataRun)) {
-
                     if (filterCqlStr.length() > 0) {
-
                         filterCqlStr.append(" and " + layerDataRun);
                     } else {
-
                         filterCqlStr.append(layerDataRun);
-
                     }
-
                 }
-
                 System.out.println("查询条件:" + filterCqlStr.toString());
-
-
                 Map<String, Object> mapParams = new HashMap<String, Object>();
                 if (filterCqlStr.length() > 0) {
                     mapParams.put("cql", filterCqlStr.toString());
                 }
-
                 pageResult = ecqlService.cqlQuery(cqlDsParams, mapParams);
-
-
-
-            }else if(layerDataType != null && !"".equals(layerDataType) && "sql".equals(layerDataType)){
-
+            } else if (layerDataType != null && !"".equals(layerDataType) && "sql".equals(layerDataType)) {
                 if (layerDataRun != null && !"".equals(layerDataRun)) {
-
                     //安照sql语句的占位符?的顺序来设置sql语句的动态参数
                     Object[] bindArgs = new Object[0];
-
-                    pageResult = sqlService.sqlQuery4Jdbc(cqlDsParams,layerDataRun,bindArgs);
-
-                }else{
-
+                    pageResult = sqlService.sqlQuery4Jdbc(cqlDsParams, layerDataRun, bindArgs);
+                } else {
                     log.info("执行图层数据类型:" + layerDataType + "和图层代码:" + requestParam.getLayers() + " 的执行内容为空或者为null");
-
                 }
-
-
-
             }
-
-
-            if (pageResult!=null && pageResult.getRecordCount() > 0 ) {
-
+            if (pageResult != null && pageResult.getRecordCount() > 0) {
                 List<Map<String, Object>> cqlDataList = (List<Map<String, Object>>) pageResult.getDatas();
                 //3根据空间地理数据生成图层二进制数据
-                ShapeUtils.drawImage(requestParam.getBbox(), convert(cqlDataList,layerGroupDsView.getBoxColumn()), layerStyleViewList,g2);
-
+                long l1 = System.currentTimeMillis();
+                System.out.println("查询耗时:" + (l1 - l));
+                BufferedImage bufferedImage = ShapeUtils.drawImage(requestParam.getBbox(), cqlDataList, layerGroupDsView.getBoxColumn(), layerStyleViewList);
+                biMap.put(layerGroupDsView.getLayerCode(),bufferedImage);
+                System.out.println("瓦片生成:" + (System.currentTimeMillis() - l1) + "数据大小:" + cqlDataList.size());
             } else {
-
                 log.info("根据查询过滤规则条件:" + filterCqlStr.toString() + "和图层代码:" + requestParam.getLayers() + " 没有找到图层对应的数据源的空间地理数据");
             }
-
-        }
+        });
+        BufferedImage image = new BufferedImage(requestParam.getWidth(), requestParam.getHeight(), BufferedImage.TYPE_INT_ARGB);
+        Graphics2D g2 = image.createGraphics();
+        layerGroupDsViewList.forEach(item-> g2.drawImage(biMap.get(item.getLayerCode()), 0, 0, null));
         ByteArrayOutputStream buffer = new ByteArrayOutputStream();
         try {
             ImageIO.write(image, "png", buffer);
@@ -191,6 +168,112 @@ public class TileServiceImpl implements ITileService {
         return null;
     }
 
+    @Override
+    public FeatureInfo getFeatureInfo(GeoRequestParam requestParam, List<LayerGroupDsView> layerGroupDsViewList, Map<String, List<LayerStyleView>> dataMaps) {
+        FeatureInfo featureInfo = new FeatureInfo();
+        List<Map<String, Object>> features = new CopyOnWriteArrayList<>();
+        layerGroupDsViewList.parallelStream().forEach(layerGroupDsView -> {
+            long l = System.currentTimeMillis();
+            //获取图层代码对应的样式
+            List<LayerStyleView> layerStyleViewList = new ArrayList<LayerStyleView>();
+            if (dataMaps.containsKey(layerGroupDsView.getLayerCode())) {
+                layerStyleViewList = dataMaps.get(layerGroupDsView.getLayerCode());
+            }
+            String host = layerGroupDsView.getHost().split(",")[0].split(":")[0];
+            String port = layerGroupDsView.getHost().split(",")[0].split(":")[1];
+
+            Map<String, Object> cqlDsParams = new HashMap<String, Object>();
+            cqlDsParams.put(DBCPDataSourceFactory.DSTYPE.key, "DBCP");
+            cqlDsParams.put(DBCPDataSourceFactory.DRIVERCLASS.key, "com.mysql.cj.jdbc.Driver");
+            cqlDsParams.put(DBCPDataSourceFactory.JDBC_URL.key, "jdbc:mysql://" + host + ":" + port + "/" + layerGroupDsView.getDataBase() + "?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai");
+            cqlDsParams.put(DBCPDataSourceFactory.USERNAME.key, layerGroupDsView.getUserName());
+            cqlDsParams.put(DBCPDataSourceFactory.PASSWORD.key, layerGroupDsView.getUserPassword());
+            cqlDsParams.put(DBCPDataSourceFactory.MAXACTIVE.key, Integer.valueOf(10));
+            cqlDsParams.put(DBCPDataSourceFactory.MAXIDLE.key, Integer.valueOf(1));
+            cqlDsParams.put(JDBCDataStoreFactory.HOST.key, host);
+            cqlDsParams.put(JDBCDataStoreFactory.DATABASE.key, layerGroupDsView.getDataBase());
+            cqlDsParams.put(JDBCDataStoreFactory.PORT.key, port);
+            cqlDsParams.put("tableName", layerGroupDsView.getTableName());
+
+
+            String layerDataType = layerGroupDsView.getLayerDataType();
+            String layerDataRun = layerGroupDsView.getLayerDataRun();
+
+            PageResult pageResult = null;
+
+            StringBuffer filterCqlStr = new StringBuffer();
+
+            if (layerDataType != null && !"".equals(layerDataType) && "cql".equals(layerDataType)) {
+
+                //2根据cql规则获取图层对应的空间地理数据
+
+                long currentTimeMillis = System.currentTimeMillis();
+
+                String filterCql = requestParam.getCqlFilter();
+
+                if (filterCql != null && !"".equals(filterCql)) {
+
+                    filterCqlStr.append(filterCql);
+                }
+
+                String bbox = requestParam.getBbox();
+                if (bbox != null && !"".equals(bbox)) {
+
+                    StringBuffer sbBbox = new StringBuffer();
+                    sbBbox.append("(bbox (");
+                    sbBbox.append("location,");
+                    sbBbox.append(requestParam.getBbox() + "))");
+
+                    if (filterCqlStr.length() > 0) {
+
+                        filterCqlStr.append(" and " + sbBbox.toString());
+                    } else {
+
+                        filterCqlStr.append(sbBbox.toString());
+
+                    }
+
+                }
+                if (layerDataRun != null && !"".equals(layerDataRun)) {
+                    if (filterCqlStr.length() > 0) {
+                        filterCqlStr.append(" and " + layerDataRun);
+                    } else {
+                        filterCqlStr.append(layerDataRun);
+                    }
+                }
+                System.out.println("查询条件:" + filterCqlStr.toString());
+                Map<String, Object> mapParams = new HashMap<String, Object>();
+                if (filterCqlStr.length() > 0) {
+                    mapParams.put("cql", filterCqlStr.toString());
+                }
+                pageResult = ecqlService.cqlQuery(cqlDsParams, mapParams);
+            } else if (layerDataType != null && !"".equals(layerDataType) && "sql".equals(layerDataType)) {
+                if (layerDataRun != null && !"".equals(layerDataRun)) {
+                    //安照sql语句的占位符?的顺序来设置sql语句的动态参数
+                    Object[] bindArgs = new Object[0];
+                    pageResult = sqlService.sqlQuery4Jdbc(cqlDsParams, layerDataRun, bindArgs);
+                } else {
+                    log.info("执行图层数据类型:" + layerDataType + "和图层代码:" + requestParam.getLayers() + " 的执行内容为空或者为null");
+                }
+            }
+            if (pageResult != null && pageResult.getRecordCount() > 0) {
+                List<Map<String, Object>> cqlDataList = (List<Map<String, Object>>) pageResult.getDatas();
+                //3根据空间地理数据生成图层二进制数据
+                long l1 = System.currentTimeMillis();
+                System.out.println("查询耗时:" + (l1 - l));
+                List<Map<String, Object>> maps = ShapeUtils.detectClick(requestParam.getBbox(), cqlDataList, layerGroupDsView.getBoxColumn(), layerStyleViewList, requestParam.getX(), requestParam.getY());
+                features.addAll(maps);
+                System.out.println("瓦片生成:" + (System.currentTimeMillis() - l1) + "数据大小:" + cqlDataList.size());
+            } else {
+                log.info("根据查询过滤规则条件:" + filterCqlStr.toString() + "和图层代码:" + requestParam.getLayers() + " 没有找到图层对应的数据源的空间地理数据");
+            }
+        });
+        featureInfo.setFeatures(features);
+        featureInfo.setNumberReturned(features.size());
+        featureInfo.setTimeStamp(DateUtil.format(new Date(),DateTimeFormatter.ISO_INSTANT));
+        return featureInfo;
+    }
+
     public static double[] parseBbox(String bboxString) {
         String[] bboxValuesStr = bboxString.split(",");
         if (bboxValuesStr.length != 4) {

+ 38 - 66
tile-service/src/main/java/cn/com/taiji/tile/util/ShapeUtils.java

@@ -1,30 +1,26 @@
 package cn.com.taiji.tile.util;
 
 import cn.com.taiji.common.model.LayerStyleView;
-import cn.com.taiji.tile.model.POI;
 import cn.com.taiji.tile.style.ShapeStyle;
 import cn.hutool.core.util.BooleanUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.locationtech.jts.geom.Coordinate;
 import org.locationtech.jts.geom.Geometry;
+import org.locationtech.jts.io.ParseException;
+import org.locationtech.jts.io.WKTReader;
 import org.springframework.beans.BeanUtils;
 
 import javax.imageio.ImageIO;
 import java.awt.*;
 import java.awt.image.BufferedImage;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.net.URL;
-import java.util.Arrays;
 import java.util.List;
+import java.util.Map;
 import java.util.Objects;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.function.Consumer;
-import java.util.stream.Collectors;
-
-import static org.apache.coyote.http11.Constants.a;
 
 /**
  * @author zzyx 2024/1/5
@@ -36,43 +32,7 @@ public class ShapeUtils {
     public static final int WIDTH = 256;
     public static final int HEIGHT = 256;
 
-    /**
-     * 获取瓦片字节数组
-     *
-     * @param bboxStr    逗号拼接的bbox字符串
-     * @param dataList   数据集合
-     * @return 瓦片字节数组
-     */
-    public static byte[] getTileByte(String bboxStr, List<POI> dataList, List<LayerStyleView>  layerStyleViews) {
-        ShapeStyle shapeStyle=new ShapeStyle();
-        BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
-        //样式转换
-        for (LayerStyleView layerStyleView : layerStyleViews) {
-            BeanUtils.copyProperties(layerStyleView, shapeStyle);
-
-            setColorFromHex(layerStyleView.getColor(), shapeStyle::setColor);
-            shapeStyle.setIsFill(Objects.equals(layerStyleView.getIsFill(), 1));
-
-            setColorFromHex(layerStyleView.getBorderColor(), shapeStyle::setBorderColor);
-            shapeStyle.setIsDashed(Objects.equals(layerStyleView.getIsDashed(), 1));
-
-            setDashPattern(layerStyleView.getDashPattern(), shapeStyle::setDashPattern);
-            setImage(layerStyleView.getBgImage(), shapeStyle::setBgImage);
-            shapeStyle.setIsShowName(Objects.equals(layerStyleView.getIsShowName(), 1));
-
-            setColorFromHex(layerStyleView.getFontColor(), shapeStyle::setFontColor);
-            setImage(layerStyleView.getCenterPointImage(), shapeStyle::setCenterPointImage);
-            setImage(layerStyleView.getPointMarkerImage(), shapeStyle::setPointMarkerImage);
-        }
-        renderShape(image, bboxStr, dataList, shapeStyle);
-        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
-        try {
-            ImageIO.write(image, "png", buffer);
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-        return buffer.toByteArray();
-    }
+    public final static WKTReader reader = new WKTReader();
 
 
     private static void setImage(String imageUrl, Consumer<BufferedImage> imageConsumer) {
@@ -110,15 +70,15 @@ public class ShapeUtils {
     }
 
 
-    private static void drawPolygonShape(double[] bbox, Graphics2D graphics, Geometry geometry, POI poi, ShapeStyle shapeStyle) {
+    private static void drawPolygonShape(double[] bbox, Graphics2D graphics, Geometry geometry, Map<String, Object> poi, ShapeStyle shapeStyle) {
         drawPolygonToTile(shapeStyle, geometry, graphics, bbox);
         //是否需要设置字名称
-        if (BooleanUtil.isTrue(shapeStyle.getIsShowName()) && StringUtils.isNotBlank(poi.getName())) {
+        if (BooleanUtil.isTrue(shapeStyle.getIsShowName()) && StringUtils.isNotBlank(poi.get("name").toString())) {
             org.locationtech.jts.geom.Point centroid = geometry.getCentroid();
             int[] pxy = TileUtils.toPixelXY(centroid.getX(), centroid.getY(), bbox[0], bbox[1], bbox[2], bbox[3]);
             //设置字体样式
             Font font = new Font("Arial", Font.TRUETYPE_FONT, shapeStyle.getFontSize());
-            String s = poi.getName();
+            String s = poi.get("name").toString();
             graphics.setColor(shapeStyle.getFontColor());
             graphics.setFont(font);
             graphics.drawString(s, pxy[0], pxy[1]);
@@ -149,23 +109,23 @@ public class ShapeUtils {
         graphics.drawPolyline(xpoint, ypoint, geometry.getCoordinates().length);
     }
 
-    public static void drawPointShape(double[] bbox, Graphics2D graphics, Geometry geometry, POI poi, ShapeStyle shapeStyle) {
+    public static void drawPointShape(double[] bbox, Graphics2D graphics, Geometry geometry, Map<String, Object> poi, ShapeStyle shapeStyle) {
         int[] pxy = TileUtils.toPixelXY(geometry.getCoordinate().x, geometry.getCoordinate().y, bbox[0], bbox[1], bbox[2], bbox[3]);
         //设置边框 实现轮廓
         graphics.setColor(shapeStyle.getColor());
         graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
         //设置字体
         //设置字体样式
-        if (BooleanUtil.isTrue(shapeStyle.getIsShowName())) {
+        if (BooleanUtil.isTrue(shapeStyle.getIsShowName()) && StringUtils.isNotBlank(poi.get("name").toString())) {
             Font font = new Font("Arial", Font.BOLD, shapeStyle.getFontSize());
-            String s = poi.getName();
+            String s = poi.get("name").toString();
             graphics.setColor(shapeStyle.getFontColor());
             graphics.setFont(font);
             graphics.drawString(s, pxy[0], pxy[1]);
         }
         BufferedImage pointMarkerImage = shapeStyle.getPointMarkerImage();
         if (pointMarkerImage != null) {
-            graphics.drawImage(TileUtils.scaleWidthHeight(pointMarkerImage, shapeStyle.getPointMarkerImageWidth(), shapeStyle.getPointMarkerImageHeight()), pxy[0], pxy[1], null);
+            graphics.drawImage(pointMarkerImage, pxy[0], pxy[1], null);
         } else {
             drawPointShape(shapeStyle, graphics, pxy);
         }
@@ -291,9 +251,8 @@ public class ShapeUtils {
         }
     }
 
-    public static List<POI> detectClick(String bboxStr, List<POI> dataList, ShapeStyle shapeStyle, int x, int y) {
-        List<POI> clickSelectedDataList = new CopyOnWriteArrayList<>();
-//        renderAndDetectClick(image, bboxStr, dataList, shapeStyle, x, y, clickSelectedDataList, true);
+    public static List<Map<String, Object>> detectClick(String bboxStr,List<Map<String, Object>> dataList, String shapeKey, List<LayerStyleView> layerStyleViews, int x, int y) {
+        List<Map<String, Object>> clickSelectedDataList = new CopyOnWriteArrayList<>();
         String[] split = bboxStr.split(",");
         double[] bbox = new double[split.length];
         for (int i = 0; i < split.length; i++) {
@@ -302,7 +261,7 @@ public class ShapeUtils {
         dataList.parallelStream().forEach(poi -> {
             BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
             Graphics2D graphics = image.createGraphics();
-            drawShape(shapeStyle, poi, bbox, graphics);
+            drawShape(getShapeStyle(layerStyleViews), poi, bbox, graphics, shapeKey);
             //如果选中
             int rgb = image.getRGB(x, y);
             int alpha = (rgb >> 24) & 0xff; // 提取alpha值
@@ -314,20 +273,27 @@ public class ShapeUtils {
         return clickSelectedDataList;
     }
 
-    public static void renderShape(BufferedImage image, String bboxStr, List<POI> dataList, ShapeStyle shapeStyle) {
+    public static void renderShape(BufferedImage image, String bboxStr, List<Map<String, Object>> dataList, ShapeStyle shapeStyle, String shapeKey) {
         String[] split = bboxStr.split(",");
         double[] bbox = new double[split.length];
         for (int i = 0; i < split.length; i++) {
             bbox[i] = Double.parseDouble(split[i]);
         }
         Graphics2D graphics = image.createGraphics();
-        long l = System.currentTimeMillis();
-        dataList.parallelStream().forEach(poi -> drawShape(shapeStyle, poi, bbox, graphics));
+        dataList.parallelStream().forEach(poi -> drawShape(shapeStyle, poi, bbox, graphics, shapeKey));
     }
 
-    private static void drawShape(ShapeStyle shapeStyle, POI poi, double[] bbox, Graphics2D graphics) {
-        Geometry shape = GeoUtils.getGeoUtils().createGeometry(poi.getShape());
-        if(shape!=null) {
+    private static void drawShape(ShapeStyle shapeStyle, Map<String, Object> poi, double[] bbox, Graphics2D graphics, String shapeKey) {
+//        Geometry shape = GeoUtils.getGeoUtils().createGeometry(poi.get(shapeKey));
+
+        Geometry shape = null;
+        long l = System.currentTimeMillis();
+        try {
+            shape = reader.read(poi.get(shapeKey).toString());
+        } catch (ParseException e) {
+            throw new RuntimeException(e);
+        }
+        if (shape != null) {
             if (StringUtils.equals(shape.getGeometryType(), "Polygon")) {
                 drawPolygonShape(bbox, graphics, shape, poi, shapeStyle);
             } else if (StringUtils.equalsAny(shape.getGeometryType(), "LinearRing", "LineString", "MultiLineString")) {
@@ -338,10 +304,14 @@ public class ShapeUtils {
         }
     }
 
-    public static void drawImage(String bboxStr, List<POI> dataList, List<LayerStyleView> layerStyleViews, Graphics2D g2) {
-        ShapeStyle shapeStyle=new ShapeStyle();
+    public static BufferedImage drawImage(String bboxStr, List<Map<String, Object>> dataList, String shapeKey, List<LayerStyleView> layerStyleViews) {
         BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
-        //样式转换
+        renderShape(image, bboxStr, dataList, getShapeStyle(layerStyleViews), shapeKey);
+        return image;
+    }
+
+    public static ShapeStyle getShapeStyle(List<LayerStyleView> layerStyleViews){
+        ShapeStyle shapeStyle = new ShapeStyle();
         for (LayerStyleView layerStyleView : layerStyleViews) {
             BeanUtils.copyProperties(layerStyleView, shapeStyle);
 
@@ -358,8 +328,10 @@ public class ShapeUtils {
             setColorFromHex(layerStyleView.getFontColor(), shapeStyle::setFontColor);
             setImage(layerStyleView.getCenterPointImage(), shapeStyle::setCenterPointImage);
             setImage(layerStyleView.getPointMarkerImage(), shapeStyle::setPointMarkerImage);
+            if(shapeStyle.getPointMarkerImage()!=null){
+                shapeStyle.setPointMarkerImage(TileUtils.scaleWidthHeight(shapeStyle.getPointMarkerImage(),shapeStyle.getPointMarkerImageWidth(),shapeStyle.getPointMarkerImageHeight()));;
+            }
         }
-        renderShape(image, bboxStr, dataList, shapeStyle);
-        g2.drawImage(image, 0, 0, null);
+        return shapeStyle;
     }
 }

+ 29 - 10
tile-web/src/main/java/cn/com/taiji/web/controller/TileWebController.java

@@ -6,18 +6,22 @@ import cn.com.taiji.common.domain.Result;
 import cn.com.taiji.common.model.LayerGroupDsView;
 import cn.com.taiji.common.model.LayerStyleView;
 import cn.com.taiji.cql.model.GeoRequestParam;
+import cn.com.taiji.tile.model.FeatureInfo;
 import cn.com.taiji.tile.service.ITileService;
 import cn.com.taiji.web.service.IGeoDataSourceService;
 import com.alibaba.fastjson.JSONObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.annotation.PostConstruct;
 import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -40,6 +44,17 @@ public class TileWebController {
     @Autowired
     private IGeoDataSourceService geoDataSourceService;
 
+    @PostConstruct
+    public void initData(){
+        try {
+            List<LayerGroupDsView> layerGroupDsViewList = geoDataSourceService.layerCodeGeoDataSource("socialManagementElement");
+
+
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
 
     @ApiOperation("面向瓦片的点击查询")
     @GetMapping("/queryElements")
@@ -69,20 +84,24 @@ public class TileWebController {
                     for(LayerGroupDsView layerGroupDsView:layerGroupDsViewList){
 
                         layerCodeList.add(layerGroupDsView.getLayerCode());
-
-
                     }
 
                     Map<String,List<LayerStyleView>> dataMaps = geoDataSourceService.layerCodeShapeStyle(layerCodeList);
 
-
-                    byte[] ret = tileService.tileData(geoRequestParam,layerGroupDsViewList,dataMaps);
-
-                    responseWrite(response, "image/png", ret);
-
-
-
-
+                    if(StringUtils.equals(geoRequestParam.getRequest(),"GetMap")) {
+                        byte[] ret = tileService.tileData(geoRequestParam, layerGroupDsViewList, dataMaps);
+                        responseWrite(response, "image/png", ret);
+                    }else if(StringUtils.equals(geoRequestParam.getRequest(),"GetFeatureInfo")){
+                        FeatureInfo featureInfo= tileService.getFeatureInfo(geoRequestParam, layerGroupDsViewList, dataMaps);
+                        // 转换List为JSON
+                        ObjectMapper mapper = new ObjectMapper();
+                        String json = mapper.writeValueAsString(featureInfo);
+                        // 设置响应类型和编码
+                        response.setContentType("application/json");
+                        response.setCharacterEncoding("UTF-8");
+                        // 将JSON写入响应
+                        response.getWriter().write(json);
+                    }
                 }else{
 
                     log.info("根据图层代码:" + geoRequestParam.getLayers() + "获取图层对应的数据源为空或者为null");