Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8821297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:49:06+00:00 2026-06-14T05:49:06+00:00

The SelectFeature method in Control class provides a way of adding and removing popups

  • 0

The SelectFeature method in Control class provides a way of adding and removing popups on the Vector layer by listening to events featureselected and featureunselected respectively. Below shows a sample code that I obtained from an example in the openlayers website:

// create the layer with listeners to create and destroy popups
var vector = new OpenLayers.Layer.Vector("Points",{
 eventListeners:{
  'featureselected':function(evt){
   var feature = evt.feature;
   var popup = new OpenLayers.Popup.FramedCloud("popup",
    OpenLayers.LonLat.fromString(feature.geometry.toShortString()),
    null,
    "<div style='font-size:.8em'>Feature: " + feature.id +"<br>Foo: </div>",
    null,
    true
   );
   feature.popup = popup;
   map.addPopup(popup);
  },
  'featureunselected':function(evt){
   var feature = evt.feature;
   map.removePopup(feature.popup);
   feature.popup.destroy();
   feature.popup = null;
  }
 }
});

vector.addFeatures(features);

// create the select feature control
var selector = new OpenLayers.Control.SelectFeature(vector,{
 hover:true, # this line
 autoActivate:true
});

The code above will allow a popup to be shown upon mouseover on the Geometry object (icon or marker on the map). If the line hover:true is removed, the popup will be shown only upon a mouse click on the Geometry object.

What I want, is to be able to display one type of popup (example, an image plus a title) upon mouseover and another type (example, detailed description) upon a mouse click. I am not sure how this could be done. Some help would be much appreciated. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:49:08+00:00Added an answer on June 14, 2026 at 5:49 am

    Also, there another way, it’s rather hack than correct usage of API, but seems to work. You can overwrite over and out callbacks.

    var selectControl = new OpenLayers.Control.SelectFeature(vectorLayer, {
    
        callbacks: {
            over: function(feat) {
                console.log('Show popup type 1');
            },
            out: function(feat) {
                console.log('Hide popup type 1');
            }
        },
    
        eventListeners: {
            featurehighlighted: function(feat) {
                console.log('Show popup type 2');
            },
            featureunhighlighted: function(feat) {
                console.log('Hide popup type 2');
            }
        }    
    });
    

    Here’s working example: http://jsfiddle.net/eW8DV/1/

    Take a look on select control’s source to understand details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a vector-layer for displaying markers as features on my map, but now
I'm implementing an OpenLayers SelectFeature control, and trying to position an JQuery UI dialog
I've got a map that displays a KML Vector layer with some markers. When
I have a task to design a control of size ComboBox (GXT) with Multi-select
I've been working with OpenLayers, and i made a layer tree (all layers are
I have a OpenLayers.Layer.GML layer build with GeoJSON data given by MapFish. When I
I'm going to optimize the data access layer of my php web application. Currently,
I have a problem. I have a map with OpenLayers layer. Next i have
I want to use a drag to select feature, but rather than select a
This is really two questions one leading into the other. Firstly what does 'Permission

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.