MapLibre GL JS first stub
This commit is contained in:
@@ -0,0 +1,122 @@
|
|||||||
|
All files inside the /dist folder are under the following license
|
||||||
|
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
Copyright (c) 2023, MapLibre contributors
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
* Neither the name of MapLibre GL JS nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this software
|
||||||
|
without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Contains code from mapbox-gl-js v1.13 and earlier
|
||||||
|
|
||||||
|
Version v1.13 of mapbox-gl-js and earlier are licensed under a BSD-3-Clause license
|
||||||
|
|
||||||
|
Copyright (c) 2020, Mapbox
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
* Neither the name of Mapbox GL JS nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this software
|
||||||
|
without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||||
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Contains code from glfx.js
|
||||||
|
|
||||||
|
Copyright (C) 2011 by Evan Wallace
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Contains a portion of d3-color https://github.com/d3/d3-color
|
||||||
|
|
||||||
|
Copyright 2010-2016 Mike Bostock
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
* Neither the name of the author nor the names of contributors may be used to
|
||||||
|
endorse or promote products derived from this software without specific prior
|
||||||
|
written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||||
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,33 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<script src="https://unpkg.com/maplibre-gl@latest/dist/maplibre-gl.js"></script>
|
||||||
|
<link href="https://unpkg.com/maplibre-gl@latest/dist/maplibre-gl.css" rel="stylesheet"/>
|
||||||
|
<style>
|
||||||
|
html, body, #map {
|
||||||
|
margin: 0;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div id="map" style="width: 100%; height: 100%"></div>
|
||||||
|
<script>
|
||||||
|
const map = new maplibregl.Map({
|
||||||
|
center: [13.388, 52.517],
|
||||||
|
zoom: 9.5,
|
||||||
|
container: 'map',
|
||||||
|
})
|
||||||
|
|
||||||
|
window.setMapStyle = function(styleUrl) {
|
||||||
|
if (!map) return;
|
||||||
|
map.setStyle(styleUrl);
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
+78
-2
@@ -1,10 +1,23 @@
|
|||||||
package eu.konggdev.strikemaps.map.renderer.implementation;
|
package eu.konggdev.strikemaps.map.renderer.implementation;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.webkit.WebChromeClient;
|
||||||
|
import android.webkit.WebSettings;
|
||||||
|
import android.webkit.WebView;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
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.overlay.MapOverlay;
|
||||||
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.geometry.LatLng;
|
import org.maplibre.android.geometry.LatLng;
|
||||||
|
import org.maplibre.android.maps.Style;
|
||||||
import org.maplibre.geojson.Feature;
|
import org.maplibre.geojson.Feature;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -12,14 +25,55 @@ import java.util.List;
|
|||||||
|
|
||||||
//Stub for now
|
//Stub for now
|
||||||
public class MapLibreGLJSRenderer implements MapRenderer {
|
public class MapLibreGLJSRenderer implements MapRenderer {
|
||||||
|
|
||||||
|
AppController app;
|
||||||
|
|
||||||
|
MapComponent controller;
|
||||||
|
|
||||||
|
final WebView webView;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload() {
|
public void reload() {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
|
||||||
|
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);
|
||||||
|
|
||||||
|
webView.evaluateJavascript(
|
||||||
|
"",
|
||||||
|
null
|
||||||
|
);
|
||||||
|
} catch (Exception e) {
|
||||||
|
app.logcat("Failed to reload Map");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView() {
|
public View getView() {
|
||||||
return null;
|
return webView;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -27,5 +81,27 @@ public class MapLibreGLJSRenderer implements MapRenderer {
|
|||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MapLibreGLJSRenderer(AppController app, MapComponent controller) { }
|
@SuppressLint({"JavascriptInterface", "SetJavaScriptEnabled"})
|
||||||
|
public MapLibreGLJSRenderer(AppController app, MapComponent controller) {
|
||||||
|
webView = new WebView(app.getActivity());
|
||||||
|
webView.setLayoutParams(
|
||||||
|
new ViewGroup.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
WebSettings settings = webView.getSettings();
|
||||||
|
settings.setJavaScriptEnabled(true);
|
||||||
|
settings.setDomStorageEnabled(true);
|
||||||
|
settings.setAllowFileAccess(true);
|
||||||
|
|
||||||
|
webView.setWebChromeClient(new WebChromeClient());
|
||||||
|
|
||||||
|
webView.addJavascriptInterface(new Bridge(), "AndroidBridge");
|
||||||
|
|
||||||
|
webView.loadUrl("file:///android_asset/maplibre/gl-js/index.html");
|
||||||
|
}
|
||||||
|
|
||||||
|
class Bridge { }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package eu.konggdev.strikemaps.ui.factory;
|
package eu.konggdev.strikemaps.ui.factory;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.content.Intent;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ScrollView;
|
import android.widget.ScrollView;
|
||||||
|
import android.widget.Toast;
|
||||||
import eu.konggdev.strikemaps.app.AppController;
|
import eu.konggdev.strikemaps.app.AppController;
|
||||||
import eu.konggdev.strikemaps.ui.element.item.PreviewItem;
|
import eu.konggdev.strikemaps.ui.element.item.PreviewItem;
|
||||||
import org.maplibre.geojson.Feature;
|
import org.maplibre.geojson.Feature;
|
||||||
@@ -45,4 +47,27 @@ public final class AlertDialogFactory {
|
|||||||
.setPositiveButton("OK", null)
|
.setPositiveButton("OK", null)
|
||||||
.create();
|
.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static AlertDialog restartDialog(AppController app) {
|
||||||
|
return new AlertDialog.Builder(app.getActivity())
|
||||||
|
.setTitle("Restart required")
|
||||||
|
.setMessage("Restart the app to apply changes.")
|
||||||
|
.setCancelable(false)
|
||||||
|
.setNegativeButton("Cancel", (d, w) -> {
|
||||||
|
Toast.makeText(app.getActivity(),
|
||||||
|
"Changes will be applied on next restart",
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
d.dismiss();
|
||||||
|
})
|
||||||
|
.setPositiveButton("Restart", (d, w) -> {
|
||||||
|
Intent i = app.getActivity().getPackageManager()
|
||||||
|
.getLaunchIntentForPackage(app.getActivity().getPackageName());
|
||||||
|
if (i != null) {
|
||||||
|
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
app.getActivity().startActivity(i);
|
||||||
|
}
|
||||||
|
Runtime.getRuntime().exit(0);
|
||||||
|
})
|
||||||
|
.create();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
@@ -14,6 +14,8 @@ import com.google.android.material.appbar.MaterialToolbar;
|
|||||||
import eu.konggdev.strikemaps.R;
|
import eu.konggdev.strikemaps.R;
|
||||||
import eu.konggdev.strikemaps.data.helper.UserPrefsHelper;
|
import eu.konggdev.strikemaps.data.helper.UserPrefsHelper;
|
||||||
import eu.konggdev.strikemaps.app.AppController;
|
import eu.konggdev.strikemaps.app.AppController;
|
||||||
|
import eu.konggdev.strikemaps.map.MapComponent;
|
||||||
|
import eu.konggdev.strikemaps.ui.factory.AlertDialogFactory;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@@ -42,11 +44,18 @@ public class FragmentLayoutContentSettings extends Fragment implements MainConte
|
|||||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
mapRendererSelector.setAdapter(adapter);
|
mapRendererSelector.setAdapter(adapter);
|
||||||
mapRendererSelector.setSelection(UserPrefsHelper.mapRenderer(app.getPrefs()));
|
mapRendererSelector.setSelection(UserPrefsHelper.mapRenderer(app.getPrefs()));
|
||||||
|
final boolean[] ignoreFirst = {true};
|
||||||
mapRendererSelector.setOnItemSelectedListener(
|
mapRendererSelector.setOnItemSelectedListener(
|
||||||
new AdapterView.OnItemSelectedListener() {
|
new AdapterView.OnItemSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
if (ignoreFirst[0]) {
|
||||||
|
ignoreFirst[0] = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
UserPrefsHelper.mapRenderer(app.getPrefs(), position);
|
UserPrefsHelper.mapRenderer(app.getPrefs(), position);
|
||||||
|
app.getUi().alert(AlertDialogFactory.restartDialog(app));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user