[OpenLayers-Dev] text rendering support in openlayers for wfs layers

Pierre GIRAUD bluecarto at gmail.com
Tue Nov 6 04:22:43 EST 2007


As said by Bart, I'm trying to get text into the renderer so that
people can have labels on vector features.
Some work is already done in the camptocamp sandbox.

I'm having a look at your and I'll pick some good ideas in there for sure.

Some other comments below :

On Nov 5, 2007 8:30 PM, dave c <dc at openapp.ie> wrote:
> I posted on this last month but i didnt get any response so i went ahead
> anyways. Now what i put together is only a first pass of sorts and is a
> little crude in places but i was hoping that someone here could have a look
> at it and tell me if it could be used within openlayers as i dont want to
> have to continually be updating it myself. Of course you may not like the way
> i went about it or have no plans to implement text rendering.

You're wrong : people are interested in having text rendering into OpenLayers.
We'll just have to find a common way to get it into the trunk as soon
as possible. If needed, I'll open a new wiki page so that others
interested folks can give their point of view.

> Using openlayers 2.5 stable, I created a patch for this version if anyone
> wants to have a  look. The patch is called patch.txt and is attached to this
> mail. So run "patch -p0 < ../patch.txt" to update.

Your code seem a bit different from mine but not that much. I'll try
to find what is better in both.

> Just a few quick points and issues i had.
> One reason to get text rendering working for example was, i needed to be able
> to output the names of certain hospitals on a map centered on there point on
> the map. Firstly i have "extractAttributes: true" and added an layer option
> called  "textAttrToDisplay" which is the name of the attribute to be
> displayed within each feature that was coming from my database.

I totally agree with Andreas on that point. It would be better if we
follow already existing terminology. The SLD's one seems correct. And
it will easier to connect to the SLD parser when it is in the trunk.

> Now biggest issue i had was in svg the text was rendering upside down due to
> the "transform scale(1,-1)" and so i just created a 2nd root node called
> textroot which i appended to the renderedRoot and added all text nodes to it
> instead. Of course this wasn't an issue in vml. Is there a better way ?

I didn't created a new root for text. Instead, I just transformed the
scale back and it just works.
A problem with having a new root may raise up when user wants to
select a feature. Events won't go through the text root node.
Though, this solution may have one advantage. This way, all the labels
are on top of the layer.

> I tried finding a quick example that you could quickly test this out on
> yourselves, but all the wfs examples i looked at in openlayers did not return
> any other data except there co-ordinates, but i assume a number of ye would
> be able to get it running quickly with your own local datasets.
> So as an example of its use, say this is some of the data returned from my
> database,
> <gml:featureMember>
>         <fs:hospital fid="1">
>         <fs:geometry>
>         <gml:Point>
> <gml:coordinates>99771.29,47991.03</gml:coordinates>
> </gml:Point>
> </fs:geometry>
> <fs:hospname>Bantry</fs:hospname>
> <fs:county>Co Cork</fs:county>
> <fs:he_admin_area>South</fs:he_admin_area>
> <fs:address>Bantry</fs:address>
> <fs:recordno>21</fs:recordno>
> <fs:regionname>Region 2</fs:regionname>
> </fs:hospital>
> </gml:featureMember>
> And i wanted to display the hospital name, i would add textAttrToDisplay as an
> option to the layer with the value hospname.
> var lOptions = {
> extractAttributes: true,
> textAttrToDisplay : 'hospname'
> }
> layer2 = new
> OpenLayers.Layer.WFS( "Hospital", "http://localhost/~dave/featureserver/featureserver.cgi/hospital?format=WFS",
> { maxfeatures:10},  lOptions);
> map.addLayer(layer2);

Text label should work for every possible type of Vector layer. We can
easily have examples working with simple dataset that don't need a WFS
server connection.
In my first implementation (sandbox), I don't deal with vector
features attributes. This is the next step I want to work on.


More information about the Dev mailing list