Getting Started example in Samples #32

This commit is contained in:
Emux 2018-02-24 16:31:22 +02:00
parent 27bf0316de
commit 88d94ede01
No known key found for this signature in database
GPG Key ID: 89C6921D7AF2BDD0
19 changed files with 144 additions and 37 deletions

View File

@ -23,7 +23,7 @@ If you have any questions or problems, don't hesitate to ask our public [mailing
- GeoJSON vector tiles (e.g. Mapzen, Nextzen)
- Raster tiles: any quadtree-scheme tiles as texture
- Backends:
- Android
- Android ([example](vtm-android-example/src/org/oscim/android/test/GettingStarted.java))
- iOS (libGDX/RoboVM, [instructions](docs/ios.md))
- Desktop (libGDX/LWJGL, [instructions](docs/desktop.md))
- HTML5/WebGL (libGDX/GWT, [instructions](docs/web.md))

View File

@ -39,6 +39,9 @@
<activity
android:name=".ClusterMarkerOverlayActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".GettingStarted"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".GdxActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />

View File

@ -59,12 +59,11 @@ public class AtlasMultiTextureActivity extends MarkerOverlayActivity {
java.util.Map<Object, TextureRegion> regionsMap = new LinkedHashMap<>();
List<TextureAtlas> atlasList = new ArrayList<>();
float scale = getResources().getDisplayMetrics().density;
Canvas canvas = CanvasAdapter.newCanvas();
Paint paint = CanvasAdapter.newPaint();
paint.setTypeface(Paint.FontFamily.DEFAULT, Paint.FontStyle.NORMAL);
paint.setTextSize(12 * scale);
paint.setStrokeWidth(2 * scale);
paint.setTextSize(12 * CanvasAdapter.getScale());
paint.setStrokeWidth(2 * CanvasAdapter.getScale());
paint.setColor(Color.BLACK);
List<MarkerItem> pts = new ArrayList<>();
for (double lat = -90; lat <= 90; lat += 10) {
@ -72,12 +71,12 @@ public class AtlasMultiTextureActivity extends MarkerOverlayActivity {
String title = lat + "/" + lon;
pts.add(new MarkerItem(title, "", new GeoPoint(lat, lon)));
Bitmap bmp = CanvasAdapter.newBitmap((int) (40 * scale), (int) (40 * scale), 0);
Bitmap bmp = CanvasAdapter.newBitmap((int) (40 * CanvasAdapter.getScale()), (int) (40 * CanvasAdapter.getScale()), 0);
canvas.setBitmap(bmp);
canvas.fillColor(Color.GREEN);
canvas.drawText(Double.toString(lat), 3 * scale, 17 * scale, paint);
canvas.drawText(Double.toString(lon), 3 * scale, 35 * scale, paint);
canvas.drawText(Double.toString(lat), 3 * CanvasAdapter.getScale(), 17 * CanvasAdapter.getScale(), paint);
canvas.drawText(Double.toString(lon), 3 * CanvasAdapter.getScale(), 35 * CanvasAdapter.getScale(), paint);
inputMap.put(title, bmp);
}
}

View File

@ -116,7 +116,7 @@ public class BaseMapActivity extends MapActivity {
} else {
item.setChecked(true);
if (mGridLayer == null)
mGridLayer = new TileGridLayer(mMap, getResources().getDisplayMetrics().density);
mGridLayer = new TileGridLayer(mMap);
mMap.layers().add(mGridLayer);
}

View File

@ -64,7 +64,7 @@ public class GdxActivity extends AndroidApplication {
TileSource ts = OSciMap4TileSource.builder()
.httpFactory(new OkHttpEngine.OkHttpFactory())
.build();
initDefaultLayers(ts, false, true, true, getResources().getDisplayMetrics().density);
initDefaultLayers(ts, false, true, true);
}
}
}

View File

