Hello all,
I'm using geotools v14.3 to load a shapefile (Java Swing application). I
want to allow the customers to use the mouse to click on the map area to
draw new points, lines and polygons. First, I'm testing the points. So, a
customer should be able to draw a point on the clicked location.
*My current approach*
After following few articles, I first capture the clicked mouse location
with a mapmouselistener.
@Override
public void onMouseClicked(MapMouseEvent ev) {
System.out.println("mouse clicked : " + ev.getWorldPos());
DirectPosition2D p = ev.getWorldPos();
drawMyPoint(p.getX(), p.getY());
}
Point drawing function is as follows.
void drawMyPoint(double x, double y) {
SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
b.setName("MyFeatureType");
// set crs
b.setCRS(DefaultGeographicCRS.WGS84);
// add geometry
b.add("location", Point.class);
// build the type
final SimpleFeatureType TYPE = b.buildFeatureType();
// create features using the type defined
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE);
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
com.vividsolutions.jts.geom.Point point =
geometryFactory.createPoint(new Coordinate(x, y));
featureBuilder.add(point);
SimpleFeature feature = featureBuilder.buildFeature("FeaturePoint");
DefaultFeatureCollection featureCollection = new
DefaultFeatureCollection("internal", TYPE);
featureCollection.add(feature); //Add feature 1
// Add feature 2, 3, etc
Style style = SLD.createPointStyle("Star", Color.BLUE,
Color.BLUE, 0.3f, 15);
Layer layer = new FeatureLayer(featureCollection, style);
layer.setTitle("NewPoint");
map.addLayer(layer);
mapPane.repaint();
}
*Problem*
I can see the layer name being added to the map layer table. But the point
is not visible on the map.
I would be thankful for any insights.
Thank you.
--
regards,
*Thilina Yapa Bandara*
(*ආයුබෝවන් *- May All Beings Live Long)
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
GeoTools-GT2-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users