1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

GetFeatureInfo on mouse hover on feature in OpenLayers 3

Discussion in 'Programming/Internet' started by Vishal, Oct 8, 2018.

  1. Vishal

    Vishal Guest

    I am able to get popup onclick on the feature but want to get popup also on mouse hover on the feature (polygon,point). Can anyone help me out. For onclick I used below code -

    var feature_onClick;
    map.on('click', function(evt) {

    feature_onClick = map.forEachFeatureAtPixel(evt.pixel, function(feature, layer) {
    return feature;

    if (feature_onClick) {
    var content = document.getElementById('popup-content');
    content.innerHTML = feature_onClick.getProperties().name;
    container.style.display = 'block';

    For mouse hover I am using below code but unable to get pop up. Only cursor changes to pointer.

    map.on('pointermove', function(e) {
    if (e.dragging) {
    var pixel = map.getEventPixel(e.originalEvent);
    var hit = map.hasFeatureAtPixel(pixel);
    map.getTarget().style.cursor = hit ? 'pointer' : '';

    Login To add answer/comment

Share This Page