首页 / 浏览问题 / WebGIS / 问题详情
移动端点击事件被重复触发
8EXP 2023年03月21日
SuperMap.Control.SelectFeature 被重复触发两次,点击feature一次,拖动屏幕又被触发一次;并且地图无法响应点击事件

3 个回答

您好,本地测试不会触发多次,请检查是否有注册多个控件。方便的话请附上关键代码,以便进一步排查。本地测试代码如下:

 function addData() {
        var polygon_data = [[-16, 30], [-16, 0], [50, 0], [50, 30]];
        var points = [];
        for (var i = 0, len = polygon_data.length; i < len; i++) {
            var point = new SuperMap.Geometry.Point(polygon_data[i][0], polygon_data[i][1]);
            points.push(point);
        }
        var linearRing = new SuperMap.Geometry.LinearRing(points);
        var polygon = new SuperMap.Geometry.Polygon([linearRing]);
        var polygon_feature = new SuperMap.Feature.Vector(polygon);
        vectorLayer.addFeatures([polygon_feature]);
        var selectFeature = new SuperMap.Control.SelectFeature(vectorLayer,
       {onSelect:onFeatureSelect});
   //map上添加控件
   map.addControl(selectFeature);
   //激活控件
   selectFeature.activate();
    }

    var count=0;
    function onFeatureSelect(feature) {
    count++;
     alert(count)
    }

1,076EXP 2023年03月22日

您好,您这边使用的是Classic吗,我这边在移动端测试是没有重复触发的现象的,您可以参考我的测试代码:

<!--********************************************************************
* Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title data-i18n="resources.title_vectorDataEvent"></title>
    <style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
            width: 100%;
            height: 100%
        }

        #map {
            position: absolute;
            width: 100%;
            height: 100%;
        }

        #toolbar {
            position: absolute;
            top: 50px;
            right: 10px;
            text-align: center;
            z-index: 100;
            border-radius: 4px;
        }
    </style>
</head>
<body>
<div id="toolbar" class="panel panel-primary">
    <div class='panel-heading'>
        <h5 class='panel-title text-center' data-i18n="resources.title_vectorDataEvent"></h5></div>
    <div class='panel-body content'>
        <input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_addData" onclick="addData()"/>
    </div>
</div>
<div id="map"></div>
<script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
<script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
<script>
    var map, layer, vectorlayer, pointFeature,
        host = window.isLocal ? window.server : "https://iserver.supermap.io",
        url = host + "/iserver/services/map-world/rest/maps/World";

    init();

    function init() {
        map = new SuperMap.Map("map", {
            controls: [
                new SuperMap.Control.Zoom(),
                new SuperMap.Control.Navigation(),
            ]
        });
        map.addControl(new SuperMap.Control.LayerSwitcher(), new SuperMap.Pixel(42, 80));
        layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url, null, {maxResolution: "auto"});
        layer.events.on({"layerInitialized": addLayer});
        vectorlayer = new SuperMap.Layer.Vector("vectorLayer");
        var selectFeature = new SuperMap.Control.SelectFeature(vectorlayer,
            {
                onSelect:onFeatureSelect
            });
        map.addControl(selectFeature);
        selectFeature.activate();

    }
    //打开对应的信息框
    var infowin = null;
    var Nums =0;
   //要素被选中时调用此函数,需要传入当前选中要素参数feature
   function onFeatureSelect(feature) {
       Nums+=1;;
          console.log(Nums)
       if (infowin) {
            try {
                infowin.hide();
                infowin.destroy();
            }
            catch (e) {
            }
        }
 
        var popup = new SuperMap.Popup("test"+Nums,
                   new SuperMap.LonLat(5,40),
                   new SuperMap.Size(200,200),
                   "test"+Nums,
                   true);

        infowin = popup;
        map.addPopup(popup);
}

    function addLayer() {

        map.addLayers([layer, vectorlayer]);
        //显示地图范围
        map.setCenter(new SuperMap.LonLat(0, 0), 0);
    }

    var infowin = null;

    function closeInfoWin() {
        if (infowin) {
            try {
                infowin.hide();
                infowin.destroy();
            }
            catch (e) {
            }
        }
    }

    function addData() {

        vectorlayer.removeAllFeatures();
        var point = new SuperMap.Geometry.Point(0, 0);
        pointFeature = new SuperMap.Feature.Vector(point);
        pointFeature.style = {
            fillColor: "red",
            strokeColor: "yellow",
            pointRadius: 7
        };
        vectorlayer.addFeatures(pointFeature);
    }
</script>

</body>
</html>

https://iclient.supermap.io/examples/classic/editor.html#overlay_vectorDataEvent

希望可以帮助到您。

10,388EXP 2023年03月22日
你好,查看你的代码中是否添加了Control.Navigation控件,移除这个控件可解决地图无法响应点击的情况。另外SelectFeature控件触发两次,可在实例化该控件的时候设置repeat: false。
1,686EXP 2023年03月22日
我确认试试,感谢
...