Draw / display a route by GPS coordinates (GPX) with .Net Maui control "Microsoft.Maui.Controls.Maps" - maui

Is it possible to draw a route with the control "Microsoft.Maui.Controls.Maps" in .net Maui?
I have a GPX file that I would like to display on the map.
Example data:
<?xml version="1.0"?>
<gpx xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" xmlns="http://www.topografix.com/GPX/1/1">
<trk>
<name>XYZ</name>
<desc>XYZ</desc>
<trkseg>
<trkpt lat="42.847881" lon="-80.467515">
<ele>245.54</ele>
<time>2020-03-27T12:15:00Z</time>
<desc />
<fix>none</fix>
</trkpt>
<trkpt lat="42.848728" lon="-80.43962">
<ele>237.30</ele>
<time>2020-03-27T12:25:00Z</time>
<desc />
<fix>none</fix>
</trkpt>
...
</trkseg>
</trk>
</gpx>

As mentioned by #ToolmakerSteve: you can use Polylines.
Microsoft documentation: Create a polyline
Note: You need to zoom in on the map a lot to see the route. Even with a very high StrokeWidth used
Example:
// instantiate a polyline
Polyline polyline = new Polyline
{
StrokeColor = Colors.Red,
StrokeWidth = 8
};
foreach (var waypoint in waypoints)
{
polyline.Geopath.Add(new Location(waypoint.Latitude, waypoint.Longitude));
}
// Add the Polyline to the map's MapElements collection
map.MapElements.Add(polyline);
Example to load GPX File: Using Linq to XML with C# to Read Gpx Files

Related

Leaflet - once layer use more times?

I have Leaflet map with one date layer joined with:
<script src="data/Hranicesttu0.js"></script>
Function:
function pop_Hranicesttu0(feature, layer) {
...
map.addLayer(layer_Hranicesttu0);
Legend is defined:
L.control.layers(baseMaps,{'<img src="legend/Hranicesttu0.png" /> Hranice státu': layer_Hranicesttu0,}
I need this Hranicesttu0.js reuse as another layer(s) (in legend too) without new file something.js. Is it possible?
Example: http://l.kelv.cz/

Identifying pushpins after plotting them - Bingmaps

I am currently working with Bing maps version 8 . I was previously working with version 7 . When plotting pushpins in version 7 a htmlContent attribute was sent along with the pushpins. What this html content did was that the pushpin was contained inside the div element .
var pushpinOptions = {
htmlContent: "<div id='container" + siteIndex + "'style='pointer-events: all !important; z-index: 35000; '></div><div id='lines"+siteIndex+"'></div>",
anchor:new Microsoft.Maps.Point(iconWidth/2,iconHeight/2),
width: iconWidth,
height: iconHeight
};
var pin = new Microsoft.Maps.Pushpin(latLon, pushpinOptions);
I used Konva JS to plot over these pushpins which i plotted with BingMaps.
var stage = new Konva.Stage({
container: 'container' + siteIndex,
width: width,
height: height,
stroke: 'green'
});
'container' + siteIndex, was the id of the div i set in bing maps pushpins which i used in konva to plot another image over the pushpins. This is my requirement . I have to plot a pushpin with coordinates and then plot some images over the pushpins . Now when i shifted from v7 to v8 for various reasons, I am facing an issue .
In v8 htmlContent is not sent with the pushpins, rather we send an svg image which has no way to identify after being plotted other than co-ordinates .
var customHtml = '<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50"><circle id="myCircle htmlId" cx="25" cy="25" r="20" stroke="orange" stroke-width="4" fill="yellow" /></svg>';
var pin = new Microsoft.Maps.Pushpin(latLon, {
icon: customHtml.replace("htmlId",siteIndex.toString()),
anchor: new Microsoft.Maps.Point(iconWidth/2,iconHeight/2)
});
Now , what i am lokking for is a way to either plot images with a third party api which plots over co-ordinates or find to way to get access of the pushpins i plotted without the html content i.e with svg images. When i access the id with
document.getElementById("myCircle 0");
i get null.
I have looked for many different third party apis like leafleat js, konva js , Graphics js. But i do not find a way to identify my pushpins .
Is there a way to achieve what i wish to? There must be.
HTML pushpins are not supported in Bing Maps V8 as they can't be drawn on an HTML5 canvas. Using SVG would render on the Canvas but there is no DOM element create, which is why you aren't able to use document.getElementById. Using DOM elements with maps really limits performance and is the main reason why rendering is now done with an HTML5 canvas. That said, even in V7 using the approach of custom HTML in general so you can do document.getElementById to retrieve the pushpins was not a good approach. If you want to assign a unique ID to each pushpin and then be able to retrieve it, you should use a custom JavaScript property, or the existing metadata property. For example:
var pin = new Microsoft.Maps.Pushpin(map.getCenter());
pin.metadata = {
id: 'myCircle 0'
};
map.entities.push(pin);
function getPushpinById(id){
var pin;
for(var i=0,len = map.entities.getLength(), i<len;i++){
pin = map.entities.get(i);
if(pin.metadata && pin.metadata.id === id){
return pin;
}
}
}
Using this approach would allow the greatest performance in your app. However, if you really want to use custom HTML to create pushpins, it is possible to achieve this in V8 by using a custom overlay. Here is a code sample: https://msdn.microsoft.com/en-US/library/mt762877.aspx

How to draw a path between two nodes using Leaflet

I have a set of lat and long points which form a route from source to destination. I have used polyline method of Leaflet to draw the path between the source to destination, but it gives a scrambled path.
var firstpolyline = new L.polyline(latlong, {
color: 'red',
weight: 3,
opacity: 0.5,
smoothFactor: 1
});
firstpolyline.addTo(mym[![enter image description here][1]][1]ap);
The latlong in the above code is an array of latitude and longitude points. But it gives a scrambled output like this:
imgur.com/aZrGa.jpg
But the latlong points form a single correct path from source to destination. I have been using polyLine. What mistake am I doing? Should I use some other methods of Leaflet?
Edit after #ivansanchez comment
The latlong arrays are of type L.LatLng(x,y) where L is the Leaflet object. Here is a snippet:
1. var mymap = L.map('mapid').setView([17.387140, 78.491684], 13);
2. L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: "© <a href='http://osm.org/copyright'>OpenStreetMap</a> contributors"
}).addTo(mymap);
3. var latlngs = [
[15.89625,80.53544],
[15.89626,80.53542],
[15.89628,80.53536],
[15.89617,80.53539],
[15.89621,80.53547]
];
4. var path = L.polyline.antPath(latlngs,{"delay":400,"dashArray":[10,20],"weight":5,"color":"black","paused":true,"reverse":false}
).addTo(mymap);
5. mymap.addLayer(path);
mymap.fitBounds(path.getBounds());
EXPLANATION:
To set the map view on given latlongs([17.387140, 78.491684]), 13 means zoom.
Adding tiles on the maps.
Latlongs.
Drawing polylines ant paths by setting css.
Add the layer to the path.
It was my mistake, Polyline works properly. I had an array of latlng that were not in an order. Putting an ordered latlng points helped me plot the route correctly between source and destination.

