NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

I need to change zoom level dynamically in openstreet map according to displayed number of markers, means if there is only one location is marked i need more zoom and if there is more than one locations are marked i need zoom level is less( because i want to see all markers).I'm using OpenLayers library. Can any one help me..? Thanks in adavace...

asked 31 Jul '12, 05:57

pramod_ck's gravatar image

accept rate: 0%

edited 31 Jul '12, 13:50

SomeoneElse's gravatar image

SomeoneElse ♦


I'm guessing that you're using a Javascript library to display OpenStreetMap tiles (perhaps one of the ones mentioned here)?

A bit more information about what you're trying to do would help.

(31 Jul '12, 11:45) SomeoneElse ♦

ya, I'm using OpenLayers library only. The problem is we want to display several markers on a map and want to calculate the optimal zoom-level like Google Maps does. We already calculated the centerpoint of the map but now we have a hard time to calculate the correct zoomlevel to display the whole markers..

(31 Jul '12, 11:54) pramod_ck

Which javascript library? OpenLayers or Leaflet? (you should edit your question to supply more details)

(31 Jul '12, 12:18) Harry Wood

I'm using OpenLayers library..

(31 Jul '12, 12:20) pramod_ck

This is more an OpenLayers question than an OpenStreetMap question. See for means to get help. What you probably want to do is use OpenLayers' "zoomToExtent" function, using an extent that you have created with reference to the sum of all your markers.

permanent link

answered 31 Jul '12, 10:10

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
accept rate: 23%

@Frederik Ramm, Thanks. Actually i'm very new to this.. So first i need to define the bounds right..?

(31 Jul '12, 10:25) pramod_ck

You can take a look at this other question.

For zooming on your markers (the zoom will automatically be computed), you have to invoke zoomToExtent as said Frederik: map.zoomToExtent(markersLayer.getDataExtent());

permanent link

answered 28 Aug '12, 12:40

NicolasDumoulin's gravatar image

accept rate: 13%

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 31 Jul '12, 05:57

question was seen: 15,298 times

last updated: 28 Aug '12, 12:40

NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum