From 08d5f7b0a0b24c042aa5976f66bf3a1b5b754478 Mon Sep 17 00:00:00 2001 From: Richard Zahoransky Date: Mon, 7 Nov 2011 16:29:56 +0100 Subject: Localization Code. How-To will follow... --- gui/MapTest.java | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 gui/MapTest.java (limited to 'gui/MapTest.java') diff --git a/gui/MapTest.java b/gui/MapTest.java new file mode 100644 index 0000000..97d457d --- /dev/null +++ b/gui/MapTest.java @@ -0,0 +1,119 @@ +package gui; + +import helper.ListBTS; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Polygon; +import java.awt.Rectangle; +import java.awt.geom.Point2D; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JFrame; + +import org.jdesktop.swingx.JXMapKit; +import org.jdesktop.swingx.JXMapKit.DefaultProviders; +import org.jdesktop.swingx.JXMapViewer; +import org.jdesktop.swingx.mapviewer.GeoPosition; +import org.jdesktop.swingx.painter.Painter; + +import DataStructure.GSMMap; +import DataStructure.SingleBTS; + +public class MapTest { + public static void createGui() throws FileNotFoundException, IOException, + ClassNotFoundException { + JFrame frame = new JFrame(); + frame.setVisible(true); + frame.setSize(400, 400); + JXMapKit mapViewer = new JXMapKit(); + // JXMapViewer + // Painter + mapViewer.setDefaultProvider(DefaultProviders.OpenStreetMaps); + mapViewer.setDataProviderCreditShown(true); + frame.add(mapViewer); + System.out.println("da"); + + ObjectInputStream ois = new ObjectInputStream(new FileInputStream( + "interpolatedGSMMap.obj")); + GSMMap map = (GSMMap) ois.readObject(); + SingleBTS[] content = map.content(); + final ArrayList btss = new ArrayList(); + for (int x = 0; x < map.Xcoords.length; x++) { + for (int y = 0; y < map.Ycoords.length; y++) { + SingleBTS current = ListBTS.getARFCN(map.map[x][y], content[0]); + if (current != null) { + btss.add(new GeoPosition(map.Ycoords[y], map.Xcoords[x])); + } + } + } + + Painter polygonOverlay = new Painter() { + + public void paint(Graphics2D g, JXMapViewer map, int w, int h) { + g = (Graphics2D) g.create(); + // convert from viewport to world bitmap + Rectangle rect = map.getViewportBounds(); + g.translate(-rect.x, -rect.y); + + // create a polygon + Polygon poly = new Polygon(); + for (GeoPosition gp : btss) { + // convert geo to world bitmap pixel + Point2D pt = map.getTileFactory().geoToPixel(gp, + map.getZoom()); + poly.addPoint((int) pt.getX(), (int) pt.getY()); + } + + // do the drawing + g.setColor(new Color(255, 0, 0, 100)); + g.fill(poly); + g.setColor(Color.RED); + g.draw(poly); + + g.dispose(); + } + + }; + mapViewer.getMainMap().setOverlayPainter(polygonOverlay); + + } + + public static void main(String[] args) throws FileNotFoundException, + IOException, ClassNotFoundException { + createGui(); + + final List region = new ArrayList(); + region.add(new GeoPosition(38.266, 12.4)); + region.add(new GeoPosition(38.283, 15.65)); + region.add(new GeoPosition(36.583, 15.166)); + region.add(new GeoPosition(37.616, 12.25)); + /* + * Painter polygonOverlay = new Painter() { + * + * public void paint(Graphics2D g, JXMapViewer map, int w, int h) { g = + * (Graphics2D) g.create(); // convert from viewport to world bitmap + * Rectangle rect = map.getViewportBounds(); g.translate(-rect.x, + * -rect.y); + * + * // create a polygon Polygon poly = new Polygon(); for (GeoPosition gp + * : region) { // convert geo to world bitmap pixel Point2D pt = + * map.getTileFactory().geoToPixel(gp, map.getZoom()); + * poly.addPoint((int) pt.getX(), (int) pt.getY()); } + * + * // do the drawing g.setColor(new Color(255, 0, 0, 100)); + * g.fill(poly); g.setColor(Color.RED); g.draw(poly); + * + * g.dispose(); } + * + * }; + */ + + } + +} \ No newline at end of file -- cgit v1.2.3-55-g7522