Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable movable Gmap

Tags:

google-maps

is it possible to disable the move inside of a google mal (v3) for the time i drag a marker? I don't want to use i.e. the static map. I need the generall function of movement, but for the moment I drag a marker, the map should not move.

Thanks a lot!

like image 294
Thomas1703 Avatar asked Sep 21 '12 21:09

Thomas1703


People also ask

How do I use GMAP in AutoCAD?

The control will display as an empty rectangle: With the control selected, open the Properties panel. Apart from the usual Control properties, you’ll find some GMap-specific properties there. Now things will get interesting: CanDragMap – If true, the user can drag the map using the right mouse button. You’ll probably want to keep this set to true.

Is there a new GMAP tutorial for Visual Studio 2015?

We have a fresh GMap.NET tutorial about maps, markers, polygons and routes that’s updated for Visual Studio 2015 and GMap.NET 1.7! Note that we have more tutorials up on how to add routes to GMap.NET, calculating the area of a polygon in GMap.NET, and removing the red cross from a map in GMap.NET.

How do I add a gmapcontrol to a form?

This should contain the GMapControl. Verify that there’s a check next to this control, and when you click OK, the control should be in your Toolbox and can be dragged to a form. Now add a new form (your fresh C# Windows Application should already have one) and drag the GMapControl to it.

How do I move the map on the map?

If the user swipes the map with one finger, an overlay appears on the map, with a prompt telling the user to use two fingers to move the map. On desktop applications, users can zoom or pan the map by scrolling while pressing a modifier key (the ctrl or ⌘ key).


2 Answers

Markers have dragstart and dragend events. On dragstart, disable the "movement" functionality on the Map by setting various MapOptions to false, like draggable, scrollwheel, etc. On dragend, set the MapOptions back to true.

Here is a function you can use to disable or enable map movement based on a boolean. It assumes your Map variable is map.

function disableMovement(disable) {
    var mapOptions;
    if (disable) {
        mapOptions = {
            draggable: false,
            scrollwheel: false,
            disableDoubleClickZoom: true,
            zoomControl: false
        };
    } else {
        mapOptions = {
            draggable: true,
            scrollwheel: true,
            disableDoubleClickZoom: false,
            zoomControl: true
        };
    }
    map.setOptions(mapOptions);
}

And then you use this in your events like this (marker is your Marker variable):

google.maps.event.addListener(marker, 'dragstart', function() {
    disableMovement(true);
});

google.maps.event.addListener(marker, 'dragend', function() {
    disableMovement(false);
});
like image 157
Gady Avatar answered Sep 20 '22 03:09

Gady


gmap.setOptions({'scrollwheel': false});

like image 36
Robert Liguori Avatar answered Sep 21 '22 03:09

Robert Liguori