Search in sources :

Example 16 with BinaryMapDataObject

use of net.osmand.binary.BinaryMapDataObject in project Osmand by osmandapp.

the class OsmandRenderer method sortObjectsByProperOrder.

private void sortObjectsByProperOrder(RenderingContext rc, List<BinaryMapDataObject> objects, RenderingRuleSearchRequest render, List<MapDataObjectPrimitive> pointsArray, List<MapDataObjectPrimitive> polygonsArray, List<MapDataObjectPrimitive> linesResArray) {
    int sz = objects.size();
    List<MapDataObjectPrimitive> linesArray = new ArrayList<OsmandRenderer.MapDataObjectPrimitive>();
    if (render != null) {
        render.clearState();
        float mult = (float) (1. / MapUtils.getPowZoom(Math.max(31 - (rc.zoom + 8), 0)));
        for (int i = 0; i < sz; i++) {
            BinaryMapDataObject o = objects.get(i);
            for (int j = 0; j < o.getTypes().length; j++) {
                int wholeType = o.getTypes()[j];
                int layer = 0;
                if (o.getPointsLength() > 1) {
                    layer = o.getSimpleLayer();
                }
                TagValuePair pair = o.getMapIndex().decodeType(wholeType);
                if (pair != null) {
                    render.setTagValueZoomLayer(pair.tag, pair.value, rc.zoom, layer, o);
                    render.setBooleanFilter(render.ALL.R_AREA, o.isArea());
                    render.setBooleanFilter(render.ALL.R_POINT, o.getPointsLength() == 1);
                    render.setBooleanFilter(render.ALL.R_CYCLE, o.isCycle());
                    if (render.search(RenderingRulesStorage.ORDER_RULES)) {
                        int objectType = render.getIntPropertyValue(render.ALL.R_OBJECT_TYPE);
                        boolean ignorePointArea = render.getIntPropertyValue(render.ALL.R_IGNORE_POLYGON_AS_POINT_AREA) != 0;
                        int order = render.getIntPropertyValue(render.ALL.R_ORDER);
                        MapDataObjectPrimitive mapObj = new MapDataObjectPrimitive();
                        mapObj.objectType = objectType;
                        mapObj.order = order;
                        mapObj.typeInd = j;
                        mapObj.obj = o;
                        if (objectType == 3) {
                            MapDataObjectPrimitive pointObj = mapObj;
                            pointObj.objectType = 1;
                            double area = polygonArea(mapObj, mult);
                            mapObj.area = area;
                            if (area > MAX_V) {
                                mapObj.order = mapObj.order + (1. / area);
                                if (order < DEFAULT_POLYGON_MAX) {
                                    polygonsArray.add(mapObj);
                                } else {
                                    linesArray.add(mapObj);
                                }
                                if (area > MAX_V_AREA || ignorePointArea) {
                                    pointsArray.add(pointObj);
                                }
                            }
                        } else if (objectType == 1) {
                            pointsArray.add(mapObj);
                        } else {
                            linesArray.add(mapObj);
                        }
                        if (render.isSpecified(render.ALL.R_SHADOW_LEVEL)) {
                            rc.shadowLevelMin = Math.min(rc.shadowLevelMin, order);
                            rc.shadowLevelMax = Math.max(rc.shadowLevelMax, order);
                            render.clearValue(render.ALL.R_SHADOW_LEVEL);
                        }
                    }
                }
            }
            if (rc.interrupted) {
                return;
            }
        }
    }
    Collections.sort(polygonsArray, sortByOrder());
    Collections.sort(pointsArray, sortByOrder());
    Collections.sort(linesArray, sortByOrder());
    filterLinesByDensity(rc, linesResArray, linesArray);
}
Also used : BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) TagValuePair(net.osmand.binary.BinaryMapIndexReader.TagValuePair) Paint(android.graphics.Paint)

Example 17 with BinaryMapDataObject

use of net.osmand.binary.BinaryMapDataObject in project Osmand by osmandapp.

