SuperMap iClient for Leaflet 几何查询(圆形)

【问题描述】:在使用iClient for Leaflet的过程中,有时会遇到需要通过圆形来进行几何查询的场景,此时就可以使用超图(SuperMap)提供的Geometry 查询参数类来实现。但是通过查询相关的API文档,geometry仅支持L.polygon,并且使用Leaflet生成的圆也仅仅是一个点对象,无法直接实现。

【解决方案】

(1)利用点生成缓冲区的方式来生成面对象,再进行几何查询。

这边以iClient for Leaflet官网示例【几何对象缓冲区分析】为例:https://iclient.supermap.io/examples/leaflet/editor.html#04_bufferAnalystService_geometry

//对生成的点进行缓冲区分析
geoBufferAnalystParams = new L.supermap.GeometryBufferAnalystParameters({
       sourceGeometry: roadLine,
       bufferSetting: new L.supermap.BufferSetting({
       endType: L.supermap.BufferEndType.ROUND,
       leftDistance: new L.supermap.BufferDistance({value: 300}),
       rightDistance: new L.supermap.BufferDistance({value: 300}),
       semicircleLineSegment: 50
            })
        });
bufferAnalystService.bufferAnalysis(geoBufferAnalystParams, function (serviceResult) {
       resultLayer = L.geoJSON(serviceResult.result.resultGeometry).addTo(map);

 (2)将circle转化为polygon

①利用 leaflet-geoman.js 提供的方法L.PM.Utils.circleToPolygon()

这边以iClient for Leaflet官网示例【几何查询】为例:

https://iclient.supermap.io/examples/leaflet/editor.html#01_mapQueryByGeometry

<!--引入脚本及css文件-->
<script src="https://unpkg.com/@geoman-io/leaflet-geoman-free@latest/dist/leaflet-geoman.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/@geoman-io/leaflet-geoman-free@latest/dist/leaflet-geoman.css" />
//几何查询
function query() {
        var circle = L.circle([0,20], {color: 'red',radius:2000000});
        var polygon = L.PM.Utils.circleToPolygon(circle, 600);
        polygon.addTo(map);
        var param = new L.supermap.QueryByGeometryParameters({
            queryParams: {name: "Capitals@World.1"},
            geometry: polygon
        });
        new L.supermap
            .QueryService(url)
            .queryByGeometry(param, function (serviceResult) {
                var result = serviceResult.result;
                resultLayer = L.geoJSON(result.recordsets[0].features).addTo(map);
            });
    }

②获取圆心,通过计算生成点集并以此生成polygon

参考:iClient for Leaflet 空间查询,圆形空间查询_程序猿小郑的博客-优快云博客_leaflet 空间计算

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

吃辣我第一

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值