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);
}
}
diff --git a/vtm-android-example/src/org/oscim/android/test/BaseMapActivity.java b/vtm-android-example/src/org/oscim/android/test/BaseMapActivity.java
index e0547245..2a891039 100644
--- a/vtm-android-example/src/org/oscim/android/test/BaseMapActivity.java
+++ b/vtm-android-example/src/org/oscim/android/test/BaseMapActivity.java
@@ -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);
}
diff --git a/vtm-android-example/src/org/oscim/android/test/GdxActivity.java b/vtm-android-example/src/org/oscim/android/test/GdxActivity.java
index a49a9b68..d330cee6 100644
--- a/vtm-android-example/src/org/oscim/android/test/GdxActivity.java
+++ b/vtm-android-example/src/org/oscim/android/test/GdxActivity.java
@@ -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);
}
}
}
diff --git a/vtm-android-example/src/org/oscim/android/test/GettingStarted.java b/vtm-android-example/src/org/oscim/android/test/GettingStarted.java
new file mode 100644
index 00000000..847dbf58
--- /dev/null
+++ b/vtm-android-example/src/org/oscim/android/test/GettingStarted.java
@@ -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 .
+ */
+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.
+ *
+ * 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();
+ }
+}
diff --git a/vtm-android-example/src/org/oscim/android/test/JeoIndoorActivity.java b/vtm-android-example/src/org/oscim/android/test/JeoIndoorActivity.java
index 98841008..de66d744 100644
--- a/vtm-android-example/src/org/oscim/android/test/JeoIndoorActivity.java
+++ b/vtm-android-example/src/org/oscim/android/test/JeoIndoorActivity.java
@@ -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);
diff --git a/vtm-android-example/src/org/oscim/android/test/LayerGroupActivity.java b/vtm-android-example/src/org/oscim/android/test/LayerGroupActivity.java
index 3dd404de..038bb9e8 100644
--- a/vtm-android-example/src/org/oscim/android/test/LayerGroupActivity.java
+++ b/vtm-android-example/src/org/oscim/android/test/LayerGroupActivity.java
@@ -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);
diff --git a/vtm-android-example/src/org/oscim/android/test/MapsforgeActivity.java b/vtm-android-example/src/org/oscim/android/test/MapsforgeActivity.java
index e0e2df69..dedec007 100644
--- a/vtm-android-example/src/org/oscim/android/test/MapsforgeActivity.java
+++ b/vtm-android-example/src/org/oscim/android/test/MapsforgeActivity.java
@@ -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();
diff --git a/vtm-android-example/src/org/oscim/android/test/MapzenGeojsonActivity.java b/vtm-android-example/src/org/oscim/android/test/MapzenGeojsonActivity.java
index 2ed8def4..7d8aac3d 100644
--- a/vtm-android-example/src/org/oscim/android/test/MapzenGeojsonActivity.java
+++ b/vtm-android-example/src/org/oscim/android/test/MapzenGeojsonActivity.java
@@ -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
diff --git a/vtm-android-example/src/org/oscim/android/test/MapzenMvtActivity.java b/vtm-android-example/src/org/oscim/android/test/MapzenMvtActivity.java
index 8f73f563..1a96ed75 100644
--- a/vtm-android-example/src/org/oscim/android/test/MapzenMvtActivity.java
+++ b/vtm-android-example/src/org/oscim/android/test/MapzenMvtActivity.java
@@ -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
diff --git a/vtm-android-example/src/org/oscim/android/test/NextzenGeojsonActivity.java b/vtm-android-example/src/org/oscim/android/test/NextzenGeojsonActivity.java
index a6abd99e..77687102 100644
--- a/vtm-android-example/src/org/oscim/android/test/NextzenGeojsonActivity.java
+++ b/vtm-android-example/src/org/oscim/android/test/NextzenGeojsonActivity.java
@@ -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
diff --git a/vtm-android-example/src/org/oscim/android/test/NextzenMvtActivity.java b/vtm-android-example/src/org/oscim/android/test/NextzenMvtActivity.java
index 8da1cd14..a2f13c29 100644
--- a/vtm-android-example/src/org/oscim/android/test/NextzenMvtActivity.java
+++ b/vtm-android-example/src/org/oscim/android/test/NextzenMvtActivity.java
@@ -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
diff --git a/vtm-android-example/src/org/oscim/android/test/OpenMapTilesMvtActivity.java b/vtm-android-example/src/org/oscim/android/test/OpenMapTilesMvtActivity.java
index 6326a4fe..483e229a 100644
--- a/vtm-android-example/src/org/oscim/android/test/OpenMapTilesMvtActivity.java
+++ b/vtm-android-example/src/org/oscim/android/test/OpenMapTilesMvtActivity.java
@@ -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
diff --git a/vtm-android-example/src/org/oscim/android/test/ReverseGeocodeActivity.java b/vtm-android-example/src/org/oscim/android/test/ReverseGeocodeActivity.java
index e734efec..0ccc4fcb 100644
--- a/vtm-android-example/src/org/oscim/android/test/ReverseGeocodeActivity.java
+++ b/vtm-android-example/src/org/oscim/android/test/ReverseGeocodeActivity.java
@@ -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);
}
}
diff --git a/vtm-android-example/src/org/oscim/android/test/Samples.java b/vtm-android-example/src/org/oscim/android/test/Samples.java
index 32dac566..69c5a05d 100644
--- a/vtm-android-example/src/org/oscim/android/test/Samples.java
+++ b/vtm-android-example/src/org/oscim/android/test/Samples.java
@@ -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));
diff --git a/vtm-android-example/src/org/oscim/android/test/SimpleMapActivity.java b/vtm-android-example/src/org/oscim/android/test/SimpleMapActivity.java
index 02b4fc13..d2fc81e8 100644
--- a/vtm-android-example/src/org/oscim/android/test/SimpleMapActivity.java
+++ b/vtm-android-example/src/org/oscim/android/test/SimpleMapActivity.java
@@ -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);
diff --git a/vtm-app/src/org/oscim/app/MapLayers.java b/vtm-app/src/org/oscim/app/MapLayers.java
index bd11925b..dccaae95 100644
--- a/vtm-app/src/org/oscim/app/MapLayers.java
+++ b/vtm-app/src/org/oscim/app/MapLayers.java
@@ -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 {
diff --git a/vtm-gdx/src/org/oscim/gdx/GdxMap.java b/vtm-gdx/src/org/oscim/gdx/GdxMap.java
index 694fb8df..357e072b 100644
--- a/vtm-gdx/src/org/oscim/gdx/GdxMap.java
+++ b/vtm-gdx/src/org/oscim/gdx/GdxMap.java
@@ -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