Custom raster generated by gdal2tiles with leaflet

I was able to generate a tiles folder with gdal2tiles.py which allows me to show a geotiff file on a map :
And all my geotiff file generated are in gray scale and I would like to be able to color them and add a legend to see which value correspond to which color. Here is my actual code which allows me to do this :
<div id="map"></div>
<button id="populate">Populate with 10 markers</button>
<script type="text/javascript">
var map = L.map('map').setView([45, -93], 3);
/* setting some basemap options */
var tile_options = {
subdomains: '1234'
};
/* the base map tile layer */
var basemap = L.tileLayer('http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.png',tile_options);
basemap.addTo(map);
/* the georeferenced map tile layer */
var layer = L.tileLayer('./outputf/{z}/{x}/{y}.png', { maxZoom: 16,tms:true });
map.addLayer(layer);
I am still looking for solution... Of if you have some better option to render a geotiff file on a map
I was able to convert grayscale to colour using gdaldem color-relief
https://gis.stackexchange.com/questions/130199/changing-color-of-raster-images-based-on-their-data-values-gdal
http://www.gdal.org/gdaldem.html#gdaldem_color_relief

creating colored stripes in android ListView

I am trying to create thin colored stripes in my app. This is similar to stripes of different color that we see in calendar apps.
Is there any easy way to do it.
What I am doing:
I have a shape defined with width and height and I am trying to apply it to background of my ListView as it will occupy certain part of the ListView.
What is happening:
This is getting applied to the whole background.
What I need:
I am looking for help which can make this as stripes instead of complete background.
or any other way or alternatives for doing the same.
Some code:
rectangle.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="0dp"
/>
<size
android:width="20dp"
android:height="40dp" />
<solid
android:color="#color/opaque_red"
/>
</shape>
list_view_item_cell.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="95dp"
android:divider="?android:dividerVertical"
android:showDividers="middle" >
You can add a View of the width and height equal to that certain part where you want to have the colored background.
For example, if you want to show colored strip of width and height = 20dip. And this colored strip should appear at the left top of List item. Below is the sample
list_view_item_cell.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="95dp"
android:divider="?android:dividerVertical"
android:showDividers="middle" >
<!-- You can use any view here. Set background "rectangle.xml" drawable to this view.-->
<View
android:layout_width="20dip"
android:layout_height="20dip"
android:background="#drawable/rectangle"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
/>
</RelativeLayout>
Yes changing the colour of the shape is possible programatically.
Assume if you have a LayerDrawable set to the view background:
Then this is something which you can do:
LayerDrawable layerList = (LayerDrawable) view.getBackground();
if(layerList != null) {
final RotateDrawable shape = (RotateDrawable) layerList
.findDrawableByLayerId(R.id.header_titled);
final GradientDrawable tildShapeDrawable = (GradientDrawable)shape.getDrawable();
if (tildShapeDrawable != null) {
tildShapeDrawable.setColor(android.R.color.white);
}
}