2

I'm using tileWMS to get my layers from geoserver.
So when I click the map, I get the feature info if click on the layer, but then if I draw let's just say polygon, if the point is on the layer, the click trigger on map will run as well. I've tried interaction select with vector but doesn't work with tileWMS. I can remove the draw interaction after draw but how can I handle so it won't get the feature info while drawing? is it possible to do something like addinteraction and removeinteraction but with tileWMS? I'm using openlayers 3 recently.

https://i.ibb.co/5vZwPYx/2.png

Thanks.

// this is my layer & map
var layer = new ol.layer.Tile(
{
    source      : new ol.source.TileWMS(
    {
        url: 'http://localhost:2121/geoserver/geoserver/wms',
        params: {'LAYERS': 'geoserver:coordinate_polygon', 'TILED': true},
        serverType: 'geoserver'
    })    
});

var map = new ol.Map(
{    
    pixelRatio: 1,
    controls: ol.control.defaults().extend([zoomslider, mousePositionControl]),
    loadTilesWhileInteracting: true,
    layers: [osm, layer, layer_draw_vector],
    target: 'map',
    view: view
});
// ----------------------------

//the trigger
map.on('singleclick', function(evt)
{
    //doin request to geoserver let's say I alert the response
    alert(feature[0].properties.name;
}

map.addInteraction(interaction_draw);
interaction_draw.on('drawend',function(e)
{
    alert(e.feature.getGeometry().getExtent());
}); 
// ----------------------------

1 Answer 1

2

If you use interaction_draw.setActive(true); and interaction_draw.setActive(false); to turn on and off the interaction you could check if the interaction is active before proceeding with any map click actions.

map.on('singleclick', function(evt)
{
    if (interaction_draw.getActive()) return;

    ...
    ...
    ...

});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.