UWP Custom Map for a Building - c#

Is it possible to use the Map API with a custom designed map? I'd like to build an app using a map of the building I work in, with all the fancy map abilities: zoom, pan, pushpins, points of interest, etc.
Here is the code I'm using to replace the default map:
MapZoomLevelRange range;
range.Min = 0;
range.Max = 5;
LocalMapTileDataSource dataSource = new LocalMapTileDataSource("ms-appx:///Assets/Maps/{zoomlevel}/{x}/{y}.png");
MapTileSource tileSource = new MapTileSource(dataSource);
tileSource.ZoomLevelRange = range;
tileSource.Layer = MapTileLayer.BackgroundReplacement;
TestMap1.Style = MapStyle.None;
tileSource.IsFadingEnabled = false;
TestMap1.TileSources.Add(tileSource);
I am now working on restricting the size of the map to the number of tiles I have. Horizontally the map repeats over and over. Vertically, it only shows based on the height of the tiles available.

Related

Xamarin iOS - Mapkit ArgumentNullException: Value cannot be null

My question is similar to this but I am not sure how my code relates to the answers given in the other post.
I am using MapKit in Xamarin iOS to create a custom map for my Xamarin iOS project. I have a few different custom things happening at the moment, and am using Polygons annotations and now circles that are added to my map.
I have just started implementing adding MKCircle to my map, but when I try to add Circle Overlays to my map I am receiving this error:
System.ArgumentNullException: Value cannot be null. Parameter name: polygon
I think it is being I trying to return the same overlay to two renderers, but I am not sure how to ammend this. Here is my code:
for(int i=0; i < hazards.Count; i++) //This adds 3 circles in my example
{
LatLong ltlng = JsonConvert.DeserializeObject<LatLong>(hazards[i].coordinates);
coords[i].Latitude = Convert.ToDouble(ltlng.latitude);
coords[i].Longitude = Convert.ToDouble(ltlng.longitude);
var overlay = MKCircle.Circle(coords[i], Convert.ToDouble(hazards[i].radius));
nativeMap.AddOverlay(overlay); //this is the suspected problem
}
And my renderer code here:
MKOverlayRenderer GetOverlayRenderer(MKMapView mapView, IMKOverlay overlayWrapper)
{
if (!Equals(overlayWrapper, null))
{
var overlay = ObjCRuntime.Runtime.GetNSObject(overlayWrapper.Handle) as IMKOverlay;
polygonRenderer = new MKPolygonRenderer(overlay as MKPolygon)
{
FillColor = UIColor.Red,
StrokeColor = UIColor.Blue,
Alpha = 0.4f,
LineWidth = 9
};
}
return polygonRenderer;
}
Do I need to add something to my renderer code like this?:
circleRenderer = new MKCircleRenderer(overlay as MKCircle){};
It appears all your overlays are MKCircle based:
var overlay = MKCircle.Circle(coords[i]
In your GetOverlayRenderer you casting all overlays received as MKPolygon objects which will result in a null object.
polygonRenderer = new MKPolygonRenderer(overlay as MKPolygon)
You are then trying to create a MKPolygonRenderer render for each of your overlays which would not work if you actually did have an MKCircle-based overlay.
If all your overlays are MKCircle based, then yes use:
new MKCircleRenderer(overlay as MKCircle){};

Bing Maps, retrieve locations from MapLayer children?

I'm using Bing maps with WPF and C# and I'm trying to retrieve the children that were added into the map, primarily to get their coordinates to save into the database and calculate distance between two children on different map controls.
Below is how I'm adding the child 'pushpin' into one of the maps.
bmMapdestination.Children.Clear();
e.Handled = true;
var mousePosition = e.GetPosition(bmMapdestination);
Location pinLocation = bmMapdestination.ViewportPointToLocation(mousePosition);
Pushpin pin = new Pushpin() { Location = pinLocation , Name = "DestPin"};
bmMapdestination.Children.Add(pin);
CalculateDistance();
After a couple of days coding I've come up with a bit of code to retrieve pushpins from the Bing Maps control that works how I wanted it to, this works fine when extracting for one pushpin per map, but I'm sure it could be useful for more than one.
As shown below I've used a foreach method to get the Bing Maps children, which then allowed me to work with it.
public void CalculateDistance()
{
Location pinLocation = new Location();
foreach(Pushpin pin in bmMapdestination.Children)
{
pinLocation = pin.Location;
}
txtEditPickUpEditLocation.Text = pinLocation.Latitude.ToString()+","+pinLocation.Longitude.ToString();
}

ArcObjects 10.3 Add Transparent Polygon to Map

This is an issue I have been trying to tackle for a while and decided to reach out for help. I am creating an ESRI ArcGIS Desktop Add-In that allows the user to draw a polygon and then have it added to the map. I am able to capture the polygon and add it to the map, the issue is the transparency. Currently and by default it is 100% opacity and solid. I want to make it around 50% opacity so the user can see the data behind it.
Here is the code I have so far:
public static void AddPolygonToMap(IActiveView ActiveViewInstance, IGeometry NewGeo)
{
//Local Variable Declaration
var fillShapeElement = default(IFillShapeElement);
var element = default(IElement);
var graphicsContainer = default(IGraphicsContainer);
var simpleFilleSymbol = default(ISimpleFillSymbol);
var newRgbColor = default(IRgbColor);
var lineSymbol = default(ILineSymbol);
//Use the IElement interface to set the Envelope Element's geo
element = new PolygonElement();
element.Geometry = NewGeo;
//QI for the IFillShapeElement interface so that the symbol property can be set
fillShapeElement = element as IFillShapeElement;
//Create a new fill symbol
simpleFilleSymbol = new SimpleFillSymbol();
//Create a new color marker symbol of the color black;
newRgbColor = new RgbColor();
newRgbColor.Red = 0;
newRgbColor.Green = 0;
newRgbColor.Blue = 0;
//Create a new line symbol so that we can set the width outline
lineSymbol = new SimpleLineSymbol();
lineSymbol.Color = newRgbColor;
lineSymbol.Width = 2;
//Setup the Simple Fill Symbol
simpleFilleSymbol.Color = newRgbColor;
simpleFilleSymbol.Style = esriSimpleFillStyle.esriSFSHollow;
simpleFilleSymbol.Outline = lineSymbol;
fillShapeElement.Symbol = simpleFilleSymbol;
//QI for the graphics container from the active view allows access to basic graphics layer
graphicsContainer = ActiveViewInstance as IGraphicsContainer;
//Add the new element at Z order 0
graphicsContainer.AddElement((IElement)fillShapeElement, 0);
//Show the new graphic
ActiveViewInstance.Refresh();
}
I know that this is possible somehow and I am sure it's just a line or two missing but any help would be much appreciated.
V/r,
Josh
This looks to be a graphic element that you are creating. Graphic elements do not support transparency other than 100% transparent or 0% transparent. This is outlined in the following documentation:
IColor.Transparency Property
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//001w000000nt000000
For graphic elements, 0 for transparent and 255 for opaque are the only supported values.
I hope this helps!

How to manually position ASP.Net Chart Legend?

Using the Chart controls built into ASP.Net, I'm trying to manually position the Title and the Legend so that they are directly next to each other horizontally just above the ChartArea. I've been able to manually position the Title using the following code:
chart.Titles["Title1"].Position.Auto = false;
chart.Titles["Title1"].Position.X = 10;
chart.Titles["Title1"].Position.Y = 5;
There's nothing to it, really. However, I'm attempting to position the Legend to the right of it with the following code, and the Legend doesn't even appear:
chart.Legends["Legend1"].Position.Auto = false;
chart.Legends["Legend1"].Position.X = 30;
chart.Legends["Legend1"].Position.Y = 5;
Any ideas what I'm doing wrong? This seems like it should be relatively simple. I've even tried various other coordinates, and I can't get the Legend to appear anywhere. It does appear if I use the built-in positioning such as below, but this positioning does not suit my purposes:
chart.Legends["Legend1"].Docking = Docking.Top;
chart.Legends["Legend1"].DockedToChartArea = "ChartArea1";
chart.Legends["Legend1"].IsDockedInsideChartArea = false;
chart.Legends["Legend1"].Alignment = StringAlignment.Far;
Try newing up an ElementPosition object, like this:
chart.Legends["Legend1"].Position.Auto = false;
chart.Legends["Legend1"].Position = new ElementPosition(30, 5, 100, 20);
Note: The constructor for ElementPosition takes 0 or 4 parameters (x, y, width, height).
I stumbled on this question for looking how to move legend at the bottom of a chart.
Answer for that is to use Docking property
Chart1.Legends["Legend1"].Docking = Docking.Bottom;
It may be helpful for someone in future, as this is the first link in google search.

How to model an IC in WPF?

I'm building a user control using WPF to resemble a breadboard that will be used in an electronic circuits simulation software.
The user will be able to add ICs onto that breadboard.
I've finished building the breadboard right now, it consists mainly of a grid that has a number of cells equal to the number on nodes on a real breadboard..
And right now I made users add ICs to that grid by specifying the Grid.Row and Grid.Column and determining its size by specifying Grid.RowSpan and Grid.ColumnSpan:
Here is the C# code:
private int usedVerticalPins = 0;
void AddICs(int pinNum)
{
var rect = new Rectangle() { Fill = new SolidColorBrush(Colors.Black),Stroke = new SolidColorBrush(Colors.White)};
rect.SetValue(Grid.RowProperty, usedVerticalPins);
rect.SetValue(Grid.ColumnProperty, 7);
rect.SetValue(Grid.RowSpanProperty, (pinNum / 2));
rect.SetValue(Grid.ColumnSpanProperty, 3);
BreadboardControl.BreadboardGrid.Children.Add(rect);
usedVerticalPins += (pinNum / 2);
}
But as you can see, it looks like plain rectangles not as ICs, so I thought of inheriting the class Rectangle and edit the way it looks by I found that it is a sealed class..
I want the ICs to look like with all pins and stuff..
So can you please suggest a way to do it..!?

Categories

Resources