Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
945
Using xamMap within ElementHost
posted

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

Parents Reply
  • 3255
    Verified Answer
    posted in reply to David

    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://ko.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;
                }
    
            }
    

     

Children