I want to use leaflet map kit in xamarin.forms uwp project. For that I have created index.html file in pcl project. But when I'm trying to read that file it always returns null.
index.html
<!DOCTYPE html>
<html>
<head>
<title>LeafletMap</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<!--leaflet js-->
<script src="JS/leaflet.js"></script>
<!--leaflet css-->
<link rel="stylesheet" href="CSS/leaflet.css" />
<style>
html, body {
height: 100%;
margin: 0;
}
#map {
width: 600px;
height: 400px;
}
</style>
<style>
body {
padding: 0;
margin: 0;
}
#map {
height: 100%;
width: 100vw;
}
</style>
</head>
<body>
<div id='map'></div>
<script type="text/javascript">
var mbAttr = '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
mbUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
mbUrl2 = 'http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
mbAttr2 = 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community';
var OSM = L.tileLayer(mbUrl, { id: 'OSM', attribution: mbAttr }),
Sat = L.tileLayer(mbUrl2, { id: 'Sat', attribution: mbAttr2 });
var baseLayers = {
"OSM": OSM,
"Satellite": Sat
};
var markerGroup = new L.LayerGroup();
// Map initialization
var map = L.map('map',{
center: [-2.1319654, -79.9319396],
zoom:5,
layer: [OSM]
});
map.addLayer(markerGroup);
L.control.layers(baseLayers).addTo(map);
</script>
</body>
</html>
InitializeMap
var source = new HtmlWebViewSource();
source.BaseUrl = DependencyService.Get<IBaseUrl>().Get();
var assembly = typeof(MainPage).GetTypeInfo().Assembly;
var stream = assembly.GetManifestResourceStream("LeafletMap.index.html");
StreamReader reader = null;
if (stream != null)
{
try
{
reader = new StreamReader(stream);
source.Html = reader.ReadToEnd();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"Exception \n - {ex.Message}");
}
finally
{
if (reader != null)
{
reader.Dispose();
}
}
webView.Source = source;
}
This line always returns null.
assembly.GetManifestResourceStream("LeafletMap.index.html");
Anyone know how to use leaflet mapkit in xamarin.forms?
I have referred this sample: https://github.com/osekom/LeafletMapXamarinForms.
It's working fine as it has old versioned xamarin.forms the same is not working with latest version.