When using geofield map in views (for a proximity search), if the view has no results, the map displays zoomed into the middle of the ocean near Fiji. It may be argued that this is more of a feature request, but I'm leaning towards reporting it as a bug since I think the fiji map seems random.
I'm a newbie when it comes to this, but I found a fix that worked for me:
1) resetZoom should be set to false if there are no features.
2) Needing a default map center for no results. These values should be added to the map settings page in the view ("No Results map center point"). (for my purposes I hard coded it). Value should only be added if there are no features or the map will flicker on load.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | geofield_map_center-9.patch | 3.58 KB | el1_1el |
| #7 | geofield_map_center-7.patch | 7.53 KB | el1_1el |
| #6 | geofield_map_center-6.patch | 7.33 KB | el1_1el |
| #5 | geofield_map_center-5.patch | 3.12 KB | caktux |
| #4 | geofield_map_center.patch | 2.45 KB | caktux |
Comments
Comment #1
samgreco commentedI am struggling with this too. Where is the resetZoom setting? And where did you hard code the default map center?
Comment #2
sr631 commentedI made my hack/fix in geofield_map\js\geofield_map.js
For the map center...
Around line 44 the var myOptions =...
Before setting those values, I check to see
if(features.length > 1) {if it is, I use the default options. Otherwise, I added to the default options:
For resetZoom...I added it around line 88...I changed it to check the features first:
I hope that helps! I wish I knew how to get this bug assigned/fixed for real!
Comment #3
samgreco commentedThanks for the quick response. I appreciate it.
I have it working very well except for those issues, so I will give it a go and see what happens.
The Geofield map a really a nice little light weight solution.
Comment #4
caktux commentedDefault map center as a setting
Comment #5
caktux commentedDefault value, picked up by Features and not required...
Comment #6
el1_1el commentedThis is a duplicate of this - https://drupal.org/node/1707046 - so I added the option on caktux's patch to display the No results behavior. It would be nice if someone knows how to make it display both.....
Comment #7
el1_1el commentedI had an issue with the above patch when a single item was returned. If the map center was not set, I would get a blank map because the "features" object in the js file returns a length of "undefined" if only one item comes through the view or if no items come through the view - see http://stackoverflow.com/questions/4690520/javascript-object-literal-len... and http://stackoverflow.com/questions/5223/length-of-javascript-object-ie-a...
I added " || map_settings.center==''" to the "if (features.length >= 1){" line in the geofield_map.js file and that solved the problem if the center was unset because then the map center was never set. However, if the center was set and a single item was returned, the map always centered on the lat,long entered and at the default zoom level because a single item did not have a length and thus it was never centered on the single item returned.
If the view returned no items, the feature object had keys of "type" and "message", when a single item was returned the keys began with "gm_accessors_" and continued, and when multiple items were returned keys were the more familiar 0,1...
So I swapped the line
with the lines
based on this - http://stackoverflow.com/questions/909003/javascript-getting-the-first-i...
I've attached an updated patch below with the first solution commented out in case anyone needs that or sees a problem with the second solution.
Sorry if this is overly verbose or unhelpful.
cheers,
e
Comment #8
Ice-D commentedThis functionality must be added to the module please. It's very important to have a defined default center. Showing some piece of ocean is really not good.
Comment #9
bisonbleu commentedWhen trying to patch version 7.x-2.1 with patch in #7 I get an error.
Patch in #5 applies without complaints.
Map is centered when there are no results.
The No Results message (if there is one) is not displayed.
Comment #10
el1_1el commentedhmm..may have been crlf line returns. this seems to apply now in git.
Comment #11
bisonbleu commentedThanks @el
Patch in #10 applies flawlessly.
- The No Results message is displayed if no value exists for Map center.
- If a value exists for Map center then map is centered on that value, no message is displayed.
Comment #12
hanskuiters commentedApplied patch #10. Nice work.
Comment #14
Brandonian commentedThanks for the patch, @el! I reworked it to use the geofield_latlon widget that's provided with the module and cleaned up the UI form a little bit. Committed to 7.x-2.x
http://drupalcode.org/project/geofield.git/commit/8e345d9
Comment #15
Brandonian commentedMarking as fixed
Comment #17
fmfpereira commentedI had the same problem with geofield-7.x-2.x-dev
The map is beeing centered on the ocean and no result condition is beeing shown.
I have noticed that geofield_map_center width no coordinates is not being avaliated.
I had to override views before execution.
Comment #18
amuli commentedSame problem with geofield-7.x-2.3.
Trying solution #17, my implementation of
hook_views_pre_execute()— I also triedhook_views_post_build()— executes for every view BUT the one I want to modify the parameters. I can't figure why. Any idea ?