Would like to use xamMap within a ElementHost control on a windows form control. Therefore I don't have Xaml code file or Designtime capabilities.
Can I get design time capabilities?
Any ecample code for full C# code based implementation of a XamMap control.
All I want to do display is at least one (maybe a couple of shapefiles) and load a dataset from a web service with lat longs and place points of interest and respond to clicking on POI. will need zoom and panning capabilities.
Thanks
Thanks that worked
Hello Ahrensd,
I created a sample for you which shows the data point on a map. I sent you this sample through the support case CAS-76704-Q48YYP. You’ll be able to access this case from the My Support Activity page: <https://es.infragistics.com/Membership/MySupport.aspx>.
The sample is based on the following help topic.
http://help.infragistics.com/NetAdvantage/WPFDV/2010.3/CLR4.0/?page=xamWebMap_Add_Image_Using_Map_Elements.html
Below is the xaml
<ig:XamMap.Layers> <ig:MapLayer LayerName="statesLayer" x:Name="usa_st" FillMode="RandomInterpolate" Brushes="Green yellow Red" ToolTip="{}{Name}: Pop. {Value:n0}" Imported="usa_st_Imported"> <!--FillMode="Chloropleth"--> <!-- Note: Actual Shapefile is loaded in code-behind using absolute path and this XAML code is provided for your convenience --> <ig:MapLayer.Reader> <ig:ShapeFileReader Uri="/../../Shapefiles/usa_st" DataMapping="Caption=STATE_ABBR; Name=STATE_NAME; Value=POP1997; Abbreviation=STATE_ABBR;Area=AREA;SubRegion=SUB_REGION" /> </ig:MapLayer.Reader> </ig:MapLayer> <ig:MapLayer x:Name="symbolLayer" Imported="symbolLayer_Imported"> <ig:MapLayer.ValueTemplate> <DataTemplate> <Image Width="50" Height="50" Source="/Images/phone.png" /> </DataTemplate> </ig:MapLayer.ValueTemplate> </ig:MapLayer> </ig:XamMap.Layers>
Here is the code behind:
private void usa_st_Imported(object sender, MapLayerImportEventArgs e) { if(e.Action == MapLayerImportAction.End) { // Find Element using Name property MapElement newYork = theMap.Layers[0].Elements.FindElement("Name", "New York").ElementAt<MapElement>(0); // Get Point data from Cartesian coordinates Point nyOrigin = new Point(newYork.WorldRect.X + 350000, newYork.WorldRect.Y + 300000); // Create Element SymbolElement element = new SymbolElement() { SymbolOrigin = nyOrigin, Caption = "Best Phones", SymbolType = MapSymbolType.None, SymbolSize = 20 }; // Assign arbitrary value so that Value Template can be used element.Value = 1; theMap.Layers[1].Elements.Add(element); // Make enough space in layer for the added shape Rect worldRect = theMap.Layers[1].WorldRect; worldRect.Union(element.WorldRect); theMap.Layers[1].WorldRect = worldRect; } }
Finaly got the shapefile to display, but still no luck placing points of interest on the map.
The elements seem to be there but not displayed
my xaml file is ...
<UserControl x:Class="WPFControl.Map" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="849" d:DesignWidth="462" xmlns:ig="http://schemas.infragistics.com/xaml"> <Grid> <DockPanel LastChildFill="True"> <ig:XamMap HorizontalAlignment="Left" Name="xamMap1" VerticalAlignment="Top" ClipToBounds="False" GridDisplayMode="None" MapProjectionType="SphericalMercator"> <ig:MapNavigationPane ig:XamDock.Edge="InsideRight" Margin="10"/> <ig:XamMap.Layers> <ig:MapLayer LayerName="QueenslandLayer"> <ig:MapLayer.Reader> <ig:ShapeFileReader Uri="/../../ShapeFiles/Queensland(Simple)"/> </ig:MapLayer.Reader> </ig:MapLayer> <ig:MapLayer LayerName="Stations"/> </ig:XamMap.Layers> </ig:XamMap> </DockPanel> </Grid> </UserControl>
with cs file of control
namespace WPFControl { /// <summary> /// Interaction logic for UserControl1.xaml /// </summary> public partial class Map : UserControl { public MapLayerCollection Layers { get { return xamMap1.Layers; } set { xamMap1.Layers = value; } } public Rect WorldRect { get { return xamMap1.WorldRect; } set { xamMap1.WorldRect = value; } } public Projection MapProjection { get { return xamMap1.MapProjection; } set { xamMap1.MapProjection = value; } } public event MapElementClickEventHandler ElementClick { add { xamMap1.ElementClick += value; } remove { xamMap1.ElementClick -= value; } } public Map() { InitializeComponent(); } } } and Mainform code which has the ElementHost control public MainForm() { service = new SPOTA1WebServiceClient(); InitializeComponent(); ultraChart1.Visible = false; mapControl.ElementClick += new MapElementClickEventHandler(mapControl_ElementClick); StationPosition[] stations = service.GetStationPosition(); foreach (StationPosition stationPosition in stations) { System.Windows.Point origin = mapControl.MapProjection.ProjectToMap(new System.Windows.Point(stationPosition.Longitude, stationPosition.Latitude)); SymbolElement element = new SymbolElement() { SymbolOrigin = origin, Caption = stationPosition.Name, Value=stationPosition.Code, SymbolType = MapSymbolType.Diamond, SymbolSize = 5, }; mapControl.Layers["Stations"].Elements.Add(element); stationPositionBindingSource.Add(stationPosition); } } void mapControl_ElementClick(object sender, MapElementClickEventArgs e) { if (e.Element.GetType().Equals(typeof(SymbolElement))) updateGrid2(Convert.ToInt32(e.Element.Value)); }
namespace WPFControl { /// <summary> /// Interaction logic for UserControl1.xaml /// </summary> public partial class Map : UserControl { public MapLayerCollection Layers { get { return xamMap1.Layers; } set { xamMap1.Layers = value; } } public Rect WorldRect { get { return xamMap1.WorldRect; } set { xamMap1.WorldRect = value; } } public Projection MapProjection { get { return xamMap1.MapProjection; } set { xamMap1.MapProjection = value; } } public event MapElementClickEventHandler ElementClick { add { xamMap1.ElementClick += value; } remove { xamMap1.ElementClick -= value; } } public Map() { InitializeComponent(); } } }
and Mainform code which has the ElementHost control
public MainForm() { service = new SPOTA1WebServiceClient(); InitializeComponent(); ultraChart1.Visible = false; mapControl.ElementClick += new MapElementClickEventHandler(mapControl_ElementClick); StationPosition[] stations = service.GetStationPosition(); foreach (StationPosition stationPosition in stations) { System.Windows.Point origin = mapControl.MapProjection.ProjectToMap(new System.Windows.Point(stationPosition.Longitude, stationPosition.Latitude)); SymbolElement element = new SymbolElement() { SymbolOrigin = origin, Caption = stationPosition.Name, Value=stationPosition.Code, SymbolType = MapSymbolType.Diamond, SymbolSize = 5, }; mapControl.Layers["Stations"].Elements.Add(element); stationPositionBindingSource.Add(stationPosition); } } void mapControl_ElementClick(object sender, MapElementClickEventArgs e) { if (e.Element.GetType().Equals(typeof(SymbolElement))) updateGrid2(Convert.ToInt32(e.Element.Value)); }
Asma,
Yes, this gives the basic recipe. And I've been able to host the control in a ElementHost control. However so far I can't get the shapefile to be displayed. and I was hoping also on some guidance on the best way of loading some 5000 points of intetest and making them clickable.
I would suggest you to add xamMap to a UserControl and add the UserControl to the ElementHost. You can also expose properties of the xamMap control to the UserControl.
The following blog post describes how to host a WPF control in a windows forms application. This blog post also describes how to expose WPF properties.
http://blogs.infragistics.com/wpf/articles/hosting-a-wpf-control-in-a-windows-forms-application.aspx
The following topics have some examples on how to use xamMap control.
http://help.infragistics.com/NetAdvantage/WPFDV/2010.3/CLR4.0/?page=SL_DV_Developers_Guide_xamWebMap.html
http://community.infragistics.com/blogs/mihail_mateev/archive/2010/08/06/using-infragistics-xammap-silverlight-wpf-control-with-sql-server-spatial.aspx
Please let me know if you have any questions on this matter.