Skip to content

Commit

Permalink
Fix : Missing init key for maptiler and update style
Browse files Browse the repository at this point in the history
  • Loading branch information
ravenfeld committed Oct 18, 2024
1 parent 256967a commit 4cd4cf2
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.maplibre.android.plugins.testapp

enum class TestStyles(val url: String) {
POSITRON(url = "https://tiles.openfreemap.org/styles/positron"),
BRIGHT(url = "https://tiles.openfreemap.org/styles/bright"),
LIBERTY(url = "https://tiles.openfreemap.org/styles/liberty")
}
10 changes: 2 additions & 8 deletions app/src/main/java/org/maplibre/android/plugins/testapp/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.maplibre.android.plugins.testapp
import android.content.Context
import android.location.Location
import android.text.TextUtils
import org.maplibre.android.maps.Style
import timber.log.Timber
import java.io.BufferedReader
import java.io.IOException
Expand All @@ -17,12 +16,7 @@ import java.util.*
*/
object Utils {

private val STYLES = arrayOf(
Style.getPredefinedStyle("Streets"),
Style.getPredefinedStyle("Outdoors"),
Style.getPredefinedStyle("Light"),
Style.getPredefinedStyle("Dark")
)
private val STYLES = TestStyles.entries.toTypedArray()

private var index: Int = 0

Expand All @@ -38,7 +32,7 @@ object Utils {
if (index == STYLES.size) {
index = 0
}
return STYLES[index]
return STYLES[index].url
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import android.widget.Spinner;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.MenuItemCompat;
import org.maplibre.android.MapLibre;
import org.maplibre.android.WellKnownTileServer;
import org.maplibre.android.camera.CameraUpdateFactory;
import org.maplibre.android.geometry.LatLng;
import org.maplibre.android.maps.MapLibreMap;
Expand All @@ -22,7 +20,7 @@
import org.maplibre.android.plugins.annotation.Symbol;
import org.maplibre.android.plugins.annotation.SymbolManager;
import org.maplibre.android.plugins.annotation.SymbolOptions;
import org.maplibre.android.plugins.testapp.BuildConfig;
import org.maplibre.android.plugins.testapp.TestStyles;
import org.maplibre.android.plugins.testapp.R;
import org.maplibre.android.plugins.testapp.Utils;
import org.maplibre.geojson.Feature;
Expand Down Expand Up @@ -56,7 +54,6 @@ public class BulkSymbolActivity extends AppCompatActivity implements AdapterView
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_annotation);
MapLibre.getInstance(this, BuildConfig.MAPTILER_API_KEY, WellKnownTileServer.MapTiler);
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this::initMap);
Expand All @@ -71,7 +68,7 @@ private void initMap(MapLibreMap mapLibreMap) {
);

