Mapsforge: multiple map files, closes #208
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2016 devemux86
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.tiling.source.mapfile;
|
||||
|
||||
public interface IMapFileTileSource {
|
||||
|
||||
void setCallback(MapFileTileSource.Callback callback);
|
||||
|
||||
void setPreferredLanguage(String preferredLanguage);
|
||||
}
|
||||
@@ -30,7 +30,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
|
||||
public class MapFileTileSource extends TileSource {
|
||||
public class MapFileTileSource extends TileSource implements IMapFileTileSource {
|
||||
private static final Logger log = LoggerFactory.getLogger(MapFileTileSource.class);
|
||||
|
||||
/**
|
||||
@@ -70,6 +70,7 @@ public class MapFileTileSource extends TileSource {
|
||||
return MapFileUtils.extract(s, preferredLanguage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCallback(Callback callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
@@ -90,6 +91,7 @@ public class MapFileTileSource extends TileSource {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPreferredLanguage(String preferredLanguage) {
|
||||
this.preferredLanguage = preferredLanguage;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2016 devemux86
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.tiling.source.mapfile;
|
||||
|
||||
import org.oscim.backend.canvas.Bitmap;
|
||||
import org.oscim.core.MapElement;
|
||||
import org.oscim.tiling.ITileDataSink;
|
||||
import org.oscim.tiling.QueryResult;
|
||||
|
||||
class MultiMapDataSink implements ITileDataSink {
|
||||
|
||||
private QueryResult result;
|
||||
private final ITileDataSink tileDataSink;
|
||||
|
||||
MultiMapDataSink(ITileDataSink tileDataSink) {
|
||||
this.tileDataSink = tileDataSink;
|
||||
}
|
||||
|
||||
QueryResult getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(MapElement element) {
|
||||
tileDataSink.process(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTileImage(Bitmap bitmap) {
|
||||
tileDataSink.setTileImage(bitmap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completed(QueryResult result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2016 devemux86
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.tiling.source.mapfile;
|
||||
|
||||
import org.oscim.layers.tile.MapTile;
|
||||
import org.oscim.tiling.ITileDataSink;
|
||||
import org.oscim.tiling.ITileDataSource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MultiMapDatabase implements ITileDataSource {
|
||||
|
||||
private final List<MapDatabase> mapDatabases = new ArrayList<>();
|
||||
|
||||
public boolean add(MapDatabase mapDatabase) {
|
||||
if (mapDatabases.contains(mapDatabase)) {
|
||||
throw new IllegalArgumentException("Duplicate map database");
|
||||
}
|
||||
return mapDatabases.add(mapDatabase);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void query(MapTile tile, ITileDataSink mapDataSink) {
|
||||
MultiMapDataSink multiMapDataSink = new MultiMapDataSink(mapDataSink);
|
||||
for (MapDatabase mapDatabase : mapDatabases) {
|
||||
mapDatabase.query(tile, multiMapDataSink);
|
||||
}
|
||||
mapDataSink.completed(multiMapDataSink.getResult());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
for (MapDatabase mapDatabase : mapDatabases) {
|
||||
mapDatabase.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
for (MapDatabase mapDatabase : mapDatabases) {
|
||||
mapDatabase.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright 2016 devemux86
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.tiling.source.mapfile;
|
||||
|
||||
import org.oscim.core.BoundingBox;
|
||||
import org.oscim.tiling.ITileDataSource;
|
||||
import org.oscim.tiling.TileSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MultiMapFileTileSource extends TileSource implements IMapFileTileSource {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MultiMapFileTileSource.class);
|
||||
|
||||
private final List<MapFileTileSource> mapFileTileSources = new ArrayList<>();
|
||||
|
||||
public MultiMapFileTileSource() {
|
||||
this(0, 17);
|
||||
}
|
||||
|
||||
public MultiMapFileTileSource(int zoomMin, int zoomMax) {
|
||||
super(zoomMin, zoomMax);
|
||||
}
|
||||
|
||||
public boolean add(MapFileTileSource mapFileTileSource) {
|
||||
if (mapFileTileSources.contains(mapFileTileSource)) {
|
||||
throw new IllegalArgumentException("Duplicate map file tile source");
|
||||
}
|
||||
return mapFileTileSources.add(mapFileTileSource);
|
||||
}
|
||||
|
||||
public BoundingBox getBoundingBox() {
|
||||
BoundingBox boundingBox = null;
|
||||
for (MapFileTileSource mapFileTileSource : mapFileTileSources) {
|
||||
boundingBox = (boundingBox == null) ? mapFileTileSource.getMapInfo().boundingBox : boundingBox.extendBoundingBox(mapFileTileSource.getMapInfo().boundingBox);
|
||||
}
|
||||
return boundingBox;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITileDataSource getDataSource() {
|
||||
MultiMapDatabase multiMapDatabase = new MultiMapDatabase();
|
||||
for (MapFileTileSource mapFileTileSource : mapFileTileSources) {
|
||||
try {
|
||||
multiMapDatabase.add(new MapDatabase(mapFileTileSource));
|
||||
} catch (IOException e) {
|
||||
log.debug(e.getMessage());
|
||||
}
|
||||
}
|
||||
return multiMapDatabase;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OpenResult open() {
|
||||
OpenResult openResult = OpenResult.SUCCESS;
|
||||
for (MapFileTileSource mapFileTileSource : mapFileTileSources) {
|
||||
OpenResult result = mapFileTileSource.open();
|
||||
if (result != OpenResult.SUCCESS)
|
||||
openResult = result;
|
||||
}
|
||||
return openResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
for (MapFileTileSource mapFileTileSource : mapFileTileSources) {
|
||||
mapFileTileSource.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCallback(MapFileTileSource.Callback callback) {
|
||||
for (MapFileTileSource mapFileTileSource : mapFileTileSources) {
|
||||
mapFileTileSource.setCallback(callback);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPreferredLanguage(String preferredLanguage) {
|
||||
for (MapFileTileSource mapFileTileSource : mapFileTileSources) {
|
||||
mapFileTileSource.setPreferredLanguage(preferredLanguage);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user