I have pushpins on my map in Visual Studio (below is the code that does this). But they are blue dots. I want to change my pushpins to something else besides blue dots. I found this website that gives a bunch of syntax of pushpins. (http://msdn.microsoft.com/en-us/library/ff701719.aspx) Currently, it displays the pushpin as number 77. I don't know if this is the default pushpin, or what. But I want to change it to something else like 71 so it gives more information. Any idea how I can do this with my code I have below?
Thanks!! :)
private async void PopulateMap()
{
//put data on map
LocationCollection locationCollection = new LocationCollection();
if (_group != null)
{
foreach (SampleDataItem item in _group.Items)
{
Pushpin myPushpin = new Pushpin();
myPushpin.Text = item.Title;
//created new location
Location rentLocation = new Location(Convert.ToDouble(item.Latitude), Convert.ToDouble(item.Longitude));
MapLayer.SetPosition(myPushpin, rentLocation);
rentalMap.Children.Add(myPushpin);
locationCollection.Add(rentLocation);
}
}
The documentation you referenced is for the Static imagery API and those pushpins are not available outside of that service. That said it's very easy to create custom pushpins. If you simply want to change the color try using the background property of the Pushpin class. Alternatively you can create a custom style that has a DataTemplate and apply that to the pushpin. If you simply want to use an image as a pushpin you can create an Image object, or any UIElement and add it to the map the same way you do a pushpin.
I'm assuming you are creating a Windows 8 app. If so, take a look at my free ebook on crating location intelligent windows store apps. In chapter 4 I show how to create custom pushpins: http://rbrundritt.wordpress.com/my-book/
You can also find all the code samples for the book here: http://code.msdn.microsoft.com/Location-Intelligence-for-1c691d0e
Related
I'm trying to change MapView in my Xamarin Forms app (with Mapsui and Prism), as I need separate view to store Pins. First MapView (let's call it default) is for displaying all pins from list. Second MapView (history) is for displaying new pins, which are removed when leaving Page.
I have Dictionary for storing my MapViews to have easy way to access any view I want. Every created MapView has the same instance of Map. I want to change from default to history which should hide pins that are added in default view.
I change view with this:
public void ChangeView(string name)
{
var prev = MapView;
loggerService.Info($"Pins: {prev.Pins.Count}");
MapView = GetView(name); // Current MapView in XAML, returns instance of MapView
loggerService.Info($"New view pins: {MapView.Pins.Count}");
Task.Factory.StartNew(() =>
{
Task.Delay(2000).Wait();
loggerService.Info($"View pins: {MapView.Pins.Count}");
});
MapView.Refresh();
}
extra code with log is for debugging purposes - it shows correct values (prev pins = 7, new pins = 0, view pins = 0).
I've added history view without Zoom buttons to make sure it is changing - and it is (so there is no need to post XAML, I think).
How should I change MapView to hide pins when navigating to history and show them when I switch back to default view?
Or is there a better way to 'group' Pins and hide/show them basing on name?
Update
I think this may be important to mention:
public Pin AddMarker(Position point)
{
var pin = new Pin(MapView)
{
Label = "PinType.Pin",
Position = point,
Type = PinType.Pin,
Transparency = 0.5f,
Color = Xamarin.Forms.Color.FromRgb(2, 144, 210),
Scale = 0.5f,
};
MapView.Pins.Add(pin);
return pin;
}
This is the way I add Pins to view. This is the same MapView as above (all the code is from MapService).
Some options
Perhaps you can bind the IsVisible property of the Pins to a HistoryMode field on your view. I never used this myself.
Use some of the lower level functionality. Like
Use separate layers for default and history and enable/disable them when needed. You might need to do the conversion of WGS84 (gps coordinates) to SphericalMercator. https://mapsui.com/api/Mapsui.Projection.SphericalMercator.html?q=sphericalmercator
Use a ThemeStyle. It has a method that can be use to specify any style you need (visible/color/symbol) based and the feature attributes. https://mapsui.com/api/Mapsui.Styles.Thematics.ThemeStyle.html?q=themestyle
For the lower level functionality you may need to the samples to get you on your way: https://mapsui.com/documentation/samples.html
I have a inherited Listview which standard has to be in Tile Mode. When using this control, the DrawItem gives e.bounds which are clearly bounds of largeIcon view ?? When debugging to check the view it is actually set to, it says it's in Tile view ?? Yet e.DrawText draws LargeIcon view ??
......... Edit: .................
This seems only to happen when the control is placed upon another usercontrol?
......... Edit 2: .................
It gets stranger ... When i add buttons next to the list to change the view at runtime, "Tile" is the same as "LargeIcon", and "List" view is the same as "SmallIcons" ??? I've also completely removed the ownerdraw ...
.......... Edit 3: .................
MSDN Documentation:
Tile view
Each item appears as a full-sized icon
with the item label and subitem
information to the right of it. The
subitem information that appears is
specified by the application. This
view is available only on Windows XP
and the Windows Server 2003 family.
On earlier operating systems, this value is ignored and the ListView
control displays in the LargeIcon
view.
Well I am on XP ?!?
...... Edit 4 .....................
Holy mother of strangeness ...
We are now at the point we've completely stripped down EVERYTING ... We have a standard listview on a form, manually filled with 3 values. No Ownerdraw. It is set to Tile.
When we start this form, the list is drawn as LARGEICON.
Now, we start another blank solution, copy this exact same form to the new project, start debug and low and behold .. it is drawn in TILE view ????
... help ...
public class InheritedListView : ListView
{
//Hiding members ... mwuahahahahaha //yeah i was still laughing then
[BrowsableAttribute(false)]
public new View View
{
get { return base.View; }
}
public InheritedListView()
{
base.View = View.Tile;
this.OwnerDraw = true;
base.DrawItem += new DrawListViewItemEventHandler(DualLineGrid_DrawItem);
}
void DualLineGrid_DrawItem(object sender, DrawListViewItemEventArgs e)
{
View v = this.View;
//**when debugging, v is Tile, however e.DrawText() draws in LargeIcon mode,
// e.Bounds also reflects LargeIcon mode ???? **
}
................................
This code behaves differently at different solutions:
private void InitializeComponent()
{
System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem("fhsdhdsfhsdfhs");
System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem("fdshdsfhdsfhsd");
System.Windows.Forms.ListViewItem listViewItem3 = new System.Windows.Forms.ListViewItem("hdshsdfhsdfhsdfsdfsdf");
this.listView1 = new System.Windows.Forms.ListView();
this.SuspendLayout();
//
// listView1
//
this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
listViewItem1,
listViewItem2,
listViewItem3});
this.listView1.Location = new System.Drawing.Point(36, 12);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(487, 242);
this.listView1.TabIndex = 2;
this.listView1.TileSize = new System.Drawing.Size(480, 50);
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.Tile;
//
// TestControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(595, 712);
this.Controls.Add(this.listView1);
this.Name = "TestControl";
this.Text = "TestControl";
this.ResumeLayout(false);
}
#endregion
OK, we found it. The magic spell is:
Application.EnableVisualStyles();
We skipped this line of code to test our form.
If you don't call this method before you create your form with your listview, TILE view gets drawn as LARGEICON.
Seems totally logical ... :-(
http://blogs.msdn.com/rprabhu/archive/2003/09/28/56540.aspx
Q What does Application.EnableVisualStyles actually do?
Windows XP ships with two versions of the Common Controls Library (comctl32.dll) - versions 5.8 and 6.0. v5.8 renders controls in the "Classic" style that you get on Windows NT/2000 and Windows 9x. v6.0 renders controls using the XP Visual Styles look and feel. Since most Windows Forms controls are based on comctl32, how they are rendered depends on which version of comctl32 is used to do the rendering. By default, v5.8 is used to render the client area of the app and v6.0 is used to render the non-client area. That is why you see the title bar and window borders automatically render "themed", while the controls (like Button, TextBox, ListView, ComboBox and so on) have the classic look by default.
In v1.0 of the Framework, the way to get visual styles in a Windows Forms app was to ship a manifest file with the app, that has information in it to indicate that v6.0 of comctl32 should be used for rendering. While this works fine, many developers felt it cumbersome to author, maintain and deploy manifest files. They felt the need to be able to do this programmatically. Now, the Platform SDK does provide API to do this. Basically, you need to create and activate an Activation Context that has pretty much the same DLL redirection information in it as the manifest file. The Activation Context API can be used to do this in a way suitable to your application.
If you take a look at these API, you will probably notice that they aren't very easy to use. While the advanced developers may like to tinker around with activation contexts, it is probably not something a developer who wants some "quick and dirty" code to get visual styles will do. So the Windows Forms team decided to wrap these API and expose a simple method that developers could call, that would isolate them from these complexities. So, essentially, when you call Application.EnableVisualStyles, we set up an activation context around the application's message loop, so that comctl32 function calls can be properly redirected to comctl32 v6.0. That way, you don't need to include a manifest with your app.
im using Xamarin with MvvmCross.
Ive done a FragmentDialog with a recyclerView inside, the list is populated via bindings on xml file, so i have no adapter and i should keep it this way.
If im not wrong, theres no built in way to make the recyclerView take only the size needed for its content, this should not be a problem, but in this case i need the list to start from bottom...
So i did this (its a custom fullscreen dialog) :
MvxRecyclerView list = Dialog.FindViewById<MvxRecyclerView>(Resource.Id.recyclerview);
list.LayoutChange += List_LayoutChange;
Then in layoutChange
private void List_LayoutChange(object sender, View.LayoutChangeEventArgs e)
{
MvxRecyclerView list = Dialog.FindViewById<MvxRecyclerView>(Resource.Id.recyclerview);
int itemHeight = list.GetChildAt(0).Height;
if (itemHeight != 0)
{
ViewGroup.LayoutParams prms = list.LayoutParameters;
prms.Height = itemHeight * list.GetAdapter().ItemCount;
list.LayoutParameters = prms;
list.LayoutChange -= List_LayoutChange;
list.RequestLayout();
}
}
That was working fine, the list get exactly the height needed and the list looks like it starts from bottom.
Now the client tell me that he doesnt like the fullscreen dialog and wants the status bar, i think that should be easy, just to remove this line at the dialog creation right?
dialog.Window.AddFlags(WindowManagerFlags.Fullscreen);
But looks like its not that easy, when the dialog its not fullscreen the layoutParams change seems to have no effect, it just dont do nothing.
My method is being called and i get the right item height, it just dont change the recyclerview height.
Notice that setting fullscreen at creation and clearing the flag after the recyclerview params change works
So looks like it only works during fullscreen mode.
Can someone throw some light at this?
Thanks in advance.
As you said, RecyclerView was not aware of its size.
Since last update to the support lib, it is !
http://android-developers.blogspot.fr/2016/02/android-support-library-232.html
The RecyclerView widget provides an advanced and flexible base for creating lists and grids as well as supporting animations. This release brings an exciting new feature to the LayoutManager API: auto-measurement! This allows a RecyclerView to size itself based on the size of its contents. This means that previously unavailable scenarios, such as using WRAP_CONTENT for a dimension of the RecyclerView, are now possible. You’ll find all built in LayoutManagers now support auto-measurement.
I would suggest to wait for the Xamarin wrapped lib (there is already a beta https://www.nuget.org/packages/Xamarin.Android.Support.v4/23.2.0-beta1)
I am a newbie
I have a database with addresses and longitude/ lattitude data.
I want to write a small windows application that is able to put multiple pushpins or other marks on the map using longitude and lattitude-
The user types ind the address
The system gets the longitude and laittude and adds the pushpins on the map.
I really need some help and guidance to get started.
I can manage th database call and gui stuff, but i havent been able to successfully adding a bing map and set the pushpins in a simple winform application yet.
Im using visual studio 2012
I have downloaded and installed the Bing Maps WPF control
So adding a map to a wpf app is super easy. Following the steps here: https://msdn.microsoft.com/en-us/library/hh745791.aspx
I'll quickly go over the steps mentioned in the article:
Step 1. You have already completed since you have the Bing Maps WPF control.
Step 2. Get a Bing Maps Key
Step 3. Add the xmlns:m annotation to your Window
xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF"
Step 4. Add a maps Control to your Window. It will be nested within something like the
Like this
<Grid>
<m:Map x:Name="myMap"
CredentialsProvider="Your Key From Step 2"/>
</Grid>
Step 5. In your Code behind, add pins to your map
public MainWindow()
{
InitializeComponent();
Pushpin pin = new Pushpin();
pin.Location = new Location(37.1481402218342, -119.644248783588);
// Adds the pushpin to the map.
myMap.Children.Add(pin);
// Removes pushpin from the map.
// myMap.Children.Remove(pin);
}
I have created a new UIElement that derives from Systen.Windows.Controls.Canvas.
I am trying to handle flicks made on this object.
Everything is done in C#, in code (no XAML) using the Silverlight Phone Toolkit (February version as I want to target 7.0)
In my object constructor I do:
//Create gesture handling
gl = GestureService.GetGestureListener(this);
gl.Flick += new EventHandler<FlickGestureEventArgs>(gl_Flick);
and gl_Flick is simply:
void gl_Flick(object sender, FlickGestureEventArgs e)
{
if (e.HorizontalVelocity >= 0)
{
// Right swipe (flick)
if (gotSwipe != null)
{
gotSwipe(this, e);
}
}
}
Now, in the constructor, I also create and add a few TextBlocks
For some reason, the flick is only generating an event if done over one of those TextBocks. If I do the flick on any of the empty area of the Canvas nothing occurs.
As I can't find any documentations related to the Silverlight toolkit, everything has been done via trials&errors.
How could I do, so the flick will be recognised when performed anywhere over this canvas and not limited to over the children it contains?
I'm more focused towards WPF, but the way you talk about it reminds me of the classic null background issue.
The solution: set a non null background for your canvas.
EDIT: something like
myCanvas.Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 1));