首页 / 浏览问题 / WebGIS / 问题详情
Web端开发调用地图服务地物查询功能不正常
11EXP 2023年08月21日

使用产品:iserver 11i  操作系统:win11 
问题详细描述:将网页上的示例代码复制在本地以后,将引入改成了在线引入,但是地图查询的功能显示不出来

引入方式从官网上粘贴下来以后改成了在线引入,但是运行时浏览器会报错。说第47行的resource没有定义
 

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_getFeatureByBounds"></title>
    <!-- <script type="text/javascript" src="../js/include-web.js"></script> -->
    <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>
</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>
    <script type="text/javascript" src="../../dist/leaflet/include-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(resources.text_capital + ":" + feature.properties.CAPITAL);
                        }
                    }).addTo(map);
                });
        }
    </script>
</body>

</html>

1个回答

您好,范围查询demo使用在线引用我这边测试是没有问题的,您这边参考一下呢。

<!--********************************************************************
* Copyright© 2000 - 2023 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_getFeatureByBounds"></title>
    <script type="text/javascript" src="../js/include-web.js"></script>
</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>

希望可以帮助到您。

10,733EXP 2023年08月21日
我使用您的代码,但是浏览器上还是显示了一个框体,没有坐标的显示。F12查看以后依旧会报错
你把我的代码存成html文件直接运行有问题吗?

或者你试试我的。

链接:https://pan.baidu.com/s/1MmLZl4YqpRFwX0GFDSXNdw?pwd=7206
提取码:7206
--来自百度网盘超级会员V6的分享
网盘里的可以了,是吧resourse没有定义的部分换成了别的形式
resourse 是示例工程里的工程参数文件,不输入iclient部分里的,如果你要用resource,那就版爱的代码写到iClient leaflet的示例工程Example文件夹里。
...