I want to add labels with geocoordinates on the grid of the map. I have previously asked you this question and you have shared some code with me (How can I label the coordinate position of the grid coordinate lines), but I had no time to try it before. So, now I am trying to adapt this code as bellowe

But I have no got the positive resoult yet with this work and also I have no any errors... Am I doing somthing wrong? Could you at least describe the steps to create these labels, please..?

  • You need a text symbolizer – Ian Turton May 1 '19 at 16:14
  • Yes! Thanks a lot! I don’t have enough words to express my gratitude for you... – asker May 1 '19 at 18:03

LineFeatureBuilder creates attributes called value and label which you can use in the display of the grid lines. Value is just the numeric value while label is formatted and has a unit symbol too.

To put the labels on screen you need to use a TextSymbolizer (see the styling docs for more details). More information of line labelling is best found in the GeoServer documentation on SLD.

    // "labelPoint" feature type style
    StyleBuilder sb = new StyleBuilder();
    FilterFactory2 ff = sb.getFilterFactory();

    // creation of the TextSymbolizer
    AnchorPoint anchorPoint =
            sb.createAnchorPoint(sb.literalExpression(0), sb.literalExpression(0));
    PointPlacement pointPlacement =
            sb.createPointPlacement(anchorPoint, null, sb.literalExpression(0));
    TextSymbolizer textSymbolizer =
                    new Font[] {sb.createFont("Lucida Sans", 10), sb.createFont("Arial", 10)},
    Style style = sb.createStyle();
    FeatureTypeStyle featureTypeStyle =
                    "labelPoint", new Symbolizer[] {textSymbolizer, lineSymbolizer});
  • Thanks a lot! I've got it! – asker May 3 '19 at 9:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.