UWP C#: Adding MapPolygon to MapControl - c#

I am trying to add a polygon to my map by using the following code example (retrieved from https://learn.microsoft.com/en-us/windows/uwp/maps-and-location/display-poi#add-a-shape):
public void HighlightArea() {
double centerLatitude = myMap.Center.Position.Latitude;
double centerLongitude = myMap.Center.Position.Longitude;
var mapPolygon = new MapPolygon
{
Path = new Geopath(new List<BasicGeoposition> {
new BasicGeoposition() {Latitude=centerLatitude+0.0005, Longitude=centerLongitude-0.001 },
new BasicGeoposition() {Latitude=centerLatitude-0.0005, Longitude=centerLongitude-0.001 },
new BasicGeoposition() {Latitude=centerLatitude-0.0005, Longitude=centerLongitude+0.001 },
new BasicGeoposition() {Latitude=centerLatitude+0.0005, Longitude=centerLongitude+0.001 },
}),
ZIndex = 1,
FillColor = Colors.Red,
StrokeColor = Colors.Blue,
StrokeThickness = 3,
StrokeDashed = false,
};
// Add MapPolygon to a layer on the map control.
var MyHighlights = new List<MapElement>();
MyHighlights.Add(mapPolygon);
var HighlightsLayer = new MapElementsLayer
{
ZIndex = 1,
MapElements = MyHighlights
};
myMap.Layers.Add(HighlightsLayer);
}
The polygon is shown on the map initially, but it disappears within 2 seconds from when it appeared (it fades away). I have successfully added a MapPolyline that sticks to the map by using an example I retrieved from the same link, which is why I cannot understand why the MapPolygon will not stick.
What may cause the polygon to fade away?

Related

Why is my reversed MagnitudeAxis Polar Plot not rendering with Oxyplot?

I'm trying to create a Polar Plot with Oxyplot in my WPF application. I want the MagnitudeAxis to be reversed so I made the StartPosition = 1 and the EndPosition = 0. However this causes the plot not to render. It looks it may be due to the variables a0 and a1 being set to 0 in the UpdateTransform() method in MagnitudeAxis.cs but it may be something else (not exactly sure what all these variables represent).
Here's my code to set up the polar plot:
/// dictionary of angles: magnitudes
dict = {-180: -18, -179: -17.9, ... , 0: 0, ... , 178: -17.8, 179: -17.9}
PlotModel myPlot = new PlotModel
{
Title = "Polar Plot",
PlotType = PlotType.Polar,
PlotAreaBorderThickness = new OxyThickness(0),
};
var series1 = new ScatterSeries
{
Title = "Polar Series",
MarkerType = MarkerType.Circle,
MarkerSize = 3,
MarkerFill = OxyColor.FromRgb(255, 0, 0),
};
var axis1 = new AngleAxis
{
StartPosition = 1,
EndPosition = 0,
StartAngle = 270,
EndAngle = -90,
Title = "Angle",
LabelFormatter = d => $"{d}",
MajorStep = 30,
Minimum = -180,
Maximum = 180,
MinorGridlineStyle = LineStyle.None,
};
var axis2 = new MagnitudeAxis
{
/// here's where I set the Start and End Position
StartPosition = 1,
EndPosition = 0,
MajorStep = 6,
Title = "Magnitude",
MinorGridlineStyle = LineStyle.None,
Minimum = dict.Values.Min();
Maximum = dict.Values.Max()
};
foreach (KeyValuePair<double, double> keyValuePair in dict)
{
series1.Points.Add(new ScatterPoint(keyValuePair.Value, keyValuePair.Key));
}
myPlot.Axes.Add(axis1);
myPlot.Axes.Add(axis2);
myPlot.Series.Add(series1);
This is what I get when the plot tries rendering:
This is what I get when I use default Start/End Positions:
What I want is the default plot with 0 in the center and -18 on the edge instead.
This is my first question ever on SO, so let me know if there's any other information I should provide.

Bind Polyline from MVVM Googlemap Xamarin

After getting position from Google map Api and looking to create polyline between two points but problem is Polyline->GeoPath is readonly.
How to assign Positions to GeoPath or bind position directly to map?
I am using following this sample
Map map = new Map
{
// ...
};
// instantiate a polyline
Polyline polyline = new Polyline
{
StrokeColor = Color.Blue,
StrokeWidth = 12,
Geopath =
{
new Position(47.6381401, -122.1317367),
new Position(47.6381473, -122.1350841),
new Position(47.6382847, -122.1353094),
new Position(47.6384582, -122.1354703),
new Position(47.6401136, -122.1360819),
new Position(47.6403883, -122.1364681),
new Position(47.6407426, -122.1377019),
new Position(47.6412558, -122.1404056),
new Position(47.6414148, -122.1418647),
new Position(47.6414654, -122.1432702)
}
};
// add the polyline to the map's MapElements collection
map.MapElements.Add(polyline);
Polyline -> Geopath -> Add will solve the issue
Polyline polyline = new Polyline
{
StrokeColor = Color.Blue,
StrokeWidth = 12
}
polyline.GeoPath.Add(new Position)

Add Pushpin to MapControl in UWP

I'd like to add a Pushpin to a MapControl in a Windows 10 app, but it seems the control is gone since Windows 8.1.
It was as simple as that:
Pushpin locationPushpin = new Pushpin();
locationPushpin.Background = new SolidColorBrush(Colors.Purple);
locationPushpin.Content = "You are here";
locationPushpin.Tag = "locationPushpin";
locationPushpin.Location = watcher.Position.Location;
this.map.Children.Add(locationPushpin);
this.map.SetView(watcher.Position.Location, 18.0);
But Pushpin type is not recognized anymore...
Map control has changed little in UWP - take a look at Windows.UI.Xaml.Controls.Maps namespace.
As for adding Pushpins (POIs), you can do it in couple of ways. For example:
// get position
Geopoint myPoint = new Geopoint(new BasicGeoposition() { Latitude = 51, Longitude = 0 });
//create POI
MapIcon myPOI = new MapIcon { Location = myPoint, NormalizedAnchorPoint = new Point(0.5, 1.0), Title = "My position", ZIndex = 0 };
// add to map and center it
myMap.MapElements.Add(myPOI);
myMap.Center = myPoint;
myMap.ZoomLevel = 10;
For more guidelines visit MSDN.

How Can I Change The Color Of Polyline Back to The Previous One On Click Google Api V2 C# Web App?

I am easily changing the color of polyline on click button my code below,
var points = [
new GLatLng(24.85229, 67.01703),
new GLatLng(24.914463, 67.0965958)];
var polyline = new GPolyline(points, '#ff0000', 5, 0.7);
GEvent.addListener(polyline, "click", function() {polyline.setStrokeStyle({ color: "#0000FF" }); });
map.addOverlay(polyline);
but I want to change its color back to previous one on click such that if its initial color is red and on click it changes to blue then on other click it changes it to red again ... . then what should I do ?
Hopes for your reply..
There are many solutions for this. one is to create a swap function:
var activeColor = '#ff0000';
var inactiveColor = '#0000FF';
var points = [
new GLatLng(24.85229, 67.01703),
new GLatLng(24.914463, 67.0965958)];
var polyline = new GPolyline(points, activeColor, 5, 0.7);
GEvent.addListener(polyline, "click", function() {
// swap activecolor with inactivecolor
var color = inactiveColor;
inactiveColor = activeColor;
activeColor = color;
// set activecolor
polyline.setStrokeStyle({ color: activeColor });
});
map.addOverlay(polyline);

ZedGraph filling areas

I am using the ZedGraph control and want to fill one side of the graph function with some color and other side with other color.
PointPairList list1 = new PointPairList();
list1.Add(0, 4);
list1.Add(4, 0);
LineItem myCurve = myPane.AddCurve("y(n)", list1, Color.Red, SymbolType.Diamond);
//This filling bottom side.
myCurve.Line.Fill = new Fill(Color.White, Color.FromArgb(113, 255, 0, 0), 90F);
//How to fill the top side?
I'm not very clear on what you're asking - but hopefully the below will help. You said in comments
Can I fill some polygon area in Zedgraph?
So here's how...
var zed = new ZedGraph.ZedGraphControl { Dock = System.Windows.Forms.DockStyle.Fill };
var poly = new ZedGraph.PolyObj
{
Points = new[]
{
new ZedGraph.PointD(0, 0),
new ZedGraph.PointD(0.5, 1),
new ZedGraph.PointD(1, 0.5),
new ZedGraph.PointD(0, 0)
},
Fill = new ZedGraph.Fill(Color.Blue),
ZOrder = ZedGraph.ZOrder.E_BehindCurves
};
var poly1 = new ZedGraph.PolyObj
{
Points = new[]
{
new ZedGraph.PointD(1, 0),
new ZedGraph.PointD(0.25, 1),
new ZedGraph.PointD(0.5, 0),
new ZedGraph.PointD(1, 0)
},
Fill = new ZedGraph.Fill(Color.Red),
ZOrder = ZedGraph.ZOrder.E_BehindCurves
};
zed.GraphPane.AddCurve("Line", new[] { 0.0, 1.0 }, new[] { 0.0, 1.0 }, Color.Green);
zed.GraphPane.GraphObjList.Add(poly1);
zed.GraphPane.GraphObjList.Add(poly);
Results in
Hopefully this will point you in the right direction!
(Code in VB as requested via http://converter.telerik.com/ - no guarentee of the VB code working or even compiling!)

Categories

Resources