Compare commits
8 Commits
61a1f588c0
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a50a38dcb | |||
| 44081e82cb | |||
| 419d18b5ee | |||
| d72e14b52d | |||
| 0ddb424854 | |||
| 5856474398 | |||
| cd9efed381 | |||
| 35c8ec3a68 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -9,3 +9,4 @@ DS_Store
|
|||||||
.cxx
|
.cxx
|
||||||
local.properties
|
local.properties
|
||||||
/legacy_code/
|
/legacy_code/
|
||||||
|
maptiler*
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
## Strike Maps Project Android Client
|
## Strike Maps Project Android Client
|
||||||
|
|
||||||
Strike Maps is a project hoping to create a multi-platform, <br>
|
Strike Maps is a project hoping to create a multi-platform, <br>
|
||||||
user-facing, complete FOSS mapping stack, focusing on style customization <br>
|
user-facing, complete FOSS mapping stack, focusing on customization <br>
|
||||||
and offline features.
|
and offline features.
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -5,6 +5,7 @@
|
|||||||
"sources": {
|
"sources": {
|
||||||
"satelite": {
|
"satelite": {
|
||||||
"type": "raster",
|
"type": "raster",
|
||||||
|
"schema" : "raster",
|
||||||
"tiles": [
|
"tiles": [
|
||||||
"https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
|
"https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
|
||||||
],
|
],
|
||||||
@@ -14,8 +15,6 @@
|
|||||||
"tileSize": 512
|
"tileSize": 512
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sprite": "",
|
|
||||||
"glyphs": "https://orangemug.github.io/font-glyphs/glyphs/{fontstack}/{range}.pbf",
|
|
||||||
"layers": [
|
"layers": [
|
||||||
{
|
{
|
||||||
"id": "satelite",
|
"id": "satelite",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package eu.konggdev.strikemaps.helper;
|
package eu.konggdev.strikemaps.data.helper;
|
||||||
|
|
||||||
import android.content.res.AssetManager;
|
import android.content.res.AssetManager;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package eu.konggdev.strikemaps.helper;
|
package eu.konggdev.strikemaps.data.helper;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package eu.konggdev.strikemaps.provider;
|
package eu.konggdev.strikemaps.data.provider;
|
||||||
|
|
||||||
public class HttpDataProvider implements Provider {
|
public class HttpDataProvider implements Provider {
|
||||||
//TODO
|
//TODO
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package eu.konggdev.strikemaps.provider;
|
package eu.konggdev.strikemaps.data.provider;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package eu.konggdev.strikemaps.data.provider;
|
||||||
|
|
||||||
|
public interface Provider {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,9 +2,10 @@ package eu.konggdev.strikemaps.map;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import eu.konggdev.strikemaps.Component;
|
import eu.konggdev.strikemaps.Component;
|
||||||
import eu.konggdev.strikemaps.factory.AlertDialogFactory;
|
import eu.konggdev.strikemaps.ui.factory.AlertDialogFactory;
|
||||||
import eu.konggdev.strikemaps.helper.UserPrefsHelper;
|
import eu.konggdev.strikemaps.data.helper.UserPrefsHelper;
|
||||||
import eu.konggdev.strikemaps.map.renderer.implementation.VtmRenderer;
|
import eu.konggdev.strikemaps.map.renderer.implementation.VtmRenderer;
|
||||||
|
import eu.konggdev.strikemaps.map.style.MapStyle;
|
||||||
import org.maplibre.android.geometry.LatLng;
|
import org.maplibre.android.geometry.LatLng;
|
||||||
import org.maplibre.geojson.Feature;
|
import org.maplibre.geojson.Feature;
|
||||||
|
|
||||||
@@ -18,7 +19,7 @@ public class MapComponent implements Component {
|
|||||||
MapRenderer mapRenderer;
|
MapRenderer mapRenderer;
|
||||||
AppController app;
|
AppController app;
|
||||||
|
|
||||||
public String style;
|
public MapStyle style;
|
||||||
public Map<Class<? extends MapOverlay>, MapOverlay> overlays = new HashMap<>();
|
public Map<Class<? extends MapOverlay>, MapOverlay> overlays = new HashMap<>();
|
||||||
public MapComponent(AppController ref) {
|
public MapComponent(AppController ref) {
|
||||||
this.app = ref;
|
this.app = ref;
|
||||||
@@ -37,7 +38,7 @@ public class MapComponent implements Component {
|
|||||||
return new FragmentLayoutContentMap(mapRenderer.getView());
|
return new FragmentLayoutContentMap(mapRenderer.getView());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStyle(String style) {
|
public void setStyle(MapStyle style) {
|
||||||
this.style = style;
|
this.style = style;
|
||||||
mapRenderer.reload();
|
mapRenderer.reload();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package eu.konggdev.strikemaps.map.layer;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
|
||||||
|
public class MapLayer {
|
||||||
|
public JsonNode layer;
|
||||||
|
|
||||||
|
public MapLayer(JsonNode layer) {
|
||||||
|
this.layer = layer;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package eu.konggdev.strikemaps.map.layer;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import eu.konggdev.strikemaps.map.source.MapSource;
|
||||||
|
|
||||||
|
public class SourcedMapLayer {
|
||||||
|
public String key;
|
||||||
|
public MapSource source;
|
||||||
|
public JsonNode layer;
|
||||||
|
|
||||||
|
public SourcedMapLayer(String key, MapSource source, JsonNode layer) {
|
||||||
|
this.key = key;
|
||||||
|
this.source = source;
|
||||||
|
this.layer = layer;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package eu.konggdev.strikemaps.map.overlay;
|
package eu.konggdev.strikemaps.map.overlay;
|
||||||
|
|
||||||
import eu.konggdev.strikemaps.map.layer.MapLayer;
|
import eu.konggdev.strikemaps.map.layer.SourcedMapLayer;
|
||||||
|
|
||||||
/* More or less a data-driven layer factory */
|
/* More or less a data-driven layer factory */
|
||||||
public interface MapOverlay {
|
public interface MapOverlay {
|
||||||
public MapLayer makeLayer();
|
public SourcedMapLayer makeLayer();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
package eu.konggdev.strikemaps.map.overlay.implementation;
|
||||||
|
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.location.Location;
|
||||||
|
import android.location.LocationListener;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import eu.konggdev.strikemaps.app.AppController;
|
||||||
|
import eu.konggdev.strikemaps.map.MapComponent;
|
||||||
|
import eu.konggdev.strikemaps.map.layer.SourcedMapLayer;
|
||||||
|
import eu.konggdev.strikemaps.map.overlay.MapOverlay;
|
||||||
|
import eu.konggdev.strikemaps.map.source.MapSource;
|
||||||
|
|
||||||
|
import eu.konggdev.strikemaps.data.provider.LocationDataProvider;
|
||||||
|
import org.maplibre.geojson.Feature;
|
||||||
|
import org.maplibre.geojson.FeatureCollection;
|
||||||
|
import org.maplibre.geojson.Point;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
|
|
||||||
|
public class LocationOverlay implements MapOverlay, LocationListener {
|
||||||
|
LocationDataProvider locationDataProvider;
|
||||||
|
AppController app;
|
||||||
|
MapComponent map;
|
||||||
|
|
||||||
|
public Location currentLocation = null;
|
||||||
|
|
||||||
|
public LocationOverlay(AppController app) {
|
||||||
|
this.app = app;
|
||||||
|
this.map = app.getMap();
|
||||||
|
this.locationDataProvider = new LocationDataProvider(app.getActivity(), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SourcedMapLayer makeLayer() {
|
||||||
|
MapSource source = new MapSource();
|
||||||
|
|
||||||
|
source.type = "geojson";
|
||||||
|
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
try {
|
||||||
|
ObjectNode data = mapper.createObjectNode();
|
||||||
|
data.put("type", "Feature");
|
||||||
|
|
||||||
|
if(currentLocation != null) {
|
||||||
|
ObjectNode geometry = mapper.createObjectNode();
|
||||||
|
geometry.put("type", "Point");
|
||||||
|
|
||||||
|
ArrayNode coordinates = mapper.createArrayNode();
|
||||||
|
coordinates.add(currentLocation.getLongitude());
|
||||||
|
coordinates.add(currentLocation.getLatitude());
|
||||||
|
|
||||||
|
geometry.set("coordinates", coordinates);
|
||||||
|
data.set("geometry", geometry);
|
||||||
|
data.set("properties", mapper.createObjectNode());
|
||||||
|
}
|
||||||
|
source.data = data;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectNode layer = mapper.createObjectNode();
|
||||||
|
layer.put("id", "location");
|
||||||
|
layer.put("type", "circle");
|
||||||
|
layer.put("source", "location");
|
||||||
|
|
||||||
|
ObjectNode paint = mapper.createObjectNode();
|
||||||
|
paint.put("circle-radius", 5);
|
||||||
|
paint.put("circle-color", "#1E88E5");
|
||||||
|
paint.put("circle-stroke-color", "#FFFFFF");
|
||||||
|
paint.put("circle-stroke-width", 1.5);
|
||||||
|
|
||||||
|
layer.set("paint", paint);
|
||||||
|
|
||||||
|
ObjectNode layout = mapper.createObjectNode();
|
||||||
|
layout.put("circle-pitch-alignment", "map");
|
||||||
|
|
||||||
|
layer.set("layout", layout);
|
||||||
|
|
||||||
|
ArrayNode layers = mapper.createArrayNode();
|
||||||
|
layers.add(layer);
|
||||||
|
|
||||||
|
return new SourcedMapLayer("location", source, layers);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLocationChanged(@NonNull Location location) {
|
||||||
|
this.currentLocation = location;
|
||||||
|
map.onOverlayUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
package eu.konggdev.strikemaps.map.overlay.overlay;
|
package eu.konggdev.strikemaps.map.overlay.implementation;
|
||||||
|
|
||||||
import eu.konggdev.strikemaps.map.layer.MapLayer;
|
import eu.konggdev.strikemaps.map.layer.MapLayer;
|
||||||
|
import eu.konggdev.strikemaps.map.layer.SourcedMapLayer;
|
||||||
import eu.konggdev.strikemaps.map.overlay.MapOverlay;
|
import eu.konggdev.strikemaps.map.overlay.MapOverlay;
|
||||||
|
|
||||||
public class PointSelectionOverlay implements MapOverlay {
|
public class PointSelectionOverlay implements MapOverlay {
|
||||||
@Override
|
@Override
|
||||||
public MapLayer makeLayer() {
|
public SourcedMapLayer makeLayer() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
package eu.konggdev.strikemaps.map.overlay.overlay;
|
|
||||||
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.location.Location;
|
|
||||||
import android.location.LocationListener;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import eu.konggdev.strikemaps.app.AppController;
|
|
||||||
import eu.konggdev.strikemaps.map.MapComponent;
|
|
||||||
import eu.konggdev.strikemaps.map.layer.MapLayer;
|
|
||||||
|
|
||||||
import eu.konggdev.strikemaps.map.overlay.MapOverlay;
|
|
||||||
import eu.konggdev.strikemaps.provider.LocationDataProvider;
|
|
||||||
import org.maplibre.android.style.layers.CircleLayer;
|
|
||||||
import org.maplibre.android.style.layers.Property;
|
|
||||||
import org.maplibre.android.style.sources.GeoJsonSource;
|
|
||||||
import org.maplibre.geojson.Feature;
|
|
||||||
import org.maplibre.geojson.FeatureCollection;
|
|
||||||
import org.maplibre.geojson.Point;
|
|
||||||
|
|
||||||
import static org.maplibre.android.style.layers.PropertyFactory.*;
|
|
||||||
|
|
||||||
public class LocationOverlay implements MapOverlay, LocationListener {
|
|
||||||
LocationDataProvider locationDataProvider;
|
|
||||||
AppController app;
|
|
||||||
MapComponent map;
|
|
||||||
|
|
||||||
public Location currentLocation = null;
|
|
||||||
|
|
||||||
public LocationOverlay(AppController app) {
|
|
||||||
this.app = app;
|
|
||||||
this.map = app.getMap();
|
|
||||||
this.locationDataProvider = new LocationDataProvider(app.getActivity(), this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MapLayer makeLayer() {
|
|
||||||
GeoJsonSource source = new GeoJsonSource(
|
|
||||||
"location",
|
|
||||||
FeatureCollection.fromFeatures(new Feature[]{}) // empty
|
|
||||||
);
|
|
||||||
|
|
||||||
if (currentLocation != null)
|
|
||||||
source.setGeoJson(Feature.fromGeometry(Point.fromLngLat(currentLocation.getLongitude(), currentLocation.getLatitude())));
|
|
||||||
|
|
||||||
CircleLayer layer = new CircleLayer("location", "location");
|
|
||||||
layer.setProperties(
|
|
||||||
circleRadius(5f),
|
|
||||||
circleColor(Color.parseColor("#1E88E5")),
|
|
||||||
circleStrokeColor(Color.WHITE),
|
|
||||||
circleStrokeWidth(1.5f),
|
|
||||||
circlePitchAlignment(Property.CIRCLE_PITCH_ALIGNMENT_MAP)
|
|
||||||
);
|
|
||||||
|
|
||||||
return new MapLayer(source, layer);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLocationChanged(@NonNull Location location) {
|
|
||||||
this.currentLocation = location;
|
|
||||||
map.onOverlayUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -15,5 +15,6 @@ public interface MapRenderer {
|
|||||||
|
|
||||||
View getView();
|
View getView();
|
||||||
|
|
||||||
|
//TODO: Get rid of MapLibre Feature class dependence
|
||||||
List<Feature> featuresAtPoint(LatLng point);
|
List<Feature> featuresAtPoint(LatLng point);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,15 @@ import android.view.View;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import eu.konggdev.strikemaps.helper.FileHelper;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import eu.konggdev.strikemaps.helper.UserPrefsHelper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
|
import eu.konggdev.strikemaps.data.helper.UserPrefsHelper;
|
||||||
import eu.konggdev.strikemaps.map.overlay.MapOverlay;
|
import eu.konggdev.strikemaps.map.overlay.MapOverlay;
|
||||||
import eu.konggdev.strikemaps.map.layer.MapLayer;
|
import eu.konggdev.strikemaps.map.layer.SourcedMapLayer;
|
||||||
import eu.konggdev.strikemaps.map.renderer.MapRenderer;
|
import eu.konggdev.strikemaps.map.renderer.MapRenderer;
|
||||||
|
import eu.konggdev.strikemaps.map.style.MapStyle;
|
||||||
import org.maplibre.android.MapLibre;
|
import org.maplibre.android.MapLibre;
|
||||||
import org.maplibre.android.geometry.LatLng;
|
import org.maplibre.android.geometry.LatLng;
|
||||||
import org.maplibre.android.maps.MapLibreMap;
|
import org.maplibre.android.maps.MapLibreMap;
|
||||||
@@ -37,18 +41,40 @@ public class MapLibreNativeRenderer implements MapRenderer, OnMapReadyCallback {
|
|||||||
mapView.getMapAsync(this);
|
mapView.getMapAsync(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void passLayer(MapLayer layer) {
|
|
||||||
map.getStyle().addSource(layer.source);
|
|
||||||
map.getStyle().addLayer(layer.layer);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload() {
|
public void reload() {
|
||||||
map.setStyle(new Style.Builder().fromJson(controller.style), style -> {
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
for(MapOverlay overlay : controller.overlays.values()) {
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
|
||||||
passLayer(overlay.makeLayer());
|
MapStyle style = controller.style;
|
||||||
|
try {
|
||||||
|
/* Take metadata from MapStyle
|
||||||
|
everything outside sources, layers */
|
||||||
|
ObjectNode root = style.metadata.deepCopy();
|
||||||
|
|
||||||
|
//Sources
|
||||||
|
ObjectNode sources = mapper.createObjectNode();
|
||||||
|
style.sources.forEach((k, v) -> sources.set(k, mapper.valueToTree(v)));
|
||||||
|
|
||||||
|
//Layers
|
||||||
|
ArrayNode layers = mapper.createArrayNode();
|
||||||
|
layers.addAll((ArrayNode) style.layerDefinitions);
|
||||||
|
|
||||||
|
//Overlays
|
||||||
|
for (MapOverlay overlay : controller.overlays.values()) {
|
||||||
|
SourcedMapLayer overlayLayer = overlay.makeLayer();
|
||||||
|
sources.set(overlayLayer.key, mapper.valueToTree(overlayLayer.source));
|
||||||
|
layers.addAll((ArrayNode) overlayLayer.layer);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Set all to root
|
||||||
|
root.set("sources", sources);
|
||||||
|
root.set("layers", layers);
|
||||||
|
|
||||||
|
map.setStyle(new Style.Builder().fromJson(mapper.writeValueAsString(root)));
|
||||||
|
} catch (Exception e) {
|
||||||
|
app.logcat("Failed to reload Map");
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -65,7 +91,7 @@ public class MapLibreNativeRenderer implements MapRenderer, OnMapReadyCallback {
|
|||||||
public void onMapReady(@NonNull MapLibreMap maplibreMap) {
|
public void onMapReady(@NonNull MapLibreMap maplibreMap) {
|
||||||
this.map = maplibreMap;
|
this.map = maplibreMap;
|
||||||
|
|
||||||
controller.style = FileHelper.loadStringFromAssetFile(UserPrefsHelper.startupMapStyle(app.getPrefs()), app);
|
controller.setStyle(MapStyle.fromMapLibreJsonFile(UserPrefsHelper.startupMapStyle(app.getPrefs()), app));
|
||||||
|
|
||||||
//I have my own implementation of attribution that credits MapLibre among others, it's not as bad as it looks :)
|
//I have my own implementation of attribution that credits MapLibre among others, it's not as bad as it looks :)
|
||||||
map.getUiSettings().setLogoEnabled(false);
|
map.getUiSettings().setLogoEnabled(false);
|
||||||
@@ -73,6 +99,5 @@ public class MapLibreNativeRenderer implements MapRenderer, OnMapReadyCallback {
|
|||||||
|
|
||||||
map.addOnMapClickListener(point -> controller.onMapClick(point));
|
map.addOnMapClickListener(point -> controller.onMapClick(point));
|
||||||
map.addOnMapLongClickListener(point -> controller.onMapLongClick(point));
|
map.addOnMapLongClickListener(point -> controller.onMapLongClick(point));
|
||||||
this.reload();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,21 @@
|
|||||||
package eu.konggdev.strikemaps.map.source;
|
package eu.konggdev.strikemaps.map.source;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
|
||||||
public class MapSource {
|
public class MapSource {
|
||||||
public final String url;
|
public String url;
|
||||||
public final String type;
|
public JsonNode data;
|
||||||
public final String schema;
|
public String type;
|
||||||
public MapSource(String url, String type, String schema) {
|
public String schema;
|
||||||
this.url = url;
|
|
||||||
this.type = type;
|
public JsonNode tiles;
|
||||||
this.schema = schema;
|
public int minzoom;
|
||||||
}
|
public int maxzoom;
|
||||||
|
public String scheme;
|
||||||
|
public int tileSize;
|
||||||
|
|
||||||
|
public String attribution;
|
||||||
|
|
||||||
|
public String encoding;
|
||||||
|
public MapSource() { }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,26 @@
|
|||||||
package eu.konggdev.strikemaps.map.style;
|
package eu.konggdev.strikemaps.map.style;
|
||||||
|
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import eu.konggdev.strikemaps.app.AppController;
|
import eu.konggdev.strikemaps.app.AppController;
|
||||||
import eu.konggdev.strikemaps.helper.FileHelper;
|
import eu.konggdev.strikemaps.data.helper.FileHelper;
|
||||||
import eu.konggdev.strikemaps.map.layer.MapLayer;
|
|
||||||
import eu.konggdev.strikemaps.map.source.MapSource;
|
import eu.konggdev.strikemaps.map.source.MapSource;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
|
||||||
public class MapStyle {
|
public class MapStyle {
|
||||||
public int version;
|
//Only local data
|
||||||
public String name;
|
public String name;
|
||||||
public String icon;
|
public Bitmap icon;
|
||||||
public String description;
|
|
||||||
|
|
||||||
|
public JsonNode metadata; // everything except layers + sources
|
||||||
public Map<String, MapSource> sources;
|
public Map<String, MapSource> sources;
|
||||||
public List<MapLayer> layers;
|
public ArrayNode layerDefinitions; // the "layers" array
|
||||||
|
|
||||||
public JsonNode raw;
|
|
||||||
|
|
||||||
//FIXME
|
//FIXME
|
||||||
public static MapStyle fromMapLibreJsonFile(String filename, AppController app) {
|
public static MapStyle fromMapLibreJsonFile(String filename, AppController app) {
|
||||||
@@ -30,34 +31,38 @@ public class MapStyle {
|
|||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
try {
|
try {
|
||||||
JsonNode root = mapper.readTree(styleContents);
|
JsonNode root = mapper.readTree(styleContents);
|
||||||
MapStyle style = new MapStyle();
|
|
||||||
|
|
||||||
style.version = root.path("version").asInt();
|
MapStyle style = new MapStyle();
|
||||||
style.name = root.path("name").asText();
|
style.name = root.path("name").asText();
|
||||||
style.icon = root.path("icon").asText();
|
style.icon = getIcon(root.path("icon").asText(), app);
|
||||||
style.description = root.path("description").asText();
|
|
||||||
|
|
||||||
style.sources = mapper.convertValue(
|
style.sources = mapper.convertValue(
|
||||||
root.path("sources"),
|
root.path("sources"),
|
||||||
new TypeReference<Map<String, MapSource>>() {}
|
new TypeReference<Map<String, MapSource>>() {}
|
||||||
);
|
);
|
||||||
|
|
||||||
style.layers = new ArrayList<>();
|
style.layerDefinitions = root.withArray("layers");
|
||||||
for (JsonNode layerNode : root.path("layers")) {
|
|
||||||
|
|
||||||
MapLayer layer = mapper.treeToValue(layerNode, MapLayer.class);
|
ObjectNode metadata = root.deepCopy();
|
||||||
|
metadata.remove("layers");
|
||||||
layer.raw = layerNode; // IMPORTANT
|
metadata.remove("sources");
|
||||||
|
style.metadata = metadata;
|
||||||
style.layers.add(layer);
|
|
||||||
}
|
|
||||||
|
|
||||||
style.raw = root; // full backup
|
|
||||||
|
|
||||||
return style;
|
return style;
|
||||||
} catch ( Exception e ) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Bitmap getIcon(String iconLocator, AppController app) {
|
||||||
|
switch(iconLocator.split("//")[0]) {
|
||||||
|
//TODO: https
|
||||||
|
case "assets:":
|
||||||
|
return BitmapFactory.decodeStream(FileHelper.openAssetStream("bundled/icon/" + iconLocator.split("//")[1], app));
|
||||||
|
default:
|
||||||
|
app.logcat("Unimplemented icon locator space: " + iconLocator);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
package eu.konggdev.strikemaps.provider;
|
|
||||||
|
|
||||||
public interface Provider {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,26 +1,22 @@
|
|||||||
package eu.konggdev.strikemaps.ui.element.item;
|
package eu.konggdev.strikemaps.ui.element.item;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import eu.konggdev.strikemaps.R;
|
import eu.konggdev.strikemaps.R;
|
||||||
import eu.konggdev.strikemaps.app.AppController;
|
|
||||||
import eu.konggdev.strikemaps.helper.FileHelper;
|
|
||||||
import eu.konggdev.strikemaps.map.MapComponent;
|
import eu.konggdev.strikemaps.map.MapComponent;
|
||||||
|
import eu.konggdev.strikemaps.map.style.MapStyle;
|
||||||
import eu.konggdev.strikemaps.ui.UIComponent;
|
import eu.konggdev.strikemaps.ui.UIComponent;
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
public class GenericItem implements UIItem {
|
public class GenericItem implements UIItem {
|
||||||
@NonNull public String name;
|
@NonNull public String name;
|
||||||
public Bitmap image;
|
public Bitmap image;
|
||||||
public Runnable onClick;
|
public Runnable onClick;
|
||||||
boolean hasImage;
|
boolean hasImage;
|
||||||
|
|
||||||
public GenericItem(String refName) {
|
public GenericItem(String refName) {
|
||||||
this.name = refName;
|
this.name = refName;
|
||||||
hasImage = false;
|
hasImage = false;
|
||||||
@@ -42,28 +38,11 @@ public class GenericItem implements UIItem {
|
|||||||
hasImage = true;
|
hasImage = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//FIXME: Ugly glue static constructor
|
public final static GenericItem fromStyle(MapStyle style, MapComponent map) {
|
||||||
public final static GenericItem fromStyle(String style, AppController app, MapComponent map) {
|
if(style == null) return new GenericItem("Unknown");
|
||||||
try {
|
if(style.icon != null)
|
||||||
JSONObject styleJson = new JSONObject(style);
|
return new GenericItem(style.name, style.icon, () -> map.setStyle(style));
|
||||||
String name = "Unknown"; //Fallback name
|
return new GenericItem(style.name, () -> map.setStyle(style));
|
||||||
if (styleJson.has("name")) name = styleJson.getString("name");
|
|
||||||
if (styleJson.has("icon")) {
|
|
||||||
switch(styleJson.getString("icon").split("//")[0]) {
|
|
||||||
//TODO: https
|
|
||||||
case "assets:":
|
|
||||||
Bitmap icon = BitmapFactory.decodeStream(FileHelper.openAssetStream("bundled/icon/" + styleJson.getString("icon").split("//")[1], app));
|
|
||||||
return new GenericItem(name, icon, () -> map.setStyle(style));
|
|
||||||
default:
|
|
||||||
app.logcat("Unimplemented icon source requested in style: " + name);
|
|
||||||
return new GenericItem(name, () -> map.setStyle(style));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new GenericItem(name, () -> map.setStyle(style));
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return new GenericItem("Exception!", () -> map.setStyle(style));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public View makeView(UIComponent spawner) {
|
public View makeView(UIComponent spawner) {
|
||||||
View v = spawner.inflateUi(R.layout.item_generic);
|
View v = spawner.inflateUi(R.layout.item_generic);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package eu.konggdev.strikemaps.factory;
|
package eu.konggdev.strikemaps.ui.factory;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
@@ -15,8 +15,8 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import eu.konggdev.strikemaps.R;
|
import eu.konggdev.strikemaps.R;
|
||||||
import eu.konggdev.strikemaps.app.AppController;
|
import eu.konggdev.strikemaps.app.AppController;
|
||||||
import eu.konggdev.strikemaps.helper.UserPrefsHelper;
|
import eu.konggdev.strikemaps.data.helper.UserPrefsHelper;
|
||||||
import eu.konggdev.strikemaps.map.overlay.overlay.LocationOverlay;
|
import eu.konggdev.strikemaps.map.overlay.implementation.LocationOverlay;
|
||||||
import eu.konggdev.strikemaps.ui.fragment.popup.FragmentMapChangePopup;
|
import eu.konggdev.strikemaps.ui.fragment.popup.FragmentMapChangePopup;
|
||||||
|
|
||||||
public class FragmentLayoutControls extends Fragment implements Layout {
|
public class FragmentLayoutControls extends Fragment implements Layout {
|
||||||
|
|||||||
@@ -9,15 +9,15 @@ import android.widget.LinearLayout;
|
|||||||
|
|
||||||
import eu.konggdev.strikemaps.R;
|
import eu.konggdev.strikemaps.R;
|
||||||
import eu.konggdev.strikemaps.app.AppController;
|
import eu.konggdev.strikemaps.app.AppController;
|
||||||
import eu.konggdev.strikemaps.helper.FileHelper;
|
import eu.konggdev.strikemaps.data.helper.FileHelper;
|
||||||
import eu.konggdev.strikemaps.factory.AlertDialogFactory;
|
|
||||||
import eu.konggdev.strikemaps.map.MapComponent;
|
import eu.konggdev.strikemaps.map.MapComponent;
|
||||||
|
|
||||||
|
import eu.konggdev.strikemaps.map.style.MapStyle;
|
||||||
import eu.konggdev.strikemaps.ui.UIComponent;
|
import eu.konggdev.strikemaps.ui.UIComponent;
|
||||||
import eu.konggdev.strikemaps.ui.element.item.GenericItem;
|
import eu.konggdev.strikemaps.ui.element.item.GenericItem;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@@ -35,6 +35,7 @@ public class FragmentMapChangePopup extends Fragment implements Popup {
|
|||||||
this.ui = app.getUi();
|
this.ui = app.getUi();
|
||||||
this.region = region;
|
this.region = region;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer getRegion() {
|
public Integer getRegion() {
|
||||||
return region;
|
return region;
|
||||||
@@ -50,12 +51,11 @@ public class FragmentMapChangePopup extends Fragment implements Popup {
|
|||||||
//FIXME
|
//FIXME
|
||||||
setupButton(view, R.id.closeButton, click(() -> ui.getCurrentScreen().closePopup()));
|
setupButton(view, R.id.closeButton, click(() -> ui.getCurrentScreen().closePopup()));
|
||||||
setupDragHandle(view, view, () -> ui.getCurrentScreen().closePopup());
|
setupDragHandle(view, view, () -> ui.getCurrentScreen().closePopup());
|
||||||
String[] stylePaths = ArrayUtils.addAll(FileHelper.getAssetFiles("bundled/style", ".style.json", app), FileHelper.getUserFiles("style", ".style.json", app));
|
List<String> stylePaths = new ArrayList<>();
|
||||||
List<View> views = new ArrayList<>();
|
stylePaths.addAll(Arrays.asList(FileHelper.getAssetFiles("bundled/style", ".style.json", app)));
|
||||||
|
stylePaths.addAll(Arrays.asList(FileHelper.getUserFiles("style", ".style.json", app)));
|
||||||
LinearLayout stylesLayout = view.findViewById(R.id.stylesLayout);
|
LinearLayout stylesLayout = view.findViewById(R.id.stylesLayout);
|
||||||
for(String i : stylePaths) {
|
for (String style : stylePaths)
|
||||||
if(i.startsWith("/storage")) stylesLayout.addView(GenericItem.fromStyle(FileHelper.loadStringFromUserFile(i), app, map).makeView(ui));
|
stylesLayout.addView(GenericItem.fromStyle(MapStyle.fromMapLibreJsonFile(style, app), map).makeView(ui));
|
||||||
else stylesLayout.addView(GenericItem.fromStyle(FileHelper.loadStringFromAssetFile(i, app), app, map).makeView(ui));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user