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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T13:09:34+00:00 2026-05-22T13:09:34+00:00

I have a html map that uses world map image as its background. I

  • 0

I have a html map that uses world map image as its background.

I can make a js function that changes div’s background position, but I like to change background position when user click on the map then drag like google map.

so I have a sample page here: http://lab.qacode.com/map which uses http://lab.qacode.com/map/map.jpg

I would appreciate any advice or tip.

  • 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-22T13:09:34+00:00Added an answer on May 22, 2026 at 1:09 pm

    An easy way to make this work is to use jQuery UI’s draggable

    HTML

    <div id="map">
        <div class="map-canvas"></div>    
    </div>
    

    JavaScript

    // Pre-select elements
    var map = $("#map"),
        canvas = map.find(".map-canvas");
    
    // Calculate canvas constraints
    var maxLeft = map.width()-canvas.width(),
        maxTop = map.height()-canvas.height();
    
    // Make canvas draggable
    canvas.draggable({
        drag: function(e, ui) {
            // Check if canvas is within constraints
            if (ui.position.left > 0) {
                ui.position.left = 0;
            } else if (ui.position.left < maxLeft) {
                ui.position.left = maxLeft;
            }
            if (ui.position.top > 0) {
                ui.position.top = 0;
            } else if (ui.position.top < maxTop) {
                ui.position.top = maxTop;
            }
        }
    });
    

    Placing markers

    It’s possible to place a marker (or whatever) on the map. It’s very easy, and the coords are based on pixels within the canvas. For the marker in the test case it’s 150px from left and top of canvas.

    // Create simple dot marker
    $("<div></div>")
        .addClass("map-marker")
        .appendTo(canvas)
        .offset(function(){
            return { left: 150, top: 150 };
        })
        // Append a label
        .append("<span><- Dot</span>");
    

    Now to something a little more advanced, namely the (in)famous Google Maps pin.

    // Create draggable Google Maps pin marker
    var pin =
    $("<div></div>")
        .addClass("google-pin")
        .appendTo(canvas)
        .offset(function(){
            return { left: 50, top: 50 };
        })
        // Bind mouseup/down for visual confirmation of grab
        .bind({
            mousedown: function(){
                var os = pin.offset();
                pin.offset(function(){
                    return { top: os.top-3 };
                });
            },
            mouseup: function(){
                var os = pin.offset();
                pin.offset(function(){
                    return { top: os.top+3 };
                });
            }
        })
        // Make it draggable
        .draggable({
            start: function(e,ui){
                ui.helper.offset(function(){
                    return { top: ui.offset.top-2 };
                });
            },
            container: canvas
        });
    

    See test case on jsFiddle

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

Sidebar

Related Questions

I have html code that looks roughly like this: <div id=id1> <div id=id2> <p>some
I am writing an HTML form that uses a google map, but to reduce
I have a piece of template HTML that is returned from a Javascript function:
I want choose all the <li> in my html that have the <span>Google Map</span>
have created a map that I'm trying to have function similar to 'My Maps'.
I have an HTML Table that looks like this: The user can update any
I have HTML that includes symbols such as the Trademark TM as superscript (™).
I have HTML code like this : <div> <a>Link A1</a> <a>Link A2</a> <a>Link A3</a>
I have an HTML Mail template, with a place holder for the image. I
I have a HTML page that scrolls up and down (not a lot, but

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.