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!
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.
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.
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.
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).
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);
});
gmap.setOptions({'scrollwheel': false});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With