Search in sources :

Example 11 with WorldRegion

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());
    }
}
Also used : OsmandRegions(net.osmand.map.OsmandRegions) WorldRegion(net.osmand.map.WorldRegion) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) ResourceManager(net.osmand.plus.resources.ResourceManager) IOException(java.io.IOException) IndexItem(net.osmand.plus.download.IndexItem) LinkedList(java.util.LinkedList)

Example 12 with WorldRegion

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;
}
Also used : WorldRegion(net.osmand.map.WorldRegion) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) MapZoomPair(net.osmand.binary.MapZooms.MapZoomPair) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) Map(java.util.Map)

Example 13 with WorldRegion

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;
}
Also used : WorldRegion(net.osmand.map.WorldRegion) SpannableString(android.text.SpannableString)

Example 14 with WorldRegion

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;
}
Also used : WorldRegion(net.osmand.map.WorldRegion)

Example 15 with WorldRegion

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()));
        }
    }
}
Also used : WorldRegion(net.osmand.map.WorldRegion) ArrayList(java.util.ArrayList)

Aggregations

WorldRegion (net.osmand.map.WorldRegion)17 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)10 OsmandRegions (net.osmand.map.OsmandRegions)8 LinkedHashMap (java.util.LinkedHashMap)6 LinkedList (java.util.LinkedList)6 ArrayList (java.util.ArrayList)4 IndexItem (net.osmand.plus.download.IndexItem)4 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)3 IOException (java.io.IOException)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 HashMap (java.util.HashMap)3 Paint (android.graphics.Paint)2 SpannableString (android.text.SpannableString)2 TextPaint (android.text.TextPaint)2 File (java.io.File)2 Connection (java.sql.Connection)2 List (java.util.List)2 Map (java.util.Map)2 TagValuePair (net.osmand.binary.BinaryMapIndexReader.TagValuePair)2