Update MapViewer.
This commit is contained in:
parent
5899dfa276
commit
24eeab7971
3 changed files with 936 additions and 904 deletions
|
@ -13,7 +13,6 @@ import java.awt.event.WindowAdapter;
|
|||
import java.awt.event.WindowEvent;
|
||||
import java.awt.geom.NoninvertibleTransformException;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
@ -43,9 +42,9 @@ import javax.swing.filechooser.FileNameExtensionFilter;
|
|||
|
||||
import org.insa.algo.shortestpath.BellmanFordAlgorithm;
|
||||
import org.insa.algo.shortestpath.ShortestPathAlgorithm;
|
||||
import org.insa.algo.shortestpath.ShortestPathGraphicObserver;
|
||||
import org.insa.algo.shortestpath.ShortestPathData;
|
||||
import org.insa.algo.shortestpath.ShortestPathData.Mode;
|
||||
import org.insa.algo.shortestpath.ShortestPathGraphicObserver;
|
||||
import org.insa.algo.shortestpath.ShortestPathSolution;
|
||||
import org.insa.algo.weakconnectivity.WeaklyConnectedComponentGraphicObserver;
|
||||
import org.insa.algo.weakconnectivity.WeaklyConnectedComponentsAlgorithm;
|
||||
|
@ -77,7 +76,7 @@ public class MainWindow extends JFrame {
|
|||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
// redirects data to the text area
|
||||
textArea.setText(textArea.getText() + String.valueOf((char)b));
|
||||
textArea.setText(textArea.getText() + String.valueOf((char) b));
|
||||
// scrolls the text area to the end of data
|
||||
textArea.setCaretPosition(textArea.getDocument().getLength());
|
||||
// keeps the textArea up to date
|
||||
|
@ -138,7 +137,7 @@ public class MainWindow extends JFrame {
|
|||
Point lonlat;
|
||||
try {
|
||||
// TODO: Fix
|
||||
lonlat = ((BasicDrawing)drawing).getLongitudeLatitude(evt);
|
||||
lonlat = ((BasicDrawing) drawing).getLongitudeLatitude(evt);
|
||||
}
|
||||
catch (NoninvertibleTransformException e) {
|
||||
// Should never happens in "normal" circumstances...
|
||||
|
@ -293,11 +292,11 @@ public class MainWindow extends JFrame {
|
|||
}
|
||||
currentThread.start();
|
||||
}
|
||||
|
||||
private void launchThread(Runnable runnable) {
|
||||
launchThread(runnable, true);
|
||||
}
|
||||
|
||||
|
||||
private void clearCurrentThread() {
|
||||
stopThreadTimer();
|
||||
threadPanel.setVisible(false);
|
||||
|
@ -321,16 +320,14 @@ public class MainWindow extends JFrame {
|
|||
private JMenuBar createMenuBar() {
|
||||
|
||||
// Open Map item...
|
||||
openMapItem = new JMenuItem("Open Map... ",
|
||||
KeyEvent.VK_O);
|
||||
openMapItem.setAccelerator(KeyStroke.getKeyStroke(
|
||||
KeyEvent.VK_O, ActionEvent.ALT_MASK));
|
||||
openMapItem = new JMenuItem("Open Map... ", KeyEvent.VK_O);
|
||||
openMapItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.ALT_MASK));
|
||||
openMapItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
FileNameExtensionFilter filter = new FileNameExtensionFilter(
|
||||
"Map & compressed map files", "map", "map2", "map.gz");
|
||||
"Map & compressed map files", "map", "map2", "mapgr", "map.gz");
|
||||
chooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
|
||||
chooser.setFileFilter(filter);
|
||||
if (chooser.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION) {
|
||||
|
@ -341,12 +338,14 @@ public class MainWindow extends JFrame {
|
|||
DataInputStream stream;
|
||||
try {
|
||||
stream = Openfile.open(path);
|
||||
} catch (IOException e1) {
|
||||
JOptionPane.showMessageDialog(MainWindow.this, "Cannot open the selected file.");
|
||||
return ;
|
||||
}
|
||||
catch (IOException e1) {
|
||||
JOptionPane.showMessageDialog(MainWindow.this,
|
||||
"Cannot open the selected file.");
|
||||
return;
|
||||
}
|
||||
AbstractGraphReader reader;
|
||||
if (path.endsWith(".map2")) {
|
||||
if (path.endsWith(".map2") || path.endsWith("mapgr")) {
|
||||
reader = new BinaryGraphReaderV2(stream);
|
||||
}
|
||||
else {
|
||||
|
@ -356,9 +355,10 @@ public class MainWindow extends JFrame {
|
|||
graph = reader.read();
|
||||
}
|
||||
catch (Exception exception) {
|
||||
JOptionPane.showMessageDialog(MainWindow.this, "Unable to read graph from the selected file.");
|
||||
JOptionPane.showMessageDialog(MainWindow.this,
|
||||
"Unable to read graph from the selected file.");
|
||||
exception.printStackTrace(System.out);
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
drawing.clear();
|
||||
drawing.drawGraph(graph);
|
||||
|
@ -366,7 +366,8 @@ public class MainWindow extends JFrame {
|
|||
for (JMenuItem item: graphLockItems) {
|
||||
item.setEnabled(true);
|
||||
}
|
||||
mapIdPanel.setText("Map ID: 0x" + Integer.toHexString(graph.getMapId()));
|
||||
mapIdPanel
|
||||
.setText("Map ID: 0x" + Integer.toHexString(graph.getMapId()));
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
|
@ -375,8 +376,7 @@ public class MainWindow extends JFrame {
|
|||
|
||||
// Open Path item...
|
||||
JMenuItem openPathItem = new JMenuItem("Open Path... ", KeyEvent.VK_P);
|
||||
openPathItem.setAccelerator(KeyStroke.getKeyStroke(
|
||||
KeyEvent.VK_P, ActionEvent.ALT_MASK));
|
||||
openPathItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.ALT_MASK));
|
||||
openPathItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
@ -390,20 +390,24 @@ public class MainWindow extends JFrame {
|
|||
try {
|
||||
reader = new BinaryPathReader(
|
||||
Openfile.open(chooser.getSelectedFile().getAbsolutePath()));
|
||||
} catch (IOException e1) {
|
||||
JOptionPane.showMessageDialog(MainWindow.this, "Cannot open the selected file.");
|
||||
return ;
|
||||
}
|
||||
catch (IOException e1) {
|
||||
JOptionPane.showMessageDialog(MainWindow.this,
|
||||
"Cannot open the selected file.");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
currentPath = reader.readPath(graph);
|
||||
}
|
||||
catch (MapMismatchException exception) {
|
||||
JOptionPane.showMessageDialog(MainWindow.this, "The selected file does not contain a path for the current graph.");
|
||||
JOptionPane.showMessageDialog(MainWindow.this,
|
||||
"The selected file does not contain a path for the current graph.");
|
||||
return;
|
||||
}
|
||||
catch (Exception exception) {
|
||||
JOptionPane.showMessageDialog(MainWindow.this, "Unable to read path from the selected file.");
|
||||
return ;
|
||||
JOptionPane.showMessageDialog(MainWindow.this,
|
||||
"Unable to read path from the selected file.");
|
||||
return;
|
||||
}
|
||||
drawing.drawPath(currentPath);
|
||||
}
|
||||
|
@ -413,16 +417,16 @@ public class MainWindow extends JFrame {
|
|||
|
||||
// Close item
|
||||
JMenuItem closeItem = new JMenuItem("Quit", KeyEvent.VK_Q);
|
||||
closeItem.setAccelerator(KeyStroke.getKeyStroke(
|
||||
KeyEvent.VK_Q, ActionEvent.ALT_MASK));
|
||||
closeItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK));
|
||||
closeItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
MainWindow.this.dispatchEvent(new WindowEvent(MainWindow.this, WindowEvent.WINDOW_CLOSING));
|
||||
MainWindow.this.dispatchEvent(
|
||||
new WindowEvent(MainWindow.this, WindowEvent.WINDOW_CLOSING));
|
||||
}
|
||||
});
|
||||
|
||||
//Build the first menu.
|
||||
// Build the first menu.
|
||||
JMenu fileMenu = new JMenu("File");
|
||||
fileMenu.add(openMapItem);
|
||||
fileMenu.add(openPathItem);
|
||||
|
@ -431,8 +435,7 @@ public class MainWindow extends JFrame {
|
|||
|
||||
// Second menu
|
||||
JMenuItem drawGraphItem = new JMenuItem("Redraw", KeyEvent.VK_R);
|
||||
drawGraphItem.setAccelerator(KeyStroke.getKeyStroke(
|
||||
KeyEvent.VK_R, ActionEvent.ALT_MASK));
|
||||
drawGraphItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.ALT_MASK));
|
||||
drawGraphItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
@ -452,8 +455,7 @@ public class MainWindow extends JFrame {
|
|||
});
|
||||
graphLockItems.add(drawGraphItem);
|
||||
JMenuItem drawGraphBWItem = new JMenuItem("Redraw (B&W)", KeyEvent.VK_B);
|
||||
drawGraphBWItem.setAccelerator(KeyStroke.getKeyStroke(
|
||||
KeyEvent.VK_B, ActionEvent.ALT_MASK));
|
||||
drawGraphBWItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.ALT_MASK));
|
||||
drawGraphBWItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
@ -473,8 +475,8 @@ public class MainWindow extends JFrame {
|
|||
});
|
||||
graphLockItems.add(drawGraphBWItem);
|
||||
JMenuItem drawGraphMapsforgeItem = new JMenuItem("Redraw (Map)", KeyEvent.VK_M);
|
||||
drawGraphMapsforgeItem.setAccelerator(KeyStroke.getKeyStroke(
|
||||
KeyEvent.VK_M, ActionEvent.ALT_MASK));
|
||||
drawGraphMapsforgeItem
|
||||
.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, ActionEvent.ALT_MASK));
|
||||
drawGraphMapsforgeItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
@ -509,7 +511,8 @@ public class MainWindow extends JFrame {
|
|||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
WeaklyConnectedComponentsData instance = new WeaklyConnectedComponentsData(graph);
|
||||
WeaklyConnectedComponentsAlgorithm algo = new WeaklyConnectedComponentsAlgorithm(instance);
|
||||
WeaklyConnectedComponentsAlgorithm algo = new WeaklyConnectedComponentsAlgorithm(
|
||||
instance);
|
||||
algo.addObserver(new WeaklyConnectedComponentGraphicObserver(drawing));
|
||||
// algo.addObserver(new WeaklyConnectedComponentTextObserver(printStream));
|
||||
launchThread(new Runnable() {
|
||||
|
@ -526,9 +529,8 @@ public class MainWindow extends JFrame {
|
|||
bellmanItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
int idx = JOptionPane.showOptionDialog(MainWindow.this,
|
||||
"Which mode do you want?", "Mode selection",
|
||||
JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,
|
||||
int idx = JOptionPane.showOptionDialog(MainWindow.this, "Which mode do you want?",
|
||||
"Mode selection", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,
|
||||
null, Mode.values(), Mode.LENGTH);
|
||||
|
||||
if (idx != -1) {
|
||||
|
@ -594,8 +596,8 @@ public class MainWindow extends JFrame {
|
|||
public void actionPerformed(ActionEvent e) {
|
||||
if (currentThread != null && currentThread.isAlive()) {
|
||||
int confirmed = JOptionPane.showConfirmDialog(null,
|
||||
"Are you sure you want to kill the running thread?", "Kill Confirmation",
|
||||
JOptionPane.YES_NO_OPTION);
|
||||
"Are you sure you want to kill the running thread?",
|
||||
"Kill Confirmation", JOptionPane.YES_NO_OPTION);
|
||||
if (confirmed == JOptionPane.YES_OPTION) {
|
||||
stopCurrentThread();
|
||||
clearCurrentThread();
|
||||
|
@ -610,8 +612,8 @@ public class MainWindow extends JFrame {
|
|||
public void actionPerformed(ActionEvent e) {
|
||||
Duration elapsed = Duration.between(threadStartTime, Instant.now());
|
||||
long seconds = elapsed.getSeconds();
|
||||
threadTimerLabel.setText(String.format(
|
||||
"%02d:%02d:%02d", seconds/3600, seconds/60 % 60, seconds % 60));
|
||||
threadTimerLabel.setText(String.format("%02d:%02d:%02d", seconds / 3600,
|
||||
seconds / 60 % 60, seconds % 60));
|
||||
}
|
||||
});
|
||||
threadTimer.setInitialDelay(0);
|
||||
|
@ -636,14 +638,14 @@ public class MainWindow extends JFrame {
|
|||
|
||||
// Try to set system look and feel.
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()) ;
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
catch (Exception e) { }
|
||||
|
||||
MainWindow w = new MainWindow();
|
||||
w.setExtendedState(JFrame.MAXIMIZED_BOTH);
|
||||
w.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,20 @@
|
|||
*/
|
||||
package org.insa.base;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.WindowConstants;
|
||||
|
||||
import org.insa.graph.Arc;
|
||||
import org.insa.graph.Graph;
|
||||
import org.insa.graph.Path;
|
||||
|
@ -34,7 +48,6 @@ import org.mapsforge.core.model.MapPosition;
|
|||
import org.mapsforge.core.model.Point;
|
||||
import org.mapsforge.core.util.LatLongUtils;
|
||||
import org.mapsforge.core.util.Parameters;
|
||||
import org.mapsforge.core.util.Utils;
|
||||
import org.mapsforge.map.awt.graphics.AwtGraphicFactory;
|
||||
import org.mapsforge.map.awt.util.AwtUtil;
|
||||
import org.mapsforge.map.awt.util.JavaPreferences;
|
||||
|
@ -59,21 +72,6 @@ import org.mapsforge.map.model.common.PreferencesFacade;
|
|||
import org.mapsforge.map.reader.MapFile;
|
||||
import org.mapsforge.map.rendertheme.InternalRenderTheme;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.WindowConstants;
|
||||
|
||||
public final class Samples {
|
||||
private static final GraphicFactory GRAPHIC_FACTORY = AwtGraphicFactory.INSTANCE;
|
||||
private static final boolean SHOW_DEBUG_LAYERS = false;
|
||||
|
@ -85,7 +83,8 @@ public final class Samples {
|
|||
/**
|
||||
* Starts the {@code Samples}.
|
||||
*
|
||||
* @param args command line args: expects the map files as multiple parameters
|
||||
* @param args
|
||||
* command line args: expects the map files as multiple parameters
|
||||
* with possible SRTM hgt folder as 1st argument.
|
||||
* @throws Exception
|
||||
*/
|
||||
|
@ -100,7 +99,8 @@ public final class Samples {
|
|||
HillsRenderConfig hillsCfg = null;
|
||||
File demFolder = getDemFolder(args);
|
||||
if (demFolder != null) {
|
||||
MemoryCachingHgtReaderTileSource tileSource = new MemoryCachingHgtReaderTileSource(demFolder, new DiffuseLightShadingAlgorithm(), AwtGraphicFactory.INSTANCE);
|
||||
MemoryCachingHgtReaderTileSource tileSource = new MemoryCachingHgtReaderTileSource(
|
||||
demFolder, new DiffuseLightShadingAlgorithm(), AwtGraphicFactory.INSTANCE);
|
||||
tileSource.setEnableInterpolationOverlap(true);
|
||||
hillsCfg = new HillsRenderConfig(tileSource);
|
||||
hillsCfg.indexOnThread();
|
||||
|
@ -113,7 +113,8 @@ public final class Samples {
|
|||
|
||||
// addAPath(mapView);
|
||||
|
||||
final PreferencesFacade preferencesFacade = new JavaPreferences(Preferences.userNodeForPackage(Samples.class));
|
||||
final PreferencesFacade preferencesFacade = new JavaPreferences(
|
||||
Preferences.userNodeForPackage(Samples.class));
|
||||
|
||||
final JFrame frame = new JFrame();
|
||||
frame.setTitle("Mapsforge Samples");
|
||||
|
@ -125,7 +126,8 @@ public final class Samples {
|
|||
frame.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
int result = JOptionPane.showConfirmDialog(frame, MESSAGE, TITLE, JOptionPane.YES_NO_OPTION);
|
||||
int result = JOptionPane.showConfirmDialog(frame, MESSAGE, TITLE,
|
||||
JOptionPane.YES_NO_OPTION);
|
||||
if (result == JOptionPane.YES_OPTION) {
|
||||
mapView.getModel().save(preferencesFacade);
|
||||
mapView.destroyAll();
|
||||
|
@ -138,9 +140,13 @@ public final class Samples {
|
|||
public void windowOpened(WindowEvent e) {
|
||||
final Model model = mapView.getModel();
|
||||
model.init(preferencesFacade);
|
||||
if (model.mapViewPosition.getZoomLevel() == 0 || !boundingBox.contains(model.mapViewPosition.getCenter())) {
|
||||
byte zoomLevel = LatLongUtils.zoomForBounds(model.mapViewDimension.getDimension(), boundingBox, model.displayModel.getTileSize());
|
||||
model.mapViewPosition.setMapPosition(new MapPosition(boundingBox.getCenterPoint(), zoomLevel));
|
||||
if (model.mapViewPosition.getZoomLevel() == 0
|
||||
|| !boundingBox.contains(model.mapViewPosition.getCenter())) {
|
||||
byte zoomLevel = LatLongUtils.zoomForBounds(
|
||||
model.mapViewDimension.getDimension(), boundingBox,
|
||||
model.displayModel.getTileSize());
|
||||
model.mapViewPosition.setMapPosition(
|
||||
new MapPosition(boundingBox.getCenterPoint(), zoomLevel));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -150,7 +156,8 @@ public final class Samples {
|
|||
private static void addAPath(MapView mapView) throws Exception {
|
||||
|
||||
Graph gr = (new BinaryGraphReader(Openfile.open("Maps/midip.map"))).read();
|
||||
Path path = (new BinaryPathReader(Openfile.open("Paths/chemin_0x400_119963_96676.path"))).readPath(gr);
|
||||
Path path = (new BinaryPathReader(Openfile.open("Paths/chemin_0x400_119963_96676.path")))
|
||||
.readPath(gr);
|
||||
|
||||
Paint paintStroke = AwtGraphicFactory.INSTANCE.createPaint();
|
||||
paintStroke.setColor(Color.GREEN);
|
||||
|
@ -159,27 +166,26 @@ public final class Samples {
|
|||
|
||||
Polyline line = new Polyline(paintStroke, AwtGraphicFactory.INSTANCE);
|
||||
|
||||
for (Arc arc: path.getArcs()) {
|
||||
for (Arc arc : path.getArcs()) {
|
||||
ArrayList<org.insa.graph.Point> points = arc.getPoints();
|
||||
for (int i = 0; i < points.size(); ++i) {
|
||||
line.getLatLongs().add(new LatLong(points.get(i).getLatitude(), points.get(i).getLongitude()));
|
||||
line.getLatLongs().add(
|
||||
new LatLong(points.get(i).getLatitude(), points.get(i).getLongitude()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mapView.getLayerManager().getLayers().add(line);
|
||||
}
|
||||
|
||||
private static BoundingBox addLayers(MapView mapView, List<File> mapFiles, HillsRenderConfig hillsRenderConfig) {
|
||||
private static BoundingBox addLayers(MapView mapView, List<File> mapFiles,
|
||||
HillsRenderConfig hillsRenderConfig) {
|
||||
Layers layers = mapView.getLayerManager().getLayers();
|
||||
|
||||
int tileSize = SHOW_RASTER_MAP ? 256 : 512;
|
||||
|
||||
// Tile cache
|
||||
TileCache tileCache = AwtUtil.createTileCache(
|
||||
tileSize,
|
||||
mapView.getModel().frameBufferModel.getOverdrawFactor(),
|
||||
1024,
|
||||
TileCache tileCache = AwtUtil.createTileCache(tileSize,
|
||||
mapView.getModel().frameBufferModel.getOverdrawFactor(), 1024,
|
||||
new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()));
|
||||
|
||||
final BoundingBox boundingBox;
|
||||
|
@ -187,20 +193,25 @@ public final class Samples {
|
|||
// Raster
|
||||
mapView.getModel().displayModel.setFixedTileSize(tileSize);
|
||||
TileSource tileSource = OpenStreetMapMapnik.INSTANCE;
|
||||
TileDownloadLayer tileDownloadLayer = createTileDownloadLayer(tileCache, mapView.getModel().mapViewPosition, tileSource);
|
||||
TileDownloadLayer tileDownloadLayer = createTileDownloadLayer(tileCache,
|
||||
mapView.getModel().mapViewPosition, tileSource);
|
||||
layers.add(tileDownloadLayer);
|
||||
tileDownloadLayer.start();
|
||||
mapView.setZoomLevelMin(tileSource.getZoomLevelMin());
|
||||
mapView.setZoomLevelMax(tileSource.getZoomLevelMax());
|
||||
boundingBox = new BoundingBox(LatLongUtils.LATITUDE_MIN, LatLongUtils.LONGITUDE_MIN, LatLongUtils.LATITUDE_MAX, LatLongUtils.LONGITUDE_MAX);
|
||||
} else {
|
||||
boundingBox = new BoundingBox(LatLongUtils.LATITUDE_MIN, LatLongUtils.LONGITUDE_MIN,
|
||||
LatLongUtils.LATITUDE_MAX, LatLongUtils.LONGITUDE_MAX);
|
||||
}
|
||||
else {
|
||||
// Vector
|
||||
mapView.getModel().displayModel.setFixedTileSize(tileSize);
|
||||
MultiMapDataStore mapDataStore = new MultiMapDataStore(MultiMapDataStore.DataPolicy.RETURN_ALL);
|
||||
MultiMapDataStore mapDataStore = new MultiMapDataStore(
|
||||
MultiMapDataStore.DataPolicy.RETURN_ALL);
|
||||
for (File file : mapFiles) {
|
||||
mapDataStore.addMapDataStore(new MapFile(file), false, false);
|
||||
}
|
||||
TileRendererLayer tileRendererLayer = createTileRendererLayer(tileCache, mapDataStore, mapView.getModel().mapViewPosition, hillsRenderConfig);
|
||||
TileRendererLayer tileRendererLayer = createTileRendererLayer(tileCache, mapDataStore,
|
||||
mapView.getModel().mapViewPosition, hillsRenderConfig);
|
||||
layers.add(tileRendererLayer);
|
||||
boundingBox = mapDataStore.boundingBox();
|
||||
}
|
||||
|
@ -225,7 +236,8 @@ public final class Samples {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static TileDownloadLayer createTileDownloadLayer(TileCache tileCache, MapViewPosition mapViewPosition, TileSource tileSource) {
|
||||
private static TileDownloadLayer createTileDownloadLayer(TileCache tileCache,
|
||||
MapViewPosition mapViewPosition, TileSource tileSource) {
|
||||
return new TileDownloadLayer(tileCache, mapViewPosition, tileSource, GRAPHIC_FACTORY) {
|
||||
@Override
|
||||
public boolean onTap(LatLong tapLatLong, Point layerXY, Point tapXY) {
|
||||
|
@ -235,8 +247,11 @@ public final class Samples {
|
|||
};
|
||||
}
|
||||
|
||||
private static TileRendererLayer createTileRendererLayer(TileCache tileCache, MapDataStore mapDataStore, MapViewPosition mapViewPosition, HillsRenderConfig hillsRenderConfig) {
|
||||
TileRendererLayer tileRendererLayer = new TileRendererLayer(tileCache, mapDataStore, mapViewPosition, false, true, false, GRAPHIC_FACTORY, hillsRenderConfig) {
|
||||
private static TileRendererLayer createTileRendererLayer(TileCache tileCache,
|
||||
MapDataStore mapDataStore, MapViewPosition mapViewPosition,
|
||||
HillsRenderConfig hillsRenderConfig) {
|
||||
TileRendererLayer tileRendererLayer = new TileRendererLayer(tileCache, mapDataStore,
|
||||
mapViewPosition, false, true, false, GRAPHIC_FACTORY, hillsRenderConfig) {
|
||||
@Override
|
||||
public boolean onTap(LatLong tapLatLong, Point layerXY, Point tapXY) {
|
||||
System.out.println("Tap on: " + tapLatLong);
|
||||
|
@ -269,9 +284,11 @@ public final class Samples {
|
|||
File mapFile = new File(arg);
|
||||
if (!mapFile.exists()) {
|
||||
throw new IllegalArgumentException("file does not exist: " + mapFile);
|
||||
} else if (!mapFile.isFile()) {
|
||||
}
|
||||
else if (!mapFile.isFile()) {
|
||||
throw new IllegalArgumentException("not a file: " + mapFile);
|
||||
} else if (!mapFile.canRead()) {
|
||||
}
|
||||
else if (!mapFile.canRead()) {
|
||||
throw new IllegalArgumentException("cannot read file: " + mapFile);
|
||||
}
|
||||
result.add(mapFile);
|
||||
|
|
|
@ -4,12 +4,13 @@ import java.awt.Color;
|
|||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
|
||||
import org.insa.graph.Arc;
|
||||
import org.insa.graph.Graph;
|
||||
|
@ -24,10 +25,8 @@ import org.mapsforge.core.model.MapPosition;
|
|||
import org.mapsforge.core.util.LatLongUtils;
|
||||
import org.mapsforge.map.awt.graphics.AwtGraphicFactory;
|
||||
import org.mapsforge.map.awt.util.AwtUtil;
|
||||
import org.mapsforge.map.awt.util.JavaPreferences;
|
||||
import org.mapsforge.map.awt.view.MapView;
|
||||
import org.mapsforge.map.datastore.MapDataStore;
|
||||
import org.mapsforge.map.layer.Layer;
|
||||
import org.mapsforge.map.layer.Layers;
|
||||
import org.mapsforge.map.layer.cache.TileCache;
|
||||
import org.mapsforge.map.layer.hills.HillsRenderConfig;
|
||||
|
@ -37,14 +36,10 @@ import org.mapsforge.map.layer.renderer.TileRendererLayer;
|
|||
import org.mapsforge.map.model.DisplayModel;
|
||||
import org.mapsforge.map.model.MapViewPosition;
|
||||
import org.mapsforge.map.model.Model;
|
||||
import org.mapsforge.map.model.common.Observer;
|
||||
import org.mapsforge.map.model.common.PreferencesFacade;
|
||||
import org.mapsforge.map.reader.MapFile;
|
||||
import org.mapsforge.map.rendertheme.InternalRenderTheme;
|
||||
import org.mapsforge.map.rendertheme.XmlRenderTheme;
|
||||
|
||||
import com.google.common.util.concurrent.SettableFuture;
|
||||
|
||||
public class MapViewDrawing extends MapView implements Drawing {
|
||||
|
||||
/**
|
||||
|
@ -67,12 +62,11 @@ public class MapViewDrawing extends MapView implements Drawing {
|
|||
ArrayList<Paint> extraLayers;
|
||||
|
||||
public MapViewDrawing() {
|
||||
setBackground(Color.WHITE);
|
||||
getMapScaleBar().setVisible(true);
|
||||
this.tileSize = DEFAULT_TILE_SIZE;
|
||||
DisplayModel model = getModel().displayModel;
|
||||
model.setFixedTileSize(tileSize);
|
||||
model.setBackgroundColor(convertColor(Color.WHITE));
|
||||
// model.setBackgroundColor(convertColor(Color.WHITE));
|
||||
|
||||
extraLayers = new ArrayList<Paint>();
|
||||
addMouseWheelListener(new MouseAdapter() {
|
||||
|
@ -87,8 +81,8 @@ public class MapViewDrawing extends MapView implements Drawing {
|
|||
}
|
||||
|
||||
protected int convertColor(Color color) {
|
||||
return GRAPHIC_FACTORY.createColor(color.getAlpha(), color.getRed(),
|
||||
color.getGreen(), color.getBlue());
|
||||
return GRAPHIC_FACTORY.createColor(color.getAlpha(), color.getRed(), color.getGreen(),
|
||||
color.getBlue());
|
||||
}
|
||||
|
||||
private int getStrokeWidth(int width) {
|
||||
|
@ -113,11 +107,10 @@ public class MapViewDrawing extends MapView implements Drawing {
|
|||
* @param color
|
||||
* @return
|
||||
*/
|
||||
private static File getMapsforgeFileFromGraph(Graph graph) {
|
||||
private File getMapsforgeFileFromGraph(Graph graph) {
|
||||
// TODO: Find a way to change this...
|
||||
Map<Integer, String> idToNames = new HashMap<Integer, String>();
|
||||
idToNames.put(0x100, "insa");
|
||||
idToNames.put(0x101, "insa");
|
||||
idToNames.put(0x110, "paris");
|
||||
idToNames.put(0x200, "mayotte");
|
||||
idToNames.put(0x250, "newzealand");
|
||||
|
@ -128,7 +121,19 @@ public class MapViewDrawing extends MapView implements Drawing {
|
|||
File file = null;
|
||||
if (idToNames.containsKey(graph.getMapId())) {
|
||||
file = new File("Maps/" + idToNames.get(graph.getMapId()) + ".mapfg");
|
||||
if (!file.exists()) {
|
||||
file = new File("Maps/new/" + idToNames.get(graph.getMapId()) + ".mapfg");
|
||||
}
|
||||
}
|
||||
|
||||
if (file == null || !file.exists()) {
|
||||
JFileChooser fileChooser = new JFileChooser("Maps/");
|
||||
fileChooser.setFileFilter(new FileNameExtensionFilter("mapsforge files", "" + "mapfg"));
|
||||
if (fileChooser.showOpenDialog(this.getParent()) == JFileChooser.APPROVE_OPTION) {
|
||||
file = fileChooser.getSelectedFile();
|
||||
}
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
|
@ -136,10 +141,14 @@ public class MapViewDrawing extends MapView implements Drawing {
|
|||
return new LatLong(point.getLatitude(), point.getLongitude());
|
||||
}
|
||||
|
||||
private static TileRendererLayer createTileRendererLayer(TileCache tileCache, MapDataStore mapDataStore, MapViewPosition mapViewPosition, HillsRenderConfig hillsRenderConfig) {
|
||||
TileRendererLayer tileRendererLayer = new TileRendererLayer(tileCache, mapDataStore, mapViewPosition, false, true, false, GRAPHIC_FACTORY, hillsRenderConfig) {
|
||||
private static TileRendererLayer createTileRendererLayer(TileCache tileCache,
|
||||
MapDataStore mapDataStore, MapViewPosition mapViewPosition,
|
||||
HillsRenderConfig hillsRenderConfig) {
|
||||
TileRendererLayer tileRendererLayer = new TileRendererLayer(tileCache, mapDataStore,
|
||||
mapViewPosition, false, true, false, GRAPHIC_FACTORY, hillsRenderConfig) {
|
||||
@Override
|
||||
public boolean onTap(LatLong tapLatLong, org.mapsforge.core.model.Point layerXY, org.mapsforge.core.model.Point tapXY) {
|
||||
public boolean onTap(LatLong tapLatLong, org.mapsforge.core.model.Point layerXY,
|
||||
org.mapsforge.core.model.Point tapXY) {
|
||||
System.out.println("Tap on: " + tapLatLong);
|
||||
return true;
|
||||
}
|
||||
|
@ -197,9 +206,9 @@ public class MapViewDrawing extends MapView implements Drawing {
|
|||
File graphFile = getMapsforgeFileFromGraph(graph);
|
||||
|
||||
// Tile cache
|
||||
TileCache tileCache = AwtUtil.createTileCache(
|
||||
tileSize, getModel().frameBufferModel.getOverdrawFactor(),
|
||||
1024, new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()));
|
||||
TileCache tileCache = AwtUtil.createTileCache(tileSize,
|
||||
getModel().frameBufferModel.getOverdrawFactor(), 1024,
|
||||
new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()));
|
||||
|
||||
// Layers
|
||||
Layers layers = getLayerManager().getLayers();
|
||||
|
@ -211,9 +220,12 @@ public class MapViewDrawing extends MapView implements Drawing {
|
|||
BoundingBox boundingBox = mapDataStore.boundingBox();
|
||||
|
||||
final Model model = getModel();
|
||||
if (model.mapViewPosition.getZoomLevel() == 0 || !boundingBox.contains(model.mapViewPosition.getCenter())) {
|
||||
byte zoomLevel = LatLongUtils.zoomForBounds(model.mapViewDimension.getDimension(), boundingBox, model.displayModel.getTileSize());
|
||||
model.mapViewPosition.setMapPosition(new MapPosition(boundingBox.getCenterPoint(), zoomLevel));
|
||||
if (model.mapViewPosition.getZoomLevel() == 0
|
||||
|| !boundingBox.contains(model.mapViewPosition.getCenter())) {
|
||||
byte zoomLevel = LatLongUtils.zoomForBounds(model.mapViewDimension.getDimension(),
|
||||
boundingBox, model.displayModel.getTileSize());
|
||||
model.mapViewPosition
|
||||
.setMapPosition(new MapPosition(boundingBox.getCenterPoint(), zoomLevel));
|
||||
model.mapViewPosition.setZoomLevelMin(zoomLevel);
|
||||
}
|
||||
}
|
||||
|
@ -230,7 +242,8 @@ public class MapViewDrawing extends MapView implements Drawing {
|
|||
for (Arc arc: path.getArcs()) {
|
||||
ArrayList<Point> points = arc.getPoints();
|
||||
for (int i = 0; i < points.size(); ++i) {
|
||||
line.getLatLongs().add(new LatLong(points.get(i).getLatitude(), points.get(i).getLongitude()));
|
||||
line.getLatLongs().add(
|
||||
new LatLong(points.get(i).getLatitude(), points.get(i).getLongitude()));
|
||||
}
|
||||
}
|
||||
getLayerManager().getLayers().add(line);
|
||||
|
|
Loading…
Reference in a new issue