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 7952743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:57:00+00:00 2026-06-04T02:57:00+00:00

How can the click event on a GML track be caught in Open Layers?

  • 0

How can the click event on a GML track be caught in Open Layers?

I have the following code:

var gmlTrack = new OpenLayers.Layer.GML("Track", myGpxUrl, {
    format: OpenLayers.Format.GPX,
    projection: new OpenLayers.Projection("EPSG:4326")
});

I thought that the solution would be to add the following lines:

gmlTrack.events.register("click", gmlTrack, function(e){
    alert("Click on GPX track!");
});

But it doesn’t work.

To be clear: I only want the click event to be triggered when the user clicks on the GPX track.

What am I doing wrong and how can I fix it?

Thank you.

  • 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-04T02:57:01+00:00Added an answer on June 4, 2026 at 2:57 am

    You can achieve what you are looking for using a select feature control (which enables OpenLayers to know how to handle the events)

        selectControl = new OpenLayers.Control.SelectFeature(
            [gmlTrack],
            {
                clickout: true, toggle: false,
                multiple: false, hover: false,
                onSelect: trackSelected
            }
        );
    
        map.addControl(selectControl);
        selectControl.activate();
    

    And include some handler for trackSelected e.g.

    function trackSelected(feature){
        alert("something here");  
    }
    

    This is a useful OpenLayers example

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

Sidebar

Related Questions

i can reference link with specific id with following code $(document).ready(function(){ $(a#example_link_id).click(function(event){ var url
A button can use Command.Open property and Click event. But Button.Click event executes before
A button can use Command.Open property and Click event. But Button.Click event executes before
How can I rewrite this code to coffeescript: $('.delete_action').click(function(event) { $.get('/delete_action?name=' + event.target.name +
How can I attach a click event on to a TreeViewItem? The following works
I have heard that we can create the click event of the Button by
Like how the click() can be used to trigger a click event on an
I want to know that can mouse click event detects colors or even strings.
How can I add click event to newly added item of menu? Below is
Can someone help me how to disable the click event on first column and

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.