首页 / 浏览问题 / 云GIS / 问题详情
如何将参数传到Marker的点击事件中
18EXP 2017年05月24日
如何将添加Marker的方法中的data数据传递到点击事件openInfoWin中

function addMarker(){

    var data;
    var markerlayer=new SuperMap.Layer.Markers("markerLayer");
    markerlayer.clearMarkers();//清除所添加的标注
    var size = new SuperMap.Size(44,33);
    var offset = new SuperMap.Pixel(-(size.w/2), -size.h);
    var icon = new SuperMap.Icon('./theme/images/marker.png', size, offset);
    var marker =new SuperMap.Marker(new SuperMap.LonLat(11563077.084093,4302447.0461901),icon) ;
    markerlayer.addMarker(marker);
    map.addLayer(markerlayer);
    marker.events.on({
        "click":openInfoWin,
        "scope": marker
    });
}

 var infowin = null;
        function   openInfoWin()
        {    alert(data)
            closeInfoWin();
            var marker = this;
            var lonlat = marker.getLonLat();
            var size = new SuperMap.Size(0, 33);
            var offset = new SuperMap.Pixel(11, -30);
            var icon = new SuperMap.Icon("./theme/images/marker.png", size, offset);
            var popup = new SuperMap.Popup.FramedCloud("popwin",
                    new SuperMap.LonLat(lonlat.lon,lonlat.lat),
                    null,
                    "鼠标点击事件 ",
                    icon,
                    true);
            infowin = popup;    
            map.addPopup(popup);
        }

1个回答

你好:

你可以这样写,例如: var data = "test"; marker.myData = data;

然后在点击事件中这么用: var marker = this; alert(marker.myData);
5EXP 2017年05月24日
...