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