refactor BitmapTileLayer:
- move to layer.tile.bitmap - extract BitmapTileLoader - bring back GWT BitmapTileLayer to life
This commit is contained in:
@@ -14,23 +14,15 @@
|
||||
* 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.layers.tile;
|
||||
package org.oscim.layers.tile.bitmap;
|
||||
|
||||
import static org.oscim.layers.tile.MapTile.State.CANCEL;
|
||||
|
||||
import java.util.concurrent.CancellationException;
|
||||
|
||||
import org.oscim.backend.canvas.Bitmap;
|
||||
import org.oscim.core.MapElement;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.event.Event;
|
||||
import org.oscim.layers.tile.TileLayer;
|
||||
import org.oscim.layers.tile.TileLoader;
|
||||
import org.oscim.layers.tile.TileManager;
|
||||
import org.oscim.layers.tile.VectorTileRenderer;
|
||||
import org.oscim.map.Map;
|
||||
import org.oscim.renderer.elements.BitmapLayer;
|
||||
import org.oscim.renderer.elements.ElementLayers;
|
||||
import org.oscim.tiling.ITileDataSink;
|
||||
import org.oscim.tiling.ITileDataSource;
|
||||
import org.oscim.tiling.ITileDataSource.QueryResult;
|
||||
import org.oscim.tiling.TileSource;
|
||||
import org.oscim.utils.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
@@ -110,58 +102,4 @@ public class BitmapTileLayer extends TileLayer {
|
||||
protected TileLoader createLoader(TileManager tm) {
|
||||
return new BitmapTileLoader(tm, mTileSource);
|
||||
}
|
||||
|
||||
class BitmapTileLoader extends TileLoader implements ITileDataSink {
|
||||
|
||||
private final ITileDataSource mTileDataSource;
|
||||
private MapTile mTile;
|
||||
|
||||
public BitmapTileLoader(TileManager tileManager, TileSource tileSource) {
|
||||
super(tileManager);
|
||||
mTileDataSource = tileSource.getDataSource();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup() {
|
||||
mTile = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean executeJob(MapTile tile) {
|
||||
mTile = tile;
|
||||
QueryResult result = null;
|
||||
try {
|
||||
result = mTileDataSource.executeQuery(tile, this);
|
||||
} catch (CancellationException e) {
|
||||
log.debug("{} was canceled", mTile);
|
||||
} catch (Exception e) {
|
||||
log.debug("{} {}", mTile, e.getMessage());
|
||||
} finally {
|
||||
mTile = null;
|
||||
}
|
||||
return result == QueryResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTileImage(Bitmap bitmap) {
|
||||
if (isCanceled() || mTile.state(CANCEL))
|
||||
throw new CancellationException();
|
||||
|
||||
BitmapLayer l = new BitmapLayer(false);
|
||||
l.setBitmap(bitmap, Tile.SIZE, Tile.SIZE);
|
||||
mTile.layers = new ElementLayers();
|
||||
mTile.layers.setTextureLayers(l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(MapElement element) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completed(boolean success) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
75
vtm/src/org/oscim/layers/tile/bitmap/BitmapTileLoader.java
Normal file
75
vtm/src/org/oscim/layers/tile/bitmap/BitmapTileLoader.java
Normal file
@@ -0,0 +1,75 @@
|
||||
package org.oscim.layers.tile.bitmap;
|
||||
|
||||
import static org.oscim.layers.tile.MapTile.State.CANCEL;
|
||||
|
||||
import java.util.concurrent.CancellationException;
|
||||
|
||||
import org.oscim.backend.canvas.Bitmap;
|
||||
import org.oscim.core.MapElement;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.layers.tile.MapTile;
|
||||
import org.oscim.layers.tile.TileLoader;
|
||||
import org.oscim.layers.tile.TileManager;
|
||||
import org.oscim.renderer.elements.BitmapLayer;
|
||||
import org.oscim.renderer.elements.ElementLayers;
|
||||
import org.oscim.tiling.ITileDataSink;
|
||||
import org.oscim.tiling.ITileDataSource;
|
||||
import org.oscim.tiling.ITileDataSource.QueryResult;
|
||||
import org.oscim.tiling.TileSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class BitmapTileLoader extends TileLoader implements ITileDataSink {
|
||||
|
||||
protected static final Logger log = LoggerFactory.getLogger(BitmapTileLoader.class);
|
||||
|
||||
private final ITileDataSource mTileDataSource;
|
||||
private MapTile mTile;
|
||||
|
||||
public BitmapTileLoader(TileManager tileManager, TileSource tileSource) {
|
||||
super(tileManager);
|
||||
mTileDataSource = tileSource.getDataSource();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup() {
|
||||
mTile = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean executeJob(MapTile tile) {
|
||||
mTile = tile;
|
||||
QueryResult result = null;
|
||||
try {
|
||||
result = mTileDataSource.executeQuery(tile, this);
|
||||
} catch (CancellationException e) {
|
||||
log.debug("{} was canceled", mTile);
|
||||
} catch (Exception e) {
|
||||
log.debug("{} {}", mTile, e.getMessage());
|
||||
} finally {
|
||||
mTile = null;
|
||||
}
|
||||
return result == QueryResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTileImage(Bitmap bitmap) {
|
||||
if (isCanceled() || mTile.state(CANCEL))
|
||||
throw new CancellationException();
|
||||
|
||||
BitmapLayer l = new BitmapLayer(false);
|
||||
l.setBitmap(bitmap, Tile.SIZE, Tile.SIZE);
|
||||
mTile.layers = new ElementLayers();
|
||||
mTile.layers.setTextureLayers(l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(MapElement element) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completed(boolean success) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import org.oscim.event.Gesture;
|
||||
import org.oscim.event.GestureDetector;
|
||||
import org.oscim.event.MotionEvent;
|
||||
import org.oscim.layers.MapEventLayer;
|
||||
import org.oscim.layers.tile.BitmapTileLayer;
|
||||
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
|
||||
import org.oscim.layers.tile.vector.OsmTileLayer;
|
||||
import org.oscim.layers.tile.vector.VectorTileLayer;
|
||||
import org.oscim.renderer.MapRenderer;
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.oscim.tiling;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.oscim.layers.tile.BitmapTileLayer.FadeStep;
|
||||
import org.oscim.layers.tile.bitmap.BitmapTileLayer.FadeStep;
|
||||
|
||||
public abstract class TileSource {
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.oscim.tiling.source.bitmap;
|
||||
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.layers.tile.BitmapTileLayer.FadeStep;
|
||||
import org.oscim.layers.tile.bitmap.BitmapTileLayer.FadeStep;
|
||||
|
||||
/**
|
||||
* Do not use in applications unless you read through and comply to
|
||||
@@ -23,7 +23,7 @@ public class DefaultSources {
|
||||
|
||||
public static class StamenToner extends BitmapTileSource {
|
||||
public StamenToner() {
|
||||
super("http://a.tile.stamen.com/toner", 0, 16);
|
||||
super("http://opensciencemap.org/cors-stamen/toner", 0, 16);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public class DefaultSources {
|
||||
private final StringBuilder sb = new StringBuilder(32);
|
||||
|
||||
public ArcGISWorldShaded() {
|
||||
super("http://server.arcgisonline.com/ArcGIS/rest/services", 0, 6);
|
||||
super("http://server.arcgisonline.com/ArcGIS/rest/services", 0, 13);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user