Good evening everyone,
I am currently trying to display the OSM from Openlayer3 using javascript in an HTML page. As long as I stay on a classic webpage (on local with a tomcat) it work just fine and I display my own datas from a GeoJson file.
Now i want to do the same on an android webview using the same HTML & JS files, exported openlayers.js/css and the html in the assets folder. The problem is the map itself doesn't show, just the controls and copyright at the bottom. I have allowed javascript in my webview as i can execute other function from a JavascriptInterface class.
Is there any restrictions with openlayers/osm and android ?
Note : I am currently restricted to just Openlayers and a webview for this project, so i can't use things like leaflet or any Google API.
My current code is :
public class MapActivity extends AppCompatActivity {
private HashSet<Point> points;
private WebView webView;
private WebSettings wSettings;
private AssetManager assetManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
assetManager = getApplicationContext().getAssets();
try {
InputStream targetStream = assetManager.open("lieuxjson.json");
points = GeoJsonParser.readJsonStream(targetStream);
} catch (java.io.IOException e) {
e.printStackTrace();
//stop activity
}
WebView webView = new WebView(this);
webView.setClickable(true);
webView.setFocusableInTouchMode(true);
wSettings = webView.getSettings();
wSettings.setJavaScriptEnabled(true);
WebClientClass webViewClient = new WebClientClass();
webView.setWebViewClient(webViewClient);
WebChromeClient webChromeClient = new WebChromeClient();
webView.setWebChromeClient(webChromeClient);
webView.addJavascriptInterface(new WebAppInterface(this), "Android");
webView.loadUrl("file:///android_asset/index.html");
setContentView(webView);
}}
And the JS with a div id="map" and ol.js & ol.css imported :
var world = new ol.layer.Tile({ source: new ol.source.OSM() });
world.setZIndex(0);
var myview = new ol.View({
center: ol.proj.fromLonLat([37.41, 8.82]),
zoom: 3
});
var map = new ol.Map({
target: 'map',
layers: [world],
view: myview
});
asked
22 Dec '17, 14:08
Bruce Swain
21●1●1●3
accept rate:
0%