首页 / 浏览问题 / WebGIS / 问题详情
Web端开发调用地图服务地物查询功能
11EXP 2023年08月21日
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_getFeatureByBounds"></title>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.css" />
        <link rel="stylesheet" href="https://iclient.supermap.io/dist/leaflet/iclient-leaflet.min.css" />
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.js"></script>
        <script type="text/javascript" src="https://iclient.supermap.io/dist/leaflet/iclient-leaflet.js"></script>
<script type="text/javascript">
    var host = window.isLocal ? window.server : "https://iserver.supermap.io";
    var map, resultLayer,
        baseUrl = host + "/iserver/services/map-world/rest/maps/World",
        url = host + "/iserver/services/data-world/rest/data";
    map = L.map('map', {
        preferCanvas: true,
        crs: L.CRS.EPSG4326,
        center: {lon: 20, lat: -10},
        maxZoom: 18,
        zoom: 2
    });
    new L.supermap.TiledMapLayer(baseUrl).addTo(map);
    query();

    function query() {
        var polygon = L.polygon([[-20, 20], [0, 20], [0, 40], [-20, 40], [-20, 20]], {color: 'red'});
        polygon.addTo(map);
        var boundsParam = new L.supermap.GetFeaturesByBoundsParameters({
            datasetNames: ["World:Capitals"],
            bounds: polygon.getBounds()
        });
        new L.supermap
            .FeatureService(url)
            .getFeaturesByBounds(boundsParam, function (serviceResult) {
                resultLayer = L.geoJSON(serviceResult.result.features, {
                    onEachFeature: function (feature, layer) {
                        layer.bindPopup("首都"+":" + feature.properties.CAPITAL);
                    }
                }).addTo(map);
            });
    }
</script>
</body>
</html>

得出的结果是一个固定在地图上的矩形框架,那样子每次查询都需要重新定义。如何修改让他成为一个地图按钮,可以通过自定义范围来实现框选呢?

1个回答

你好,该示例只是例举了用矩形作为查询范围,如果想要自定义范围,可以在绘制多边形后,获取到图层的bounds传入查询即可。

几何绘制:https://iclient.supermap.io/examples/leaflet/editor.html#drawAndModify

1,865EXP 2023年08月21日
...