Texture atlas with marker overlays example (#284)
This commit is contained in:
parent
945b84f04f
commit
120182ec15
@ -26,6 +26,9 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".AtlasMarkerOverlayActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize" />
|
||||
<activity
|
||||
android:name=".BitmapTileMapActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize" />
|
||||
|
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright 2014 Hannes Janetzek
|
||||
* Copyright 2016 devemux86
|
||||
* Copyright 2017 Longri
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* 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.android.test;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.oscim.backend.canvas.Bitmap;
|
||||
import org.oscim.core.GeoPoint;
|
||||
import org.oscim.layers.TileGridLayer;
|
||||
import org.oscim.layers.marker.ItemizedLayer;
|
||||
import org.oscim.layers.marker.MarkerItem;
|
||||
import org.oscim.layers.marker.MarkerSymbol;
|
||||
import org.oscim.layers.marker.MarkerSymbol.HotspotPlace;
|
||||
import org.oscim.renderer.atlas.TextureAtlas;
|
||||
import org.oscim.renderer.atlas.TextureRegion;
|
||||
import org.oscim.utils.TextureAtlasUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static org.oscim.android.canvas.AndroidGraphics.drawableToBitmap;
|
||||
|
||||
public class AtlasMarkerOverlayActivity extends MarkerOverlayActivity
|
||||
implements ItemizedLayer.OnItemGestureListener<MarkerItem> {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mBitmapLayer.tileRenderer().setBitmapAlpha(0.5f);
|
||||
|
||||
// Map events receiver
|
||||
mMap.layers().add(new MapEventsReceiver(mMap));
|
||||
|
||||
/* directly load bitmap from resources */
|
||||
Bitmap bitmapPoi = drawableToBitmap(getResources(), R.drawable.marker_poi);
|
||||
|
||||
/* another option: use some bitmap drawable */
|
||||
Drawable d = getResources().getDrawable(R.drawable.marker_focus);
|
||||
Bitmap bitmapFocus = drawableToBitmap(d);
|
||||
|
||||
// Create Atlas from Bitmaps
|
||||
java.util.Map<Object, Bitmap> inputMap = new LinkedHashMap<>();
|
||||
java.util.Map<Object, TextureRegion> regionsMap = new LinkedHashMap<>();
|
||||
List<TextureAtlas> atlasList = new ArrayList<>();
|
||||
|
||||
inputMap.put("poi", bitmapPoi);
|
||||
inputMap.put("focus", bitmapFocus);
|
||||
|
||||
// Bitmaps will never used any more
|
||||
// With iOS we must flip the Y-Axis
|
||||
TextureAtlasUtils.createTextureRegions(inputMap, regionsMap, atlasList, true, false);
|
||||
|
||||
MarkerSymbol symbol;
|
||||
if (BILLBOARDS)
|
||||
symbol = new MarkerSymbol(regionsMap.get("poi"), HotspotPlace.BOTTOM_CENTER);
|
||||
else
|
||||
symbol = new MarkerSymbol(regionsMap.get("poi"), HotspotPlace.CENTER, false);
|
||||
|
||||
if (BILLBOARDS)
|
||||
mFocusMarker = new MarkerSymbol(regionsMap.get("focus"), HotspotPlace.BOTTOM_CENTER);
|
||||
else
|
||||
mFocusMarker = new MarkerSymbol(regionsMap.get("focus"), HotspotPlace.CENTER, false);
|
||||
|
||||
ItemizedLayer<MarkerItem> markerLayer =
|
||||
new ItemizedLayer<>(mMap, new ArrayList<MarkerItem>(),
|
||||
symbol, this);
|
||||
|
||||
mMap.layers().add(markerLayer);
|
||||
|
||||
List<MarkerItem> pts = new ArrayList<>();
|
||||
|
||||
for (double lat = -90; lat <= 90; lat += 5) {
|
||||
for (double lon = -180; lon <= 180; lon += 5)
|
||||
pts.add(new MarkerItem(lat + "/" + lon, "", new GeoPoint(lat, lon)));
|
||||
}
|
||||
|
||||
markerLayer.addItems(pts);
|
||||
|
||||
mMap.layers().add(new TileGridLayer(mMap, getResources().getDisplayMetrics().density));
|
||||
}
|
||||
}
|
@ -43,8 +43,8 @@ import static org.oscim.tiling.source.bitmap.DefaultSources.STAMEN_TONER;
|
||||
public class MarkerOverlayActivity extends BitmapTileMapActivity
|
||||
implements ItemizedLayer.OnItemGestureListener<MarkerItem> {
|
||||
|
||||
private static final boolean BILLBOARDS = true;
|
||||
private MarkerSymbol mFocusMarker;
|
||||
protected static final boolean BILLBOARDS = true;
|
||||
protected MarkerSymbol mFocusMarker;
|
||||
|
||||
public MarkerOverlayActivity() {
|
||||
super(STAMEN_TONER.build());
|
||||
@ -122,7 +122,7 @@ public class MarkerOverlayActivity extends BitmapTileMapActivity
|
||||
return true;
|
||||
}
|
||||
|
||||
class MapEventsReceiver extends Layer implements GestureListener {
|
||||
protected class MapEventsReceiver extends Layer implements GestureListener {
|
||||
|
||||
MapEventsReceiver(Map map) {
|
||||
super(map);
|
||||
|
@ -50,6 +50,7 @@ public class Samples extends Activity {
|
||||
|
||||
linearLayout.addView(createLabel("Overlays"));
|
||||
linearLayout.addView(createButton(MarkerOverlayActivity.class));
|
||||
linearLayout.addView(createButton(AtlasMarkerOverlayActivity.class));
|
||||
linearLayout.addView(createButton(PathOverlayActivity.class));
|
||||
linearLayout.addView(createButton(LineTexActivity.class));
|
||||
linearLayout.addView(createButton(VectorLayerMapActivity.class));
|
||||
|
94
vtm-playground/src/org/oscim/test/AtlasMarkerLayerTest.java
Normal file
94
vtm-playground/src/org/oscim/test/AtlasMarkerLayerTest.java
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright 2016 devemux86
|
||||
* Copyright 2017 Longri
|
||||
*
|
||||
* 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.test;
|
||||
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.backend.canvas.Bitmap;
|
||||
import org.oscim.core.GeoPoint;
|
||||
import org.oscim.gdx.GdxMapApp;
|
||||
import org.oscim.layers.TileGridLayer;
|
||||
import org.oscim.layers.marker.ItemizedLayer;
|
||||
import org.oscim.layers.marker.MarkerItem;
|
||||
import org.oscim.layers.marker.MarkerSymbol;
|
||||
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
|
||||
import org.oscim.renderer.atlas.TextureAtlas;
|
||||
import org.oscim.renderer.atlas.TextureRegion;
|
||||
import org.oscim.tiling.source.bitmap.DefaultSources;
|
||||
import org.oscim.utils.TextureAtlasUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static org.oscim.layers.marker.MarkerSymbol.HotspotPlace;
|
||||
|
||||
public class AtlasMarkerLayerTest extends MarkerLayerTest implements ItemizedLayer.OnItemGestureListener<MarkerItem> {
|
||||
|
||||
@Override
|
||||
public void createLayers() {
|
||||
BitmapTileLayer bitmapLayer = new BitmapTileLayer(mMap, DefaultSources.STAMEN_TONER.build());
|
||||
bitmapLayer.tileRenderer().setBitmapAlpha(0.5f);
|
||||
mMap.setBaseMap(bitmapLayer);
|
||||
|
||||
// Map events receiver
|
||||
mMap.layers().add(new MapEventsReceiver(mMap));
|
||||
|
||||
mMap.setMapPosition(0, 0, 1 << 2);
|
||||
|
||||
Bitmap bitmapPoi = CanvasAdapter.decodeBitmap(getClass().getResourceAsStream("/res/marker_poi.png"));
|
||||
Bitmap bitmapFocus = CanvasAdapter.decodeBitmap(getClass().getResourceAsStream("/res/marker_focus.png"));
|
||||
|
||||
// Create Atlas from Bitmaps
|
||||
java.util.Map<Object, Bitmap> inputMap = new LinkedHashMap<>();
|
||||
java.util.Map<Object, TextureRegion> regionsMap = new LinkedHashMap<>();
|
||||
List<TextureAtlas> atlasList = new ArrayList<>();
|
||||
|
||||
inputMap.put("poi", bitmapPoi);
|
||||
inputMap.put("focus", bitmapFocus);
|
||||
|
||||
// Bitmaps will never used any more
|
||||
// With iOS we must flip the Y-Axis
|
||||
TextureAtlasUtils.createTextureRegions(inputMap, regionsMap, atlasList, true, false);
|
||||
|
||||
MarkerSymbol symbol;
|
||||
if (BILLBOARDS)
|
||||
symbol = new MarkerSymbol(regionsMap.get("poi"), HotspotPlace.BOTTOM_CENTER);
|
||||
else
|
||||
symbol = new MarkerSymbol(regionsMap.get("poi"), HotspotPlace.CENTER, false);
|
||||
|
||||
if (BILLBOARDS)
|
||||
mFocusMarker = new MarkerSymbol(regionsMap.get("focus"), HotspotPlace.BOTTOM_CENTER);
|
||||
else
|
||||
mFocusMarker = new MarkerSymbol(regionsMap.get("focus"), HotspotPlace.CENTER, false);
|
||||
|
||||
ItemizedLayer<MarkerItem> markerLayer = new ItemizedLayer<>(mMap, new ArrayList<MarkerItem>(), symbol, this);
|
||||
mMap.layers().add(markerLayer);
|
||||
|
||||
List<MarkerItem> pts = new ArrayList<>();
|
||||
for (double lat = -90; lat <= 90; lat += 5) {
|
||||
for (double lon = -180; lon <= 180; lon += 5)
|
||||
pts.add(new MarkerItem(lat + "/" + lon, "", new GeoPoint(lat, lon)));
|
||||
}
|
||||
markerLayer.addItems(pts);
|
||||
|
||||
mMap.layers().add(new TileGridLayer(mMap));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
GdxMapApp.init();
|
||||
GdxMapApp.run(new AtlasMarkerLayerTest());
|
||||
}
|
||||
}
|
@ -37,8 +37,8 @@ import static org.oscim.layers.marker.MarkerSymbol.HotspotPlace;
|
||||
|
||||
public class MarkerLayerTest extends GdxMapApp implements ItemizedLayer.OnItemGestureListener<MarkerItem> {
|
||||
|
||||
private static final boolean BILLBOARDS = true;
|
||||
private MarkerSymbol mFocusMarker;
|
||||
protected static final boolean BILLBOARDS = true;
|
||||
protected MarkerSymbol mFocusMarker;
|
||||
|
||||
@Override
|
||||
public void createLayers() {
|
||||
@ -104,7 +104,7 @@ public class MarkerLayerTest extends GdxMapApp implements ItemizedLayer.OnItemGe
|
||||
GdxMapApp.run(new MarkerLayerTest());
|
||||
}
|
||||
|
||||
private class MapEventsReceiver extends Layer implements GestureListener {
|
||||
protected class MapEventsReceiver extends Layer implements GestureListener {
|
||||
|
||||
MapEventsReceiver(Map map) {
|
||||
super(map);
|
||||
|
Loading…
x
Reference in New Issue
Block a user