Merge branch 'master' of https://github.com/osmandapp/Osmand into colored-gpx-and-fixed-points

This commit is contained in:
fokin33 2013-12-15 14:51:03 +04:00
commit 5472eb31b4
9 changed files with 137 additions and 43 deletions

View file

@ -56,10 +56,11 @@ public class BinaryInspector {
in.inspector(args);
// test cases show info
/*in.inspector(new String[]{
"-vpoi",
//"-vmap", "-vmapobjects",
//"-vstreets", "-bbox=14.4,50.1,14.5,50.01",
"/home/victor/projects/osmand/osm-gen/Map.obf"});*/
//"-vpoi",
"-vmap", "-vmapobjects",
//"-vstreets",
"-bbox=4,55,7,50",
"/home/victor/projects/osmand/osm-gen/World_seamarks_2.obf"});*/
}
private void printToFile(String s) throws IOException {
@ -808,8 +809,8 @@ public class BinaryInspector {
PoiSubType st = p.subTypes.get(i);
println("\t\t\t" + st.name + " " + (st.text ? "text":(" encoded " + st.possibleValues.size())));
}
req.poiTypeFilter = null;//TODO: for test only
// index.searchPoi(p, req);
req.poiTypeFilter = null;//for test only
index.searchPoi(p, req);
}

View file