the class DownloadedRegionsLayer method getWorldRegionFromPoint.

private void getWorldRegionFromPoint(RotatedTileBox tb, PointF point, List<? super DownloadMapObject> dataObjects) {
    int zoom = tb.getZoom();
    if (zoom >= ZOOM_TO_SHOW_SELECTION_ST && zoom < ZOOM_TO_SHOW_SELECTION && data.results != null && osmandRegions.isInitialized()) {
        LatLon pointLatLon = tb.getLatLonFromPixel(point.x, point.y);
        int point31x = MapUtils.get31TileNumberX(pointLatLon.getLongitude());
        int point31y = MapUtils.get31TileNumberY(pointLatLon.getLatitude());
        List<BinaryMapDataObject> result = new LinkedList<>(data.results);
        Iterator<BinaryMapDataObject> it = result.iterator();
        while (it.hasNext()) {
            BinaryMapDataObject o = it.next();
            boolean isRegion = true;
            for (int i = 0; i < o.getTypes().length; i++) {
                TagValuePair tp = o.getMapIndex().decodeType(o.getTypes()[i]);
                if ("boundary".equals(tp.value)) {
                    isRegion = false;
                    break;
                }
            }
            if (!isRegion || !osmandRegions.contain(o, point31x, point31y)) {
                it.remove();
            }
        }
        OsmandRegions osmandRegions = app.getRegions();
        for (BinaryMapDataObject o : result) {
            String fullName = osmandRegions.getFullName(o);
            WorldRegion region = osmandRegions.getRegionData(fullName);
            if (region != null && region.isRegionMapDownload()) {
                List<IndexItem> indexItems = app.getDownloadThread().getIndexes().getIndexItems(region);
                List<IndexItem> dataItems = new LinkedList<>();
                IndexItem regularMapItem = null;
                for (IndexItem item : indexItems) {
                    if (item.isDownloaded() || app.getDownloadThread().isDownloading(item)) {
                        dataItems.add(item);
                        if (item.getType() == DownloadActivityType.NORMAL_FILE) {
                            regularMapItem = item;
                        }
                    }
                }
                if (dataItems.isEmpty() && regularMapItem != null) {
                    dataItems.add(regularMapItem);
                }
                if (!dataItems.isEmpty()) {
                    for (IndexItem item : dataItems) {
                        dataObjects.add(new DownloadMapObject(o, region, item, null));
                    }
                } else {
                    String downloadName = osmandRegions.getDownloadName(o);
                    List<LocalIndexInfo> infos = helper.getLocalIndexInfos(downloadName);
                    if (infos.size() == 0) {
                        dataObjects.add(new DownloadMapObject(o, region, null, null));
                    } else {
                        for (LocalIndexInfo info : infos) {
                            dataObjects.add(new DownloadMapObject(o, region, null, info));
                        }
                    }
                }
            }
        }
    }
}
Also used : WorldRegion(net.osmand.map.WorldRegion) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) LinkedList(java.util.LinkedList) IndexItem(net.osmand.plus.download.IndexItem) LatLon(net.osmand.data.LatLon) OsmandRegions(net.osmand.map.OsmandRegions) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) TagValuePair(net.osmand.binary.BinaryMapIndexReader.TagValuePair) LocalIndexInfo(net.osmand.plus.activities.LocalIndexInfo)

Example 18 with BinaryMapDataObject

use of net.osmand.binary.BinaryMapDataObject in project Osmand by osmandapp.

the class DownloadedRegionsLayer method onPrepareBufferImage.

