use of net.osmand.map.WorldRegion in project Osmand by osmandapp.
the class FirstUsageWizardFragment method searchMap.
private void searchMap() {
if (location != null) {
int point31x = MapUtils.get31TileNumberX(location.getLongitude());
int point31y = MapUtils.get31TileNumberY(location.getLatitude());
ResourceManager rm = getMyApplication().getResourceManager();
OsmandRegions osmandRegions = rm.getOsmandRegions();
List<BinaryMapDataObject> mapDataObjects = null;
try {
mapDataObjects = osmandRegions.queryBbox(point31x, point31x, point31y, point31y);
} catch (IOException e) {
e.printStackTrace();
}
String selectedFullName = "";
if (mapDataObjects != null) {
Iterator<BinaryMapDataObject> it = mapDataObjects.iterator();
while (it.hasNext()) {
BinaryMapDataObject o = it.next();
if (!osmandRegions.contain(o, point31x, point31y)) {
it.remove();
}
}
for (BinaryMapDataObject o : mapDataObjects) {
String fullName = osmandRegions.getFullName(o);
if (fullName.length() > selectedFullName.length()) {
selectedFullName = fullName;
}
}
}
if (!Algorithms.isEmpty(selectedFullName)) {
WorldRegion downloadRegion = osmandRegions.getRegionData(selectedFullName);
if (downloadRegion != null && downloadRegion.isRegionMapDownload()) {
localDownloadRegion = downloadRegion;
List<IndexItem> indexItems = new LinkedList<>(downloadThread.getIndexes().getIndexItems(downloadRegion));
for (IndexItem item : indexItems) {
if (item.getType() == DownloadActivityType.NORMAL_FILE) {
localMapIndexItem = item;
break;
}
}
}
}
baseMapIndexItem = downloadThread.getIndexes().getWorldBaseMapItem();
if (localMapIndexItem != null || baseMapIndexItem != null) {
showMapFoundFragment(getActivity());
} else {
closeWizard();
}
} else {
showNoLocationFragment(getActivity());
}
}
use of net.osmand.map.WorldRegion in project OsmAnd-tools by osmandapp.
the class ObfRegionSplitter method splitRegionMapData.
private Map<String, Map<MapZoomPair, TLongObjectHashMap<BinaryMapDataObject>>> splitRegionMapData(ObfFileInMemory allMapObjects, OsmandRegions osmandRegions) throws IOException {
Map<String, Map<MapZoomPair, TLongObjectHashMap<BinaryMapDataObject>>> result = new HashMap<>();
for (MapZoomPair p : allMapObjects.getZooms()) {
TLongObjectHashMap<BinaryMapDataObject> objects = allMapObjects.get(p);
for (BinaryMapDataObject obj : objects.valueCollection()) {
int x = obj.getPoint31XTile(0);
int y = obj.getPoint31YTile(0);
List<BinaryMapDataObject> l = osmandRegions.query(x, y);
for (BinaryMapDataObject b : l) {
if (osmandRegions.contain(b, x, y)) {
String dw = osmandRegions.getDownloadName(b);
WorldRegion wr = osmandRegions.getRegionDataByDownloadName(dw);
if (dw == null || wr == null) {
continue;
}
if (!Algorithms.isEmpty(dw) && wr.isRegionMapDownload()) {
Map<MapZoomPair, TLongObjectHashMap<BinaryMapDataObject>> mp = result.get(dw);
if (mp == null) {
mp = new LinkedHashMap<>();
result.put(dw, mp);
}
TLongObjectHashMap<BinaryMapDataObject> list = mp.get(p);
if (list == null) {
list = new TLongObjectHashMap<>();
mp.put(p, list);
}
list.put(obj.getId(), obj);
}
}
}
}
}
return result;
}
use of net.osmand.map.WorldRegion in project Osmand by osmandapp.
the class MenuController method checkIfObjectDownloaded.
private boolean checkIfObjectDownloaded(ResourceManager rm, String downloadName) {
final String regionName = Algorithms.capitalizeFirstLetterAndLowercase(downloadName) + IndexConstants.BINARY_MAP_INDEX_EXT;
final String roadsRegionName = Algorithms.capitalizeFirstLetterAndLowercase(downloadName) + ".road" + IndexConstants.BINARY_MAP_INDEX_EXT;
boolean downloaded = rm.getIndexFileNames().containsKey(regionName) || rm.getIndexFileNames().containsKey(roadsRegionName);
if (!downloaded) {
WorldRegion region = rm.getOsmandRegions().getRegionDataByDownloadName(downloadName);
if (region != null && region.getSuperregion() != null && region.getSuperregion().isRegionMapDownload()) {
return checkIfObjectDownloaded(rm, region.getSuperregion().getRegionDownloadName());
}
}
return downloaded;
}
use of net.osmand.map.WorldRegion in project Osmand by osmandapp.
the class CountrySelectionFragment method getHumanReadableName.
private static String getHumanReadableName(WorldRegion group) {
String name;
if (group.getLevel() > 2 || (group.getLevel() == 2 && group.getSuperregion().getRegionId().equals(WorldRegion.RUSSIA_REGION_ID))) {
WorldRegion parent = group.getSuperregion();
WorldRegion parentsParent = group.getSuperregion().getSuperregion();
if (group.getLevel() == 3) {
if (parentsParent.getRegionId().equals(WorldRegion.RUSSIA_REGION_ID)) {
name = parentsParent.getLocaleName() + " " + group.getLocaleName();
} else if (!parent.getRegionId().equals(WorldRegion.UNITED_KINGDOM_REGION_ID)) {
name = parent.getLocaleName() + " " + group.getLocaleName();
} else {
name = group.getLocaleName();
}
} else {
name = parent.getLocaleName() + " " + group.getLocaleName();
}
} else {
name = group.getLocaleName();
}
if (name == null) {
name = "";
}
return name;
}
use of net.osmand.map.WorldRegion in project Osmand by osmandapp.
the class CountrySelectionFragment method initCountries.
public void initCountries(OsmandApplication app) {
final WorldRegion root = app.getRegions().getWorldRegion();
ArrayList<WorldRegion> groups = new ArrayList<>();
groups.add(root);
processGroup(root, groups);
Collections.sort(groups, new Comparator<WorldRegion>() {
@Override
public int compare(WorldRegion lhs, WorldRegion rhs) {
if (lhs == root) {
return -1;
}
if (rhs == root) {
return 1;
}
return getHumanReadableName(lhs).compareTo(getHumanReadableName(rhs));
}
});
for (WorldRegion group : groups) {
String name = getHumanReadableName(group);
if (group == root) {
countryItems.add(new CountryItem(name, ""));
} else {
countryItems.add(new CountryItem(name, group.getRegionDownloadName()));
}
}
}
Aggregations