mapLibreMap.setStyle(new Style.Builder()
.fromUri(Style.getPredefinedStyle("Streets"))
.fromUri(TestStyles.LIBERTY.getUrl())
.withImage(IMAGE_ID_FIRE_HYDRANT, getDrawable(R.drawable.ic_fire_hydrant)),
style -> {
findViewById(R.id.fabStyles).setOnClickListener(v -> mapLibreMap.setStyle(Utils.INSTANCE.getNextStyle()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
import org.maplibre.android.camera.CameraUpdateFactory;
import org.maplibre.android.geometry.LatLng;
import org.maplibre.android.maps.MapView;
import org.maplibre.android.maps.Style;
import org.maplibre.android.plugins.annotation.Circle;
import org.maplibre.android.plugins.annotation.CircleManager;
import org.maplibre.android.plugins.annotation.CircleOptions;
import org.maplibre.android.plugins.annotation.OnCircleDragListener;
import org.maplibre.android.plugins.testapp.TestStyles;
import org.maplibre.android.plugins.testapp.R;
import org.maplibre.android.plugins.testapp.Utils;
import org.maplibre.android.utils.ColorUtils;
Expand Down Expand Up @@ -45,7 +45,7 @@ protected void onCreate(Bundle savedInstanceState) {

mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(maplibreMap -> maplibreMap.setStyle(Style.getPredefinedStyle("Streets"), style -> {
mapView.getMapAsync(maplibreMap -> maplibreMap.setStyle(TestStyles.BRIGHT.getUrl(), style -> {
findViewById(R.id.fabStyles).setOnClickListener(v -> maplibreMap.setStyle(Utils.INSTANCE.getNextStyle()));

maplibreMap.moveCamera(CameraUpdateFactory.zoomTo(2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.maplibre.android.plugins.annotation.Symbol;
import org.maplibre.android.plugins.annotation.SymbolManager;
import org.maplibre.android.plugins.annotation.SymbolOptions;
import org.maplibre.android.plugins.testapp.TestStyles;
import org.maplibre.android.plugins.testapp.R;
import org.maplibre.geojson.Feature;
import org.maplibre.geojson.FeatureCollection;
Expand Down Expand Up @@ -65,7 +66,7 @@ private void initMap(MapLibreMap maplibreMap) {
new Pair(0, Color.GREEN)
});

maplibreMap.setStyle(new Style.Builder().fromUri(Style.getPredefinedStyle("Streets")), style -> {
maplibreMap.setStyle(new Style.Builder().fromUri(TestStyles.BRIGHT.getUrl()), style -> {
symbolManager = new SymbolManager(mapView, maplibreMap, style, null, null, clusterOptions);
symbolManager.setIconAllowOverlap(true);
loadData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.maplibre.android.plugins.annotation.Symbol;
import org.maplibre.android.plugins.annotation.SymbolManager;
import org.maplibre.android.plugins.annotation.SymbolOptions;
import org.maplibre.android.plugins.testapp.TestStyles;
import org.maplibre.android.plugins.testapp.R;

/**
Expand Down Expand Up @@ -58,7 +59,7 @@ protected void onCreate(Bundle savedInstanceState) {
));

maplibreMap.setStyle(new Style.Builder()
.fromUri(Style.getPredefinedStyle("Streets"))
.fromUri(TestStyles.BRIGHT.getUrl())
//.withImage(ID_ICON_1, generateBitmap(R.drawable.mapbox_ic_place), true)
//.withImage(ID_ICON_2, generateBitmap(R.drawable.mapbox_ic_offline), true)
, style -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import org.maplibre.android.camera.CameraUpdateFactory;
import org.maplibre.android.geometry.LatLng;
import org.maplibre.android.maps.MapView;
import org.maplibre.android.maps.Style;
import org.maplibre.android.plugins.annotation.Fill;
import org.maplibre.android.plugins.annotation.FillManager;
import org.maplibre.android.plugins.annotation.FillOptions;
import org.maplibre.android.plugins.testapp.TestStyles;
import org.maplibre.android.plugins.testapp.R;
import org.maplibre.android.plugins.testapp.Utils;
import org.maplibre.android.utils.ColorUtils;
Expand All @@ -41,7 +41,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_annotation);
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(maplibreMap -> maplibreMap.setStyle(Style.getPredefinedStyle("Streets"), style -> {
mapView.getMapAsync(maplibreMap -> maplibreMap.setStyle(TestStyles.BRIGHT.getUrl(), style -> {
findViewById(R.id.fabStyles).setOnClickListener(v -> maplibreMap.setStyle(Utils.INSTANCE.getNextStyle()));

maplibreMap.moveCamera(CameraUpdateFactory.zoomTo(2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.maplibre.android.plugins.annotation.Fill;
import org.maplibre.android.plugins.annotation.FillManager;
import org.maplibre.android.plugins.annotation.FillOptions;
import org.maplibre.android.plugins.testapp.TestStyles;
import org.maplibre.android.plugins.testapp.R;
import org.maplibre.android.utils.ColorUtils;

Expand Down Expand Up @@ -65,7 +66,7 @@ protected void onCreate(Bundle savedInstanceState) {

@Override
public void onMapReady(@NonNull MapLibreMap map) {
map.setStyle(new Style.Builder().fromUri(Style.getPredefinedStyle("Streets")), style -> {
map.setStyle(new Style.Builder().fromUri(TestStyles.BRIGHT.getUrl()), style -> {
fillManager = new FillManager(mapView, map, style, "aerialway", null);
fillManager.addClickListener(fill -> {
Toast.makeText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import org.maplibre.android.camera.CameraUpdateFactory;
import org.maplibre.android.geometry.LatLng;
import org.maplibre.android.maps.MapView;
import org.maplibre.android.maps.Style;
import org.maplibre.android.plugins.annotation.Line;
import org.maplibre.android.plugins.annotation.LineManager;
import org.maplibre.android.plugins.annotation.LineOptions;
import org.maplibre.android.plugins.testapp.TestStyles;
import org.maplibre.android.plugins.testapp.R;
import org.maplibre.android.plugins.testapp.Utils;
import org.maplibre.android.utils.ColorUtils;
Expand All @@ -38,7 +38,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_annotation);
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(maplibreMap -> maplibreMap.setStyle(Style.getPredefinedStyle("Streets"), style -> {
mapView.getMapAsync(maplibreMap -> maplibreMap.setStyle(TestStyles.BRIGHT.getUrl(), style -> {
findViewById(R.id.fabStyles).setOnClickListener(v -> maplibreMap.setStyle(Utils.INSTANCE.getNextStyle()));

maplibreMap.moveCamera(CameraUpdateFactory.zoomTo(2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.maplibre.android.plugins.annotation.Line;
import org.maplibre.android.plugins.annotation.LineManager;
import org.maplibre.android.plugins.annotation.LineOptions;
import org.maplibre.android.plugins.testapp.TestStyles;
import org.maplibre.android.plugins.testapp.R;
import org.maplibre.android.plugins.testapp.Utils;
import org.maplibre.android.utils.ColorUtils;
Expand Down Expand Up @@ -67,7 +68,7 @@ protected void onCreate(Bundle savedInstanceState) {
4)
);

maplibreMap.setStyle(new Style.Builder().fromUri(Style.getPredefinedStyle("Streets")), style -> {
maplibreMap.setStyle(new Style.Builder().fromUri(TestStyles.BRIGHT.getUrl()), style -> {
findViewById(R.id.fabStyles).setOnClickListener(v -> maplibreMap.setStyle(Utils.INSTANCE.getNextStyle()));

lineManager = new LineManager(mapView, maplibreMap, style);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.maplibre.android.maps.Style;
import org.maplibre.android.plugins.annotation.SymbolManager;
import org.maplibre.android.plugins.annotation.SymbolOptions;
import org.maplibre.android.plugins.testapp.TestStyles;
import org.maplibre.android.plugins.testapp.R;
import org.maplibre.android.plugins.testapp.Utils;

Expand Down Expand Up @@ -53,7 +54,7 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) {
);
maplibreMap.addOnMapLongClickListener(this::addSymbol);
maplibreMap.addOnMapClickListener(this::addSymbol);
maplibreMap.setStyle(getStyleBuilder(Style.getPredefinedStyle("Streets")), style -> {
maplibreMap.setStyle(getStyleBuilder(TestStyles.BRIGHT.getUrl()), style -> {
findViewById(R.id.fabStyles).setOnClickListener(v ->
maplibreMap.setStyle(getStyleBuilder(Utils.INSTANCE.getNextStyle())));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.maplibre.android.plugins.annotation.Symbol;
import org.maplibre.android.plugins.annotation.SymbolManager;
import org.maplibre.android.plugins.annotation.SymbolOptions;
import org.maplibre.android.plugins.testapp.TestStyles;
import org.maplibre.android.plugins.testapp.R;
import org.maplibre.android.plugins.testapp.Utils;
import org.maplibre.android.style.expressions.Expression;
Expand Down Expand Up @@ -64,7 +65,7 @@ protected void onCreate(Bundle savedInstanceState) {

mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(maplibreMap -> maplibreMap.setStyle(Style.getPredefinedStyle("Streets"), style -> {
mapView.getMapAsync(maplibreMap -> maplibreMap.setStyle(TestStyles.BRIGHT.getUrl(), style -> {
findViewById(R.id.fabStyles).setOnClickListener(v -> {
maplibreMap.setStyle(Utils.INSTANCE.getNextStyle());
maplibreMap.getStyle(this::addAirplaneImageToStyle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import org.maplibre.android.geometry.LatLng
import org.maplibre.android.maps.*
import org.maplibre.android.maps.MapLibreMap
import org.maplibre.android.maps.MapView
import org.maplibre.android.maps.OnMapReadyCallback
import org.maplibre.android.maps.queryRenderedFeatures
import org.maplibre.android.plugins.testapp.TestStyles
import org.maplibre.android.plugins.testapp.databinding.ActivityMapsKtxBinding

class MapLibreKtxActivity : AppCompatActivity(), OnMapReadyCallback, MapLibreMap.OnMapClickListener {
Expand All @@ -26,7 +30,7 @@ class MapLibreKtxActivity : AppCompatActivity(), OnMapReadyCallback, MapLibreMap

override fun onMapReady(maplibreMap: MapLibreMap) {
this.maplibreMap = maplibreMap
maplibreMap.setStyle(Style.getPredefinedStyle("Streets")) {
maplibreMap.setStyle(TestStyles.BRIGHT.url) {
maplibreMap.addOnMapClickListener(this)
Toast.makeText(this, "Click on the map", Toast.LENGTH_SHORT).show()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.maplibre.android.maps.OnMapReadyCallback
import org.maplibre.android.maps.Style
import org.maplibre.android.plugins.localization.LocalizationPlugin
import org.maplibre.android.plugins.localization.MapLocale
import org.maplibre.android.plugins.testapp.TestStyles
import org.maplibre.android.plugins.testapp.R
import org.maplibre.android.plugins.testapp.Utils
import org.maplibre.android.plugins.testapp.databinding.ActivityLocalizationBinding
Expand All @@ -35,7 +36,7 @@ class LocalizationActivity : AppCompatActivity(), OnMapReadyCallback {
}

override fun onMapReady(maplibreMap: MapLibreMap) {
maplibreMap?.setStyle(Style.getPredefinedStyle("Streets")) { style ->
maplibreMap?.setStyle(TestStyles.BRIGHT.url) { style ->
this.maplibreMap = maplibreMap
localizationPlugin =
LocalizationPlugin(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import org.maplibre.android.camera.CameraUpdateFactory
import org.maplibre.android.geometry.LatLng
import org.maplibre.android.maps.MapLibreMap
import org.maplibre.android.maps.MapView
import org.maplibre.android.maps.Style
import org.maplibre.android.plugins.markerview.MarkerView
import org.maplibre.android.plugins.markerview.MarkerViewManager
import org.maplibre.android.plugins.testapp.TestStyles
import org.maplibre.android.plugins.testapp.R
import org.maplibre.android.plugins.testapp.Utils
import java.util.*
import java.util.Random

class MarkerViewActivity :
AppCompatActivity(),
Expand All @@ -37,7 +37,7 @@ class MarkerViewActivity :

mapView.onCreate(savedInstanceState)
mapView.getMapAsync { maplibreMap ->
maplibreMap.setStyle(Style.getPredefinedStyle("Streets")) { _ ->
maplibreMap.setStyle(TestStyles.BRIGHT.url) { _ ->
findViewById<View>(R.id.fabStyles).setOnClickListener { maplibreMap.setStyle(Utils.nextStyle) }

maplibreMap.moveCamera(CameraUpdateFactory.zoomTo(2.0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import androidx.appcompat.app.AppCompatActivity
import org.maplibre.android.constants.MapLibreConstants
import org.maplibre.android.geometry.LatLng
import org.maplibre.android.geometry.LatLngBounds
import org.maplibre.android.maps.Style
import org.maplibre.android.offline.OfflineTilePyramidRegionDefinition
import org.maplibre.android.plugins.offline.model.NotificationOptions
import org.maplibre.android.plugins.offline.model.OfflineDownloadOptions
import org.maplibre.android.plugins.offline.offline.OfflinePlugin
import org.maplibre.android.plugins.offline.utils.OfflineUtils
import org.maplibre.android.plugins.testapp.TestStyles
import org.maplibre.android.plugins.testapp.R
import org.maplibre.android.plugins.testapp.databinding.ActivityOfflineDownloadBinding

Expand Down Expand Up @@ -69,10 +69,9 @@ class OfflineDownloadActivity : AppCompatActivity() {

private fun initSpinner() {
val styles = ArrayList<String>()
styles.add(Style.getPredefinedStyle("Streets"))
styles.add(Style.getPredefinedStyle("Dark"))
styles.add(Style.getPredefinedStyle("Light"))
styles.add(Style.getPredefinedStyle("Outdoors"))
styles.add(TestStyles.BRIGHT.url)
styles.add(TestStyles.POSITRON.url)
styles.add(TestStyles.LIBERTY.url)
val spinnerArrayAdapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, styles)
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
binding.spinnerStyleUrl.adapter = spinnerArrayAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.maplibre.android.maps.MapView
import org.maplibre.android.maps.Style
import org.maplibre.android.plugins.scalebar.ScaleBarOptions
import org.maplibre.android.plugins.scalebar.ScaleBarPlugin
import org.maplibre.android.plugins.testapp.BuildConfig
import org.maplibre.android.plugins.testapp.TestStyles
import org.maplibre.android.plugins.testapp.databinding.ActivityScalebarBinding
import org.maplibre.android.style.layers.LineLayer
import org.maplibre.android.style.sources.GeoJsonSource
Expand All @@ -30,7 +30,7 @@ class ScalebarActivity : AppCompatActivity() {
mapView = binding.mapView
mapView.onCreate(savedInstanceState)
mapView.getMapAsync { maplibreMap ->
maplibreMap.setStyle("https://api.maptiler.com/maps/basic-v2/style.json?key=" + BuildConfig.MAPTILER_API_KEY) {
maplibreMap.setStyle(TestStyles.BRIGHT.url) {
addScalebar(maplibreMap)
setupTestLine(it)
}
Expand Down

0 comments on commit 4cd4cf2

Please sign in to comment.