I think you may want to start implementing your own labelling system.

The renderer implementations delegate the label handling out to an instance of 
LabelCache; there is one instance provided by GeoTools and applications 
sometimes implement their own. As an example uDig implements one that gathers 
up labels from a number of renderer instances that are running in different 
threads.

The thing is you can make a function (such as you are doing) but at best it is 
going to provide a label and a position that is fed into the label cache 
implementation. The label cache implementation does have some hints to control 
it (so you can have more important labels take priority); but since you are 
talking about your own clusters of features - you may want to buckle down and 
implement a label cache that knows about your clusters of features.

Cheers,
Jody


On 13/07/2010, at 12:48 AM, LSA wrote:

> Hi all,
> 
> I need to have my own custom labeling, which will place label near each 
> feature using information about clusters of features (known to my 
> application). In order to do it, I use my own function expression:
> public class MyExpression extends FunctionExpressionImpl {
>      private Set lineIDs = new HashSet();
>      
>      public MyExpression() {
>        super("MyExpression");
>      }
> 
>      @Override
>      public int getArgCount() {
>        return 0;
>      }
> 
>      @Override
>      public Object evaluate(Object objFeature) {
>        SimpleFeature feature = (SimpleFeature)objFeature;
>        Object attr1 = feature.getAttribute("Attr1");
>        return "Attr1="+attr1;
>      }
>    }
> Then I create my text symbolizer:
> 
> MyExpression myExp = new MyExpression();
> TextSymbolizer textSym = sf.createTextSymbolizer(
>             sf.createFill(ff.literal(Color.BLACK)), new 
> Font[]{sf.getDefaultFont()}, null, myExp , placement, null);
> 
> The problem that I run into is about feature passed to evaluate contains only 
> geometry, no attributes at all (except FeatureId). So, 
> feature.getAttribute("Attr1") will always return null. However, in order to 
> display my clustering information I need certain attributes of each feature.
> 
> Is this possible to do?
> 
> As a horrible workaround, I pass Map<FeautureId, SimpleFeature> to 
> MyExpression, and use these attributes. Downsides of this solution are 
> obvious.
> 
> Also I have another one question:
> Is it possible to override behaviour of the default labeling in order to show 
> only one label per cluster  of features? To what properties should I pay my 
> attention?
> Are there some examples of creating custom labeling?
> 
> Any help would be appreciated....
> 
> Thanks in advance,
> Sergey
> 
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by Sprint
> What will you do first with EVO, the first 4G phone?
> Visit sprint.com/first -- 
> http://p.sf.net/sfu/sprint-com-first_______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to