Separate layer groups example, #103

This commit is contained in:
Emux 2016-08-02 10:09:39 +03:00
parent 8eff27c303
commit cfa9326e2b
4 changed files with 114 additions and 40 deletions

View File

@ -26,36 +26,39 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity
android:name=".MapsforgeMapActivity$MapFilePicker"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".SimpleMapActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".S3DBMapActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".PathOverlayActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".MarkerOverlayActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity <activity
android:name=".BitmapTileMapActivity" android:name=".BitmapTileMapActivity"
android:configChanges="keyboardHidden|orientation|screenSize" /> android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".MapsforgeMapActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".ThemeStylerActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity <activity
android:name=".JeoIndoorMapActivity" android:name=".JeoIndoorMapActivity"
android:configChanges="keyboardHidden|orientation|screenSize" /> android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".LayerGroupActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".MapsforgeMapActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".MapsforgeMapActivity$MapFilePicker"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".MarkerOverlayActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity <activity
android:name=".OsmJsonMapActivity" android:name=".OsmJsonMapActivity"
android:configChanges="keyboardHidden|orientation|screenSize" /> android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".PathOverlayActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".S3DBMapActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".SimpleMapActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".ThemeStylerActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity <activity
android:name=".VectorLayerMapActivity" android:name=".VectorLayerMapActivity"
android:configChanges="keyboardHidden|orientation|screenSize" /> android:configChanges="keyboardHidden|orientation|screenSize" />

View File

