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

Pierre GIRAUD bluecarto at gmail.com
Tue Nov 6 15:56:48 EST 2007


I just gave it a try and it seems to work. After I merge the Andreas
sandbox in mine to get some of the great work he did, I succeeded in
having the "propertyName" (SLD tag) working in my example.

Go have a look at
http://dev.openlayers.org/sandbox/camptocamp/text/examples/vector-features-with-text.html.
If you get a quick look at the code, the label style attribute is now
written as "some literal {some variable attribute} some literal
again".
That should let the user build his own label. You are also able to
just display a single attribute value.

About performance, I don't really now how it will behave yet. I'll do
some benchs tomorrow.
Please also note that this code was quickly written. It needs much
review. I hope Andreas, or other folks can have a look.
It seem to work though !

Regards,
Pierre

On Nov 6, 2007 7:40 PM, dave c <dc at openapp.ie> wrote:
> Thanks that code of yours works for me,
>
> In relation to the label within the style, taken from the example you did,
> would i not need a labelname as well as label, or am i missing something here
>
>             var label_style = {
>                 fontFamily: 'Helvetica',
>                 fontSize: 10,
>                 fontWeight: 'bold',
>                 fillColor: '#FF0000',
>                 horizontalAlignment: 'center',
>                 labelname: 'hospname',
>                 label: 'undefined'
>             }
>
> I know you havent finished with how you will get access to the attribute it
> self, but the simplest way i know is the following in the drawFeature
> function
>
>   drawFeature: function(feature, style) {
>       if(style == null) {
>           style = feature.style;
>       }
>      if (style.labelStyle)
>      {
>      if(feature.attributes[style.labelStyle.labelname])
>      {
>      style.labelStyle.label = feature.attributes[style.labelStyle.labelname];
>       }
>       }
>       this.drawGeometry(feature.geometry, style, feature.id);
>     },
>
> so i still have extractAttributes set to true, just wondering how much of a
> performance decrease it might have, or is there a much better way.
>
>
>
> On Tuesday 06 November 2007 09:22:43 you 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=W
> > >FS", { 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