use of net.osmand.binary.BinaryMapIndexReader.TagValuePair in project OsmAnd-tools by osmandapp.
the class BinaryMapIndexWriter method writeMapEncodingRules.
public void writeMapEncodingRules(TIntObjectMap<TagValuePair> decodingRules) throws IOException {
for (int i = 1; i <= decodingRules.size(); i++) {
TagValuePair value = decodingRules.get(i);
MapEncodingRule.Builder builder = OsmandOdb.OsmAndMapIndex.MapEncodingRule.newBuilder();
if (value == null) {
break;
}
builder.setTag(value.tag);
if (value.value != null) {
builder.setValue(value.value);
}
builder.setType(value.additionalAttribute);
MapEncodingRule rulet = builder.build();
codedOutStream.writeMessage(OsmandOdb.OsmAndMapIndex.RULES_FIELD_NUMBER, rulet);
}
}
use of net.osmand.binary.BinaryMapIndexReader.TagValuePair in project Osmand by osmandapp.
the class MapRenderRepositories method readMapObjectsForRendering.
private MapIndex readMapObjectsForRendering(final int zoom, final RenderingRuleSearchRequest renderingReq, ArrayList<BinaryMapDataObject> tempResult, ArrayList<BinaryMapDataObject> basemapResult, TLongSet ids, int[] count, boolean[] ocean, boolean[] land, List<BinaryMapDataObject> coastLines, List<BinaryMapDataObject> basemapCoastLines, int leftX, int rightX, int bottomY, int topY) {
BinaryMapIndexReader.SearchFilter searchFilter = new BinaryMapIndexReader.SearchFilter() {
@Override
public boolean accept(TIntArrayList types, BinaryMapIndexReader.MapIndex root) {
for (int j = 0; j < types.size(); j++) {
int type = types.get(j);
TagValuePair pair = root.decodeType(type);
if (pair != null) {
// TODO is it fast enough ?
for (int i = 1; i <= 3; i++) {
renderingReq.setIntFilter(renderingReq.ALL.R_MINZOOM, zoom);
renderingReq.setStringFilter(renderingReq.ALL.R_TAG, pair.tag);
renderingReq.setStringFilter(renderingReq.ALL.R_VALUE, pair.value);
if (renderingReq.search(i, false)) {
return true;
}
}
renderingReq.setStringFilter(renderingReq.ALL.R_TAG, pair.tag);
renderingReq.setStringFilter(renderingReq.ALL.R_VALUE, pair.value);
if (renderingReq.search(RenderingRulesStorage.TEXT_RULES, false)) {
return true;
}
}
}
return false;
}
};
if (zoom > 16) {
searchFilter = null;
}
MapIndex mi = null;
searchRequest = BinaryMapIndexReader.buildSearchRequest(leftX, rightX, topY, bottomY, zoom, searchFilter);
for (BinaryMapIndexReader c : files.values()) {
boolean basemap = c.isBasemap();
searchRequest.clearSearchResults();
List<BinaryMapDataObject> res;
try {
res = c.searchMapIndex(searchRequest);
} catch (IOException e) {
res = new ArrayList<BinaryMapDataObject>();
// $NON-NLS-1$
log.debug("Search failed " + c.getRegionNames(), e);
}
if (res.size() > 0) {
if (basemap) {
renderedState |= 1;
} else {
renderedState |= 2;
}
}
for (BinaryMapDataObject r : res) {
if (checkForDuplicateObjectIds && !basemap) {
if (ids.contains(r.getId()) && r.getId() > 0) {
// do not add object twice
continue;
}
ids.add(r.getId());
}
count[0]++;
if (r.containsType(r.getMapIndex().coastlineEncodingType)) {
if (basemap) {
basemapCoastLines.add(r);
} else {
coastLines.add(r);
}
} else {
// do not mess coastline and other types
if (basemap) {
basemapResult.add(r);
} else {
tempResult.add(r);
}
}
if (checkWhetherInterrupted()) {
return null;
}
}
if (searchRequest.isOcean()) {
mi = c.getMapIndexes().get(0);
ocean[0] = true;
}
if (searchRequest.isLand()) {
mi = c.getMapIndexes().get(0);
land[0] = true;
}
}
return mi;
}
use of net.osmand.binary.BinaryMapIndexReader.TagValuePair 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);
}
use of net.osmand.binary.BinaryMapIndexReader.TagValuePair 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));
}
}
}
}
}
}
}
use of net.osmand.binary.BinaryMapIndexReader.TagValuePair 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);
}
Aggregations