@ -0,0 +1,79 @@
/*
* Copyright 2013 Hannes Janetzek
* Copyright 2016 devemux86
* Copyright 2016 Andrey Novikov
*
* 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.os.Bundle;
import org.oscim.backend.CanvasAdapter;
import org.oscim.layers.tile.buildings.BuildingLayer;
import org.oscim.layers.tile.vector.labeling.LabelLayer;
import org.oscim.map.Layers;
import org.oscim.renderer.BitmapRenderer;
import org.oscim.renderer.GLViewport;
import org.oscim.scalebar.DefaultMapScaleBar;
import org.oscim.scalebar.ImperialUnitAdapter;
import org.oscim.scalebar.MapScaleBar;
import org.oscim.scalebar.MapScaleBarLayer;
import org.oscim.scalebar.MetricUnitAdapter;
import org.oscim.theme.VtmThemes;
public class LayerGroupActivity extends BaseMapActivity {
private static final int GROUP_3D_OBJECTS = 1;
private static final int GROUP_LABELS = 2;
private static final int GROUP_OVERLAYS = 3;
private DefaultMapScaleBar mapScaleBar;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Layers layers = mMap.layers();
layers.addGroup(GROUP_3D_OBJECTS);
layers.add(new BuildingLayer(mMap, mBaseLayer), GROUP_3D_OBJECTS);
layers.addGroup(GROUP_LABELS);
layers.add(new LabelLayer(mMap, mBaseLayer), GROUP_LABELS);
mapScaleBar = new DefaultMapScaleBar(mMap, CanvasAdapter.dpi / 160);
mapScaleBar.setScaleBarMode(DefaultMapScaleBar.ScaleBarMode.BOTH);
mapScaleBar.setDistanceUnitAdapter(MetricUnitAdapter.INSTANCE);
mapScaleBar.setSecondaryDistanceUnitAdapter(ImperialUnitAdapter.INSTANCE);
mapScaleBar.setScaleBarPosition(MapScaleBar.ScaleBarPosition.BOTTOM_LEFT);
MapScaleBarLayer mapScaleBarLayer = new MapScaleBarLayer(mMap, mapScaleBar);
BitmapRenderer renderer = mapScaleBarLayer.getRenderer();
renderer.setPosition(GLViewport.Position.BOTTOM_LEFT);
renderer.setOffset(5 * CanvasAdapter.dpi / 160, 0);
layers.addGroup(GROUP_OVERLAYS);
layers.add(mapScaleBarLayer, GROUP_OVERLAYS);
mMap.setTheme(VtmThemes.DEFAULT);
}
@Override
protected void onDestroy() {
mapScaleBar.destroy();
super.onDestroy();
}
}

View File

@ -1,6 +1,7 @@
/* /*
* Copyright 2010, 2011, 2012, 2013 mapsforge.org * Copyright 2010, 2011, 2012, 2013 mapsforge.org
* Copyright 2013 Hannes Janetzek * Copyright 2013 Hannes Janetzek
* Copyright 2016 devemux86
* *
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
* *
@ -43,8 +44,9 @@ public class Samples extends Activity {
linearLayout.addView(createButton(SimpleMapActivity.class)); linearLayout.addView(createButton(SimpleMapActivity.class));
linearLayout.addView(createButton(BitmapTileMapActivity.class)); linearLayout.addView(createButton(BitmapTileMapActivity.class));
linearLayout.addView(createButton(MapsforgeMapActivity.class)); linearLayout.addView(createButton(MapsforgeMapActivity.class));
linearLayout.addView(createButton(PathOverlayActivity.class));
linearLayout.addView(createButton(MarkerOverlayActivity.class)); linearLayout.addView(createButton(MarkerOverlayActivity.class));
linearLayout.addView(createButton(PathOverlayActivity.class));
linearLayout.addView(createButton(LayerGroupActivity.class));
linearLayout.addView(createButton(ThemeStylerActivity.class)); linearLayout.addView(createButton(ThemeStylerActivity.class));
linearLayout.addView(createButton(S3DBMapActivity.class)); linearLayout.addView(createButton(S3DBMapActivity.class));
linearLayout.addView(createButton(JeoIndoorMapActivity.class)); linearLayout.addView(createButton(JeoIndoorMapActivity.class));

View File

@ -1,7 +1,6 @@
/* /*
* Copyright 2013 Hannes Janetzek * Copyright 2013 Hannes Janetzek
* Copyright 2016 devemux86 * Copyright 2016 devemux86
* Copyright 2016 Andrey Novikov
* *
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
* *
@ -23,9 +22,9 @@ import android.os.Bundle;
import org.oscim.backend.CanvasAdapter; import org.oscim.backend.CanvasAdapter;
import org.oscim.core.MapPosition; import org.oscim.core.MapPosition;
import org.oscim.core.MercatorProjection; import org.oscim.core.MercatorProjection;
import org.oscim.layers.GroupLayer;
import org.oscim.layers.tile.buildings.BuildingLayer; import org.oscim.layers.tile.buildings.BuildingLayer;
import org.oscim.layers.tile.vector.labeling.LabelLayer; import org.oscim.layers.tile.vector.labeling.LabelLayer;
import org.oscim.map.Layers;
import org.oscim.renderer.BitmapRenderer; import org.oscim.renderer.BitmapRenderer;
import org.oscim.renderer.GLViewport; import org.oscim.renderer.GLViewport;
import org.oscim.scalebar.DefaultMapScaleBar; import org.oscim.scalebar.DefaultMapScaleBar;
@ -38,23 +37,16 @@ import org.oscim.theme.ThemeLoader;
import org.oscim.theme.VtmThemes; import org.oscim.theme.VtmThemes;
public class SimpleMapActivity extends BaseMapActivity { public class SimpleMapActivity extends BaseMapActivity {
private static final int GROUP_3D_OBJECTS = 1;
private static final int GROUP_LABELS = 2;
private static final int GROUP_OVERLAYS = 3;
private DefaultMapScaleBar mapScaleBar; private DefaultMapScaleBar mapScaleBar;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Layers layers = mMap.layers(); GroupLayer groupLayer = new GroupLayer(mMap);
groupLayer.layers.add(new BuildingLayer(mMap, mBaseLayer));
layers.addGroup(GROUP_3D_OBJECTS); groupLayer.layers.add(new LabelLayer(mMap, mBaseLayer));
layers.add(new BuildingLayer(mMap, mBaseLayer), GROUP_3D_OBJECTS); mMap.layers().add(groupLayer);
layers.addGroup(GROUP_LABELS);
layers.add(new LabelLayer(mMap, mBaseLayer), GROUP_LABELS);
mapScaleBar = new DefaultMapScaleBar(mMap, CanvasAdapter.dpi / 160); mapScaleBar = new DefaultMapScaleBar(mMap, CanvasAdapter.dpi / 160);
mapScaleBar.setScaleBarMode(DefaultMapScaleBar.ScaleBarMode.BOTH); mapScaleBar.setScaleBarMode(DefaultMapScaleBar.ScaleBarMode.BOTH);
@ -66,9 +58,7 @@ public class SimpleMapActivity extends BaseMapActivity {
BitmapRenderer renderer = mapScaleBarLayer.getRenderer(); BitmapRenderer renderer = mapScaleBarLayer.getRenderer();
renderer.setPosition(GLViewport.Position.BOTTOM_LEFT); renderer.setPosition(GLViewport.Position.BOTTOM_LEFT);
renderer.setOffset(5 * CanvasAdapter.dpi / 160, 0); renderer.setOffset(5 * CanvasAdapter.dpi / 160, 0);
mMap.layers().add(mapScaleBarLayer);
layers.addGroup(GROUP_OVERLAYS);
layers.add(mapScaleBarLayer, GROUP_OVERLAYS);
mMap.setTheme(VtmThemes.DEFAULT); mMap.setTheme(VtmThemes.DEFAULT);
} }
@ -107,8 +97,8 @@ public class SimpleMapActivity extends BaseMapActivity {
//mMapView.map().setMapPosition(p); //mMapView.map().setMapPosition(p);
p.setScale(2 + (1 << (int) (Math.random() * 13))); p.setScale(2 + (1 << (int) (Math.random() * 13)));
// p.setX((p.getX() + (Math.random() * 4 - 2) / p.getScale())); //p.setX((p.getX() + (Math.random() * 4 - 2) / p.getScale()));
// p.setY((p.getY() + (Math.random() * 4 - 2) / p.getScale())); //p.setY((p.getY() + (Math.random() * 4 - 2) / p.getScale()));
p.setX(MercatorProjection.longitudeToX(Math.random() * 180)); p.setX(MercatorProjection.longitudeToX(Math.random() * 180));
p.setY(MercatorProjection.latitudeToY(Math.random() * 60)); p.setY(MercatorProjection.latitudeToY(Math.random() * 60));