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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:06:36+00:00 2026-05-24T14:06:36+00:00

I have a vector-layer for displaying markers as features on my map, but now

  • 0

I have a vector-layer for displaying markers as features on my map, but now mather, what I do, they are eighter draggable or clickable. What can I do to get both?

/*** Init Drag Marker
*/
    var dragFeature = new OpenLayers.Control.DragFeature(layerTrackMarker, 
        {'onComplete': updateMarker}
    );
    map.addControl(dragFeature);
    dragFeature.activate();

/*** Init Click Marker
*/
    var clickFeature = new OpenLayers.Control.SelectFeature(layerTrackMarker,
        {}
    );
    map.addControl(clickFeature);
    layerTrackMarker.events.on({
                    "featureselected": function(e) {
                        var markerId = e.feature.geometry.id;
                        removeMarker(markerId);
                        /* ToDo: show context menu */
                    },
                    "featureunselected": function(e) {
                        /* ToDo: hide context menu */
                    }
                });
    clickFeature.activate();
  • 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-05-24T14:06:37+00:00Added an answer on May 24, 2026 at 2:06 pm

    I didn’t test it, but wouldn’t something like this work?

    var dragged = false;
    var dragFeature = new OpenLayers.Control.DragFeature(layerTrackMarker, {
        onComplete: function(){
            if(dragged){
                dragCallback();
            }else{
                clickCallback();
            }
        },
        onStart: function(){
            dragged = false;
        },
        onDrag: function(){
            dragged = true;
        }
    });
    map.addControl(dragFeature);
    dragFeature.activate();
    

    Edit: onComplete doesn’t fire if there was no actual drag. Here’s the working code

    var dragged = false;
    var dragFeature = new OpenLayers.Control.DragFeature(pointLayer, {
        onStart: function(){dragged = false;},
        onDrag: function() {dragged = true;}
    });
    
    map.addControl(dragFeature);
    dragFeature.activate();
    
    map.events.register("mouseup", map , function(e){
        if(dragged == true){
            alert("dragged");
        }else{
            alert("clicked");
        }
    });
    

    jsFiddle: http://jsfiddle.net/reKRr/5/

    EDIT: this is the less hacky way of doing it

    var selectFeature = new OpenLayers.Control.SelectFeature(
        pointLayer,
        {
            onSelect: function(){            
                alert("selected");
            }
        }
    );
    
    var dragFeature = new OpenLayers.Control.DragFeature(pointLayer, {
        onComplete: function(){
            alert("drag");
        }
    });
    
    dragFeature.handlers['drag'].stopDown = false; 
    dragFeature.handlers['drag'].stopUp = false; 
    dragFeature.handlers['drag'].stopClick = false; 
    dragFeature.handlers['feature'].stopDown = false; 
    dragFeature.handlers['feature'].stopUp = false; 
    dragFeature.handlers['feature'].stopClick = false; 
    
    map.addControls([selectFeature,dragFeature]);
    
    selectFeature.activate();
    dragFeature.activate();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would have an openlayers vector layer with features scattered all over the map.
in clojure i have vector [myfn1 myfn2 myfn3] how can i call functions named
TLDR : I have an Openlayers map with a layer called 'track' I want
I have a question about XSS Can forms be used as a vector for
I am quite new to OpenLayers. Right now, I have a polygon vector with
I have this map, which I show some red markers over and whenever a
How can I programmatically move an existing marker on an OpenLayers.Layer.Markers layer? I can't
I have a vector that I want to insert into a set . This
I have a vector-like class that contains an array of objects of type T
I have a vector with 1000 nodes if(count + 1 > m_listItems.capacity()) m_listItems.reserve(count +

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.