Do not catch graphics exception too early, fix #413

This commit is contained in:
Emux 2017-09-27 14:39:01 +03:00
parent 4a848cc08c
commit 27aee33cb9
5 changed files with 120 additions and 93 deletions

View File

@ -31,6 +31,7 @@ import org.oscim.theme.VtmThemes;
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource; import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
import org.oscim.utils.TextureAtlasUtils; import org.oscim.utils.TextureAtlasUtils;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@ -41,51 +42,55 @@ public class AtlasMarkerLayerTest extends MarkerLayerTest {
@Override @Override
public void createLayers() { public void createLayers() {
// Map events receiver try {
mMap.layers().add(new MapEventsReceiver(mMap)); // Map events receiver
mMap.layers().add(new MapEventsReceiver(mMap));
VectorTileLayer l = mMap.setBaseMap(new OSciMap4TileSource()); VectorTileLayer l = mMap.setBaseMap(new OSciMap4TileSource());
mMap.layers().add(new BuildingLayer(mMap, l)); mMap.layers().add(new BuildingLayer(mMap, l));
mMap.layers().add(new LabelLayer(mMap, l)); mMap.layers().add(new LabelLayer(mMap, l));
mMap.setTheme(VtmThemes.DEFAULT); mMap.setTheme(VtmThemes.DEFAULT);
mMap.setMapPosition(0, 0, 1 << 2); mMap.setMapPosition(0, 0, 1 << 2);
Bitmap bitmapPoi = CanvasAdapter.decodeBitmap(getClass().getResourceAsStream("/res/marker_poi.png")); Bitmap bitmapPoi = CanvasAdapter.decodeBitmap(getClass().getResourceAsStream("/res/marker_poi.png"));
Bitmap bitmapFocus = CanvasAdapter.decodeBitmap(getClass().getResourceAsStream("/res/marker_focus.png")); Bitmap bitmapFocus = CanvasAdapter.decodeBitmap(getClass().getResourceAsStream("/res/marker_focus.png"));
// Create Atlas from Bitmaps // Create Atlas from Bitmaps
java.util.Map<Object, Bitmap> inputMap = new LinkedHashMap<>(); java.util.Map<Object, Bitmap> inputMap = new LinkedHashMap<>();
java.util.Map<Object, TextureRegion> regionsMap = new LinkedHashMap<>(); java.util.Map<Object, TextureRegion> regionsMap = new LinkedHashMap<>();
List<TextureAtlas> atlasList = new ArrayList<>(); List<TextureAtlas> atlasList = new ArrayList<>();
inputMap.put("poi", bitmapPoi); inputMap.put("poi", bitmapPoi);
inputMap.put("focus", bitmapFocus); inputMap.put("focus", bitmapFocus);
// Bitmaps will never used any more // Bitmaps will never used any more
// With iOS we must flip the Y-Axis // With iOS we must flip the Y-Axis
TextureAtlasUtils.createTextureRegions(inputMap, regionsMap, atlasList, true, false); TextureAtlasUtils.createTextureRegions(inputMap, regionsMap, atlasList, true, false);
MarkerSymbol symbol; MarkerSymbol symbol;
if (BILLBOARDS) if (BILLBOARDS)
symbol = new MarkerSymbol(regionsMap.get("poi"), HotspotPlace.BOTTOM_CENTER); symbol = new MarkerSymbol(regionsMap.get("poi"), HotspotPlace.BOTTOM_CENTER);
else else
symbol = new MarkerSymbol(regionsMap.get("poi"), HotspotPlace.CENTER, false); symbol = new MarkerSymbol(regionsMap.get("poi"), HotspotPlace.CENTER, false);
if (BILLBOARDS) if (BILLBOARDS)
mFocusMarker = new MarkerSymbol(regionsMap.get("focus"), HotspotPlace.BOTTOM_CENTER); mFocusMarker = new MarkerSymbol(regionsMap.get("focus"), HotspotPlace.BOTTOM_CENTER);
else else
mFocusMarker = new MarkerSymbol(regionsMap.get("focus"), HotspotPlace.CENTER, false); mFocusMarker = new MarkerSymbol(regionsMap.get("focus"), HotspotPlace.CENTER, false);
mMarkerLayer = new ItemizedLayer<>(mMap, new ArrayList<MarkerItem>(), symbol, this); mMarkerLayer = new ItemizedLayer<>(mMap, new ArrayList<MarkerItem>(), symbol, this);
mMap.layers().add(mMarkerLayer); mMap.layers().add(mMarkerLayer);
List<MarkerItem> pts = new ArrayList<>(); List<MarkerItem> pts = new ArrayList<>();
for (double lat = -90; lat <= 90; lat += 5) { for (double lat = -90; lat <= 90; lat += 5) {
for (double lon = -180; lon <= 180; lon += 5) for (double lon = -180; lon <= 180; lon += 5)
pts.add(new MarkerItem(lat + "/" + lon, "", new GeoPoint(lat, lon))); pts.add(new MarkerItem(lat + "/" + lon, "", new GeoPoint(lat, lon)));
}
mMarkerLayer.addItems(pts);
} catch (IOException e) {
e.printStackTrace();
} }
mMarkerLayer.addItems(pts);
} }
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -30,6 +30,7 @@ import org.oscim.layers.tile.vector.labeling.LabelLayer;
import org.oscim.theme.VtmThemes; import org.oscim.theme.VtmThemes;
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource; import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -40,43 +41,47 @@ public class ClusterMarkerLayerTest extends MarkerLayerTest {
@Override @Override
public void createLayers() { public void createLayers() {
// Map events receiver try {
mMap.layers().add(new MapEventsReceiver(mMap)); // Map events receiver
mMap.layers().add(new MapEventsReceiver(mMap));
VectorTileLayer l = mMap.setBaseMap(new OSciMap4TileSource()); VectorTileLayer l = mMap.setBaseMap(new OSciMap4TileSource());
mMap.layers().add(new BuildingLayer(mMap, l)); mMap.layers().add(new BuildingLayer(mMap, l));
mMap.layers().add(new LabelLayer(mMap, l)); mMap.layers().add(new LabelLayer(mMap, l));
mMap.setTheme(VtmThemes.DEFAULT); mMap.setTheme(VtmThemes.DEFAULT);
mMap.setMapPosition(53.08, 8.83, 1 << 15); mMap.setMapPosition(53.08, 8.83, 1 << 15);
Bitmap bitmapPoi = CanvasAdapter.decodeBitmap(getClass().getResourceAsStream("/res/marker_poi.png")); Bitmap bitmapPoi = CanvasAdapter.decodeBitmap(getClass().getResourceAsStream("/res/marker_poi.png"));
MarkerSymbol symbol; MarkerSymbol symbol;
if (BILLBOARDS) if (BILLBOARDS)
symbol = new MarkerSymbol(bitmapPoi, MarkerSymbol.HotspotPlace.BOTTOM_CENTER); symbol = new MarkerSymbol(bitmapPoi, MarkerSymbol.HotspotPlace.BOTTOM_CENTER);
else else
symbol = new MarkerSymbol(bitmapPoi, MarkerSymbol.HotspotPlace.CENTER, false); symbol = new MarkerSymbol(bitmapPoi, MarkerSymbol.HotspotPlace.CENTER, false);
mMarkerLayer = new ItemizedLayer<>( mMarkerLayer = new ItemizedLayer<>(
mMap, mMap,
new ArrayList<MarkerItem>(), new ArrayList<MarkerItem>(),
ClusterMarkerRenderer.factory(symbol, new ClusterMarkerRenderer.ClusterStyle(Color.WHITE, Color.BLUE)), ClusterMarkerRenderer.factory(symbol, new ClusterMarkerRenderer.ClusterStyle(Color.WHITE, Color.BLUE)),
this); this);
mMap.layers().add(mMarkerLayer); mMap.layers().add(mMarkerLayer);
// Create some markers spaced STEP degrees // Create some markers spaced STEP degrees
List<MarkerItem> pts = new ArrayList<>(); List<MarkerItem> pts = new ArrayList<>();
GeoPoint center = mMap.getMapPosition().getGeoPoint(); GeoPoint center = mMap.getMapPosition().getGeoPoint();
for (int x = -COUNT; x < COUNT; x++) { for (int x = -COUNT; x < COUNT; x++) {
for (int y = -COUNT; y < COUNT; y++) { for (int y = -COUNT; y < COUNT; y++) {
double random = STEP * Math.random() * 2; double random = STEP * Math.random() * 2;
MarkerItem item = new MarkerItem(y + ", " + x, "", MarkerItem item = new MarkerItem(y + ", " + x, "",
new GeoPoint(center.getLatitude() + y * STEP + random, center.getLongitude() + x * STEP + random) new GeoPoint(center.getLatitude() + y * STEP + random, center.getLongitude() + x * STEP + random)
); );
pts.add(item); pts.add(item);
}
} }
mMarkerLayer.addItems(pts);
} catch (IOException e) {
e.printStackTrace();
} }
mMarkerLayer.addItems(pts);
} }
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -34,6 +34,8 @@ import org.oscim.renderer.bucket.LineTexBucket;
import org.oscim.renderer.bucket.TextureItem; import org.oscim.renderer.bucket.TextureItem;
import org.oscim.theme.styles.LineStyle; import org.oscim.theme.styles.LineStyle;
import java.io.IOException;
public class LineRenderTest extends GdxMap { public class LineRenderTest extends GdxMap {
GeometryBuffer mGeom = new GeometryBuffer(2, 1); GeometryBuffer mGeom = new GeometryBuffer(2, 1);
@ -78,8 +80,13 @@ public class LineRenderTest extends GdxMap {
line4 = new LineStyle(0, null, Color.LTGRAY, 2.0f, Cap.ROUND, false, 0, 0, 0, 0, 1f, false, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT); line4 = new LineStyle(0, null, Color.LTGRAY, 2.0f, Cap.ROUND, false, 0, 0, 0, 0, 1f, false, null, true, null, LineStyle.REPEAT_START_DEFAULT, LineStyle.REPEAT_GAP_DEFAULT);
} }
TextureItem tex = new TextureItem(CanvasAdapter.getBitmapAsset("", "patterns/dot.png")); TextureItem tex = null;
tex.mipmap = true; try {
tex = new TextureItem(CanvasAdapter.getBitmapAsset("", "patterns/dot.png"));
tex.mipmap = true;
} catch (IOException e) {
e.printStackTrace();
}
line3 = LineStyle.builder() line3 = LineStyle.builder()
.stippleColor(Color.CYAN) .stippleColor(Color.CYAN)
.stipple(8) .stipple(8)

View File

@ -33,6 +33,7 @@ import org.oscim.renderer.bucket.TextureItem;
import org.oscim.theme.VtmThemes; import org.oscim.theme.VtmThemes;
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource; import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -52,8 +53,12 @@ public class LineTexTest extends GdxMapApp {
mMap.setMapPosition(0, 0, 1 << 2); mMap.setMapPosition(0, 0, 1 << 2);
tex = new TextureItem(CanvasAdapter.getBitmapAsset("", "patterns/pike.png")); try {
tex.mipmap = true; tex = new TextureItem(CanvasAdapter.getBitmapAsset("", "patterns/pike.png"));
tex.mipmap = true;
} catch (IOException e) {
e.printStackTrace();
}
createLayers(1, true); createLayers(1, true);

View File

@ -32,6 +32,7 @@ import org.oscim.map.Map;
import org.oscim.theme.VtmThemes; import org.oscim.theme.VtmThemes;
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource; import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -45,38 +46,42 @@ public class MarkerLayerTest extends GdxMapApp implements ItemizedLayer.OnItemGe
@Override @Override
public void createLayers() { public void createLayers() {
// Map events receiver try {
mMap.layers().add(new MapEventsReceiver(mMap)); // Map events receiver
mMap.layers().add(new MapEventsReceiver(mMap));
VectorTileLayer l = mMap.setBaseMap(new OSciMap4TileSource()); VectorTileLayer l = mMap.setBaseMap(new OSciMap4TileSource());
mMap.layers().add(new BuildingLayer(mMap, l)); mMap.layers().add(new BuildingLayer(mMap, l));
mMap.layers().add(new LabelLayer(mMap, l)); mMap.layers().add(new LabelLayer(mMap, l));
mMap.setTheme(VtmThemes.DEFAULT); mMap.setTheme(VtmThemes.DEFAULT);
mMap.setMapPosition(0, 0, 1 << 2); mMap.setMapPosition(0, 0, 1 << 2);
Bitmap bitmapPoi = CanvasAdapter.decodeBitmap(getClass().getResourceAsStream("/res/marker_poi.png")); Bitmap bitmapPoi = CanvasAdapter.decodeBitmap(getClass().getResourceAsStream("/res/marker_poi.png"));
MarkerSymbol symbol; MarkerSymbol symbol;
if (BILLBOARDS) if (BILLBOARDS)
symbol = new MarkerSymbol(bitmapPoi, HotspotPlace.BOTTOM_CENTER); symbol = new MarkerSymbol(bitmapPoi, HotspotPlace.BOTTOM_CENTER);
else else
symbol = new MarkerSymbol(bitmapPoi, HotspotPlace.CENTER, false); symbol = new MarkerSymbol(bitmapPoi, HotspotPlace.CENTER, false);
Bitmap bitmapFocus = CanvasAdapter.decodeBitmap(getClass().getResourceAsStream("/res/marker_focus.png")); Bitmap bitmapFocus = CanvasAdapter.decodeBitmap(getClass().getResourceAsStream("/res/marker_focus.png"));
if (BILLBOARDS) if (BILLBOARDS)
mFocusMarker = new MarkerSymbol(bitmapFocus, HotspotPlace.BOTTOM_CENTER); mFocusMarker = new MarkerSymbol(bitmapFocus, HotspotPlace.BOTTOM_CENTER);
else else
mFocusMarker = new MarkerSymbol(bitmapFocus, HotspotPlace.CENTER, false); mFocusMarker = new MarkerSymbol(bitmapFocus, HotspotPlace.CENTER, false);
mMarkerLayer = new ItemizedLayer<>(mMap, new ArrayList<MarkerItem>(), symbol, this); mMarkerLayer = new ItemizedLayer<>(mMap, new ArrayList<MarkerItem>(), symbol, this);
mMap.layers().add(mMarkerLayer); mMap.layers().add(mMarkerLayer);
List<MarkerItem> pts = new ArrayList<>(); List<MarkerItem> pts = new ArrayList<>();
for (double lat = -90; lat <= 90; lat += 5) { for (double lat = -90; lat <= 90; lat += 5) {
for (double lon = -180; lon <= 180; lon += 5) for (double lon = -180; lon <= 180; lon += 5)
pts.add(new MarkerItem(lat + "/" + lon, "", new GeoPoint(lat, lon))); pts.add(new MarkerItem(lat + "/" + lon, "", new GeoPoint(lat, lon)));
}
mMarkerLayer.addItems(pts);
} catch (IOException e) {
e.printStackTrace();
} }
mMarkerLayer.addItems(pts);
} }
@Override @Override