Compare commits
7 Commits
master
...
9c685e5e2e
| Author | SHA1 | Date | |
|---|---|---|---|
| 9c685e5e2e | |||
| fbc8b8eedb | |||
| 92d685021b | |||
| 1e9a421df2 | |||
| b4bc8feec5 | |||
| 4a625323d4 | |||
| 9c9d74d5e4 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -9,4 +9,3 @@ DS_Store
|
|||||||
.cxx
|
.cxx
|
||||||
local.properties
|
local.properties
|
||||||
/legacy_code/
|
/legacy_code/
|
||||||
maptiler*
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
"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}"
|
||||||
],
|
],
|
||||||
@@ -15,6 +14,8 @@
|
|||||||
"tileSize": 512
|
"tileSize": 512
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"sprite": "",
|
||||||
|
"glyphs": "https://orangemug.github.io/font-glyphs/glyphs/{fontstack}/{range}.pbf",
|
||||||
"layers": [
|
"layers": [
|
||||||
{
|
{
|
||||||
"id": "satelite",
|
"id": "satelite",
|
||||||
|
|||||||
@@ -106,4 +106,4 @@ public final class FileHelper {
|
|||||||
|
|
||||||
return fileList.toArray(new String[0]);
|
return fileList.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,4 +37,4 @@ public final class UserPrefsHelper {
|
|||||||
public static boolean lastLocationEnabled(SharedPreferences prefs, boolean status) {
|
public static boolean lastLocationEnabled(SharedPreferences prefs, boolean status) {
|
||||||
return prefs.edit().putBoolean(KEY_LAST_LOCATION_ENABLED, status).commit();
|
return prefs.edit().putBoolean(KEY_LAST_LOCATION_ENABLED, status).commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,16 @@
|
|||||||
package eu.konggdev.strikemaps.map.layer;
|
package eu.konggdev.strikemaps.map.layer;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import org.maplibre.android.style.layers.Layer;
|
||||||
|
import org.maplibre.android.style.sources.GeoJsonSource;
|
||||||
|
|
||||||
|
|
||||||
|
//FIXME: Get rid of reliance on MapLibre!
|
||||||
|
//Most likely implement an "AdditionalMapLayer" or something of that sorts (?)
|
||||||
public class MapLayer {
|
public class MapLayer {
|
||||||
public JsonNode layer;
|
public GeoJsonSource source;
|
||||||
|
public Layer layer;
|
||||||
public MapLayer(JsonNode layer) {
|
public MapLayer(GeoJsonSource source, Layer layer) {
|
||||||
this.layer = layer;
|
this.source = source;
|
||||||
|
this.layer = layer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
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.SourcedMapLayer;
|
import eu.konggdev.strikemaps.map.layer.MapLayer;
|
||||||
|
|
||||||
/* More or less a data-driven layer factory */
|
/* More or less a data-driven layer factory */
|
||||||
public interface MapOverlay {
|
public interface MapOverlay {
|
||||||
public SourcedMapLayer makeLayer();
|
public MapLayer makeLayer();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,18 +6,18 @@ import android.location.LocationListener;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import eu.konggdev.strikemaps.app.AppController;
|
import eu.konggdev.strikemaps.app.AppController;
|
||||||
import eu.konggdev.strikemaps.map.MapComponent;
|
import eu.konggdev.strikemaps.map.MapComponent;
|
||||||
import eu.konggdev.strikemaps.map.layer.SourcedMapLayer;
|
import eu.konggdev.strikemaps.map.layer.MapLayer;
|
||||||
import eu.konggdev.strikemaps.map.overlay.MapOverlay;
|
|
||||||
import eu.konggdev.strikemaps.map.source.MapSource;
|
|
||||||
|
|
||||||
|
import eu.konggdev.strikemaps.map.overlay.MapOverlay;
|
||||||
import eu.konggdev.strikemaps.data.provider.LocationDataProvider;
|
import eu.konggdev.strikemaps.data.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.Feature;
|
||||||
import org.maplibre.geojson.FeatureCollection;
|
import org.maplibre.geojson.FeatureCollection;
|
||||||
import org.maplibre.geojson.Point;
|
import org.maplibre.geojson.Point;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import static org.maplibre.android.style.layers.PropertyFactory.*;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
||||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
|
||||||
|
|
||||||
public class LocationOverlay implements MapOverlay, LocationListener {
|
public class LocationOverlay implements MapOverlay, LocationListener {
|
||||||
LocationDataProvider locationDataProvider;
|
LocationDataProvider locationDataProvider;
|
||||||
@@ -33,55 +33,25 @@ public class LocationOverlay implements MapOverlay, LocationListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SourcedMapLayer makeLayer() {
|
public MapLayer makeLayer() {
|
||||||
MapSource source = new MapSource();
|
GeoJsonSource source = new GeoJsonSource(
|
||||||
|
"location",
|
||||||
|
FeatureCollection.fromFeatures(new Feature[]{}) // empty
|
||||||
|
);
|
||||||
|
|
||||||
source.type = "geojson";
|
if (currentLocation != null)
|
||||||
|
source.setGeoJson(Feature.fromGeometry(Point.fromLngLat(currentLocation.getLongitude(), currentLocation.getLatitude())));
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
CircleLayer layer = new CircleLayer("location", "location");
|
||||||
try {
|
layer.setProperties(
|
||||||
ObjectNode data = mapper.createObjectNode();
|
circleRadius(5f),
|
||||||
data.put("type", "Feature");
|
circleColor(Color.parseColor("#1E88E5")),
|
||||||
|
circleStrokeColor(Color.WHITE),
|
||||||
|
circleStrokeWidth(1.5f),
|
||||||
|
circlePitchAlignment(Property.CIRCLE_PITCH_ALIGNMENT_MAP)
|
||||||
|
);
|
||||||
|
|
||||||
if(currentLocation != null) {
|
return new MapLayer(source, layer);
|
||||||
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
|
@Override
|
||||||
@@ -89,4 +59,4 @@ public class LocationOverlay implements MapOverlay, LocationListener {
|
|||||||
this.currentLocation = location;
|
this.currentLocation = location;
|
||||||
map.onOverlayUpdate();
|
map.onOverlayUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
package eu.konggdev.strikemaps.map.overlay.implementation;
|
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 SourcedMapLayer makeLayer() {
|
public MapLayer makeLayer() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,5 @@ 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,13 +4,11 @@ import android.view.View;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
||||||
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.ObjectNode;
|
||||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
|
||||||
import eu.konggdev.strikemaps.data.helper.UserPrefsHelper;
|
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.SourcedMapLayer;
|
import eu.konggdev.strikemaps.map.layer.MapLayer;
|
||||||
import eu.konggdev.strikemaps.map.renderer.MapRenderer;
|
import eu.konggdev.strikemaps.map.renderer.MapRenderer;
|
||||||
import eu.konggdev.strikemaps.map.style.MapStyle;
|
import eu.konggdev.strikemaps.map.style.MapStyle;
|
||||||
import org.maplibre.android.MapLibre;
|
import org.maplibre.android.MapLibre;
|
||||||
@@ -41,38 +39,25 @@ 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() {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
|
|
||||||
MapStyle style = controller.style;
|
MapStyle style = controller.style;
|
||||||
try {
|
try {
|
||||||
/* Take metadata from MapStyle
|
|
||||||
everything outside sources, layers */
|
|
||||||
ObjectNode root = style.metadata.deepCopy();
|
ObjectNode root = style.metadata.deepCopy();
|
||||||
|
root.set("sources", mapper.valueToTree(style.sources));
|
||||||
//Sources
|
root.set("layers", style.layerDefinitions);
|
||||||
ObjectNode sources = mapper.createObjectNode();
|
map.setStyle(new Style.Builder().fromJson(mapper.writeValueAsString(root)), intStyle -> {
|
||||||
style.sources.forEach((k, v) -> sources.set(k, mapper.valueToTree(v)));
|
for(MapOverlay overlay : controller.overlays.values()) {
|
||||||
|
passLayer(overlay.makeLayer());
|
||||||
//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) {
|
} catch (Exception e) {
|
||||||
app.logcat("Failed to reload Map");
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,18 +4,15 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|||||||
|
|
||||||
public class MapSource {
|
public class MapSource {
|
||||||
public String url;
|
public String url;
|
||||||
public JsonNode data;
|
|
||||||
public String type;
|
public String type;
|
||||||
public String schema;
|
public String schema;
|
||||||
|
|
||||||
|
public String attribution;
|
||||||
|
|
||||||
|
/* For raster sources */
|
||||||
public JsonNode tiles;
|
public JsonNode tiles;
|
||||||
public int minzoom;
|
public int minzoom;
|
||||||
public int maxzoom;
|
public int maxzoom;
|
||||||
public String scheme;
|
|
||||||
public int tileSize;
|
|
||||||
|
|
||||||
public String attribution;
|
|
||||||
|
|
||||||
public String encoding;
|
|
||||||
public MapSource() { }
|
public MapSource() { }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ 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.ObjectNode;
|
||||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
|
||||||
import eu.konggdev.strikemaps.app.AppController;
|
import eu.konggdev.strikemaps.app.AppController;
|
||||||
import eu.konggdev.strikemaps.data.helper.FileHelper;
|
import eu.konggdev.strikemaps.data.helper.FileHelper;
|
||||||
import eu.konggdev.strikemaps.map.source.MapSource;
|
import eu.konggdev.strikemaps.map.source.MapSource;
|
||||||
@@ -20,7 +19,7 @@ public class MapStyle {
|
|||||||
|
|
||||||
public JsonNode metadata; // everything except layers + sources
|
public JsonNode metadata; // everything except layers + sources
|
||||||
public Map<String, MapSource> sources;
|
public Map<String, MapSource> sources;
|
||||||
public ArrayNode layerDefinitions; // the "layers" array
|
public JsonNode layerDefinitions; // the "layers" array
|
||||||
|
|
||||||
//FIXME
|
//FIXME
|
||||||
public static MapStyle fromMapLibreJsonFile(String filename, AppController app) {
|
public static MapStyle fromMapLibreJsonFile(String filename, AppController app) {
|
||||||
@@ -41,7 +40,7 @@ public class MapStyle {
|
|||||||
new TypeReference<Map<String, MapSource>>() {}
|
new TypeReference<Map<String, MapSource>>() {}
|
||||||
);
|
);
|
||||||
|
|
||||||
style.layerDefinitions = root.withArray("layers");
|
style.layerDefinitions = root.path("layers");
|
||||||
|
|
||||||
ObjectNode metadata = root.deepCopy();
|
ObjectNode metadata = root.deepCopy();
|
||||||
metadata.remove("layers");
|
metadata.remove("layers");
|
||||||
|
|||||||
Reference in New Issue
Block a user