@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
    final int zoom = tileBox.getZoom();
    if (zoom < ZOOM_TO_SHOW_SELECTION_ST) {
        return;
    }
    // draw objects
    if (osmandRegions.isInitialized() && zoom >= ZOOM_TO_SHOW_SELECTION_ST && zoom < ZOOM_TO_SHOW_SELECTION) {
        final List<BinaryMapDataObject> currentObjects = new LinkedList<>();
        if (data.results != null) {
            currentObjects.addAll(data.results);
        }
        final List<BinaryMapDataObject> selectedObjects = new LinkedList<>(this.selectedObjects);
        if (selectedObjects.size() > 0) {
            removeObjectsFromList(currentObjects, selectedObjects);
            drawBorders(canvas, tileBox, selectedObjects, pathSelected, paintSelected);
        }
        if (zoom >= ZOOM_TO_SHOW_BORDERS_ST && zoom < ZOOM_TO_SHOW_BORDERS) {
            if (currentObjects.size() > 0) {
                List<BinaryMapDataObject> downloadedObjects = new ArrayList<>();
                List<BinaryMapDataObject> backupedObjects = new ArrayList<>();
                for (BinaryMapDataObject o : currentObjects) {
                    boolean downloaded = checkIfObjectDownloaded(osmandRegions.getDownloadName(o));
                    boolean backuped = checkIfObjectBackuped(osmandRegions.getDownloadName(o));
                    if (downloaded) {
                        downloadedObjects.add(o);
                    } else if (backuped) {
                        backupedObjects.add(o);
                    }
                }
                if (backupedObjects.size() > 0) {
                    drawBorders(canvas, tileBox, backupedObjects, pathBackuped, paintBackuped);
                }
                if (downloadedObjects.size() > 0) {
                    drawBorders(canvas, tileBox, downloadedObjects, pathDownloaded, paintDownloaded);
                }
            }
        }
    }
}
Also used : BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) ArrayList(java.util.ArrayList) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) LinkedList(java.util.LinkedList)

Example 19 with BinaryMapDataObject

use of net.osmand.binary.BinaryMapDataObject in project Osmand by osmandapp.

the class MenuController method buildMapDownloadButtonAndSizeInfo.

