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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:26:44+00:00 2026-06-01T12:26:44+00:00

I’m working with a Google Maps example code , this : http://www.wolfpil.de/v3/drag-from-outside.html which has

  • 0

I’m working with a Google Maps example code , this : http://www.wolfpil.de/v3/drag-from-outside.html which has 3 draggable markers outside the map. All I want is to use the revert ‘invalid’ option to make the markers return to the original position in case the markers do not drop in the map but I’ve failed to put it in the right line. Could you please give me a hint where do I have to put it to make it work?

function initDrag(e) {

 if(!e) var e = window.event;

  // Drag image's parent div element
 obj = e.target ? e.target.parentNode : e.srcElement.parentElement;
  if(obj.className != "drag") {
  if(e.cancelable) e.preventDefault();
    obj = null;
  return;
 }

if (obj) {
 // The currently dragged object always gets the highest z-index
 z_index++;
 obj.style.zIndex = z_index.toString();

   xpos = e.clientX - obj.offsetLeft;
 ypos = e.clientY - obj.offsetTop;

 document.onmousemove = moveObj;
}
 return false;
 }


function moveObj(e) {

if(obj && obj.className == "drag") {

  if(!e) var e = window.event;
   obj.style.left = e.clientX - xpos + "px";
  obj.style.top = e.clientY - ypos + "px";

  obj.onmouseup = function() {

  var gd = map.getDiv();
  var mLeft = gd.offsetLeft;
  var mTop = gd.offsetTop;

  var mWidth = gd.offsetWidth;
  var mHeight = gd.offsetHeight;

  var areaLeft = drag_area.offsetLeft;
  var areaTop = drag_area.offsetTop;

  var oWidth = obj.offsetWidth;
  var oHeight = obj.offsetHeight;

  // The object's pixel position relative to the document
  var x = obj.offsetLeft + areaLeft + oWidth/2;
  var y = obj.offsetTop + areaTop + oHeight/2;

  // Check if the cursor is inside the map div
  if (x > mLeft && x < (mLeft + mWidth) && y > mTop && y < (mTop + mHeight)) {

// Difference between the x property of iconAnchor
// and the middle of the icon width
var anchorDiff = 1;

// Find the object's pixel position in the map container
var g = google.maps;
var pixelpoint = new g.Point(x - mLeft -anchorDiff, y - mTop + (oHeight/2));

// Corresponding geo point on the map
var proj = dummy.getProjection();
var latlng = proj.fromContainerPixelToLatLng(pixelpoint);

// Create a corresponding marker on the map
var src = obj.firstChild.getAttribute("src");
createDraggedMarker(latlng, src);

// Create dragged marker anew
fillMarker();
   }
   };
   }
   return false;
   }


 function fillMarker() {

var m = document.createElement("div");
m.style.position = "absolute";
m.style.width = "32px";
m.style.height = "32px";

 var left;
 if (obj.id == "m1") {
 left = "0px";
 } else if (obj.id == "m2") {
 left = "50px";
 } else if (obj.id == "m3") {
  left = "100px";
 }
 m.style.left = left;

 // Set the same id and class attributes again
// m.setAttribute("id", obj.id);
// m.setAttribute((document.all?"className":"class"), "drag");
 m.id = obj.id;
 m.className = "drag";

  // Append icon
 var img = document.createElement("img");
 img.src = obj.firstChild.getAttribute("src");
 img.style.width = "32px";
   img.style.height = "32px";
 m.appendChild(img);
 drag_area.replaceChild(m, obj);

 // Clear initial object
 obj = null;
 }


 function highestOrder() {

/**
* The currently dragged marker on the map
* always gets the highest z-index too
*/
 return z_index;
}


 function createDraggedMarker(point, src) {

var g = google.maps;
var image = new g.MarkerImage(src,
  new g.Size(32, 32),
  new g.Point(0, 0),
  new g.Point(15, 32));

  var shadow = new g.MarkerImage("http://maps.gstatic.com/mapfiles/kml/paddle/A_maps.shadow.png",
  new g.Size(59, 32),
  new g.Point(0, 0),
  new g.Point(15, 32));

  var marker = new g.Marker({ position: point, map: map,
    clickable: true, draggable: true,
    raiseOnDrag: false,
    icon: image, shadow: shadow, zIndex: highestOrder()
  });

  g.event.addListener(marker, "click", function() {
  actual = marker;
  var lat = actual.getPosition().lat();
  var lng = actual.getPosition().lng();

   iw.setContent(lat.toFixed(6) + ", " + lng.toFixed(6));
   iw.open(map, this);
   });

   g.event.addListener(marker, "dragstart", function() {
  // Close infowindow when dragging the marker whose infowindow is open
  if (actual == marker) iw.close();
  // Increment z_index
   z_index++;
   marker.setZIndex(highestOrder());
       });
           }
  • 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-01T12:26:46+00:00Added an answer on June 1, 2026 at 12:26 pm

    After the code snippet

    fillMarker();
    }
    

    add an else statement like this:

    fillMarker();
    } else {
      //if the marker does not land on the map reset marker location
      var left;
      if (obj.id == "m1") {
        left = "0px";
      } else if (obj.id == "m2") {
        left = "50px";
      } else if (obj.id == "m3") {
        left = "100px";
      }
       obj.style.left = left;
       obj.style.top = "70px";
    }
    

    jsFiddle to full code: http://jsfiddle.net/6ECVs/

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

Sidebar

Related Questions

I have this code to decode numeric html entities to the UTF8 equivalent character.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
i got an object with contents of html markup in it, for example: string

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.