Search in sources :

Example 26 with WorldRegion

use of net.osmand.map.WorldRegion in project Osmand by osmandapp.

the class DownloadResources method findIndexItemsAt.

public static List<IndexItem> findIndexItemsAt(OsmandApplication app, LatLon latLon, DownloadActivityType type, boolean includeDownloaded, int limit, boolean skipIfOneDownloaded) throws IOException {
    List<IndexItem> res = new ArrayList<>();
    OsmandRegions regions = app.getRegions();
    DownloadIndexesThread downloadThread = app.getDownloadThread();
    List<WorldRegion> downloadRegions = regions.getWorldRegionsAt(latLon);
    for (WorldRegion downloadRegion : downloadRegions) {
        boolean itemDownloaded = isIndexItemDownloaded(downloadThread, type, downloadRegion, res);
        if (skipIfOneDownloaded && itemDownloaded) {
            return new ArrayList<>();
        }
        if (includeDownloaded || !itemDownloaded) {
            addIndexItem(downloadThread, type, downloadRegion, res);
        }
        if (limit != -1 && res.size() == limit) {
            break;
        }
    }
    return res;
}
Also used : OsmandRegions(net.osmand.map.OsmandRegions) WorldRegion(net.osmand.map.WorldRegion) ArrayList(java.util.ArrayList) AssetIndexItem(net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem)

Example 27 with WorldRegion

use of net.osmand.map.WorldRegion in project Osmand by osmandapp.

the class DownloadResources method prepareData.

