fix bugs and add url template
git-svn-id: https://osmand.googlecode.com/svn/trunk@399 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
5d6e9b2cd7
commit
59b29aa2e3
14 changed files with 508 additions and 80 deletions
|
@ -11,10 +11,18 @@ public class ToDoConstants {
|
|||
|
||||
|
||||
// TODO
|
||||
// 77. Implement upload gps track onto osm server
|
||||
// 77. Implement upload gps track onto osm server (? not implemented yet on OSM?)
|
||||
// 78. Add ruler to the main tile view
|
||||
// 79. Download any WMS layer and add to swing version
|
||||
// 80. Export/import points
|
||||
// 80. Export/import favorite points
|
||||
// 81. Add some objects to POI to help navigation (
|
||||
// highway (?), traffic_calming (?), barrier(?), military(?-), landuse (?), office(?), man_made(?), power(?).
|
||||
// 79. Download any WMS layer and add to swing version (add tile manager ${x}, ${y}, ${z} to swing and to android)
|
||||
|
||||
|
||||
// BUGS :
|
||||
// 1. Show different aspect view for landscape mode (+)
|
||||
// 2. Fix out of memory downloading screen (+)
|
||||
// 3. Fix view not attached (+)
|
||||
|
||||
// Improvements
|
||||
// 5. Download with wget
|
||||
|
@ -22,7 +30,7 @@ public class ToDoConstants {
|
|||
|
||||
// Not clear if it is really needed
|
||||
// 69. Add phone information to POI
|
||||
// 70. Show building numbers over map (require changin address index - index 2 more columns lat/lon for fast search)
|
||||
// 70. Show building numbers over map (require changing address index - index 2 more columns lat/lon for fast search)
|
||||
// 66. Transport routing (show next stop, total distance, show stop get out, voice) (needed ?).
|
||||
|
||||
// Unscheduled (complex)
|
||||
|
|
|
@ -1,20 +1,31 @@
|
|||
package com.osmand.map;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import com.osmand.Algoritms;
|
||||
import com.osmand.LogUtil;
|
||||
import com.osmand.osm.MapUtils;
|
||||
|
||||
|
||||
public class TileSourceManager {
|
||||
// transport "http://tile.xn--pnvkarte-m4a.de/tilegen/${z}/${x}/${y}.png", {numZoomLevels: 19,displayInLayerSwitcher:true,buffer:0});
|
||||
// var navdebug = new OpenLayers.Layer.OSM("Navigation Debug", "http://ec2-184-73-15-218.compute-1.amazonaws.com/6700/256/${z}/${x}/${y}.png", {numZoomLevels: 18,displayInLayerSwitcher:true,buffer:0});
|
||||
// "Mapsurfer Road", "http://tiles1.mapsurfer.net/tms_r.ashx?", { numZoomLevels: 19, isBaseLayer: true, type: 'png', getURL: osm_getTileURL, displayOutsideMaxExtent: true })
|
||||
private static final Log log = LogUtil.getLog(TileSourceManager.class);
|
||||
|
||||
public static class TileSourceTemplate implements ITileSource {
|
||||
private int maxZoom;
|
||||
private int minZoom;
|
||||
private String name;
|
||||
private int tileSize;
|
||||
private String urlToLoad;
|
||||
private String ext;
|
||||
protected int tileSize;
|
||||
protected String urlToLoad;
|
||||
protected String ext;
|
||||
private int avgSize;
|
||||
private int bitDensity;
|
||||
|
||||
|
@ -100,8 +111,54 @@ public class TileSourceManager {
|
|||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class WMSSourceTemplate extends TileSourceTemplate {
|
||||
|
||||
public WMSSourceTemplate(String name, String wmsUrl) {
|
||||
super("WMS " + name, wmsUrl, ".jpg", 18, 3, 256, 16, 20000); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrlToLoad(int x, int y, int zoom) {
|
||||
double yEnd = MapUtils.getLatitudeFromTile(zoom, y + 1);
|
||||
double yStart = MapUtils.getLatitudeFromTile(zoom, y );
|
||||
double xStart = MapUtils.getLongitudeFromTile(zoom, x);
|
||||
double xEnd = MapUtils.getLongitudeFromTile(zoom, x + 1);
|
||||
StringBuilder load = new StringBuilder();
|
||||
load.append(urlToLoad).append("bbox=").append(xStart).append(','). //$NON-NLS-1$
|
||||
append(yEnd).append(',').append(xEnd).append(',').append(yStart);
|
||||
load.append("&srs=EPSG:4326").append("&width=").append(tileSize).append("&height=").append(tileSize); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
return load.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static java.util.List<TileSourceTemplate> getUserDefinedTemplates(File tilesDir){
|
||||
java.util.List<TileSourceTemplate> ts = new ArrayList<TileSourceTemplate>();
|
||||
if (tilesDir != null) {
|
||||
for (File f : tilesDir.listFiles()) {
|
||||
File ch = new File(f, "url"); //$NON-NLS-1$
|
||||
if (f.isDirectory() && ch.exists()) {
|
||||
try {
|
||||
BufferedReader read = new BufferedReader(new InputStreamReader(new FileInputStream(ch), "UTF-8")); //$NON-NLS-1$
|
||||
String url = read.readLine();
|
||||
read.close();
|
||||
if (!Algoritms.isEmpty(url)) {
|
||||
url = url.replaceAll(Pattern.quote("{$x}"), "{1}"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
url = url.replaceAll(Pattern.quote("{$z}"), "{0}"); //$NON-NLS-1$//$NON-NLS-2$
|
||||
url = url.replaceAll(Pattern.quote("{$y}"), "{2}"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
TileSourceTemplate t = new TileSourceTemplate(f.getName(), url, ".jpg", 18, 1, 256, 16, 20000); //$NON-NLS-1$
|
||||
ts.add(t);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.info("Mailformed dir " + f.getName(), e); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return ts;
|
||||
}
|
||||
|
||||
static java.util.List<TileSourceTemplate> list;
|
||||
|
@ -113,14 +170,12 @@ public class TileSourceManager {
|
|||
list.add(getCycleMapSource());
|
||||
list.add(getMapSurferSource());
|
||||
list.add(getNavigationDebugSource());
|
||||
// list.add(getAerialMapSource());
|
||||
|
||||
list.add(getCloudMadeSource());
|
||||
list.add(getOpenPisteMapSource());
|
||||
list.add(getGoogleMapsSource());
|
||||
list.add(getGoogleMapsSatelliteSource());
|
||||
list.add(getGoogleMapsTerrainSource());
|
||||
// list.add(getYandexTrafficSource());
|
||||
|
||||
list.add(getMicrosoftMapsSource());
|
||||
list.add(getMicrosoftEarthSource());
|
||||
|
@ -192,7 +247,9 @@ public class TileSourceManager {
|
|||
}
|
||||
|
||||
|
||||
|
||||
// WMS layers : http://whoots.mapwarper.net/tms/{$z}/{$x}/{$y}/ {layer}/{Path}
|
||||
// 1. Landsat http://onearth.jpl.nasa.gov/wms.cgi global_mosaic (NOT WORK)
|
||||
// 2. Genshtab http://wms.latlon.org gshtab
|
||||
|
||||
protected static final char[] NUM_CHAR = { '0', '1', '2', '3' };
|
||||
|
||||
|
|
|
@ -22,11 +22,13 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.imageio.IIOException;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenu;
|
||||
|
@ -37,6 +39,7 @@ import javax.swing.UIManager;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import com.osmand.Algoritms;
|
||||
import com.osmand.LogUtil;
|
||||
import com.osmand.data.DataTileManager;
|
||||
import com.osmand.data.preparation.MapTileDownloader;
|
||||
|
@ -57,30 +60,75 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
|
|||
protected static final Log log = LogUtil.getLog(MapPanel.class);
|
||||
public static final int divNonLoadedImage = 16;
|
||||
|
||||
|
||||
public static JMenu getMenuToChooseSource(final MapPanel panel){
|
||||
final JMenu tiles = new JMenu("Source of tiles");
|
||||
final JMenu userDefined = new JMenu("User defined");
|
||||
final List<TileSourceTemplate> list = TileSourceManager.getKnownSourceTemplates();
|
||||
final List<TileSourceTemplate> udf = TileSourceManager.getUserDefinedTemplates(DataExtractionSettings.getSettings().getTilesDirectory());
|
||||
final Map<TileSourceTemplate, JCheckBoxMenuItem> items = new LinkedHashMap<TileSourceTemplate, JCheckBoxMenuItem>();
|
||||
tiles.add(userDefined);
|
||||
userDefined.add(new AbstractAction("Create new tile source"){
|
||||
private static final long serialVersionUID = -8286622335859339130L;
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
NewTileSourceDialog dlg = new NewTileSourceDialog(panel);
|
||||
dlg.showDialog();
|
||||
List<TileSourceTemplate> templates = TileSourceManager.getUserDefinedTemplates(DataExtractionSettings.getSettings().getTilesDirectory());
|
||||
TileSourceTemplate added =null;
|
||||
for(final TileSourceTemplate te : templates){
|
||||
if(!items.containsKey(te)){
|
||||
added = te;
|
||||
JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(te.getName());
|
||||
userDefined.add(menuItem);
|
||||
items.put(added, menuItem);
|
||||
menuItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
for (final Map.Entry<TileSourceTemplate, JCheckBoxMenuItem> es : items.entrySet()) {
|
||||
es.getValue().setSelected(te.equals(es.getKey()));
|
||||
}
|
||||
panel.setMapName(te);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
if(added != null){
|
||||
for (final Map.Entry<TileSourceTemplate, JCheckBoxMenuItem> es : items.entrySet()) {
|
||||
es.getValue().setSelected(added.equals(es.getKey()));
|
||||
}
|
||||
panel.setMapName(added);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for(final TileSourceTemplate l : list){
|
||||
JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(l.getName());
|
||||
menuItem.addActionListener(new ActionListener(){
|
||||
tiles.add(menuItem);
|
||||
items.put(l, menuItem);
|
||||
}
|
||||
|
||||
for(final TileSourceTemplate l : udf){
|
||||
JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(l.getName());
|
||||
userDefined.add(menuItem);
|
||||
items.put(l, menuItem);
|
||||
}
|
||||
|
||||
|
||||
for (final Map.Entry<TileSourceTemplate, JCheckBoxMenuItem> em : items.entrySet()) {
|
||||
if(Algoritms.objectEquals(panel.getMap(), em.getKey())){
|
||||
em.getValue().setSelected(true);
|
||||
}
|
||||
em.getValue().addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
for(int i=0; i<list.size() ; i++){
|
||||
if(list.get(i).equals(l)){
|
||||
((JCheckBoxMenuItem)tiles.getItem(i)).setSelected(true);
|
||||
} else {
|
||||
((JCheckBoxMenuItem)tiles.getItem(i)).setSelected(false);
|
||||
}
|
||||
for (final Map.Entry<TileSourceTemplate, JCheckBoxMenuItem> es : items.entrySet()) {
|
||||
es.getValue().setSelected(em.getKey().equals(es.getKey()));
|
||||
}
|
||||
panel.setMapName(l);
|
||||
panel.setMapName(em.getKey());
|
||||
}
|
||||
|
||||
});
|
||||
if(l.equals(TileSourceManager.getMapnikSource())){
|
||||
menuItem.setSelected(true);
|
||||
panel.setMapName(l);
|
||||
}
|
||||
tiles.add(menuItem);
|
||||
}
|
||||
|
||||
return tiles;
|
||||
|
@ -119,7 +167,7 @@ public class MapPanel extends JPanel implements IMapDownloaderCallback {
|
|||
private File tilesLocation = null;
|
||||
|
||||
// name of source map
|
||||
private ITileSource map;
|
||||
private ITileSource map = TileSourceManager.getMapnikSource();
|
||||
|
||||
// zoom level
|
||||
private int zoom = 1;
|
||||
|
|
212
DataExtractionOSM/src/com/osmand/swing/NewTileSourceDialog.java
Normal file
212
DataExtractionOSM/src/com/osmand/swing/NewTileSourceDialog.java
Normal file
|
@ -0,0 +1,212 @@
|
|||
package com.osmand.swing;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import com.osmand.Algoritms;
|
||||
import com.osmand.LogUtil;
|
||||
|
||||
public class NewTileSourceDialog extends JDialog {
|
||||
|
||||
private static final long serialVersionUID = -4862884032977071296L;
|
||||
private static final Log log = LogUtil.getLog(NewTileSourceDialog.class);
|
||||
|
||||
private JButton okButton;
|
||||
private JButton cancelButton;
|
||||
|
||||
private JTextField templateName;
|
||||
private JTextField templateUrl;
|
||||
|
||||
|
||||
public NewTileSourceDialog(Component parent){
|
||||
super(JOptionPane.getFrameForComponent(parent), true);
|
||||
setTitle("Create new tile source");
|
||||
initDialog();
|
||||
|
||||
}
|
||||
|
||||
public void showDialog(){
|
||||
setSize(800, 200);
|
||||
double x = getParent().getBounds().getCenterX();
|
||||
double y = getParent().getBounds().getCenterY();
|
||||
setLocation((int) x - getWidth() / 2, (int) y - getHeight() / 2);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
private void initDialog() {
|
||||
JPanel pane = new JPanel();
|
||||
pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
|
||||
pane.setBorder(BorderFactory.createEmptyBorder(10, 10, 5, 10));
|
||||
add(pane);
|
||||
|
||||
|
||||
createInputSourceSection(pane);
|
||||
pane.add(Box.createVerticalGlue());
|
||||
|
||||
FlowLayout l = new FlowLayout(FlowLayout.RIGHT);
|
||||
JPanel buttonsPane = new JPanel(l);
|
||||
okButton = new JButton("OK");
|
||||
buttonsPane.add(okButton);
|
||||
cancelButton = new JButton("Cancel");
|
||||
buttonsPane.add(cancelButton);
|
||||
|
||||
buttonsPane.setMaximumSize(new Dimension(Short.MAX_VALUE, (int) l.preferredLayoutSize(buttonsPane).getHeight()));
|
||||
pane.add(buttonsPane);
|
||||
|
||||
addListeners();
|
||||
}
|
||||
|
||||
|
||||
private void createInputSourceSection(JPanel root) {
|
||||
JPanel panel = new JPanel();
|
||||
GridBagLayout l = new GridBagLayout();
|
||||
panel.setLayout(l);
|
||||
panel.setBorder(BorderFactory.createTitledBorder("Input source"));
|
||||
root.add(panel);
|
||||
|
||||
|
||||
JLabel label = new JLabel("Name of template : ");
|
||||
panel.add(label);
|
||||
GridBagConstraints constr = new GridBagConstraints();
|
||||
constr.anchor = GridBagConstraints.WEST;
|
||||
constr.ipadx = 5;
|
||||
constr.gridx = 0;
|
||||
constr.gridy = 0;
|
||||
l.setConstraints(label, constr);
|
||||
|
||||
templateName = new JTextField();
|
||||
templateName.setText("Mapnik example");
|
||||
panel.add(templateName);
|
||||
constr = new GridBagConstraints();
|
||||
constr.fill = GridBagConstraints.HORIZONTAL;
|
||||
constr.ipadx = 5;
|
||||
constr.gridx = 1;
|
||||
constr.gridy = 0;
|
||||
l.setConstraints(templateName, constr);
|
||||
|
||||
label = new JLabel("Url template with placeholders {$x}, {$y}, {$z} : ");
|
||||
panel.add(label);
|
||||
constr = new GridBagConstraints();
|
||||
constr.ipadx = 5;
|
||||
constr.ipady = 10;
|
||||
constr.gridx = 0;
|
||||
constr.gridy = 1;
|
||||
constr.anchor = GridBagConstraints.WEST;
|
||||
l.setConstraints(label, constr);
|
||||
|
||||
templateUrl = new JTextField();
|
||||
// Give hint about wms
|
||||
templateUrl.setText("http://tile.openstreetmap.org/{$z}/{$x}/{$y}.png");
|
||||
panel.add(templateUrl);
|
||||
constr = new GridBagConstraints();
|
||||
constr.weightx = 1;
|
||||
constr.fill = GridBagConstraints.HORIZONTAL;
|
||||
constr.ipadx = 5;
|
||||
constr.gridx = 1;
|
||||
constr.gridy = 1;
|
||||
l.setConstraints(templateUrl, constr);
|
||||
|
||||
|
||||
label = new JLabel("To add wms service you can use retiling pattern : ");
|
||||
panel.add(label);
|
||||
constr = new GridBagConstraints();
|
||||
constr.ipadx = 5;
|
||||
constr.ipady = 10;
|
||||
constr.gridx = 0;
|
||||
constr.gridy = 2;
|
||||
constr.anchor = GridBagConstraints.WEST;
|
||||
l.setConstraints(label, constr);
|
||||
|
||||
label = new JLabel();
|
||||
// Give hint about wms
|
||||
label.setText("http://whoots.mapwarper.net/tms/{$z}/{$x}/{$y}/{layer}/http://path.to.wms.server");
|
||||
panel.add(label);
|
||||
constr = new GridBagConstraints();
|
||||
constr.weightx = 1;
|
||||
constr.fill = GridBagConstraints.HORIZONTAL;
|
||||
constr.ipadx = 5;
|
||||
constr.gridx = 1;
|
||||
constr.gridy = 2;
|
||||
l.setConstraints(label, constr);
|
||||
|
||||
panel.setMaximumSize(new Dimension(Short.MAX_VALUE, panel.getPreferredSize().height));
|
||||
}
|
||||
|
||||
private void addListeners(){
|
||||
okButton.addActionListener(new ActionListener(){
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(okPressed()){
|
||||
setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
cancelButton.addActionListener(new ActionListener(){
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
public boolean okPressed(){
|
||||
if(Algoritms.isEmpty(templateName.getText())){
|
||||
JOptionPane.showMessageDialog(this, "Please specify template name" , "Error creating new tile source", JOptionPane.ERROR_MESSAGE);
|
||||
return false;
|
||||
}
|
||||
if(Algoritms.isEmpty(templateUrl.getText())){
|
||||
JOptionPane.showMessageDialog(this, "Please specify template url" , "Error creating new tile source", JOptionPane.ERROR_MESSAGE);
|
||||
return false;
|
||||
}
|
||||
String url = templateUrl.getText();
|
||||
if(url.indexOf("{$x}") == -1 || url.indexOf("{$y}") == -1 || url.indexOf("{$z}") == -1){
|
||||
JOptionPane.showMessageDialog(this, "Please specify all placeholders {$x}, {$y}, {$z} in url" , "Error creating new tile source", JOptionPane.ERROR_MESSAGE);
|
||||
return false;
|
||||
}
|
||||
File tilesDirectory = DataExtractionSettings.getSettings().getTilesDirectory();
|
||||
if(tilesDirectory != null){
|
||||
File dir = new File(tilesDirectory, templateName.getText());
|
||||
if(dir.mkdirs()){
|
||||
try {
|
||||
FileOutputStream ous = new FileOutputStream(new File(dir, "url"));
|
||||
ous.write(url.getBytes("UTF-8"));
|
||||
ous.close();
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
log.error("Error creating new tile source " + url, e);
|
||||
} catch (IOException e) {
|
||||
log.error("Error creating new tile source " + url, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -524,7 +524,7 @@ public class OsmExtractionUI implements IMapLocationListener {
|
|||
|
||||
}
|
||||
|
||||
public void fillMenuWithActions(JMenuBar bar){
|
||||
public void fillMenuWithActions(final JMenuBar bar){
|
||||
JMenu menu = new JMenu("File");
|
||||
bar.add(menu);
|
||||
JMenuItem loadFile = new JMenuItem("Load osm file...");
|
||||
|
@ -543,8 +543,7 @@ public class OsmExtractionUI implements IMapLocationListener {
|
|||
menu.add(exitMenu);
|
||||
|
||||
JMenu tileSource = MapPanel.getMenuToChooseSource(mapPanel);
|
||||
tileSource.addSeparator();
|
||||
JMenuItem sqliteDB = new JMenuItem("Create sqlite database");
|
||||
final JMenuItem sqliteDB = new JMenuItem("Create sqlite database");
|
||||
tileSource.add(sqliteDB);
|
||||
bar.add(tileSource);
|
||||
|
||||
|
@ -650,6 +649,10 @@ public class OsmExtractionUI implements IMapLocationListener {
|
|||
DataExtractionSettings.getSettings().saveDefaultWorkingDir(fc.getSelectedFile());
|
||||
mapPanel.setTilesLocation(DataExtractionSettings.getSettings().getTilesDirectory());
|
||||
statusBarLabel.setText("Working directory : " + fc.getSelectedFile().getAbsolutePath());
|
||||
JMenu tileSource = MapPanel.getMenuToChooseSource(mapPanel);
|
||||
tileSource.add(sqliteDB);
|
||||
bar.remove(1);
|
||||
bar.add(tileSource, 1);
|
||||
updateButtonsBar();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.osmand" android:versionName="0.3.1" android:versionCode="9">
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name"
|
||||
android:debuggable="false" android:name=".activities.OsmandApplication" android:description="@string/app_description">
|
||||
android:debuggable="true" android:name=".activities.OsmandApplication" android:description="@string/app_description">
|
||||
<activity android:name=".activities.MainMenuActivity"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
|
|
|
@ -44,36 +44,48 @@ import com.osmand.data.index.IndexConstants;
|
|||
public class DownloadIndexActivity extends ListActivity {
|
||||
|
||||
private final static Log log = LogUtil.getLog(DownloadIndexActivity.class);
|
||||
private ProgressDialog progressDlg = null;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.download_index);
|
||||
|
||||
final ProgressDialog dlg = ProgressDialog.show(this, getString(R.string.downloading), getString(R.string.downloading_list_indexes));
|
||||
dlg.setCancelable(true);
|
||||
progressDlg = ProgressDialog.show(this, getString(R.string.downloading), getString(R.string.downloading_list_indexes));
|
||||
progressDlg.setCancelable(true);
|
||||
|
||||
new Thread(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
final Map<String, String> indexFiles = downloadIndex();
|
||||
dlg.dismiss();
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (indexFiles != null) {
|
||||
setListAdapter(new DownloadIndexAdapter(new ArrayList<Entry<String,String>>(indexFiles.entrySet())));
|
||||
} else {
|
||||
Toast.makeText(DownloadIndexActivity.this, R.string.list_index_files_was_not_loaded, Toast.LENGTH_LONG).show();
|
||||
if(progressDlg != null){
|
||||
progressDlg.dismiss();
|
||||
progressDlg = null;
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (indexFiles != null) {
|
||||
setListAdapter(new DownloadIndexAdapter(new ArrayList<Entry<String,String>>(indexFiles.entrySet())));
|
||||
} else {
|
||||
Toast.makeText(DownloadIndexActivity.this, R.string.list_index_files_was_not_loaded, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
}, "DownloadIndexes").start(); //$NON-NLS-1$
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
if(progressDlg != null){
|
||||
progressDlg.dismiss();
|
||||
progressDlg = null;
|
||||
}
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
protected Map<String, String> downloadIndex(){
|
||||
try {
|
||||
log.debug("Start loading list of index files"); //$NON-NLS-1$
|
||||
|
@ -166,9 +178,9 @@ public class DownloadIndexActivity extends ListActivity {
|
|||
|
||||
protected void downloadFile(final String key, final File file) {
|
||||
|
||||
final ProgressDialog dlg = ProgressDialog.show(this, getString(R.string.downloading), getString(R.string.downloading_file), true, true);
|
||||
dlg.show();
|
||||
final ProgressDialogImplementation impl = new ProgressDialogImplementation(dlg, true);
|
||||
progressDlg = ProgressDialog.show(this, getString(R.string.downloading), getString(R.string.downloading_file), true, true);
|
||||
progressDlg.show();
|
||||
final ProgressDialogImplementation impl = new ProgressDialogImplementation(progressDlg, true);
|
||||
impl.setRunnable("DownloadIndex", new Runnable(){ //$NON-NLS-1$
|
||||
|
||||
@Override
|
||||
|
@ -239,7 +251,10 @@ public class DownloadIndexActivity extends ListActivity {
|
|||
// Possibly file is corrupted
|
||||
file.delete();
|
||||
} finally {
|
||||
dlg.dismiss();
|
||||
if(progressDlg != null){
|
||||
progressDlg.dismiss();
|
||||
progressDlg = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -46,14 +46,15 @@ public class MainMenuActivity extends Activity {
|
|||
private Button settingsButton;
|
||||
private Button searchButton;
|
||||
private Button favouritesButton;
|
||||
private ProgressDialog progressDlg;
|
||||
|
||||
|
||||
|
||||
public void startApplication(){
|
||||
if(!applicationAlreadyStarted){
|
||||
// Algoritms.removeAllFiles(new File(Environment.getExternalStorageDirectory(), "/osmand/tiles/Mapnik/18"));
|
||||
final ProgressDialog dlg = ProgressDialog.show(this, getString(R.string.loading_data), getString(R.string.reading_indexes), true);
|
||||
final ProgressDialogImplementation impl = new ProgressDialogImplementation(dlg);
|
||||
progressDlg = ProgressDialog.show(this, getString(R.string.loading_data), getString(R.string.reading_indexes), true);
|
||||
final ProgressDialogImplementation impl = new ProgressDialogImplementation(progressDlg);
|
||||
impl.setRunnable("Initializing app", new Runnable(){ //$NON-NLS-1$
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -74,7 +75,10 @@ public class MainMenuActivity extends Activity {
|
|||
helper.close();
|
||||
showWarnings(warnings);
|
||||
} finally {
|
||||
dlg.dismiss();
|
||||
if(progressDlg != null){
|
||||
progressDlg.dismiss();
|
||||
progressDlg = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -175,6 +179,15 @@ public class MainMenuActivity extends Activity {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
if(progressDlg != null){
|
||||
progressDlg.dismiss();
|
||||
progressDlg = null;
|
||||
}
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
protected void showWarnings(List<String> warnings) {
|
||||
if (!warnings.isEmpty()) {
|
||||
final StringBuilder b = new StringBuilder();
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.util.Map;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
|
@ -141,8 +142,9 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
private NotificationManager mNotificationManager;
|
||||
private Handler mapPositionHandler = null;
|
||||
private int APP_NOTIFICATION_ID;
|
||||
private int currentScreenOrientation;
|
||||
|
||||
|
||||
private Dialog progressDlg = null;
|
||||
|
||||
|
||||
private boolean isMapLinkedToLocation(){
|
||||
|
@ -378,6 +380,10 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
protected void onStop() {
|
||||
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
mNotificationManager.notify(APP_NOTIFICATION_ID, getNotification());
|
||||
if(progressDlg != null){
|
||||
progressDlg.dismiss();
|
||||
progressDlg = null;
|
||||
}
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
|
@ -615,6 +621,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
|
@ -698,6 +705,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
if(OsmandSettings.getMapOrientation(this) != getRequestedOrientation()){
|
||||
setRequestedOrientation(OsmandSettings.getMapOrientation(this));
|
||||
}
|
||||
currentScreenOrientation = getWindow().getWindowManager().getDefaultDisplay().getOrientation();
|
||||
|
||||
// routing helper with current activity
|
||||
routingHelper = RoutingHelper.getInstance(this);
|
||||
|
@ -824,7 +832,11 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
@Override
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
// Attention : sensor produces a lot of events & can hang the system
|
||||
locationLayer.setHeading(event.values[0]);
|
||||
float val = event.values[0];
|
||||
if(currentScreenOrientation == 1){
|
||||
val += 90;
|
||||
}
|
||||
locationLayer.setHeading(val);
|
||||
}
|
||||
|
||||
private void updateNavigateToPointMenu(){
|
||||
|
@ -1066,7 +1078,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
final double rightLon = MapUtils.getLongitudeFromTile(zoom, tileRect.right);
|
||||
final double bottomLat = MapUtils.getLatitudeFromTile(zoom, tileRect.bottom);
|
||||
|
||||
final ProgressDialog dlg = ProgressDialog.show(this, getString(R.string.loading), getString(R.string.loading_data));
|
||||
progressDlg = ProgressDialog.show(this, getString(R.string.loading), getString(R.string.loading_data));
|
||||
new Thread(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -1085,8 +1097,11 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
} catch(Exception e) {
|
||||
Log.e(LogUtil.TAG, "Error updating local data", e); //$NON-NLS-1$
|
||||
showToast(getString(R.string.update_poi_error_local));
|
||||
}finally {
|
||||
dlg.dismiss();
|
||||
} finally {
|
||||
if(progressDlg !=null){
|
||||
progressDlg.dismiss();
|
||||
progressDlg = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, "LoadingPOI").start(); //$NON-NLS-1$
|
||||
|
|
|
@ -91,6 +91,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
private ListPreference routeServiceProvider;
|
||||
private CheckBoxPreference routeServiceEnabled;
|
||||
|
||||
private ProgressDialog progressDlg;
|
||||
|
||||
private BooleanPreference[] booleanPreferences = new BooleanPreference[]{
|
||||
// new BooleanPreference(OsmandSettings.SHOW_TRANSPORT_OVER_MAP, OsmandSettings.SHOW_TRANSPORT_OVER_MAP_DEF),
|
||||
|
@ -110,6 +111,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -444,20 +446,31 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
|||
}
|
||||
|
||||
public void reloadIndexes(){
|
||||
final ProgressDialog dlg = ProgressDialog.show(this, getString(R.string.loading_data), getString(R.string.reading_indexes), true);
|
||||
final ProgressDialogImplementation impl = new ProgressDialogImplementation(dlg);
|
||||
progressDlg = ProgressDialog.show(this, getString(R.string.loading_data), getString(R.string.reading_indexes), true);
|
||||
final ProgressDialogImplementation impl = new ProgressDialogImplementation(progressDlg);
|
||||
impl.setRunnable("Initializing app", new Runnable(){ //$NON-NLS-1$
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
showWarnings(ResourceManager.getResourceManager().reloadIndexes(impl));
|
||||
} finally {
|
||||
dlg.dismiss();
|
||||
if(progressDlg !=null){
|
||||
progressDlg.dismiss();
|
||||
progressDlg = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
impl.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
if(progressDlg !=null){
|
||||
progressDlg.dismiss();
|
||||
progressDlg = null;
|
||||
}
|
||||
super.onStop();
|
||||
}
|
||||
protected void showWarnings(List<String> warnings) {
|
||||
if (!warnings.isEmpty()) {
|
||||
|
|
|
@ -46,6 +46,8 @@ public class SearchAddressActivity extends Activity {
|
|||
private boolean radioBuilding = true;
|
||||
private Button searchOnline;
|
||||
|
||||
private ProgressDialog progressDlg;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -225,6 +227,15 @@ public class SearchAddressActivity extends Activity {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
if(progressDlg != null){
|
||||
progressDlg.dismiss();
|
||||
progressDlg = null;
|
||||
}
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
protected void updateBuildingSection(){
|
||||
if(radioBuilding){
|
||||
((TextView)findViewById(R.id.BuildingText)).setText(R.string.search_address_building);
|
||||
|
@ -313,20 +324,23 @@ public class SearchAddressActivity extends Activity {
|
|||
}
|
||||
|
||||
protected void startLoadDataInThread(String progressMsg){
|
||||
final ProgressDialog dlg = ProgressDialog.show(this, getString(R.string.loading), progressMsg, true);
|
||||
progressDlg = ProgressDialog.show(this, getString(R.string.loading), progressMsg, true);
|
||||
new Thread("Loader search data") { //$NON-NLS-1$
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
loadData();
|
||||
} finally {
|
||||
dlg.dismiss();
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateUI();
|
||||
}
|
||||
});
|
||||
if (progressDlg != null) {
|
||||
progressDlg.dismiss();
|
||||
progressDlg = null;
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateUI();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
|
|
|
@ -38,6 +38,7 @@ import com.osmand.osm.MapUtils;
|
|||
public class SearchAddressOnlineActivity extends ListActivity {
|
||||
|
||||
private LatLon location;
|
||||
private ProgressDialog progressDlg;
|
||||
private final static Log log = LogUtil.getLog(SearchAddressOnlineActivity.class);
|
||||
|
||||
@Override
|
||||
|
@ -71,7 +72,7 @@ public class SearchAddressOnlineActivity extends ListActivity {
|
|||
return;
|
||||
}
|
||||
|
||||
final ProgressDialog dlg = ProgressDialog.show(this, getString(R.string.searching), getString(R.string.searching_address));
|
||||
progressDlg = ProgressDialog.show(this, getString(R.string.searching), getString(R.string.searching_address));
|
||||
new Thread(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -118,12 +119,14 @@ public class SearchAddressOnlineActivity extends ListActivity {
|
|||
log.error("Error searching address", e); //$NON-NLS-1$
|
||||
showResult(R.string.error_io_error, null);
|
||||
} finally {
|
||||
dlg.dismiss();
|
||||
if(progressDlg != null){
|
||||
progressDlg.dismiss();
|
||||
progressDlg = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}, "SearchingAddress").start(); //$NON-NLS-1$
|
||||
|
||||
}
|
||||
|
||||
private void showResult(final int warning, final List<Place> places) {
|
||||
|
@ -139,6 +142,16 @@ public class SearchAddressOnlineActivity extends ListActivity {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
if(progressDlg != null){
|
||||
progressDlg.dismiss();
|
||||
progressDlg = null;
|
||||
}
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
||||
super.onListItemClick(l, v, position, id);
|
||||
|
|
|
@ -22,6 +22,7 @@ public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity<St
|
|||
private Street street1;
|
||||
volatile private List<Street> initialList = new ArrayList<Street>();
|
||||
private List<Street> filterList = new ArrayList<Street>();
|
||||
private ProgressDialog progressDlg;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
region = ResourceManager.getResourceManager().getRegionRepository(OsmandSettings.getLastSearchedRegion(this));
|
||||
|
@ -45,9 +46,17 @@ public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity<St
|
|||
((TextView)findViewById(R.id.Label)).setText(R.string.incremental_search_street);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
if(progressDlg != null){
|
||||
progressDlg.dismiss();
|
||||
progressDlg = null;
|
||||
}
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
protected void startLoadDataInThread(String progressMsg){
|
||||
final ProgressDialog dlg = ProgressDialog.show(this, getString(R.string.loading), progressMsg, true);
|
||||
progressDlg = ProgressDialog.show(this, getString(R.string.loading), progressMsg, true);
|
||||
new Thread("Loader search data") { //$NON-NLS-1$
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -56,13 +65,17 @@ public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity<St
|
|||
region.fillWithSuggestedStreetsIntersectStreets(city, street1, t);
|
||||
initialList = t;
|
||||
} finally {
|
||||
dlg.dismiss();
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setText(getFilter().toString());
|
||||
}
|
||||
});
|
||||
if(progressDlg != null){
|
||||
progressDlg.dismiss();
|
||||
progressDlg = null;
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setText(getFilter().toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
|
|
|
@ -10,6 +10,8 @@ import android.graphics.Path;
|
|||
import android.graphics.PointF;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Paint.Cap;
|
||||
import android.graphics.Paint.Join;
|
||||
import android.graphics.Paint.Style;
|
||||
import android.location.Location;
|
||||
import android.util.Log;
|
||||
|
@ -45,6 +47,8 @@ public class RouteLayer implements OsmandMapLayer {
|
|||
paint.setStrokeWidth(14);
|
||||
paint.setAlpha(150);
|
||||
paint.setAntiAlias(true);
|
||||
paint.setStrokeCap(Cap.ROUND);
|
||||
paint.setStrokeJoin(Join.ROUND);
|
||||
path = new Path();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue