如何从Openlayer 3映射中删除JQuery单击事件

时间:2017-09-19 21:24:34

标签: javascript jquery frontend openlayers-3

我需要在Openlayers 3地图上删除JQuery的click事件。

map.on函数位于单选按钮的更改内部,最终创建了几个单击实例

map.on('click', function (evt) {

        var url = temperatura.getSource().getGetFeatureInfoUrl(
        evt.coordinate, viewResolution, viewProjection,
        {
           'INFO_FORMAT': 'application/json',
        });
        if (url) {
            $.getJSON(url, function(result){
            var Umidade_Rel = result.features[0]['properties']['Temperatura_2m'];
            $('#information').removeClass('hidden');
            $('#information').css('background-color', '#eaca6a');
            $('#information p , #information h3').css('color', '#68a06f');
            $('#information').html('<h3>Temperatura</h3><p>' + Umidade_Rel.toFixed(2) + '</p>');
            });
        }
        });

已经尝试过:

 map.off('click', myFunction);

 map.removeEvent('click', myFunction);

 map.getViewport().removeEventListener('click', myFunction);

1 个答案:

答案 0 :(得分:0)

我设法以另一种方式规避这种情况。

在我的情况下,每次用户更改图层时都会创建一个点击事件,因此即使从地图中删除图层,活动的点击事件仍然存在(显示已删除图层的信息)

由于情况紧急,我设法通过检查活动图层来规避情况,并仅在地图上排列图层时显示信息。

Vector<Vector<String>> data=new Vector<>();
//Fill this Vector above with the initial data

Vector<String> columns=new Vector<String>();
//Fill this with column names

DefaultTableModel tableModel=new DefaultTableModel(data, columns);
JTable table=new JTable(tableModel);
//Display the table as you like

... //Query the database and get the ResultSet (let's call it rs)

while(rs.next){

  Vector<String> newRow=new Vector<>();

  //Get the data from the resultset and fill this new row

  tableModel.addRow(newRow);

}//while closing

}