This commit is contained in:
max-klaus 2019-11-18 14:23:14 +03:00
parent 8703062cf1
commit 3cbfcb05ef
2 changed files with 21 additions and 29 deletions

View file

@ -1,11 +1,5 @@
package net.osmand.plus.resources; package net.osmand.plus.resources;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.ResultMatcher; import net.osmand.ResultMatcher;
@ -15,44 +9,50 @@ import net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter;
import net.osmand.binary.BinaryMapIndexReader.SearchRequest; import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
import net.osmand.data.Amenity; import net.osmand.data.Amenity;
import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiCategory;
import net.osmand.plus.resources.ResourceManager.BinaryMapReaderResource;
import net.osmand.plus.resources.ResourceManager.BinaryMapReaderResourceType;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class AmenityIndexRepositoryBinary implements AmenityIndexRepository { public class AmenityIndexRepositoryBinary implements AmenityIndexRepository {
private final static Log log = PlatformUtil.getLog(AmenityIndexRepositoryBinary.class); private final static Log log = PlatformUtil.getLog(AmenityIndexRepositoryBinary.class);
private final BinaryMapIndexReader index; private BinaryMapReaderResource resource;
public AmenityIndexRepositoryBinary(BinaryMapIndexReader index) { public AmenityIndexRepositoryBinary(BinaryMapReaderResource resource) {
this.index = index; this.resource = resource;
}
private BinaryMapIndexReader getOpenFile() {
return resource.getReader(BinaryMapReaderResourceType.POI);
} }
@Override @Override
public void close() { public void close() {
try {
index.close();
} catch (IOException e) {
e.printStackTrace();
}
} }
@Override @Override
public boolean checkContains(double latitude, double longitude) { public boolean checkContains(double latitude, double longitude) {
int x31 = MapUtils.get31TileNumberX(longitude); int x31 = MapUtils.get31TileNumberX(longitude);
int y31 = MapUtils.get31TileNumberY(latitude); int y31 = MapUtils.get31TileNumberY(latitude);
return index.containsPoiData(x31, y31, x31, y31); return getOpenFile().containsPoiData(x31, y31, x31, y31);
} }
@Override @Override
public boolean checkContainsInt(int top31, int left31, int bottom31, int right31) { public boolean checkContainsInt(int top31, int left31, int bottom31, int right31) {
return index.containsPoiData(left31, top31, right31, bottom31); return getOpenFile().containsPoiData(left31, top31, right31, bottom31);
} }
public synchronized Map<PoiCategory, List<String>> searchAmenityCategoriesByName(String query, Map<PoiCategory, List<String>> map) { public synchronized Map<PoiCategory, List<String>> searchAmenityCategoriesByName(String query, Map<PoiCategory, List<String>> map) {
try { try {
return index.searchPoiCategoriesByName(query, map); return getOpenFile().searchPoiCategoriesByName(query, map);
} catch (IOException e) { } catch (IOException e) {
log.error("Error searching amenities", e); //$NON-NLS-1$ log.error("Error searching amenities", e); //$NON-NLS-1$
} }
@ -65,6 +65,7 @@ public class AmenityIndexRepositoryBinary implements AmenityIndexRepository {
List<Amenity> amenities = Collections.emptyList(); List<Amenity> amenities = Collections.emptyList();
SearchRequest<Amenity> req = BinaryMapIndexReader.buildSearchPoiRequest(x, y, query, l, r, t, b,resulMatcher); SearchRequest<Amenity> req = BinaryMapIndexReader.buildSearchPoiRequest(x, y, query, l, r, t, b,resulMatcher);
try { try {
BinaryMapIndexReader index = getOpenFile();
amenities = index.searchPoiByName(req); amenities = index.searchPoiByName(req);
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
String nm = ""; String nm = "";
@ -90,7 +91,7 @@ public class AmenityIndexRepositoryBinary implements AmenityIndexRepository {
filter, matcher); filter, matcher);
List<Amenity> result = null; List<Amenity> result = null;
try { try {
result = index.searchPoi(req); result = getOpenFile().searchPoi(req);
} catch (IOException e) { } catch (IOException e) {
log.error("Error searching amenities", e); //$NON-NLS-1$ log.error("Error searching amenities", e); //$NON-NLS-1$
} }
@ -108,7 +109,7 @@ public class AmenityIndexRepositoryBinary implements AmenityIndexRepository {
SearchRequest<Amenity> req = BinaryMapIndexReader.buildSearchPoiRequest(locations, radius, SearchRequest<Amenity> req = BinaryMapIndexReader.buildSearchPoiRequest(locations, radius,
filter, matcher ); filter, matcher );
try { try {
result = index.searchPoi(req); result = getOpenFile().searchPoi(req);
} catch (IOException e) { } catch (IOException e) {
log.error("Error searching amenities", e); //$NON-NLS-1$ log.error("Error searching amenities", e); //$NON-NLS-1$
return result; return result;

View file

@ -62,7 +62,6 @@ import java.io.InputStream;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
@ -72,8 +71,6 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import gnu.trove.iterator.TLongObjectIterator;
import gnu.trove.map.hash.TIntObjectHashMap;
import gnu.trove.map.hash.TLongObjectHashMap; import gnu.trove.map.hash.TLongObjectHashMap;
import static net.osmand.plus.download.DownloadOsmandIndexesHelper.assetMapping; import static net.osmand.plus.download.DownloadOsmandIndexesHelper.assetMapping;
@ -736,13 +733,7 @@ public class ResourceManager {
resource.setUseForPublicTransport(true); resource.setUseForPublicTransport(true);
} }
if (mapReader.containsPoiData()) { if (mapReader.containsPoiData()) {
try { amenityRepositories.put(f.getName(), new AmenityIndexRepositoryBinary(resource));
RandomAccessFile raf = new RandomAccessFile(f, "r"); //$NON-NLS-1$
amenityRepositories.put(f.getName(), new AmenityIndexRepositoryBinary(new BinaryMapIndexReader(raf, mapReader)));
} catch (IOException e) {
log.error("Exception reading " + f.getAbsolutePath(), e); //$NON-NLS-1$
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$
}
} }
} }
} catch (SQLiteException e) { } catch (SQLiteException e) {