Reputation: 51
I need to remove the click event by JQuery on the Openlayers 3 map.
The map.on function is inside the change of the radio button, and ends up creating several instances of the click
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>');
});
}
});
Already tried:
map.off('click', myFunction);
map.removeEvent('click', myFunction);
map.getViewport().removeEventListener('click', myFunction);
Upvotes: 0
Views: 358
Reputation: 51
I managed to circumvent the situation in another way.
In my case a click event was created every time the user changed the layer, so even removing the layer from the map, the active click event remained (displaying the information of the removed layer)
As the case was urgent, I managed to circumvent the situation by checking the active layers, and only displaying the information if the layer is arranged on the map.
if (url && verifyLayer('Mylayer') == 'true'){
- code -
}
function verificaLayer(name){
var valid = '';
map.getLayers().forEach(function(layer){
var layername = (layer['values _']['name']);
if(name == layername){
valid = 'true';
}
});
return valid;
}
Upvotes: 0