Samples for Shadow and Overpass (#670)

This commit is contained in:
Gustl22 2019-02-21 00:41:35 +01:00 committed by Emux
parent 8e685b7ebb
commit 31077cb637
No known key found for this signature in database
GPG Key ID: 64ED9980896038C3
9 changed files with 222 additions and 2 deletions

View File

@ -112,6 +112,9 @@
<activity
android:name=".OSciMapS3DBActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".OverpassActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".PathOverlayActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
@ -130,6 +133,9 @@
<activity
android:name=".RotateMarkerOverlayActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".ShadowActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".SimpleMapActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />

View File

@ -9,6 +9,7 @@ configurations.all {
dependencies {
implementation project(':vtm-android')
implementation project(':vtm-extras')
implementation project(':vtm-http')
implementation project(':vtm-jeo')
implementation project(':vtm-json')

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.oscim.android.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#cc000000"
android:orientation="horizontal">
<SeekBar
android:id="@+id/seekBarShadow"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:max="2000"
android:padding="10dp"
android:progress="400" />
<ToggleButton
android:id="@+id/toggleCurrentSun"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:onClick="onToggleCurrentSun"
android:textOn="@string/now" />
</LinearLayout>
</RelativeLayout>

View File

@ -24,5 +24,6 @@
<string name="search">Search</string>
<string name="search_key">\'*\' or OSM key</string>
<string name="search_value">void or value</string>
<string name="now">Now</string>
</resources>

View File

@ -0,0 +1,72 @@
/*
* Copyright 2019 Gustl22
*
* 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.layers.tile.bitmap.BitmapTileLayer;
import org.oscim.layers.tile.buildings.BuildingLayer;
import org.oscim.layers.tile.buildings.S3DBLayer;
import org.oscim.layers.tile.vector.VectorTileLayer;
import org.oscim.layers.tile.vector.labeling.LabelLayer;
import org.oscim.map.Viewport;
import org.oscim.theme.VtmThemes;
import org.oscim.tiling.TileSource;
import org.oscim.tiling.source.OkHttpEngine;
import org.oscim.tiling.source.bitmap.DefaultSources;
import org.oscim.tiling.source.overpass.OverpassTileSource;
/**
* Use Overpass API data for vector layer.
* Only for developing as can be error-prone.
* Take care of overpass provider licenses.
*/
public class OverpassActivity extends MapActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TileSource tileSource = OverpassTileSource.builder()
.httpFactory(new OkHttpEngine.OkHttpFactory())
.zoomMin(15)
.zoomMax(17)
.build();
VectorTileLayer l = mMap.setBaseMap(tileSource);
TileSource bitmapTileSource = DefaultSources.OPENSTREETMAP
.httpFactory(new OkHttpEngine.OkHttpFactory())
.zoomMax(15)
.fadeSteps(new BitmapTileLayer.FadeStep[]{
new BitmapTileLayer.FadeStep(15, 16, 1f, 0f),
new BitmapTileLayer.FadeStep(16, Viewport.MAX_ZOOM_LEVEL, 0f, 0f)
})
.build();
mMap.layers().add(new BitmapTileLayer(mMap, bitmapTileSource));
BuildingLayer.RAW_DATA = true;
mMap.layers().add(new S3DBLayer(mMap, l));
mMap.layers().add(new LabelLayer(mMap, l));
mMap.setTheme(VtmThemes.DEFAULT);
}
@Override
protected void onDestroy() {
super.onDestroy();
BuildingLayer.RAW_DATA = false;
}
}

View File

@ -2,8 +2,12 @@
* Copyright 2010, 2011, 2012, 2013 mapsforge.org
* Copyright 2013 Hannes Janetzek
* Copyright 2016-2018 devemux86
* Copyright 2016 mar-v-in
* Copyright 2016 Mathieu de Brito
* Copyright 2017-2018 Longri
* Copyright 2017 nebular
* Copyright 2018 boldtrn
* Copyright 2018-2019 Gustl22
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
@ -108,6 +112,7 @@ public class Samples extends Activity {
linearLayout.addView(createButton(MapsforgeS3DBActivity.class));
linearLayout.addView(createButton(AtlasThemeActivity.class));
linearLayout.addView(createButton(POTTextureActivity.class));
linearLayout.addView(createButton(ShadowActivity.class));
linearLayout.addView(createLabel("Raster Maps"));
linearLayout.addView(createButton(BitmapTileActivity.class));
@ -136,5 +141,6 @@ public class Samples extends Activity {
linearLayout.addView(createButton(ThemeStylerActivity.class));
linearLayout.addView(createButton(JeoIndoorActivity.class));
linearLayout.addView(createButton(GdxPoi3DActivity.class));
linearLayout.addView(createButton(OverpassActivity.class));
}
}

View File

@ -0,0 +1,80 @@
/*
* Copyright 2019 Gustl22
*
* 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 android.view.View;
import android.widget.SeekBar;
import android.widget.ToggleButton;
import org.oscim.layers.tile.buildings.BuildingLayer;
import org.oscim.renderer.ExtrusionRenderer;
import org.oscim.renderer.light.Sun;
public class ShadowActivity extends SimpleMapActivity implements SeekBar.OnSeekBarChangeListener {
public ShadowActivity() {
super(R.layout.activity_shadow);
}
private SeekBar mSeekBar;
@Override
public void onCreate(Bundle savedInstanceState) {
BuildingLayer.SHADOW = true;
super.onCreate(savedInstanceState);
mSeekBar = findViewById(R.id.seekBarShadow);
mSeekBar.setOnSeekBarChangeListener(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
BuildingLayer.SHADOW = false;
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int id = seekBar.getId();
if (id == R.id.seekBarShadow) {
Sun sun = mBuildingLayer.getExtrusionRenderer().getSun();
sun.setProgress(progress / 1000f);
sun.updatePosition();
sun.updateColor();
mMap.updateMap(true);
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
public void onToggleCurrentSun(View view) {
boolean isCurrentSun = ((ToggleButton) view).isChecked();
mSeekBar.setEnabled(!isCurrentSun);
ExtrusionRenderer extrusionRenderer = mBuildingLayer.getExtrusionRenderer();
extrusionRenderer.enableCurrentSunPos(isCurrentSun);
extrusionRenderer.getSun().update();
mSeekBar.setProgress((int) (extrusionRenderer.getSun().getProgress() * 1000));
mMap.updateMap(true);
}
}

View File

@ -1,6 +1,7 @@
/*
* Copyright 2013 Hannes Janetzek
* Copyright 2016-2018 devemux86
* Copyright 2019 Gustl22
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
@ -39,6 +40,17 @@ import org.oscim.theme.VtmThemes;
public class SimpleMapActivity extends BaseMapActivity {
private DefaultMapScaleBar mapScaleBar;
BuildingLayer mBuildingLayer;
LabelLayer mLabelLayer;
public SimpleMapActivity(int contentView) {
super(contentView);
}
public SimpleMapActivity() {
super();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -48,8 +60,10 @@ public class SimpleMapActivity extends BaseMapActivity {
void createLayers() {
GroupLayer groupLayer = new GroupLayer(mMap);
groupLayer.layers.add(new BuildingLayer(mMap, mBaseLayer));
groupLayer.layers.add(new LabelLayer(mMap, mBaseLayer));
mBuildingLayer = new BuildingLayer(mMap, mBaseLayer);
groupLayer.layers.add(mBuildingLayer);
mLabelLayer = new LabelLayer(mMap, mBaseLayer);
groupLayer.layers.add(mLabelLayer);
mMap.layers().add(groupLayer);
mapScaleBar = new DefaultMapScaleBar(mMap);

View File

@ -68,6 +68,7 @@ public class MapsforgeTest extends GdxMapApp {
VectorTileLayer l = mMap.setBaseMap(tileSource);
loadTheme(null);
BuildingLayer.SHADOW = SHADOWS;
BuildingLayer buildingLayer = s3db ? new S3DBLayer(mMap, l) : new BuildingLayer(mMap, l);
mMap.layers().add(buildingLayer);
@ -116,6 +117,9 @@ public class MapsforgeTest extends GdxMapApp {
@Override
public void dispose() {
if (SHADOWS)
BuildingLayer.SHADOW = false;
MapPreferences.saveMapPosition(mMap.getMapPosition());
super.dispose();
}