Current 3.x dev version of openlayers does not have this function

Comments

basvredeling’s picture

Issue summary: View changes

The function can be replaced by:

// Get preset options, filtered to those which have the GeoField source.
  ctools_include('export');
  $maps = ctools_export_crud_load_all('openlayers_maps');
  $map_options = array();
  foreach ($maps as $machine_name => $data) {
    /** @var \Drupal\openlayers\Map\OLMap $map */
    $map = openlayers_object_load('Map', $data);
    foreach ($map->getSources() as $source) {
      if ($source instanceof \Drupal\openlayers\Source\Geofield) {
        $map_options[$machine_name] = $data->name;
      }
    }
  }

This code needs refactoring into a separate function though. As is marked in openlayers_ui.admin.inc line 19: "// Todo: Rewrite properly and create a generic function to load all objects."

Don't forget to turn on the openlayers_geofield module.

basvredeling’s picture

Status: Active » Needs review
StatusFileSize
new3.33 KB

I've added a patch for geofield 7.x-2.x which should fix some more openlayers 3 issues all related to the map presets not being available.
Actually I think geofield needs a 3.x branch to match openlayers 3. That way, we don't break openlayers 2 compatibility.

milos.kroulik’s picture

Thanks for the patch. Regarding the new branch - I don't think, it's a good idea, since Leaflet module (and possibly others) also uses Geofield. Generally, formatter modules should maintain compatibility with modules providing fields they operate on, not the other way around.

basvredeling’s picture

If we don't make another branch I propose we add another check for the OL version. Either:

$info = system_get_info('module', 'openlayers'); 
if (version_compare($info['version'], '2.0') >= 0) {
// ... do stuff
}

or

if (is_callable('openlayers_preset_options')) {
// ... do stuff
}