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

  • SEARCH
  • Home
  • 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 8867119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:57:06+00:00 2026-06-14T16:57:06+00:00

I have written a basic function to allow me to display a popup from

  • 0

I have written a basic function to allow me to display a popup from a link outside the map. The functionality to open the popup is working fine, but I can’t then close it.

Demo link: http://www.catchingtherain.com/bikestats/stations.php – click on links in left-hand tabbed panels.

Here’s a bit more detail …

A typical map has about 300 features on a vector layer ‘stations’ loaded from kml. These are activated onload using

select = new OpenLayers.Control.SelectFeature(stations);           
stations.events.on({
                "featureselected": onFeatureSelect,
                "featureunselected": onFeatureUnselect
                });
map.addLayer(stations);
map.addControl(select);
select.activate();

which works fine – I can open and close popups.

With my off-map links I am calling onclick=”showMyPopup([x]) with [x] being an ID attribute loaded in from the kml. The showMyPopup function is

function showMyPopup(myID){
    for(var a = 0; a < stations.features.length; a++){    //loop through all the features
    var feature = stations.features[a];
    if (feature.attributes.ID.value == myID) {            //until it finds the one with the matching ID attribute
       var content = "<h4>" + feature.attributes.name + "</h4>" + feature.attributes.description;
       popup = new OpenLayers.Popup.FramedCloud("chicken",
                                     feature.geometry.getBounds().getCenterLonLat(),
                                     new OpenLayers.Size(200,200),
                                     content,
                                     null, true, onPopupClose);
       feature.popup = popup;
       map.addPopup(popup);
       }
    }
}

This opens the correct popup from the stations layer as expected, and I can see the popup using the DOM inspector on the stations layer just as it would appear if loaded by clicking on the map feature, but there’s then seemingly no way of closing it. The original features on the stations layer are working fine though (opening and closing).

Any help would be much appreciated (maybe there’s a simpler way of tackling this?)

Thanks, James

PS and just in case, here’s the onFeatureUnselect function …

function onFeatureUnselect(event) {
        var feature = event.feature;
        if(feature.popup) {
            map.removePopup(feature.popup);
            feature.popup.destroy();
            delete feature.popup;
        }
     }
  • 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-14T16:57:08+00:00Added an answer on June 14, 2026 at 4:57 pm

    Your on onPopupClose() function is:

    function onPopupClose(evt) {
        select.unselectAll();
    }
    

    When you select feature from map and click on popup’s Close icon, then feature will be unselected, but popup is not closed yet. Then, onFeatureUnselect event is triggered, and popup is actually closed.

    When you create popup by showMyPopup() function, you are not selecting it. onPopupClose() is called, but it doesn’t close popup. onFeatureUnselect is not triggered.

    I suggest to select feature in showMyPopup() function. featureselected event will be fired and popup is created by onFeatureSelect(), and user can close popup both with popup’s Close icon and unselecting feature on map.

    But alas, there’s a possible bug (or unexpected behaviour) in OL, when you select feature with code and try to unselect it with clickout. It’s described here: http://lists.osgeo.org/pipermail/openlayers-users/2012-September/026349.html One possible fix is to set SelectControl.handlers.feature.lastFeature manually.

    function showMyPopup(myID){
        for(var a = 0; a < stations.features.length; a++){    //loop through all the features
            var feature = stations.features[a];
            if (feature.attributes.ID.value == myID) {            //until it finds the one with the matching ID attribute
    
                // select is your SelectFeature control
                select.select(feature);
                // Fix for unselect bug
                select.handlers.feature.lastFeature = feature;
    
                break;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a basic script for the mail functionality. I am trying to
I have written a function to take in the data from a Sirit IDentity
I have written a basic Application for windows mobile 5. It is using visual
I have an application written in pure/basic Java without GUI. I have three classes
Although I know the basic concepts of binary representation, I have never really written
I have a basic web application written in Java, running on a tomcat on
Does anyone have a solution for a basic, compact Finite state machine/automata written in
I have written this code inside a servlet to delete certain records from three
I have written this code in JavaScript and works perfectly fine when I include
I'm learning javascript and jquery and have written a very basic script inside my

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.