0

I want to restrict the ability for someone to pan away from the extent the map has when it's loaded.

I have a map of New Zealand to be viewed at a national and regional level but worried people will get lost if they pan out to sea as it is the only geography loaded.

Ideally someone can pan around regions but not too far from New Zealand.

2

Unless there is some direct way to do this through CartoDB options, it depends on what javascript library you're using on the front end to display the CartoDB tiles (gmaps, leaflet, openlayers, etc.).

For example, with google maps, you can set draggable to false in MapOptions. This will prevent panning by dragging

Draggable (boolean)
If false, prevents the map from being dragged. Dragging is enabled by default. https://developers.google.com/maps/documentation/javascript/reference#MapOptions

In a similar way, this example shows how to disable zooming and panning with a Leaflet map, by removing the ZoomControl and also disabling map dragging, zooming. This is a mapbox.js example, but something similar should work with leaflet (I haven't tested this however):

var map = L.mapbox.map('map', 'examples.map-20v6611k', {zoomControl: false});

// disable drag and zoom handlers
map.dragging.disable(); 
map.touchZoom.disable();
map.doubleClickZoom.disable();
map.scrollWheelZoom.disable();
// disable tap handler, if present.
if (map.tap) map.tap.disable();

Finally, this post from 2012 shows how to disable map controls in OpenLayers by passing an empty controls array when declaring a new map:

var map = new OpenLayers.Map('map', { controls: [] });
  • I figured that it may require something more than the web interface. Hopefully it may be an option in the future. – parnelandr Mar 17 '14 at 22:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.