@ -0,0 +1,104 @@
/*
* Copyright 2018 devemux86
*
* 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.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import org.oscim.android.MapView;
import org.oscim.backend.CanvasAdapter;
import org.oscim.layers.tile.buildings.BuildingLayer;
import org.oscim.layers.tile.vector.VectorTileLayer;
import org.oscim.layers.tile.vector.labeling.LabelLayer;
import org.oscim.renderer.GLViewport;
import org.oscim.scalebar.DefaultMapScaleBar;
import org.oscim.scalebar.MapScaleBar;
import org.oscim.scalebar.MapScaleBarLayer;
import org.oscim.theme.VtmThemes;
import org.oscim.tiling.source.mapfile.MapFileTileSource;
import java.io.File;
/**
* A very basic Android app example.
* <p>
* You'll need a map with filename germany.map from download.mapsforge.org in device storage.
* Can be berlin.map renamed as germany.map because of smaller size.
*/
public class GettingStarted extends Activity {
// Name of the map file in device storage
private static final String MAP_FILE = "germany.map";
private MapView mapView;
private MapScaleBar mapScaleBar;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Map view
mapView = new MapView(this);
setContentView(mapView);
// Tile source
MapFileTileSource tileSource = new MapFileTileSource();
String mapPath = new File(Environment.getExternalStorageDirectory(), MAP_FILE).getAbsolutePath();
if (tileSource.setMapFile(mapPath)) {
// Vector layer
VectorTileLayer tileLayer = mapView.map().setBaseMap(tileSource);
// Building layer
mapView.map().layers().add(new BuildingLayer(mapView.map(), tileLayer));
// Label layer
mapView.map().layers().add(new LabelLayer(mapView.map(), tileLayer));
// Render theme
mapView.map().setTheme(VtmThemes.DEFAULT);
// Scale bar
mapScaleBar = new DefaultMapScaleBar(mapView.map());
MapScaleBarLayer mapScaleBarLayer = new MapScaleBarLayer(mapView.map(), mapScaleBar);
mapScaleBarLayer.getRenderer().setPosition(GLViewport.Position.BOTTOM_LEFT);
mapScaleBarLayer.getRenderer().setOffset(5 * CanvasAdapter.getScale(), 0);
mapView.map().layers().add(mapScaleBarLayer);
// Note: this map position is specific to Berlin area
mapView.map().setMapPosition(52.517037, 13.38886, 1 << 12);
}
}
@Override
protected void onResume() {
super.onResume();
mapView.onResume();
}
@Override
protected void onPause() {
mapView.onPause();
super.onPause();
}
@Override
protected void onDestroy() {
if (mapScaleBar != null)
mapScaleBar.destroy();
mapView.onDestroy();
super.onDestroy();
}
}

View File