public void buildMapDownloadButtonAndSizeInfo(final LatLon latLon) {
    new AsyncTask<Void, Void, BinaryMapDataObject>() {

        ResourceManager rm;

        OsmandRegions osmandRegions;

        String selectedFullName = "";

        @Override
        protected void onPreExecute() {
            rm = getMapActivity().getMyApplication().getResourceManager();
            osmandRegions = rm.getOsmandRegions();
        }

        @Override
        protected BinaryMapDataObject doInBackground(Void... voids) {
            int point31x = MapUtils.get31TileNumberX(latLon.getLongitude());
            int point31y = MapUtils.get31TileNumberY(latLon.getLatitude());
            List<BinaryMapDataObject> mapDataObjects = null;
            try {
                mapDataObjects = osmandRegions.queryBbox(point31x, point31x, point31y, point31y);
            } catch (IOException e) {
                e.printStackTrace();
            }
            BinaryMapDataObject binaryMapDataObject = null;
            if (mapDataObjects != null) {
                Iterator<BinaryMapDataObject> it = mapDataObjects.iterator();
                while (it.hasNext()) {
                    BinaryMapDataObject o = it.next();
                    if (o.getTypes() != null) {
                        boolean isRegion = true;
                        for (int i = 0; i < o.getTypes().length; i++) {
                            TagValuePair tp = o.getMapIndex().decodeType(o.getTypes()[i]);
                            if ("boundary".equals(tp.value)) {
                                isRegion = false;
                                break;
                            }
                        }
                        if (!isRegion || !osmandRegions.contain(o, point31x, point31y)) {
                            it.remove();
                        }
                    }
                }
                double smallestArea = -1;
                for (BinaryMapDataObject o : mapDataObjects) {
                    String downloadName = osmandRegions.getDownloadName(o);
                    if (!Algorithms.isEmpty(downloadName)) {
                        boolean downloaded = checkIfObjectDownloaded(rm, downloadName);
                        if (downloaded) {
                            binaryMapDataObject = null;
                            break;
                        } else {
                            String fullName = osmandRegions.getFullName(o);
                            WorldRegion region = osmandRegions.getRegionData(fullName);
                            if (region != null && region.isRegionMapDownload()) {
                                double area = OsmandRegions.getArea(o);
                                if (smallestArea == -1) {
                                    smallestArea = area;
                                    selectedFullName = fullName;
                                    binaryMapDataObject = o;
                                } else if (area < smallestArea) {
                                    smallestArea = area;
                                    selectedFullName = fullName;
                                    binaryMapDataObject = o;
                                }
                            }
                        }
                    }
                }
            }
            return binaryMapDataObject;
        }

        @Override
        protected void onPostExecute(BinaryMapDataObject binaryMapDataObject) {
            downloadMapDataObject = binaryMapDataObject;
            downloaded = downloadMapDataObject == null;
            if (!downloaded) {
                downloadThread = getMapActivity().getMyApplication().getDownloadThread();
                downloadRegion = osmandRegions.getRegionData(selectedFullName);
                if (downloadRegion != null && downloadRegion.isRegionMapDownload()) {
                    List<IndexItem> indexItems = downloadThread.getIndexes().getIndexItems(downloadRegion);
                    for (IndexItem item : indexItems) {
                        if (item.getType() == DownloadActivityType.NORMAL_FILE && (item.isDownloaded() || downloadThread.isDownloading(item))) {
                            indexItem = item;
                        }
                    }
                }
                leftDownloadButtonController = new TitleButtonController() {

                    @Override
                    public void buttonPressed() {
                        if (indexItem != null) {
                            if (indexItem.getType() == DownloadActivityType.NORMAL_FILE) {
                                new DownloadValidationManager(getMapActivity().getMyApplication()).startDownload(getMapActivity(), indexItem);
                            }
                        }
                    }
                };
                leftDownloadButtonController.caption = downloadRegion != null ? downloadRegion.getLocaleName() : getMapActivity().getString(R.string.shared_string_download);
                leftDownloadButtonController.leftIconId = R.drawable.ic_action_import;
                titleProgressController = new TitleProgressController() {

                    @Override
                    public void buttonPressed() {
                        if (indexItem != null) {
                            downloadThread.cancelDownload(indexItem);
                        }
                    }
                };
                if (!downloadThread.getIndexes().isDownloadedFromInternet) {
                    if (getMapActivity().getMyApplication().getSettings().isInternetConnectionAvailable()) {
                        downloadThread.runReloadIndexFiles();
                    }
                }
                if (mapContextMenu != null) {
                    mapContextMenu.updateMenuUI();
                }
            }
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : WorldRegion(net.osmand.map.WorldRegion) ResourceManager(net.osmand.plus.resources.ResourceManager) SpannableString(android.text.SpannableString) IOException(java.io.IOException) IndexItem(net.osmand.plus.download.IndexItem) OsmandRegions(net.osmand.map.OsmandRegions) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) TagValuePair(net.osmand.binary.BinaryMapIndexReader.TagValuePair) DownloadValidationManager(net.osmand.plus.download.DownloadValidationManager)

Example 20 with BinaryMapDataObject

use of net.osmand.binary.BinaryMapDataObject 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)

Aggregations

BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)41 IOException (java.io.IOException)12 LinkedHashMap (java.util.LinkedHashMap)11 ArrayList (java.util.ArrayList)10 WorldRegion (net.osmand.map.WorldRegion)10 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)9 File (java.io.File)9 MapIndex (net.osmand.binary.BinaryMapIndexReader.MapIndex)8 TagValuePair (net.osmand.binary.BinaryMapIndexReader.TagValuePair)8 Paint (android.graphics.Paint)7 TIntArrayList (gnu.trove.list.array.TIntArrayList)7 LinkedList (java.util.LinkedList)7 OsmandRegions (net.osmand.map.OsmandRegions)7 HashMap (java.util.HashMap)6 TreeSet (java.util.TreeSet)6 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)6 QuadRect (net.osmand.data.QuadRect)6 TextPaint (android.text.TextPaint)5 RandomAccessFile (java.io.RandomAccessFile)5 Map (java.util.Map)5