Hi Kelvin- Right now, any technique will have some amount of jumpiness when the user nears the restricted area. You can star this feature request for letting developers specify a pan bounds: http://code.google.com/p/gmaps-api-issues/issues/detail?id=750
You could also overlay a grey box or area around your target area, which could produce a similar effect (depending on your use case). - pamela On Thu, Jul 16, 2009 at 8:02 PM, Kelvin Luck <[email protected]> wrote: > > Hi, > > I am trying to do something very similar to this to stop the user from > being able to drag into the "empty space" above or below the map. My > MOVE_STEP listener currently looks like this: > > var topCornerLatLng:LatLng = map.fromViewportToLatLng(new Point(0,0)); > if (topCornerLatLng.lat() > 85) { > var latDiff:Number = topCornerLatLng.lat() - 85; > var newCenter:LatLng = new LatLng(event.latLng.lat() - latDiff, > event.latLng.lng()); > map.setCenter(newCenter); > } > > It kind of works but the map gets very jerky as you drag to the top of > the map. Is there a better solution? > > I thought that maybe calling event.preventDefault(); or > event.stopPropagation(); would prevent google from trying to update > the maps position (and therefore allow my setCenter code to work > correctly) but that didn't seem to make any difference... > > Is there any way to achieve what I am trying to do? > > Thanks in advance, > > Kelvin :) > > On May 31, 8:07 pm, pamela fox <[email protected]> wrote: > > Hi Luc - > > > > You can use something like the code shown below - basically, it > > restricts the user from panning too far by listening to the MOVE_STEP > > event and panning back if they go too far. > > > > - pamela > > > > // Define bounds somewhere application > > private var mapBounds:LatLngBounds; > > > > // Add listener after map is created > > map.addEventListener(MapMoveEvent.MOVE_STEP, onMoveStepEvent); > > > > /** > > * Restrict padding on movement such that the center > > * of the map stays within bounds. > > * > > * @param event move event information. > > * @author Scott Selikoff > > */ > > private function onMoveStepEventHandler(event:Event):void { > > > > if(!mapBounds.containsLatLng(map.getCenter())) { > > // Initialize new point > > var newLatitude:Number = map.getCenter().lat(); > > var newLongitude:Number = map.getCenter().lng(); > > > > // Initial min/max > > var minLatitude:Number = > mapBounds.getSouthEast().lat(); > > var maxLatitude:Number = > mapBounds.getNorthEast().lat(); > > var minLongitude:Number = > mapBounds.getNorthWest().lng(); > > var maxLongitude:Number = > mapBounds.getNorthEast().lng(); > > > > // Adjust Latitude as needed > > if(newLatitude < minLatitude) { > > newLatitude = minLatitude; > > } else if(newLatitude > maxLatitude) { > > newLatitude = maxLatitude; > > } > > > > // Adjust Longitude as needed > > if(minLongitude < maxLongitude) { > > // Normal Case > > if(newLongitude < minLongitude) { > > newLongitude = minLongitude; > > } else if(newLongitude > maxLongitude) { > > newLongitude = maxLongitude; > > } > > } else { > > // Case where bounds is on > > International date line since West > East > > if(newLongitude < minLongitude && > > newLongitude > maxLongitude) { > > // Bound detected, choose > > nearest neighbor > > > > if(Math.abs(newLongitude-minLongitude) < > > Math.abs(newLongitude-maxLongitude)) { > > newLongitude = > minLongitude; > > } else { > > newLongitude = > maxLongitude; > > } > > } > > } > > map.setCenter(new > LatLng(newLatitude,newLongitude)); > > } > > } > > > > On Sat, May 30, 2009 at 12:57 PM, Luc Barthelet <[email protected]> wrote: > > > > > Asking again. Did I miss some answer somehow? > > > I am trying to constrain the dragging of the map to a rectangle, but I > have not figured out anyway to do that. > > > > > Thank you, > > > Luc > > > > > -----Original Message----- > > > From: [email protected] [mailto: > [email protected]] On Behalf Of Luc Barthelet > > > Sent: Sunday, May 24, 2009 5:06 PM > > > To: [email protected] > > > Subject: Limiting the drag boundaries of the map > > > > > I have a custom map, and it would be nice to be able to control to > which extend the user can drag the map around. > > > I would like to prevent the 'around the world' wrapping of the map, as > my map is currently only a small portion of a future larger map. > > > > > Is there a way to do that already? or would that be a new feature? > > > > > Thank you, > > > Luc > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Maps API For Flash" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/google-maps-api-for-flash?hl=en -~----------~----~----~----~------~----~------~--~---