@ -38,6 +38,7 @@ public class AmenityType {
public static AmenityType ADMINISTRATIVE = reg("administrative", "administrative"); // [TAG] administrative //$NON-NLS-1$ //$NON-NLS-2$
public static AmenityType EDUCATION = reg("education", "amenity"); // school, ... //$NON-NLS-1$ //$NON-NLS-2$
public static AmenityType MAN_MADE = reg("man_made", "man_made"); // [TAG] man_made and others //$NON-NLS-1$ //$NON-NLS-2$
public static AmenityType SEAMARK = reg("seamark", "seamark"); // [TAG] seamark //$NON-NLS-1$ //$NON-NLS-2$
public static AmenityType SUSTENANCE = reg("sustenance", "amenity"); // restaurant, cafe, ... //$NON-NLS-1$ //$NON-NLS-2$
public static AmenityType SHOP = reg("shop", "shop"); // [TAG] amenity convenience = reg("", product); clothes,... //$NON-NLS-1$ //$NON-NLS-2$

View file

@ -6,18 +6,18 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
import net.osmand.PlatformUtil;
import net.osmand.data.AmenityType;
import net.osmand.osm.edit.Entity;
import net.osmand.osm.edit.OSMSettings.OSMTagKey;
import net.osmand.util.Algorithms;
@ -132,8 +132,77 @@ public class MapRenderingTypes {
return amenityTypeNameToTagVal;
}
public Collection<Map<String, String>> splitTagsIntoDifferentObjects(final Map<String, String> tags) {
// check open sea maps tags
boolean split = splitIsNeeded(tags);
if(!split) {
return Collections.singleton(tags);
} else {
return splitOpenSeaMapsTags(tags);
}
}
protected boolean splitIsNeeded(final Map<String, String> tags) {
boolean seamark = false;
for(String s : tags.keySet()) {
if(s.startsWith("seamark:")) {
seamark = true;
break;
}
}
return seamark;
}
private Collection<Map<String, String>> splitOpenSeaMapsTags(final Map<String, String> tags) {
Map<String, Map<String, String>> groupByOpenSeamaps = new HashMap<String, Map<String, String>>();
Map<String, String> common = new HashMap<String, String>();
String ATTACHED_KEY = "seamark:attached";
String type = "";
for (String s : tags.keySet()) {
String value = tags.get(s);
if (s.equals("seamark:type")) {
type = value;
common.put(ATTACHED_KEY, openSeaType(value));
} else if (s.startsWith("seamark:")) {
String stype = s.substring("seamark:".length());
int ind = stype.indexOf(':');
if (ind == -1) {
common.put(s, value);
} else {
String group = openSeaType(stype.substring(0, ind));
String add = stype.substring(ind + 1);
if (!groupByOpenSeamaps.containsKey(group)) {
groupByOpenSeamaps.put(group, new HashMap<String, String>());
}
groupByOpenSeamaps.get(group).put("seamark:" + add, value);
}
} else {
common.put(s, value);
}
}
List<Map<String, String>> res = new ArrayList<Map<String,String>>();
for (Entry<String, Map<String, String>> g : groupByOpenSeamaps.entrySet()) {
g.getValue().putAll(common);
g.getValue().put("seamark", g.getKey());
if (openSeaType(type).equals(g.getKey())) {
g.getValue().remove(ATTACHED_KEY);
g.getValue().put("seamark", type);
res.add(0, g.getValue());
} else {
res.add(g.getValue());
}
}
return res;
}
private String openSeaType(String value) {
if(value.equals("light_major") || value.equals("light_minor")) {
return "light";
}
return value;
}
public Map<String, AmenityType> getAmenityNameToType(){
if(amenityNameToType == null){
amenityNameToType = new LinkedHashMap<String, AmenityType>();
@ -207,14 +276,13 @@ public class MapRenderingTypes {
return nameEnRuleType;
}
public Map<String, String> getAmenityAdditionalInfo(Entity e, AmenityType type, String subtype) {
public Map<String, String> getAmenityAdditionalInfo(Map<String, String> tags, AmenityType type, String subtype) {
Map<String, String> map = new LinkedHashMap<String, String>();
Collection<String> tagKeySet = e.getTagKeySet();
for (String tag : tagKeySet) {
String val = e.getTag(tag);
for (String tag : tags.keySet()) {
String val = tags.get(tag);
MapRulType rType = getAmenityRuleType(tag, val);
if (rType != null && val.length() > 0) {
if(rType == nameEnRuleType && Algorithms.objectEquals(val, e.getTag(OSMTagKey.NAME))) {
if(rType == nameEnRuleType && Algorithms.objectEquals(val, tags.get(OSMTagKey.NAME))) {
continue;
}
if(rType.targetTagValue != null) {
@ -226,7 +294,7 @@ public class MapRenderingTypes {
Iterator<TagValuePattern> it = rType.applyToTagValue.iterator();
while(!applied && it.hasNext()) {
TagValuePattern nv = it.next();
applied = nv.isApplicable(e);
applied = nv.isApplicable(tags);
}
}
if (applied) {
@ -275,14 +343,14 @@ public class MapRenderingTypes {
Map<String, MapRulType> rules = getEncodingRuleTypes();
MapRulType rt = rules.get(constructRuleKey(tag, val));
if(rt != null && rt.isPOISpecified()) {
if(relation && !rt.relation) {
if((relation && !rt.relation) || rt.isAdditionalOrText()) {
return null;
}
return rt.poiCategory;
}
rt = rules.get(constructRuleKey(tag, null));
if(rt != null && rt.isPOISpecified()) {
if(relation && !rt.relation) {
if((relation && !rt.relation) || rt.isAdditionalOrText()) {
return null;
}
return rt.poiCategory;
@ -517,11 +585,11 @@ public class MapRenderingTypes {
}
}
public boolean isApplicable(Entity e ){
public boolean isApplicable(Map<String, String> e ){
if(value == null) {
return e.getTag(tag) != null;
return e.get(tag) != null;
}
return value.equals(e.getTag(tag));
return value.equals(e.get(tag));
}
@Override
@ -729,5 +797,7 @@ public class MapRenderingTypes {
}
}

View file

@ -142,6 +142,10 @@ public abstract class Entity {
return tags.put(key, value);
}
public void replaceTags(Map<String, String> toPut){
tags = new LinkedHashMap<String, String>(toPut);
}
public String getTag(OSMTagKey key){
return getTag(key.getValue());
}

View file

@ -2,6 +2,7 @@ package net.osmand.osm.edit;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import net.osmand.data.Amenity;
import net.osmand.data.AmenityType;
@ -62,12 +63,16 @@ public class EntityParser {
mo.setName(op);
}
public static Amenity parseAmenity(Entity entity, AmenityType type, String subtype, MapRenderingTypes types) {
public static Amenity parseAmenity(Entity entity, AmenityType type, String subtype, Map<String, String> tagValues,
MapRenderingTypes types) {
Amenity am = new Amenity();
parseMapObject(am, entity);
if(tagValues == null) {
tagValues = entity.getTags();
}
am.setType(type);
am.setSubType(subtype);
am.setAdditionalInfo(types.getAmenityAdditionalInfo(entity, type, subtype));
am.setAdditionalInfo(types.getAmenityAdditionalInfo(tagValues, type, subtype));
am.setAdditionalInfo("website", getWebSiteURL(entity));
return am;
}
@ -102,19 +107,22 @@ public class EntityParser {
public static List<Amenity> parseAmenities(MapRenderingTypes renderingTypes,
Entity entity, List<Amenity> amenitiesList){
amenitiesList.clear();
// it could be collection of amenities
boolean relation = entity instanceof Relation;
Collection<String> keySet = entity.getTagKeySet();
if (!keySet.isEmpty()) {
boolean purerelation = relation && !"multipolygon".equals(entity.getTag("type"));
for (String t : keySet) {
AmenityType type = purerelation? renderingTypes.getAmenityTypeForRelation(t, entity.getTag(t)):
renderingTypes.getAmenityType(t, entity.getTag(t));
if (type != null) {
String subtype = renderingTypes.getAmenitySubtype(t, entity.getTag(t));
Amenity a = parseAmenity(entity, type, subtype, renderingTypes);
if(checkAmenitiesToAdd(a, amenitiesList) && !"no".equals(subtype)){
amenitiesList.add(a);
Collection<Map<String, String>> it = renderingTypes.splitTagsIntoDifferentObjects(entity.getTags());
for(Map<String, String> tags : it) {
if (!tags.isEmpty()) {
boolean purerelation = relation && !"multipolygon".equals(tags.get("type"));
for (Map.Entry<String, String> e : tags.entrySet()) {
AmenityType type = purerelation ? renderingTypes.getAmenityTypeForRelation(e.getKey(), e.getValue())
: renderingTypes.getAmenityType(e.getKey(), e.getValue());
if (type != null) {
String subtype = renderingTypes.getAmenitySubtype(e.getKey(), e.getValue());
Amenity a = parseAmenity(entity, type, subtype, tags, renderingTypes);
if (checkAmenitiesToAdd(a, amenitiesList) && !"no".equals(subtype)) {
amenitiesList.add(a);
}
}
}
}

View file

@ -9,8 +9,9 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="app_modes_choose_descr">Choose available application modes in application</string>
<string name="app_modes_choose">Application Modes</string>
<string name="amenity_type_seamark">Seamark</string>
<string name="app_modes_choose_descr">Choose use profiles visible in application</string>
<string name="app_modes_choose">Application Profiles</string>
<string name="map_widget_appearance">Remaining elements:</string>
<string name="map_widget_map_rendering">Map rendering:</string>
<string name="app_mode_hiking">Hiking</string>

View file

@ -30,7 +30,7 @@ public class ApplicationMode {
icon(R.drawable.ic_bicycle, R.drawable.ic_action_bicycle_light, R.drawable.ic_action_bicycle_dark).reg();
public static final ApplicationMode PEDESTRIAN = create(R.string.app_mode_pedestrian, "pedestrian").speed(1.5f, 5).
icon(R.drawable.ic_pedestrian, R.drawable.ic_action_pedestrian_light, R.drawable.ic_action_parking_dark).reg();
icon(R.drawable.ic_pedestrian, R.drawable.ic_action_pedestrian_light, R.drawable.ic_action_pedestrian_dark).reg();
public static final ApplicationMode AIRCRAFT = create(R.string.app_mode_aircraft, "aircraft").speed(40f, 100).carLocation().
icon(R.drawable.ic_aircraft, R.drawable.ic_action_aircraft_light, R.drawable.ic_action_aircraft_dark).reg();

View file

@ -127,8 +127,8 @@ public class NavigateAction {
final List<ApplicationMode> values = new ArrayList<ApplicationMode>(ApplicationMode.values(app.getSettings()));
values.remove(ApplicationMode.DEFAULT);
View view = mapActivity.getLayoutInflater().inflate(R.layout.calculate_route, null);
boolean osmandRouter = mapActivity.getMyApplication().getSettings().ROUTER_SERVICE.get() == RouteService.OSMAND;
final View view = mapActivity.getLayoutInflater().inflate(R.layout.calculate_route, null);
final CheckBox nonoptimal = (CheckBox) view.findViewById(R.id.OptimalCheckox);
LinearLayout topLayout = (LinearLayout) view.findViewById(R.id.LinearLayout);
final ToggleButton[] buttons = createToggles(values, topLayout, mapActivity);
@ -137,11 +137,7 @@ public class NavigateAction {
final List<LatLon> toList = new ArrayList<LatLon>();
final Spinner toSpinner = setupToSpinner(mapView, name,view, toList, style);
if(osmandRouter && targets.hasLongDistancesInBetween(current != null ? current : mapView, 150000)) {
TextView textView = (TextView) view.findViewById(R.id.ValidateTextView);
textView.setText(R.string.route_is_too_long);
textView.setVisibility(View.VISIBLE);
}
String via = generateViaDescription();
if(via.length() == 0){
@ -155,6 +151,7 @@ public class NavigateAction {
if(appMode == ApplicationMode.DEFAULT) {
appMode = ApplicationMode.CAR;
}
updateTooLongDistance(current != null ? current : mapView, targets, view, appMode);
for (int i = 0; i < buttons.length; i++) {
if (buttons[i] != null) {
final int ind = i;
@ -169,6 +166,7 @@ public class NavigateAction {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
nonoptimal.setChecked(!settings.OPTIMAL_ROUTE_MODE.getModeValue(buttonAppMode));
updateTooLongDistance(current != null ? current : mapView, targets, view, buttonAppMode);
for (int j = 0; j < buttons.length; j++) {
if (buttons[j] != null) {
if (buttons[j].isChecked() != (ind == j)) {
@ -280,6 +278,17 @@ public class NavigateAction {
builder.show();
}
private void updateTooLongDistance(final Location start, final TargetPointsHelper targets, View view, ApplicationMode appMode) {
boolean osmandRouter = mapActivity.getMyApplication().getSettings().ROUTER_SERVICE.getModeValue(appMode)== RouteService.OSMAND;
TextView textView = (TextView) view.findViewById(R.id.ValidateTextView);
if(osmandRouter && targets.hasLongDistancesInBetween(start, 150000)) {
textView.setText(R.string.route_is_too_long);
textView.setVisibility(View.VISIBLE);
} else{
textView.setVisibility(View.GONE);
}
}
private static ToggleButton[] createToggles(final List<ApplicationMode> values, LinearLayout topLayout, Context ctx) {
final ToggleButton[] buttons = new ToggleButton[values.size()];
HorizontalScrollView scroll = new HorizontalScrollView(ctx);

View file

@ -129,7 +129,7 @@ public class EditingPOIActivity implements DialogProvider {
}
private void showPOIDialog(int dialogID, Node n, AmenityType type, String subType) {
Amenity a = EntityParser.parseAmenity(n, type, subType, MapRenderingTypes.getDefault());
Amenity a = EntityParser.parseAmenity(n, type, subType, null, MapRenderingTypes.getDefault());
dialogBundle.putSerializable(KEY_AMENITY, a);
dialogBundle.putSerializable(KEY_AMENITY_NODE, n);
ctx.showDialog(dialogID);