If an Openlayers map is included in a form that uses #ajax, Drupal.detachBehaviors() is run by Drupal core's ajax code, which results in the map being deleted from Drupal.openlayers.instances[map_id].

The map itself is not destroyed - just the storage of the instance in Drupal.openlayers.instances. I'm not sure if there is a reason for this.

I am trying to write Javascript that adds layers to the map dynamically after it is loaded, and the only way for me to access the Openlayers map object is to use Drupal.openlayers.getMapById() - but that doesn't work when Drupal.openlayers.instances isn't populated.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

m.stenta created an issue. See original summary.

m.stenta’s picture

Status: Active » Needs review
FileSize
651 bytes

Attached is a patch that reverts just one part of this commit: http://cgit.drupalcode.org/openlayers/commit/?h=7.x-2.x&id=28cdc1c0bd275...

I'm not sure if there was a reason for adding that code - or if perhaps it was just for cleanup purposes. That makes sense, but I think it's unnecessary in this instance.

Status: Needs review » Needs work

The last submitted patch, 2: openlayers_detach-2688029-1.patch, failed testing.

m.stenta’s picture

This patch breaks AJAX map replacements. Need to figure out a different solution. See #2755899: Geocode button doesn't work

m.stenta’s picture

Status: Needs work » Needs review
FileSize
593 bytes

Ok, after some debugging, I discovered that it simply needs "context" included in the call to jQuery!

Here is a much simpler patch, which solves the original issue, and does not cause conflicts as described in #2755899: Geocode button doesn't work

Status: Needs review » Needs work

The last submitted patch, 5: openlayers_detach-2688029-5.patch, failed testing.

m.stenta’s picture

Status: Needs work » Needs review

  • Pol committed b626e7a on 7.x-3.x authored by m.stenta
    Issue #2688029 by m.stenta: Map instances removed by Drupal....
Pol’s picture

Status: Needs review » Fixed

Nice catch !

Thanks !!!

Status: Fixed » Closed (fixed)

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