Hi to all,
Can any one please help me. When I click any place on the JMapFrame I want to
get a point on the JMapFrame i.e I want to create a new point in JMapFrame. I
wrote some code for this after that I don't know what I have do. Because I am
not a that much programmer. Please find here attached file which contains my
code.
Thanks in advance.
Regards,
D Pardhu.
package org.geotools.Police;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.text.MessageFormat;
import javax.swing.JButton;
import javax.swing.JToolBar;
import org.geotools.data.FileDataStore;
import org.geotools.data.FileDataStoreFinder;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.geometry.jts.JTSFactoryFinder;
import org.geotools.map.FeatureLayer;
import org.geotools.map.Layer;
import org.geotools.map.MapContent;
import org.geotools.styling.SLD;
import org.geotools.styling.Style;
import org.geotools.swing.JMapFrame;
import org.geotools.swing.event.MapMouseEvent;
import org.geotools.swing.tool.CursorTool;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKTReader;
public class RoughCreatingPoint {
private JMapFrame mapFrame;
private SimpleFeatureSource featureSource;
//private com.vividsolutions.jts.geom.Point point;
MapContent map = new MapContent();
public static void main(String[] args) throws Exception {
RoughCreatingPoint me = new RoughCreatingPoint();
File file = new File("E:\\Information System\\MCR Boundary\\MCR_BOUNDARY.shp");
me.displayShapefile(file);
}
public void displayShapefile(File file) throws Exception {
FileDataStore store = FileDataStoreFinder.getDataStore(file);
featureSource = store.getFeatureSource();
//MapContent map = new MapContent();
map.setTitle("Creating Points");
Style style = SLD.createPolygonStyle(Color.BLUE, Color.CYAN, 0.5f, null, null);
Layer layer = new FeatureLayer(featureSource, style);
map.addLayer(layer);
mapFrame = new JMapFrame(map);
mapFrame.enableToolBar(true);
mapFrame.enableStatusBar(true);
JToolBar toolBar = mapFrame.getToolBar();
JButton btn = new JButton("Create");
toolBar.addSeparator();
toolBar.add(btn);
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
mapFrame.getMapPane().setCursorTool(
new CursorTool() {
@Override
public void onMouseClicked(MapMouseEvent ev) {
createFeatures(ev);
}
});
}
});
mapFrame.setSize(600, 600);
mapFrame.setVisible(true);
}
@SuppressWarnings("deprecation")
void createFeatures(MapMouseEvent ev) {
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory( null );
WKTReader reader = new WKTReader( geometryFactory );
try {
Point point = (Point) reader.read("POINT (1 1)");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(MessageFormat.format("Created Point: {0}", ev.getMapPosition()));
}
}
------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users