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.

Comments

samgreco’s picture

I am struggling with this too. Where is the resetZoom setting? And where did you hard code the default map center?

sr631’s picture

I 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:

center: new google.maps.LatLng(49.1715, -101.2500)

For resetZoom...I added it around line 88...I changed it to check the features first:

if(features.length >= 1) {
  if (resetZoom) {
      map.fitBounds(range);
  } else {
      map.setCenter(range.getCenter());
  }
}

I hope that helps! I wish I knew how to get this bug assigned/fixed for real!

samgreco’s picture

Thanks 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.

caktux’s picture

Version: 7.x-1.1 » 7.x-2.x-dev
Status: Active » Needs work
StatusFileSize
new2.45 KB

Default map center as a setting

caktux’s picture

StatusFileSize
new3.12 KB

Default value, picked up by Features and not required...

el1_1el’s picture

StatusFileSize
new7.33 KB

This 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.....

el1_1el’s picture

Status: Needs work » Needs review
StatusFileSize
new7.53 KB

I 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

if (features.length >= 1 || map_settings.center=='') {

with the lines

for (first in features) break;
if (first!='type') {

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

Ice-D’s picture

This 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.

bisonbleu’s picture

Issue summary: View changes

When trying to patch version 7.x-2.1 with patch in #7 I get an error.

ren$ patch -p1 < geofield_map_center-7.patch
patch unexpectedly ends in middle of line
patch: **** Only garbage was found in the patch input.

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.

el1_1el’s picture

StatusFileSize
new3.58 KB

hmm..may have been crlf line returns. this seems to apply now in git.

bisonbleu’s picture

Thanks @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.

hanskuiters’s picture

Status: Needs review » Reviewed & tested by the community

Applied patch #10. Nice work.

  • Brandonian committed 8e345d9 on 7.x-2.x authored by el
    #1733864 - View no results unhandled - map resetZoom results in map of...
Brandonian’s picture

Thanks 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

Brandonian’s picture

Status: Reviewed & tested by the community » Fixed

Marking as fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

fmfpereira’s picture

I 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.

/**
* implements hook_views_pre_execute
* unsets the geofield_map_center if there is no available center coordinates
* this is required in order to hide the map apply the no results condition on view
* @param $view
*/
function my_module_views_pre_execute(&$view) {
   if(isset($view->style_plugin->options["geofield_map_center"])) {
      if(!$view->style_plugin->options["geofield_map_center"]["lat"] && !$view->style_plugin->options["geofield_map_center"]["lat"]) {
      $view->style_plugin->options["geofield_map_center"] = NULL;
      }
   }
}
amuli’s picture

Same problem with geofield-7.x-2.3.

Trying solution #17, my implementation of hook_views_pre_execute() — I also tried hook_views_post_build() — executes for every view BUT the one I want to modify the parameters. I can't figure why. Any idea ?