Allow map installation through internet
This commit is contained in:
parent
1a1d45aff3
commit
247c7ffae0
7 changed files with 101 additions and 28 deletions
|
@ -22,7 +22,6 @@ import javax.xml.parsers.SAXParser;
|
|||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.osm.MapUtils;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.xml.sax.Attributes;
|
||||
|
@ -314,10 +313,7 @@ public class TileSourceManager {
|
|||
public static java.util.List<TileSourceTemplate> getKnownSourceTemplates() {
|
||||
java.util.List<TileSourceTemplate> list = new ArrayList<TileSourceTemplate>();
|
||||
list.add(getMapnikSource());
|
||||
list.add(getOsmaRenderSource());
|
||||
list.add(getCycleMapSource());
|
||||
list.add(getCloudMadeSource());
|
||||
|
||||
return list;
|
||||
|
||||
}
|
||||
|
@ -326,32 +322,33 @@ public class TileSourceManager {
|
|||
return new TileSourceTemplate("Mapnik", "http://tile.openstreetmap.org/{0}/{1}/{2}.png", ".png", 18, 1, 256, 8, 18000); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
|
||||
public static TileSourceTemplate getOsmaRenderSource(){
|
||||
return new TileSourceTemplate("OsmaRender", "http://tah.openstreetmap.org/Tiles/tile/{0}/{1}/{2}.png", ".png", 17, 1, 256, 8, 18000); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
|
||||
public static TileSourceTemplate getCycleMapSource(){
|
||||
return new TileSourceTemplate("CycleMap", "http://b.tile.opencyclemap.org/cycle/{0}/{1}/{2}.png", ".png", 17, 0, 256, 32, 18000); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
|
||||
public static TileSourceTemplate getCloudMadeSource(){
|
||||
return new TileSourceTemplate("Cloudmade", "http://tile.cloudmade.com/7ded028e030c5929b28bf823486ce84f/1/256/{0}/{1}/{2}.png", ".png", 18, 0, 256, 16, 18000); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
|
||||
|
||||
public static List<TileSourceTemplate> downloadTileSourceTemplates() {
|
||||
final List<TileSourceTemplate> templates = new ArrayList<TileSourceTemplate>();
|
||||
try {
|
||||
URLConnection connection = new URL("http://download.osmand.net/tile_sources.php").openConnection();
|
||||
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
|
||||
final SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
|
||||
saxParser.parse(connection.getInputStream(), new DefaultHandler(){
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||
String name = saxParser.isNamespaceAware() ? localName : qName;
|
||||
Map<String, String> attrs = new LinkedHashMap<String, String>();
|
||||
if(qName.equals("tile_source")){
|
||||
if(name.equals("tile_source")){
|
||||
attrs.clear();
|
||||
for(int i=0; i< attributes.getLength(); i++){
|
||||
attrs.put(attributes.getQName(i), attributes.getValue(i));
|
||||
String local = attributes.getLocalName(i);
|
||||
if(local != null){
|
||||
attrs.put(local, attributes.getValue(i));
|
||||
} else if(attributes.getQName(i) != null){
|
||||
attrs.put(attributes.getQName(i), attributes.getValue(i));
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
TileSourceTemplate template = createTileSourceTemplate(attrs);
|
||||
if(template != null){
|
||||
|
@ -359,9 +356,6 @@ public class TileSourceManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
} catch (IOException e) {
|
||||
log.error("Exception while downloading tile sources", e);
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="tile_source_already_installed">Карта уже установлена, настройки будут обновлены</string>
|
||||
<string name="select_tile_source_to_install">Выберите карты для установки или обновления</string>
|
||||
<string name="internet_not_available">Интернет соединение не доступно</string>
|
||||
<string name="more_external_layer">Больше...</string>
|
||||
<string name="create_poi_link_to_osm_doc"><u>Интернет OSM</u> классификация</string>
|
||||
<string name="error_doing_search">Ошибка offline поиска</string>
|
||||
<string name="search_offline_geo_error">Невозможно разобрать запрос : {0}</string>
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<resources>
|
||||
<string name="tile_source_already_installed">Map is already installed, settings will be updated</string>
|
||||
<string name="select_tile_source_to_install">Select maps to install or update</string>
|
||||
<string name="internet_not_available">Internet connection required for operation is not available</string>
|
||||
<string name="more_external_layer">More...</string>
|
||||
<string name="level_to_switch_vector_raster_descr">Max zoom level to use vector rendering instead of raster</string>
|
||||
<string name="level_to_switch_vector_raster">Zoom vector level</string>
|
||||
<string name="tip_day_night_mode">Day/Night Mode</string>
|
||||
|
|
|
@ -146,8 +146,11 @@ public class OsmandSettings {
|
|||
|
||||
// Check internet connection available every 15 seconds
|
||||
public boolean isInternetConnectionAvailable(){
|
||||
return isInternetConnectionAvailable(false);
|
||||
}
|
||||
public boolean isInternetConnectionAvailable(boolean update){
|
||||
long delta = System.currentTimeMillis() - lastTimeInternetConnectionChecked;
|
||||
if(delta < 0 || delta > 15000){
|
||||
if(delta < 0 || delta > 15000 || update){
|
||||
ConnectivityManager mgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo active = mgr.getActiveNetworkInfo();
|
||||
if(active == null){
|
||||
|
@ -576,6 +579,20 @@ public class OsmandSettings {
|
|||
return null;
|
||||
}
|
||||
|
||||
public boolean installTileSource(TileSourceTemplate toInstall){
|
||||
File tPath = extendOsmandPath(ResourceManager.TILES_PATH);
|
||||
File dir = new File(tPath, toInstall.getName());
|
||||
dir.mkdirs();
|
||||
if(dir.exists() && dir.isDirectory()){
|
||||
try {
|
||||
TileSourceManager.createMetaInfoFile(dir, toInstall, true);
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Map<String, String> getTileSourceEntries(){
|
||||
Map<String, String> map = new LinkedHashMap<String, String>();
|
||||
File dir = extendOsmandPath(ResourceManager.TILES_PATH);
|
||||
|
|
|
@ -1101,9 +1101,6 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso
|
|||
builder.show();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected void parseLaunchIntentLocation(){
|
||||
Intent intent = getIntent();
|
||||
if(intent != null && intent.getData() != null){
|
||||
|
|
|
@ -15,6 +15,8 @@ import net.osmand.GPXUtilities.GPXFileResult;
|
|||
import net.osmand.GPXUtilities.WptPt;
|
||||
import net.osmand.data.AmenityType;
|
||||
import net.osmand.map.ITileSource;
|
||||
import net.osmand.map.TileSourceManager;
|
||||
import net.osmand.map.TileSourceManager.TileSourceTemplate;
|
||||
import net.osmand.osm.LatLon;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.PoiFilter;
|
||||
|
@ -421,12 +423,14 @@ public class MapActivityLayers {
|
|||
Map<String, String> entriesMap = settings.getTileSourceEntries();
|
||||
Builder builder = new AlertDialog.Builder(activity);
|
||||
final ArrayList<String> keys = new ArrayList<String>(entriesMap.keySet());
|
||||
String[] items = new String[entriesMap.size() + 1];
|
||||
final String[] items = new String[entriesMap.size() + 2];
|
||||
items[0] = getString(R.string.vector_data);
|
||||
int i = 1;
|
||||
for(String it : entriesMap.values()){
|
||||
items[i++] = it;
|
||||
}
|
||||
|
||||
items[i] = getString(R.string.more_external_layer);
|
||||
builder.setItems(items, new DialogInterface.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
@ -438,17 +442,70 @@ public class MapActivityLayers {
|
|||
} else {
|
||||
settings.setUsingMapVectorData(true);
|
||||
}
|
||||
updateMapSource(mapView);
|
||||
} else if (which == items.length - 1){
|
||||
installMapLayers(mapView);
|
||||
} else {
|
||||
settings.setMapTileSource(keys.get(which - 1));
|
||||
settings.setUsingMapVectorData(false);
|
||||
updateMapSource(mapView);
|
||||
}
|
||||
updateMapSource(mapView);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
|
||||
private void installMapLayers(final OsmandMapTileView mapView){
|
||||
final OsmandSettings settings = getApplication().getSettings();
|
||||
final Map<String, String> entriesMap = settings.getTileSourceEntries();
|
||||
if(!settings.isInternetConnectionAvailable(true)){
|
||||
Toast.makeText(activity, R.string.internet_not_available, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
final List<TileSourceTemplate> downloaded = TileSourceManager.downloadTileSourceTemplates();
|
||||
if(downloaded == null || downloaded.isEmpty()){
|
||||
Toast.makeText(activity, R.string.error_io_error, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
Builder builder = new AlertDialog.Builder(activity);
|
||||
String[] names = new String[downloaded.size()];
|
||||
for(int i=0; i<names.length; i++){
|
||||
names[i] = downloaded.get(i).getName();
|
||||
}
|
||||
final boolean[] selected = new boolean[downloaded.size()];
|
||||
builder.setMultiChoiceItems(names, selected, new DialogInterface.OnMultiChoiceClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
|
||||
selected[which] = isChecked;
|
||||
if(entriesMap.containsKey(downloaded.get(which).getName()) && isChecked){
|
||||
Toast.makeText(activity, R.string.tile_source_already_installed, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.default_buttons_cancel, null);
|
||||
builder.setTitle(R.string.select_tile_source_to_install);
|
||||
builder.setPositiveButton(R.string.default_buttons_apply, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
List<TileSourceTemplate> toInstall = new ArrayList<TileSourceTemplate>();
|
||||
for(int i=0; i<selected.length; i++){
|
||||
if(selected[i]){
|
||||
toInstall.add(downloaded.get(i));
|
||||
}
|
||||
}
|
||||
for(TileSourceTemplate ts : toInstall){
|
||||
settings.installTileSource(ts);
|
||||
}
|
||||
openLayerSelectionDialog(mapView);
|
||||
}
|
||||
});
|
||||
|
||||
builder.show();
|
||||
}
|
||||
|
||||
private String getString(int resId) {
|
||||
return activity.getString(resId);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
<?xml version="1.0"?>
|
||||
<tile_sources>
|
||||
<!-- by default added
|
||||
<tile_source name="Cloudmade" url_template="http://tile.cloudmade.com/7ded028e030c5929b28bf823486ce84f/1/256/{0}/{1}/{2}.png" ext=".png" min_zoom="1" max_zoom="18" tile_size="256" img_density="16" avg_img_size="18000"/> -->
|
||||
<tile_source name="OsmaRender" url_template="http://tah.openstreetmap.org/Tiles/tile/{0}/{1}/{2}.png" ext=".png" min_zoom="1" max_zoom="17" tile_size="256" img_density="16" avg_img_size="18000"/>
|
||||
<tile_source name="Cloudmade" url_template="http://tile.cloudmade.com/7ded028e030c5929b28bf823486ce84f/1/256/{0}/{1}/{2}.png" ext=".png" min_zoom="1" max_zoom="18" tile_size="256" img_density="16" avg_img_size="18000"/>
|
||||
<tile_source name="GoogleMaps" url_template="http://mt3.google.com/vt/v=w2.97&x={1}&y={2}&z={0}" ext=".png" min_zoom="1" max_zoom="19" tile_size="256" img_density="16" avg_img_size="18000"/>
|
||||
<tile_source name="GoogleMaps Satellite" url_template="http://khm1.google.com/kh/v=65&x={1}&y={2}&z={0}" ext=".jpg" min_zoom="1" max_zoom="20" tile_size="256" img_density="32" avg_img_size="18000"/>
|
||||
<tile_source name="GoogleMaps Terrain" url_template="http://mt3.google.com/vt/v=w2p.111&hl=en&x={1}&y={2}&z={0}" ext=".jpg" min_zoom="1" max_zoom="15" tile_size="256" img_density="32" avg_img_size="18000"/>
|
||||
<tile_source name="GoogleMaps Satellite" url_template="http://khm1.google.com/kh/v=65&x={1}&y={2}&z={0}" ext=".jpg" min_zoom="7" max_zoom="20" tile_size="256" img_density="32" avg_img_size="18000"/>
|
||||
<tile_source name="GoogleMaps Terrain" url_template="http://mt3.google.com/vt/v=w2p.111&hl=en&x={1}&y={2}&z={0}" ext=".jpg" min_zoom="5" max_zoom="15" tile_size="256" img_density="32" avg_img_size="18000"/>
|
||||
|
||||
<tile_source rule="cykloatlas_cz" name="Cykloatlas CZ" url_template="http://services.tmapserver.cz/tiles/gm/shc/{0}/{1}/{2}.png" ext=".png" min_zoom="7" max_zoom="15" tile_size="256" img_density="16" avg_img_size="26000"/>
|
||||
<tile_source rule="cykloatlas_cz" name="Cykloatlas CZ" url_template="http://services.tmapserver.cz/tiles/gm/shc/{0}/{1}/{2}.png" ext=".png" min_zoom="7" max_zoom="16" tile_size="256" img_density="16" avg_img_size="26000"/>
|
||||
|
||||
<tile_source name="OpenAerialMap" url_template="http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/{0}/{1}/{2}.jpg" ext=".jpg" min_zoom="1" max_zoom="13" tile_size="256" img_density="16" avg_img_size="18000"/>
|
||||
<tile_source name="MapSurfer" url_template="http://tiles1.mapsurfer.net/tms_r.ashx?z={0}&x={1}&y={2}" ext=".png" min_zoom="1" max_zoom="19" tile_size="256" img_density="16" avg_img_size="18000"/>
|
||||
|
|
Loading…
Reference in a new issue