OpenLayers – Custom Feature Style

By | January 14, 2013
OpenLayers: Custom Feature Style

OpenLayers: Custom Feature Style

Topic: OpenLayers – Custom Feature Style
Descriptions: To enable custom style to a particular feature by using renderIntent & adding new styleMap.

  1. Get Feature; var o = target_layer.features[3];
  2. Set Style Name; var styleName = o.id + '_style';
  3. Set render intent; o.renderIntent = styleName;
  4. Set the custom style; var style = new OpenLayers.Style({externalGraphic:'icons/marker_1.png'});
  5. Add new style to styleMap; o.layer.styleMap.styles[styleName] = style;
  6. Assign back to the layer’s feature; target_layer.features[3] = o;
  7. Call redraw method in o.layer; o.layer.redraw();

Leave a Reply

Your email address will not be published. Required fields are marked *

three × four =