OpenLayers OpenLayers

Ticket #736 (closed feature: fixed)

Opened 3 years ago

Last modified 3 years ago

external graphic as style for vector points

Reported by: openlayers Assigned to:
Priority: minor Milestone: 2.5 Release
Component: Renderer.SVG Version: SVN
Keywords: Cc:
State:

Description

Hi,

I have been thinking about how to implement an aspect of OGC Styled Layer Descriptors with OpenLayers vector renderers: using an external graphic as style for a point.

I came up with a quite simple solution, for which I created a patch and an extended vector-features.html example. For now, I only implemented it for the SVG renderer, where PNG, JPEG and SVG files can be used as external graphic.

How it works: The setStyle method of the renderer checks for a style property "externalGraphic", which contains an URI to a bitmap. If this property is set, the original "circle" node is removed from the root node, and a new "image" node with the same properties and the required attributes is created.

As in the SLD specification, only a size for the bitmap can be specified. So external graphics will always be rendered with same width and height. For width and height, the existing pointRadius property is used.

I would appreciate your comments, and I will gladly implement it for VML, too. But I would like to know if the way I did it is the way to go, or if there are proposals for a different way.

Regards, Andreas Hocevar.

Attachments

vectorimages.diff (3.4 kB) - added by openlayers on 05/31/07 15:24:30.
externalGraphic.diff (6.2 kB) - added by ahocevar on 06/06/07 18:12:11.
New, improved version. Implemented for both SVG and VML.
externalGraphic.2.diff (8.9 kB) - added by ahocevar on 06/17/07 11:24:02.
Improved version which allows control over aspect ratio of the image; also added a description to vector-features.html
externalGraphic.3.diff (14.4 kB) - added by ahocevar on 06/18/07 15:47:33.
Added tests in Layer/test_Vector.html; the patch is against the trunk and replaces previous patches for this ticket.

Change History

05/31/07 15:24:30 changed by openlayers

  • attachment vectorimages.diff added.

06/06/07 18:12:11 changed by ahocevar

  • attachment externalGraphic.diff added.

New, improved version. Implemented for both SVG and VML.

(follow-up: ↓ 2 ) 06/06/07 18:22:48 changed by ahocevar

The new version has support for opacity (using the fillOpacity property of the style). It keeps the aspect ratio of images, and the size is determined by the pointRadius style property. This is the behaviour suggested in the SLD specification.

Testing was mainly done using the shipTracks demo of Mapbuilder (hopefully http://demo.communitymapbuilder.org/demo/mapbuilder-ol/demo/shipTracks/, currently down). The SelectFeature control also works correctly on images.

If there are no further suggestions on that, I would kindly ask to pull it into the trunk. Otherwise I will be glad to improve the code based on your suggestions.

Regards, Andreas.

(in reply to: ↑ 1 ) 06/06/07 18:40:04 changed by ahocevar

Replying to ahocevar:

Forgot to mention that this feature is being developed in the camptocamp sandbox: http://dev.openlayers.org/sandbox/camptocamp/externalGraphics/examples/vector-features.html

I also fixed an issue with fillOpacity: unspecified fillOpacity was interpreted as 1.0 in SVG and 0.0 in VML. Now unspecified fillOpacity is rendered as 1.0 in both SVG and VML.

06/17/07 11:24:02 changed by ahocevar

  • attachment externalGraphic.2.diff added.

Improved version which allows control over aspect ratio of the image; also added a description to vector-features.html

06/18/07 15:47:33 changed by ahocevar

  • attachment externalGraphic.3.diff added.

Added tests in Layer/test_Vector.html; the patch is against the trunk and replaces previous patches for this ticket.

06/29/07 05:55:17 changed by crschmidt

  • milestone set to 2.5 Release.

06/29/07 05:57:10 changed by crschmidt

  • keywords set to review.

The tests need to be run in IE. if they pass, I'm ready for this to go in, barring any blockers. I'll try and run the tests myself today -- Erik, if this doesn't get in on my account, feel free to take it and test it to your hearts content.

07/13/07 08:33:12 changed by crschmidt

  • keywords deleted.
  • status changed from new to closed.
  • resolution set to fixed.

Ran tests in IE, passed. Committed with r3729.

woohooo. thanks andreas for all the hard work!