protected boolean prepareData(List<IndexItem> resources) {
    this.rawResources = resources;
    DownloadResourceGroup extraMapsGroup = new DownloadResourceGroup(this, DownloadResourceGroupType.EXTRA_MAPS);
    DownloadResourceGroup otherMapsGroup = new DownloadResourceGroup(this, DownloadResourceGroupType.OTHER_MAPS_GROUP);
    DownloadResourceGroup otherMapsScreen = new DownloadResourceGroup(otherMapsGroup, DownloadResourceGroupType.OTHER_MAPS);
    DownloadResourceGroup otherMaps = new DownloadResourceGroup(otherMapsGroup, DownloadResourceGroupType.OTHER_MAPS_HEADER);
    otherMapsScreen.addGroup(otherMaps);
    otherMapsGroup.addGroup(otherMapsScreen);
    DownloadResourceGroup otherGroup = new DownloadResourceGroup(this, DownloadResourceGroupType.OTHER_GROUP);
    DownloadResourceGroup voiceScreenTTS = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.VOICE_TTS);
    DownloadResourceGroup voiceScreenRec = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.VOICE_REC);
    DownloadResourceGroup fontScreen = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.FONTS);
    DownloadResourceGroup voiceTTS = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.VOICE_HEADER_TTS);
    DownloadResourceGroup voiceRec = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.VOICE_HEADER_REC);
    DownloadResourceGroup fonts = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.FONTS_HEADER);
    DownloadResourceGroup worldMaps = new DownloadResourceGroup(this, DownloadResourceGroupType.WORLD_MAPS);
    DownloadResourceGroup nauticalMapsGroup = new DownloadResourceGroup(this, DownloadResourceGroupType.NAUTICAL_MAPS_GROUP);
    DownloadResourceGroup nauticalMapsScreen = new DownloadResourceGroup(nauticalMapsGroup, DownloadResourceGroupType.NAUTICAL_MAPS);
    DownloadResourceGroup nauticalMaps = new DownloadResourceGroup(nauticalMapsGroup, DownloadResourceGroupType.NAUTICAL_MAPS_HEADER);
    DownloadResourceGroup wikivoyageMapsGroup = new DownloadResourceGroup(this, DownloadResourceGroupType.TRAVEL_GROUP);
    DownloadResourceGroup wikivoyageMapsScreen = new DownloadResourceGroup(wikivoyageMapsGroup, DownloadResourceGroupType.WIKIVOYAGE_MAPS);
    DownloadResourceGroup wikivoyageMaps = new DownloadResourceGroup(wikivoyageMapsGroup, DownloadResourceGroupType.WIKIVOYAGE_HEADER);
    Map<WorldRegion, List<IndexItem>> groupByRegion = new LinkedHashMap<>();
    OsmandRegions regs = app.getRegions();
    for (IndexItem ii : resources) {
        if (ii.getType() == DownloadActivityType.VOICE_FILE) {
            if (DownloadActivityType.isVoiceTTS(ii)) {
                voiceTTS.addItem(ii);
            } else if (DownloadActivityType.isVoiceRec(ii)) {
                voiceRec.addItem(ii);
            }
            continue;
        }
        if (ii.getType() == DownloadActivityType.FONT_FILE) {
            fonts.addItem(ii);
            continue;
        }
        if (ii.getType() == DownloadActivityType.DEPTH_CONTOUR_FILE) {
            if (InAppPurchaseHelper.isDepthContoursPurchased(app) || nauticalMaps.size() == 0) {
                nauticalMaps.addItem(ii);
            }
            continue;
        }
        if (ii.getType() == DownloadActivityType.WIKIVOYAGE_FILE) {
            if (app.getTravelHelper() instanceof TravelDbHelper) {
                wikivoyageMaps.addItem(ii);
            }
            continue;
        }
        if (ii.getType() == DownloadActivityType.TRAVEL_FILE) {
            if (ii.getFileName().contains(WIKIVOYAGE_FILE_FILTER)) {
                wikivoyageMaps.addItem(ii);
            }
            continue;
        }
        String basename = ii.getBasename().toLowerCase();
        WorldRegion wg = regs.getRegionDataByDownloadName(basename);
        if (wg != null) {
            if (!groupByRegion.containsKey(wg)) {
                groupByRegion.put(wg, new ArrayList<IndexItem>());
            }
            groupByRegion.get(wg).add(ii);
        } else {
            if (ii.getFileName().startsWith("World_")) {
                if (ii.getFileName().toLowerCase().startsWith(WORLD_SEAMARKS_KEY) || ii.getFileName().toLowerCase().startsWith(WORLD_SEAMARKS_OLD_KEY)) {
                    nauticalMaps.addItem(ii);
                } else {
                    worldMaps.addItem(ii);
                }
            } else {
                otherMaps.addItem(ii);
            }
        }
    }
    this.groupByRegion = groupByRegion;
    List<WorldRegion> customRegions = OsmandPlugin.getCustomDownloadRegions();
    if (!Algorithms.isEmpty(customRegions)) {
        addGroup(extraMapsGroup);
        for (WorldRegion region : customRegions) {
            buildRegionsGroups(region, extraMapsGroup);
        }
    }
    LinkedList<WorldRegion> queue = new LinkedList<WorldRegion>();
    LinkedList<DownloadResourceGroup> parent = new LinkedList<DownloadResourceGroup>();
    DownloadResourceGroup worldSubregions = new DownloadResourceGroup(this, DownloadResourceGroupType.SUBREGIONS);
    addGroup(worldSubregions);
    for (WorldRegion rg : region.getSubregions()) {
        queue.add(rg);
        parent.add(worldSubregions);
    }
    while (!queue.isEmpty()) {
        WorldRegion reg = queue.pollFirst();
        DownloadResourceGroup parentGroup = parent.pollFirst();
        List<WorldRegion> subregions = reg.getSubregions();
        DownloadResourceGroup mainGrp = new DownloadResourceGroup(parentGroup, DownloadResourceGroupType.REGION, reg.getRegionId());
        mainGrp.region = reg;
        parentGroup.addGroup(mainGrp);
        DownloadResourceGroup flatFiles = new DownloadResourceGroup(mainGrp, REGION_MAPS);
        List<IndexItem> list = groupByRegion.get(reg);
        if (list != null) {
            for (IndexItem ii : list) {
                flatFiles.addItem(ii);
            }
        }
        if (list != null || !reg.isContinent()) {
            mainGrp.addGroup(flatFiles);
        }
        DownloadResourceGroup subRegions = new DownloadResourceGroup(mainGrp, DownloadResourceGroupType.SUBREGIONS);
        mainGrp.addGroup(subRegions);
        // add to processing queue
        for (WorldRegion rg : subregions) {
            queue.add(rg);
            parent.add(subRegions);
        }
    }
    // Possible improvements
    // 1. if there is no subregions no need to create resource group REGIONS_MAPS - objection raise diversity and there is no value
    // 2. if there is no subregions and there only 1 index item it could be merged to the level up - objection there is no such maps
    // 3. if hillshade/srtm is disabled, all maps from inner level could be combined into 1
    addGroup(worldMaps);
    nauticalMapsScreen.addGroup(nauticalMaps);
    nauticalMapsGroup.addGroup(nauticalMapsScreen);
    addGroup(nauticalMapsGroup);
    wikivoyageMapsScreen.addGroup(wikivoyageMaps);
    wikivoyageMapsGroup.addGroup(wikivoyageMapsScreen);
    addGroup(wikivoyageMapsGroup);
    if (otherMaps.size() > 0) {
        addGroup(otherMapsGroup);
    }
    voiceScreenTTS.addGroup(voiceTTS);
    voiceScreenRec.addGroup(voiceRec);
    if (fonts.getIndividualResources() != null) {
        fontScreen.addGroup(fonts);
    }
    otherGroup.addGroup(voiceScreenTTS);
    otherGroup.addGroup(voiceScreenRec);
    if (fonts.getIndividualResources() != null) {
        otherGroup.addGroup(fontScreen);
    }
    addGroup(otherGroup);
    createHillshadeSRTMGroups();
    replaceIndividualSrtmWithGroups(region);
    createMultipleDownloadItems(region);
    trimEmptyGroups();
    updateLoadedFiles();
    return true;
}
Also used : WorldRegion(net.osmand.map.WorldRegion) TravelDbHelper(net.osmand.plus.wikivoyage.data.TravelDbHelper) AssetIndexItem(net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) OsmandRegions(net.osmand.map.OsmandRegions) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 28 with WorldRegion

