美文网首页
Postgis发布动态矢量切片服务

Postgis发布动态矢量切片服务

作者: yangkunn | 来源:发表于2024-05-15 11:34 被阅读0次
    @CrossOrigin
    @GetMapping("/tile/{z}/{x}/{y}.mvt")
    @ApiOperation("获取矢量瓦片")
    public void tile(@PathVariable("z") int z,
                     @PathVariable("x") int x,
                     @PathVariable("y") int y,
                     @RequestParam(value = "regionCode", required = false) String regionCode,
                     @RequestParam(value = "version", required = false) String version,
                     @RequestParam(value = "mapType", required = false) String mapType,
                     HttpServletResponse response) {
        mapDataService.tile(z, x, y, regionCode, version, mapType, response);
    }
 /**
     * 获取矢量瓦片
     *
     * @param z
     * @param x
     * @param y
     * @param regionCode
     * @param version
     * @param mapType
     * @param response
     */
    @Override
    public void tile(int z, int x, int y, String regionCode, String version, String mapType, HttpServletResponse response) {
        try {
            TileData tile = mapDataMapper.tile(z, x, y, regionCode, version, mapType);
            response.setContentType("application/vnd.mapbox-vector-tile");

            ServletOutputStream outputStream = response.getOutputStream();
            if (tile != null) {
                outputStream.write(tile.getTile());
            }

            outputStream.flush();
            outputStream.close();
        } catch (Exception e) {
            log.error("获取矢量切片失败", e);
        }
    }
@Data
public class TileData {

    private byte[] tile;

}
 /**
     * 获取矢量瓦片
     *
     * @param z
     * @param x
     * @param y
     * @param regionCode
     * @param version
     * @param mapType
     * @return
     * @author yk
     * @since 2022/11/22 13:54
     */
    TileData tile(@Param("z") int z, @Param("x") int x, @Param("y") int y,
                  @Param("regionCode") String regionCode, @Param("version") String version,
                  @Param("mapType") String mapType);
  <select id="tile" resultType="com.fpi.prd.erms.entity.dto.TileData">
        SELECT
            ST_AsMVT ( tile ) tile
        FROM
            (
                SELECT
                    t.id,
                    t.region_code as region_code,
                    t.version as version,
                    t.map_type as map_type,
        (case when t.map_type ='A03000001' then t2.color
        when t.map_type ='A10000001'  then t3.color
        when t.map_type ='A10000002'  then t3.color
        else t4.color

        end) as color,

                    ST_AsMVTGEOM (
                            ST_TRANSFORM(t.geom,3857),
                            ST_TileEnvelope ( #{z}, #{x}, #{y}),
                            4096,
                            0,
                            TRUE
                        ) AS geom
                FROM
            t_map_data t LEFT JOIN t_dictionary t2
        on   t2.category='redLineType' and t.red_line_type_code=t2.code
        LEFT JOIN t_dictionary t3
        on  t3.category='controlUnit'  and t.control_area_code=t3.code
        LEFT JOIN t_dictionary t4
        on  t4.category='controlArea'  and t.control_area_code=t4.code
        <where>
            t.delete_flag =0

            <if test="@org.apache.commons.lang3.StringUtils@isNotBlank(regionCode)">
                and t.region_code = #{regionCode,jdbcType=VARCHAR}
            </if>
            <if test="@org.apache.commons.lang3.StringUtils@isNotBlank(version)">
                and t.version = #{version,jdbcType=VARCHAR}
            </if>
            <if test="@org.apache.commons.lang3.StringUtils@isNotBlank(mapType)">
                and t.map_type = #{mapType,jdbcType=VARCHAR}
            </if>
        </where>
            ) AS tile
        WHERE
            tile.geom IS NOT NULL
    </select>

相关文章

网友评论

      本文标题:Postgis发布动态矢量切片服务

      本文链接:https://www.haomeiwen.com/subject/upvvfjtx.html