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

pramod_ck
41337
accept rate: 0%

edited 31 Jul '12, 13:50

SomeoneElse's gravatar image

SomeoneElse ♦
32.0k63327747

1

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
1

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 openlayers.org 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 ♦
69.4k806291086
accept rate: 24%

@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

NicolasDumoulin
3.3k42256
accept rate: 13%

Your answer
toggle preview

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×111
×86
×46
×43

question asked: 31 Jul '12, 05:57

question was seen: 11,084 times

last updated: 28 Aug '12, 12:40

powered by OSQA