@ -1,6 +1,6 @@
/*
* Copyright 2014 Hannes Janetzek
* Copyright 2016-2017 devemux86
* Copyright 2016-2018 devemux86
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
@ -25,6 +25,7 @@ import android.widget.ToggleButton;
import org.jeo.map.Style;
import org.jeo.vector.VectorDataset;
import org.oscim.backend.CanvasAdapter;
import org.oscim.backend.canvas.Color;
import org.oscim.layers.OSMIndoorLayer;
import org.oscim.layers.tile.buildings.BuildingLayer;
@ -96,11 +97,10 @@ public class JeoIndoorActivity extends BaseMapActivity {
VectorDataset data = JeoTest.readGeoJson(is);
Style style = JeoTest.getStyle();
float scale = getResources().getDisplayMetrics().density;
TextStyle textStyle = TextStyle.builder()
.isCaption(true)
.fontSize(16 * scale).color(Color.BLACK)
.strokeWidth(2.2f * scale).strokeColor(Color.WHITE)
.fontSize(16 * CanvasAdapter.getScale()).color(Color.BLACK)
.strokeWidth(2.2f * CanvasAdapter.getScale()).strokeColor(Color.WHITE)
.build();
mIndoorLayer = new OSMIndoorLayer(mMap, data, style, textStyle);
mMap.layers().add(mIndoorLayer);

View File

@ -1,6 +1,6 @@
/*
* Copyright 2013 Hannes Janetzek
* Copyright 2016-2017 devemux86
* Copyright 2016-2018 devemux86
* Copyright 2016 Andrey Novikov
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
@ -20,6 +20,7 @@ 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;
@ -61,7 +62,7 @@ public class LayerGroupActivity extends BaseMapActivity {
MapScaleBarLayer mapScaleBarLayer = new MapScaleBarLayer(mMap, mapScaleBar);
BitmapRenderer renderer = mapScaleBarLayer.getRenderer();
renderer.setPosition(GLViewport.Position.BOTTOM_LEFT);
renderer.setOffset(5 * getResources().getDisplayMetrics().density, 0);
renderer.setOffset(5 * CanvasAdapter.getScale(), 0);
layers.addGroup(GROUP_OVERLAYS);
layers.add(mapScaleBarLayer, GROUP_OVERLAYS);

View File

@ -27,6 +27,7 @@ import org.oscim.android.filepicker.FilePicker;
import org.oscim.android.filepicker.FilterByFileExtension;
import org.oscim.android.filepicker.ValidMapFile;
import org.oscim.android.filepicker.ValidRenderTheme;
import org.oscim.backend.CanvasAdapter;
import org.oscim.core.MapElement;
import org.oscim.core.MapPosition;
import org.oscim.core.Tag;
@ -156,7 +157,7 @@ public class MapsforgeActivity extends MapActivity {
} else {
item.setChecked(true);
if (mGridLayer == null)
mGridLayer = new TileGridLayer(mMap, getResources().getDisplayMetrics().density);
mGridLayer = new TileGridLayer(mMap);
mMap.layers().add(mGridLayer);
}
@ -199,7 +200,7 @@ public class MapsforgeActivity extends MapActivity {
MapScaleBarLayer mapScaleBarLayer = new MapScaleBarLayer(mMap, mMapScaleBar);
BitmapRenderer renderer = mapScaleBarLayer.getRenderer();
renderer.setPosition(GLViewport.Position.BOTTOM_LEFT);
renderer.setOffset(5 * getResources().getDisplayMetrics().density, 0);
renderer.setOffset(5 * CanvasAdapter.getScale(), 0);
mMap.layers().add(mapScaleBarLayer);
MapInfo info = mTileSource.getMapInfo();

View File

@ -1,5 +1,5 @@
/*
* Copyright 2017 devemux86
* Copyright 2017-2018 devemux86
*
* 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
@ -55,7 +55,7 @@ public class MapzenGeojsonActivity extends MapActivity {
mMap.layers().add(new BuildingLayer(mMap, l));
mMap.layers().add(new LabelLayer(mMap, l));
mMap.layers().add(new TileGridLayer(mMap, getResources().getDisplayMetrics().density));
mMap.layers().add(new TileGridLayer(mMap));
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 devemux86
* Copyright 2016-2018 devemux86
* Copyright 2017 Mathieu De Brito
*
* This program is free software: you can redistribute it and/or modify it under the
@ -56,7 +56,7 @@ public class MapzenMvtActivity extends MapActivity {
mMap.layers().add(new BuildingLayer(mMap, l));
mMap.layers().add(new LabelLayer(mMap, l));
mMap.layers().add(new TileGridLayer(mMap, getResources().getDisplayMetrics().density));
mMap.layers().add(new TileGridLayer(mMap));
}
@Override

View File

@ -55,7 +55,7 @@ public class NextzenGeojsonActivity extends MapActivity {
mMap.layers().add(new BuildingLayer(mMap, l));
mMap.layers().add(new LabelLayer(mMap, l));
mMap.layers().add(new TileGridLayer(mMap, getResources().getDisplayMetrics().density));
mMap.layers().add(new TileGridLayer(mMap));
}
@Override

View File

@ -55,7 +55,7 @@ public class NextzenMvtActivity extends MapActivity {
mMap.layers().add(new BuildingLayer(mMap, l));
mMap.layers().add(new LabelLayer(mMap, l));
mMap.layers().add(new TileGridLayer(mMap, getResources().getDisplayMetrics().density));
mMap.layers().add(new TileGridLayer(mMap));
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 devemux86
* Copyright 2016-2018 devemux86
*
* 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
@ -55,7 +55,7 @@ public class OpenMapTilesMvtActivity extends MapActivity {
mMap.layers().add(new BuildingLayer(mMap, l));
mMap.layers().add(new LabelLayer(mMap, l));
mMap.layers().add(new TileGridLayer(mMap, getResources().getDisplayMetrics().density));
mMap.layers().add(new TileGridLayer(mMap));
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright 2017 devemux86
* Copyright 2017-2018 devemux86
*
* 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
@ -69,7 +69,7 @@ public class ReverseGeocodeActivity extends MapsforgeActivity {
if (requestCode == SELECT_MAP_FILE) {
// For debug
TileGridLayer gridLayer = new TileGridLayer(mMap, getResources().getDisplayMetrics().density);
TileGridLayer gridLayer = new TileGridLayer(mMap);
mMap.layers().add(gridLayer);
}
}

View File

@ -79,6 +79,8 @@ public class Samples extends Activity {
setContentView(R.layout.activity_samples);
LinearLayout linearLayout = findViewById(R.id.samples);
linearLayout.addView(createButton(GettingStarted.class));
linearLayout.addView(createLabel(null));
linearLayout.addView(createButton(SimpleMapActivity.class));
linearLayout.addView(createButton(MapsforgeActivity.class));
/*linearLayout.addView(createButton(MapzenMvtActivity.class));

View File

@ -1,6 +1,6 @@
/*
* Copyright 2013 Hannes Janetzek
* Copyright 2016-2017 devemux86
* Copyright 2016-2018 devemux86
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
@ -19,6 +19,7 @@ package org.oscim.android.test;
import android.os.Bundle;
import org.oscim.backend.CanvasAdapter;
import org.oscim.core.MapPosition;
import org.oscim.core.MercatorProjection;
import org.oscim.layers.GroupLayer;
@ -60,7 +61,7 @@ public class SimpleMapActivity extends BaseMapActivity {
MapScaleBarLayer mapScaleBarLayer = new MapScaleBarLayer(mMap, mapScaleBar);
BitmapRenderer renderer = mapScaleBarLayer.getRenderer();
renderer.setPosition(GLViewport.Position.BOTTOM_LEFT);
renderer.setOffset(5 * getResources().getDisplayMetrics().density, 0);
renderer.setOffset(5 * CanvasAdapter.getScale(), 0);
mMap.layers().add(mapScaleBarLayer);
mMap.setTheme(VtmThemes.DEFAULT);

View File

@ -1,5 +1,6 @@
/*
* Copyright 2016 devemux86
* Copyright 2013 Hannes Janetzek
* Copyright 2016-2018 devemux86
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
@ -154,7 +155,7 @@ public class MapLayers {
if (enable) {
if (mGridOverlay == null)
mGridOverlay = new TileGridLayer(App.map, context.getResources().getDisplayMetrics().density);
mGridOverlay = new TileGridLayer(App.map);
App.map.layers().add(mGridOverlay);
} else {

View File

@ -48,11 +48,6 @@ public abstract class GdxMap implements ApplicationListener {
protected void initDefaultLayers(TileSource tileSource, boolean tileGrid, boolean labels,
boolean buildings) {
initDefaultLayers(tileSource, tileGrid, labels, buildings, 1);
}
protected void initDefaultLayers(TileSource tileSource, boolean tileGrid, boolean labels,
boolean buildings, float scale) {
Layers layers = mMap.layers();
if (tileSource != null) {
@ -67,7 +62,7 @@ public abstract class GdxMap implements ApplicationListener {
}
if (tileGrid)
layers.add(new TileGridLayer(mMap, scale));
layers.add(new TileGridLayer(mMap));
}
@Override