use of net.osmand.map.WorldRegion in project Osmand by osmandapp.

the class DownloadResources method collectItemsOfType.

@Nullable
private List<DownloadItem> collectItemsOfType(@NonNull List<WorldRegion> regions, @NonNull DownloadActivityType type) {
    List<DownloadItem> collectedItems = new ArrayList<>();
    for (WorldRegion region : regions) {
        boolean found = false;
        for (DownloadItem item : getDownloadItems(region)) {
            if (item.getType() == type) {
                found = true;
                collectedItems.add(item);
                break;
            }
        }
        if (!found)
            return null;
    }
    return collectedItems;
}
Also used : WorldRegion(net.osmand.map.WorldRegion) ArrayList(java.util.ArrayList) Nullable(androidx.annotation.Nullable)

Example 29 with WorldRegion

use of net.osmand.map.WorldRegion in project Osmand by osmandapp.

the class DownloadResources method isOsmandMapRegion.

public boolean isOsmandMapRegion(@NonNull String mapFileName) {
    OsmandRegions osmandRegions = app.getRegions();
    String downloadName = WorldRegion.getRegionDownloadName(mapFileName);
    WorldRegion region = osmandRegions.getRegionDataByDownloadName(downloadName);
    return region != null && (region.isRegionRoadsDownload() || region.isRegionMapDownload());
}
Also used : OsmandRegions(net.osmand.map.OsmandRegions) WorldRegion(net.osmand.map.WorldRegion)

Example 30 with WorldRegion

use of net.osmand.map.WorldRegion in project Osmand by osmandapp.

the class DownloadResources method replaceIndividualSrtmWithGroups.

private void replaceIndividualSrtmWithGroups(@NonNull WorldRegion region) {
    DownloadResourceGroup group = getRegionMapsGroup(region);
    if (group != null) {
        boolean useMetersByDefault = SrtmDownloadItem.isUseMetricByDefault(app);
        boolean listModified = false;
        DownloadActivityType srtmType = DownloadActivityType.SRTM_COUNTRY_FILE;
        List<DownloadItem> individualItems = group.getIndividualDownloadItems();
        if (isListContainsType(individualItems, srtmType)) {
            List<IndexItem> srtmIndexes = new ArrayList<>();
            for (DownloadItem item : individualItems) {
                if (item.getType() == srtmType && item instanceof IndexItem) {
                    srtmIndexes.add((IndexItem) item);
                }
            }
            if (srtmIndexes.size() > 0) {
                individualItems.removeAll(srtmIndexes);
                group.addItem(new SrtmDownloadItem(srtmIndexes, useMetersByDefault));
            }
            listModified = true;
        }
        if (listModified) {
            sortDownloadItems(individualItems);
        }
    }
    List<WorldRegion> subRegions = region.getSubregions();
    if (!Algorithms.isEmpty(subRegions)) {
        for (WorldRegion subRegion : subRegions) {
            replaceIndividualSrtmWithGroups(subRegion);
        }
    }
}
Also used : WorldRegion(net.osmand.map.WorldRegion) ArrayList(java.util.ArrayList) AssetIndexItem(net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem)

Aggregations

WorldRegion (net.osmand.map.WorldRegion)77 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)27 ArrayList (java.util.ArrayList)22 OsmandRegions (net.osmand.map.OsmandRegions)21 LinkedList (java.util.LinkedList)16 LatLon (net.osmand.data.LatLon)16 LinkedHashMap (java.util.LinkedHashMap)15 IndexItem (net.osmand.plus.download.IndexItem)11 Paint (android.graphics.Paint)10 TextPaint (android.text.TextPaint)10 Location (net.osmand.Location)10 AssetIndexItem (net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem)10 CustomRegion (net.osmand.plus.download.CustomRegion)8 DownloadResources (net.osmand.plus.download.DownloadResources)8 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)7 HashMap (java.util.HashMap)7 NonNull (androidx.annotation.NonNull)6 IOException (java.io.IOException)6 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6