I am using the 1st release of the ArcGIS Runtime SDK for .Net - Xamarin.Forms (nuget package here).
One of the requirements is to display a compass that indicates the north. I haven't found any build-in feature for the moment. Is someone can point me out how to implement this functionality ?
So after few research, I've implemented a custom solution:
Find a compass icon that can rotate (see this article to add image resource to Xamarin.Form)
Add the image on top of the map:
<Image x:Name="NorthArrow" />
Rotate the image when the view point changed:
MapView.ViewpointChanged += (sender, args) =>
{
NorthArrow.Rotation = -MapView.MapRotation;
};
Complete solution here.
Related
This question already has an answer here:
Drop Shadow effect in Universal Windows Application
(1 answer)
Closed 5 years ago.
I am currently trying to create a circular button with two ellipse-elements in UWP and want one of them to throw a shadow at a certain angle. I found a way to do so in WPF which looks like this:
WPF XAML:
<Ellipse>
<Ellipse.BitmapEffect>
<DropShadowBitmapEffect Color="Black" Direction="-50" ShadowDepth="50" Softness=".7"/>
</Ellipse.BitmapEffect>
</Ellipse>
What's the equivalent in UWP?
The easiest way is to use the DropShadowPanel from UWP Community Toolkit.
So first just install
Install-Package Microsoft.Toolkit.Uwp.UI.Controls -Version 2.0.0
Then use the following code in your XAML
<controls:DropShadowPanel Color="Black"
OffsetX="-50"
OffsetY="-50"
BlurRadius="50"
ShadowOpacity=".7"
Width="120"
Height="120"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch">
<Ellipse />
</controls:DropShadowPanel>
In UWP there is a different component to do this job. It's called the Composition API and is available in the NuGet Package "Win2D.uwp".
Basically you'll need to get the compositor for your visual object with
_compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
and create a drop shadow using the compositor.
_compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
// create a red sprite visual
var myVisual = _compositor.CreateSpriteVisual();
myVisual.Brush = _compositor.CreateColorBrush(Colors.Red);
myVisual.Size = new System.Numerics.Vector2(100, 100);
// create a blue drop shadow
var shadow = _compositor.CreateDropShadow();
shadow.Offset = new System.Numerics.Vector3(30, 30, 0);
shadow.Color = Colors.Blue;
myVisual.Shadow = shadow;
// render on page
ElementCompositionPreview.SetElementChildVisual(this, myVisual);
The downside beeing, that this is not quite straight forward. You can use different brushes to display images, solid colors or other stuff, it won't apply to existing visuals on screen (as far as I understand it). You can read more about the basics here. Probalby you'll need to use a surface brush, which can hold a wide variety of different visual types, like images. Currently it does not look like there is a ready made component for ellipses though.
Alternatively there exists a xaml extension which will do all that stuff for you using pure xaml, might be worth a shot and maybe also support ellipses.
As an ending note, all of this is currently a work in progress on microsofts part and should become a native part of the UWP API in the future.
I am using the 1st release of the ArcGIS Runtime SDK for .Net - Xamarin.Forms (nuget package here).
One of my requirements is to display a basic scale line on the map. I haven't found any build-in feature for the moment.
It seems to be tricky because each device has different size, different resolution... Any idea on how to implement this ?
OK after few hours, I found that the MapView component has a property UnitsPerPixel that do exactly what I needed:
I've added a small grid (to represent the scale) with a fix width:
<Grid HeightRequest="10" WidthRequest="114" x:Name="Legend">
...
</Grid>
Then when the view point changes, I compute the distance representing by this grid:
MapView.ViewpointChanged += (sender, args) =>
{
ScaleVal.Text = $"{Math.Round(Legend.Width * MapView.UnitsPerPixel, 0)}m";
};
Complete solution here.
I currently work on WPF application according to my AI interest.
I wrote a Uniform Cost Search algorithm (pathfinding) and want to present it in graphical way.
Path should be found and show on a graph which could be adjusted by user.
I'm quite new in WPF technology, I worked more with WinForms and now have a problem with creating and managing graphical elements.
In other words - I want to give opportunity to click on data grid and create your own node (sth like place on a map) which is represented by a picture, when you have a few nodes you can choose two of them and connect them to make a connection, finally you can select your start and end point and algorithm will show the shortest path (color the suitable connections).
That's it.
Image with interface
I started with adding a CreateNode method which gets click's coordinates and create a point with right X and Y. Now there is a problem with creating an image in that specific place.
I read some questions on Stack and tried to write something with Image and BitmapImge classes but still don't know how to place it in specific place.
I read about manipulating margins but aren't there any easier solutions?
Here's part of that image loading code:
public void CreateNode(Node n)
{
Point point = new Point(n.X, n.Y);
Image node = new Image();
BitmapImage logo = new BitmapImage();
logo.BeginInit();
logo.UriSource = new Uri("point.png");
logo.CacheOption = BitmapCacheOption.OnLoad;
logo.EndInit();
node.Source = logo;
}
If someone has any ideas how to create these methods in case of graphics I will really aprreciate that.
Thanks in advance
Paweł
EDIT: I was said to create new topic for my code problem so here is that here
Moving my comment to an answer to provide a little more information.
With the positioning, I'd recommend watching this video on advanced XAML techniques. He uses a custom ItemsControl and Canvas to bind the longitude and latitude of delivery trucks to show as graphics on a map. I think some of his techniques could work in your situation (or give you further ideas). I've linked to the a timestamp at the start of the relevant section.
The source code for the relevant demo is available here. See Events - 2014 TechEd Europe - DEV-B311 XAML Techniques - Demo05
The main difference from what you're doing to the video is that he uses Paths where you want to use images. You'd need to change the DataTemplates in App.xaml.cs to use images.
The video assumes some knowledge of MVVM, so if that's new to you, it's probably worth checking out a tutorial. You can find some recommendations in the answers to this question. I'd also recommend one on Rachel Lim's Blog. I found her tutorials very useful.
The first linked tutorials on WPF look like they will be useful to you. In addition to the basics it includes using images in DataTemplates.
How can I zoom in/out the webControl in Awesomium v1.7? there is no webControl.zoom in v1.7...
I am applying zoom when I start the websession, like this:
myWebControl.WebSession = WebCore.CreateWebSession(new WebPreferences() { CustomCSS = "body { zoom: 200%; }" });
But I also want to be able to apply zoom in/out after the webcontrol has been displayed.just like we did in v1.6. Im using wpf C#.
Any help would be appreciated.
The Zoom property and supporting API (similar to the one available in 1.6.x), will be available in the final release of version 1.7.
I want to use 4 point multitouch gestures in my app. The app is in silverlight (not xna), but the gestures won't apply to any controls, they will just check if user drags 4 fingers to the left or to the right of the screen.
Are there any libraries that I can use? Or what is the easiest way to implement it on my own? Can I use XNA multitouch libraries?
Cheers
As you are probably aware the WP7 silverlight API makes the assumption of two contact points for multi touch i.e. PinchStarted, PinchDelta, and PinchCompleted.
Please Check out the TouchPanel class which is in the Microsoft.Xna.Framework.Input.Touch namespace.
//Determine the maximum number of touches permited (four for WP7):
TouchPanelCapabilities tc = TouchPanel.GetCapabilities();
if(tc.IsConnected)
{
return tc.MaximumTouchCount;
}
//To read multitouch data from the touch input device you can do the following:
// Process touch events
TouchCollection touchColl = TouchPanel.GetState();
foreach (TouchLocation t in touchColl)
{
if ((t.State == TouchLocationState.Pressed)
|| (t.State == TouchLocationState.Moved))
{
//You can check the coordinates of each point (and the previous coordinate TryGetPreviousLocation())
float xcoordiante = t.Position.X;
float ycoordiante = t.Position.Y;
//Determine if touch point was moved/pressed or released use the State property
TouchLocationState st = t.State;
}
}
More details can be found here: http://msdn.microsoft.com/en-us/library/ff827744.aspx
I have not seen any libraries that specifically target 4 point touch, however, if you are looking for libraries that help with multi touch debugging I would strongly recommend http://multitouch.codeplex.com/.
The Silverlight WP7 Toolkit is awesome for doing Gesture stuff.
Download WP7 Toolkit
Then check out this awesome tutorial