I'm using geofield to input location info by placing a marker on a OpenLayers map. In earlier releases geofield would allow only one marker to be placed ('Numbers of Values' set to 1), setting another marker would remove the first marker and add the new one.
With the 7.x-1.1 release and the 7.x-1-dev versions, it no longer restricts the number of markers placed on the map.

When I reverted to the 7.x-1.0 release the field worked as expected.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ArchangelGuidz’s picture

Would like to report this is an issue too. Seems this was fixed for drawing features with OpenLayers, though not in the Geofield OL Map. I'm more of a designer than a JS-PHP guy. Can anyone help out on a fix?

phayes’s picture

I think we have this one fixed in the 2.x branch if you would like to check it out.

perke’s picture

Just upgraded from 7.x-1.1 to 7.x-2.x-dev and problem described above still appears.

phayes’s picture

@perke,

What field settings are you using? Specifically, do you have "use collections" turned on or off?

perke’s picture

FileSize
86.96 KB

hi,

storage options is set as "Store as a single collection"

here is screenshot of all settings for the geofield

thanks

perke’s picture

edit: here is better screenshot, overlay messed it up

Wouter Van den Bosch’s picture

I think this issue is related to this particular snippet of code in openlayers_behavior_geofield.js:

  //only one feature on each map register before adding our data
  if (Drupal.settings.geofield.data_storage == 'single') {
    dataLayer.events.register('featureadded', $wkt, limitFeatures);
  }

At that particular moment the Drupal.settings object does not exist, and hence the limitFeatures rule is ignored.

Commenting out the condition, results in one singular point being replaced on every click.

perke’s picture

I've tried commenting that out and it didn't worked. @Wouter, have you also upgraded from 7.x-1.1 or is it a clean install?

Wouter Van den Bosch’s picture

@Perke, I had an install with 7.x-1.0 at first, which I later upgraded to 7.x-1.1. It's only after a while that i noticed that I was now selecting multiple points and that the number of values setting was being ignored.

So after some digging I briefly altered:

  //only one feature on each map register before adding our data
  if (Drupal.settings.geofield.data_storage == 'single') {
    dataLayer.events.register('featureadded', $wkt, limitFeatures);
  }

into:

  //only one feature on each map register before adding our data
  //if (Drupal.settings.geofield.data_storage == 'single') {
    dataLayer.events.register('featureadded', $wkt, limitFeatures);
  //}

Just to check whether that could be the problem of course. As soon as I comment out those two lines, I am back to the correct 1 point behaviour.

Do make sure to clear your cache though. I've had some issues with the old JS file hanging around.

perke’s picture

ah ok, i was commenting full if statement... thanks, it worked... guess i'll use this temp fix to get this thing going on

phayes’s picture

Category: bug » support

There should be no need to patch anything. If you are storing everything as a single collection, this is expected behavior. You should be using "Store each feature separately"

nubeli’s picture

Note that in the code "single" refers to "Store each feature separately" and "collection" to "Store as a single collection." That was a bit confusing.

I've got 7.x-1.1 on a site, it was not respecting 1 value for the field and it was set to Store each feature separately. I commented out the condition and it will now allow only one feature on the map. But it still ignores the value. For example, if I set it to 5 it will still only allow one feature on the map.

ressa’s picture

Thanks @Wouter Van den Bosch (#9) that works. The file in question is located here:
sites/all/modules/geofield/includes/behaviors/js/openlayers_behavior_geofield.js

gravisrs’s picture

Another fix better than in #9 - earlier debug approach in file geofield.widgets.inc :

function geofield_widget_openlayers_afterbuild($element, &$form_state) {
  drupal_add_js(
    array('geofield' => array(
      'data_storage' => (!empty($settings['data_storage'])) ? $settings['data_storage'] : 'collection',
      ),
    ),
  'setting');

add a line like this:

function geofield_widget_openlayers_afterbuild($element, &$form_state) {
  $settings = $form_state['field'][$element['#field_name']]['und']['instance']['widget']['settings'];
  drupal_add_js(
...

please review and put fix to repo

Sinovchi’s picture

Status: Active » Reviewed & tested by the community

Thanks gravisrs,
This is really better fix for 7.x-1.1.

Brandonian’s picture

@gravisrs, can you make a patch for inclusion?

peterm95018’s picture

Had the same issue, so I created (my first) patch based on gravisrs code in #14.

Peter

peterm95018’s picture

Status: Reviewed & tested by the community » Needs review
balagan’s picture

I came here from http://drupal.org/node/1630836#comment-6869276, which I think is a duplicate of this issue. I haven't reviewed this patch, but I have also found that the $setting variable is not available from the geofield_widget_openlayers_afterbuild function, and using dpm I saw that the value needed can be accessed in the $form_state variable. I will get back to this patch tomorrow

balagan’s picture

The patch is working for me, but git produces a warning about whitespace error.

balagan’s picture

Title: Geofield does not respect the 'Number of Values' setting » Geofield does not respect the 'Number of Values' setting
Status: Needs review » Reviewed & tested by the community
balagan’s picture

Category: support » bug
gerontas’s picture

I have tested the code in #14

It successfully limits the number of points that can be placed (1 in my case) but if the map is saved and then edited again, another point can be added and the original point cannot be deleted.

gerontas’s picture

Sorry I spoke too soon - it looks as if it does work.

I discovered that I had 'Draw features' activated in the map behaviours settings. When I de-activated that the map respects the field setting.

shushu’s picture

Patch seems to work for me as well. Can this be pushed into the 1.x branch and closed ?

mr.baileys’s picture

Version: 7.x-1.1 » 7.x-1.x-dev
Status: Reviewed & tested by the community » Needs review
FileSize
683 bytes

I ran into the same issue.

The bug was introduced in #1298842-4: Map is not rendered after validation error., where part of the behavior setup code was moved from geofield_field_widget_form to geofield_widget_openlayers_afterbuild. The snippet that was moved referenced a variable ($settings) that was not moved to the new function, and thus out of scope, always triggering the default data storage fallback value 'collection'.

The patch in #17 works but seems fragile (for example, having the 'und' hardcoded.) Attached is a patch that uses field_widget_instance instead.

balagan’s picture

Well, it seems to be a lot nicer solution leaving out the 'und'.

organicwire’s picture

Patch #26 works for me.

Jarode’s picture

Status: Needs review » Reviewed & tested by the community

Yes that works !

jcisio’s picture

Priority: Normal » Major

I think it is important for the next release.

Brandonian’s picture

Status: Reviewed & tested by the community » Fixed

Patch at #26 applied. Thanks, @mr.baileys!

http://drupalcode.org/project/geofield.git/commit/39acd9e

Status: Fixed » Closed (fixed)

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