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
9 changed files with 222 additions and 2 deletions

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);