This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

is there any way to do fitbounds using OSM

0

HI,

i want to display all my points in the map and adjust zoom automatically based on the number of points, if there are more points all points should be shown with zoom out, if there are 1 point only that point has to be shown with max zoom level

please suggest solution how to achieve this

Thanks Kiran

asked 21 Feb '13, 09:52

amkiranv's gravatar image

amkiranv
1333
accept rate: 0%

edited 21 Feb '13, 20:08

gormo's gravatar image

gormo
2.9k32660

1

Where? You added Nominatim and JOSM as tags but I guess you are using either Leaflet or OpenLayers instead.

(21 Feb '13, 09:56) scai ♦

yes am using OpenLayers

(21 Feb '13, 10:07) amkiranv

One Answer:

1

This is a OpenLayers question.

Use a http://dev.openlayers.org/apidocs/files/OpenLayers/BaseTypes/Bounds-js.html , fill it with all your points, then zoom the OpenLayers viewport to the created bounds object using http://dev.openlayers.org/apidocs/files/OpenLayers/Map-js.html#OpenLayers.Map.zoomToExtent .

answered 21 Feb '13, 20:06

gormo's gravatar image

gormo
2.9k32660
accept rate: 13%

edited 21 Feb '13, 20:07

Source code available on GitHub .