I know how to create a layer and display points on JMapFrame. But I do not know how to add a text string next to a point? Below is the code to display multiple coordinates on JMapFrame, I thought adding text strings would have similar codes. Please help, thanks!
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.setName("feature1");
builder.setCRS(DefaultGeographicCRS.WGS84);
builder.add("location", Point.class);
final SimpleFeatureType TYPE = DataUtilities.createType("Points", "points", "the_geom:MultiPoint");
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);
GeometryFactory geometryFactory = (GeometryFactory) JTSFactoryFinder.getGeometryFactory();
MultiPoint points = geometryFactory.createMultiPoint(coordinates); //be careful of the order
featureBuilder.add(points);
SimpleFeature feature = featureBuilder.buildFeature(null);
DefaultFeatureCollection featureCollection = new DefaultFeatureCollection("internal", TYPE);
featureCollection.add(feature);
Style style = SLD.createPointStyle("square", Color.red, Color.red, 1.0f, 8.0f);
//Style style = SLD.createSimpleStyle(TYPE,Color.RED);
Layer layer = new FeatureLayer(featureCollection, style);
That is how I created my layer and below I managed to display my points on a shape file. I did not post all my codes because it was too many, but this is the general implementation.
MapContent map = new MapContent();
map.layers().add(layer);
JMapFrame.showMap(map);
Can anyone help me with adding text strings next to my points? Thank you so much!!!