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

Pierre GIRAUD bluecarto at gmail.com
Tue Nov 6 06:00:13 EST 2007


Below is a log about a discussion we just had with Andreas on the text
rendering. It seems like our thoughts are similar. Sorry if it is not
that readable.

important points :
 - label style including label text value should be set in a style
object not in the layer options,
 - label value should be able to deal with literals and property
values, allowing concats

Regards,
Pierre

---------------------------------------------
11:30 AM me: hello
 Andreas: hi Pierre!
11:31 AM me: I'm impressed by the job done on the SLD renderer
  this is a big to look at
11:32 AM I working on the text rendering
 Andreas: thanks. I hope it will soon go into trunk, because we need
this functionality in Mapbuilder.
  I also have an idea on text rendering.
  In the sld spec, there are literals and propertyValues.
 me: I prefer to set the label as a property in the style
11:33 AM instead of an option in the layer
  what do you think about that
  ?
 Andreas: This is exactly what I recommended yesterday to the other
guy who was working on that
 me: it would follow the SLD spec
 Andreas: exactly.
 me: but I don't want to deal with SLD before it goes to trunk
 Andreas: And right now, I'm extending the sld parser and rule classes
to also support propertyValues, not only literals.
11:34 AM me: I don't know much about propertyValues
 Andreas: well, a literal is a constant.
  If you have <PropertyValue>name</PropertyValue>
11:35 AM in your sld, this means that you do not use "name" as value,
but the value of the "name" property of your feature
 me: understood
  hum, I made Mapserver write a SLD file for me this morning
11:36 AM and there is no propertyvalue
  hum no matter
 Andreas: wait a second, I'll give you a link explaining it...
 me: I think it's understood
11:37 AM Andreas: sorry, it's PropertyName, not PropertyValue:
http://trac.osgeo.org/mapserver/ticket/1857
 me: lol
  reported by Bart
11:38 AM it's fixed in the 5.0 version
  great
  my question then is : "how I can deal with propertyName in styles
that don't come from a SLD parsing" ?
 Andreas: my idea is the following:
11:39 AM in the "value" of the according rule, you can have a string
with a bash-like syntax:
  ${population}
 me: why not a sprint syntax ?
  %s
11:40 AM ok forget it doesn't work
 Andreas: yes, because you can concat literals and property names:
 me: OK this was my thoughts too
 Andreas: ${population} inhabitants
 me: great ! this was exactly the next step I wanted to get to
11:41 AM my examples already deal with literals
  are there any other interesting syntax we could use ?
 Andreas: this is all that can be done with sld. but I'm open to extensions.
11:42 AM Although I cannot think of any ATM
 me: it also have to work without SLD
  I'll try that
11:43 AM Andreas: it does. Have you seen the example georss.html in
the ahocevar/sldRenderer sandbox?
 me: no
 Andreas: http://dev.openlayers.org/sandbox/ahocevar/sldRenderer/examples/georss.html
 me: I'll do
 Andreas: There a style is created without sld.
 me: Oh yes I did already
11:44 AM OK, last question
  in the OpenLayers.Style class
11:45 AM do the label style properties have to be in the same object ?
as new properties (fontSize, label, labelPosition, etc...) ?
  or do we have to create a new OpenLayers.LabelStyle class ?
11:46 AM Andreas: it just uses the style hashes that are already
there. so you do not need to create anything new when there are new
style properties
 me: GML has a <LabelStyle> tag
 Andreas: SLD has font and label placement.
  and even more, I think.
11:47 AM me: fill, halo
 Andreas: yes.
11:48 AM So if you create code somewhere that uses a style.labelFont
property, you can define this style in OpenLayers.Style without the
need to change anything there.
 me: rightOK, if you don't mind, I'll put this discussion into the
mailing list thread.
 Andreas: yes, go ahead. This is important.
11:49 AM And I will put some code and example together on the
PropertyName thing.
 me: and probably we will be able to merge the sandboxes someday
  have a good day, see you
11:50 AM Andreas: have a good day too, bye!

On Nov 6, 2007 10:22 AM, Pierre GIRAUD <bluecarto at gmail.com> wrote:
> Hi,
>
> 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.
>
>
> Regards,
> Pierre
>



More information about the Dev mailing list