Needs review
Project:
Geofield
Version:
7.x-2.1
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
12 Jan 2012 at 20:53 UTC
Updated:
26 Oct 2014 at 09:44 UTC
Jump to comment: Most recent
It appears that the zoom level is not being used and the map always shows fully zoomed in..
Comments
Comment #1
Brandonian commentedThanks for the bug report, @wipeout_dude. Some of this is a legitimate bug/regression from previous versions.
I've adjusted the zoom level given by the map to have the requested zoom level if the map is displaying a single point. Otherwise, the zoom level is determined by Google Map's fitBounds function, which will zoom in to fit the feature(s) being displayed.
http://drupalcode.org/project/geofield.git/commit/9f1a2ed
Comment #3
ceepeebee commentedI reopen this issue due to another unexpected behaviour related to the problem above and therefore renaming the title. (I hope you don't mind)
I just experienced a fully zoomed in map, as well. In my case the error actually lay with me due to accidently passing the same geodata twice (problem with addressfiel module saving default country as a second record) - never mind.
Anyways, this showed me that I'd be running into the same problem lateron, when displaying geodata of two (or more) datasets when they are totaly equal.
Use case (I will use the term address instead of geocode):
1. let 'geofield map' output the addresses of a group of people.
2. If the group consists of only one person: no problem, only one marker, resetZoom = false; (applied by the patch mentioned above)
3. If there is more than one address, you have to distinguish:
a) one or more addresses differ: (almost)** no problem, resetZoom = yes; the map will be zoomed accordingly to fitBounds
b) BUT if by chance all the addresses are identical, then you get the same behaviour as before: a fully zoomed in map... that is unexpected.
It may seem to be not very likely to have the same addresses (geocodes) for all sets passed,
but just consider a student hall of residence.
My fix for geofield_map.js: (just using php for syntax highlighting
Questions arising:
1. what if there are any use cases which would rely on a zoom reset even if all the displayed geocodes fall into one singular spot (= automatic zoom in). I couldn't think of any, but then you could just use standard zoom level 0.
2. what do you consider to be two _different_ locations? I guess if you set a default zoom level you want to have at least this zoom level. Only if you need to zoom out in order to see other markers outside the standard view, you would need a map.fitBounds(range). Zooming in to fit bounds leads to the unexpected behaviour described above. But that's just my opinion.
3. Similarily, what do you do, if two points are not identical but lie just next to each other? e.g. two neighbours. If you set a standard zoom level of, say 10, in many cases it would not be expected to have an automatic zoom reset. (see above)
Cutting it short, maybe an option to toggle automatic zoomreset (maybe even seperate for zooming in and zooming out) should be implemented to avoid predefining the needs out there.
Comment #4
ceepeebee commentedComment #5
ceepeebee commentedSorry, the for-loop is incorrect in the previous post. It should read as follows or similar.
I am going to correct it.
Comment #6
dariogcode commentedHi @ceepeebee I applied your changes and it works well in some circunstances, but in other not, I have multiples points with different lat/lang, but still have wrong map zoom or fit bounds.
Anyone having same issue?
Comment #7
dariogcode commentedok, for everybody trying to fix this. I fixed it (for now) using the following code:
Because the problem is when the fitbounds fully zoom the map, if the current zoom is more than our pre defined zoom then we need to set it again. Thanks to http://stackoverflow.com/a/4065006