Hi, I posted a question in an older issue (http://drupal.org/node/564964) asking a similar question but given that is for openlayers 6.x that may not be the correct place.

I have created a custom marker using a coded style following the instructions documented here - http://drupal.org/node/620602 (used hook_openlayers_style)

This works fine, in that open layers can see with style and I can apply it to a map. However I want to conditionally change the marker graphic being used based on what is in a field. I followed the instructions in the documentation here - https://drupal.org/node/1585880.

However, I need to be able to access the field object within my custom style, looking at older issue threads this seemed to be possible in 6.x but I cannot find a way to access these fields from within the function in 7.x. Because I need to calculate what is in the field before changing the graphic a simple solution such as using a token within the name of the graphic as provided in the documentation is not viable.

This issue - http://drupal.org/node/1000012 suggests that a style like the one I created are different to style plugins. 6.x seems to include functionality to create style plugins, however looking at the examples included in STYLE_PLUGINS.txt file in 6.x the class used to extend plugins does not appear to exist in 7.x-2.x.

It seems style plugins (which sound like they will do what I want) can be used in 6.x but I see no indication this is available in 7.x - is there an alternative or a work around for this? Or am I going to be left having to use custom views PHP field?

Any guidance or suggestions would be greatly appreciated.

Thanks,
Sam

Comments

sambonner’s picture

This question has been answered on a similar issue raised earlier which I bumped (apologies for the duplication) - http://drupal.org/node/1662716#comment-7255406

So style plugins are not supported in 7.x-2.x. Apparently this leaves only hacky solutions available to developers wishing to conditionally change markers if their requirements are more complex than simple token replacement in graphic file names.

pol’s picture

Status: Active » Fixed

Hello,

I'm using OpenLayers for a project these days and I succeeded to export/import my styles using a custom module.

Here's the code I used:

/**
 * Implements hook_ctools_plugins_api().
 */
function HOOK_ctools_plugin_api($module, $api) {
  if ($module == "openlayers") {
    switch ($api) {
      case 'openlayers_styles':
        return array('version' => 1);
    }
  }
}

function HOOK_openlayers_styles() {
  $name = 'output';
  $openlayers_styles = new stdClass();
  $openlayers_styles->disabled = FALSE; /* Edit this to true to make a default openlayers_styles disabled initially */
  $openlayers_styles->api_version = 1;
  $openlayers_styles->name = $name;
  $openlayers_styles->title = 'Output';
  $openlayers_styles->description = 'Output.';
  $openlayers_styles->data = array(
    'pointRadius' => 6,
    'fillColor' => '${field_color}',
    'strokeColor' => '#222222',
    'strokeWidth' => 4,
    'fillOpacity' => 0.5,
    'strokeOpacity' => 0.7,
    'strokeLinecap' => 'round',
    'strokeDashstyle' => 'dash',
    'graphicOpacity' => 1,
    'label' => '${title}',
    'labelAlign' => 'cm',
  );

  $styles[$name] = $openlayers_styles;

  return $styles;
}

I guess I can close the both issues, feel free to reopen if it's not what you want.

Status: Fixed » Closed (fixed)

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