Select to view content in your preferred language

How to add icons to the map in code-behind?

721
1
Jump to solution
12-02-2013 10:13 AM
robertstalnaker
Emerging Contributor
Hello,

I need to programmatically add icons to the map at various locations. Can anyone point me to a sample and/or tutorial for doing so please? I'm using VB.Net and assume I should be able to do something like:

Map.ElementLayer.Children.Add(imgSample, -118, 32)


But there doesn't seem to be this kind of intuitive access to the API.

Currently, I have markup:
<UserControl x:Class="Crime_Map_Test.MainPage"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"     xmlns:esri="http://schemas.esri.com/arcgis/client/2009"     mc:Ignorable="d"     d:DesignHeight="300" d:DesignWidth="400">      <Grid x:Name="LayoutRoot" Background="White">          <esri:Map x:Name="MyMap">             <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer"                      Url="http://services.arcgisonline.com/ArcGIS/rest/services/NGS_Topo_US_2D/MapServer"/>              <esri:ElementLayer>                 <esri:ElementLayer.Children>                                      </esri:ElementLayer.Children>             </esri:ElementLayer>          </esri:Map>      </Grid>  </UserControl>


And code-behind:
Imports ESRI.ArcGIS.Client.ElementLayer Imports System.Windows.UIElement Partial Public Class MainPage     Inherits UserControl      Public Sub New()         InitializeComponent()      End Sub  End Class
0 Kudos
1 Solution

Accepted Solutions
DenisT
by
Deactivated User
Set Id for the ElementLayer in XAML:
<esri:ElementLayer ID="elementLayer" />

code behind sample:
Imports ESRI.ArcGIS.Client Imports ESRI.ArcGIS.Client.Geometry  Partial Public Class MainPage     Inherits UserControl      Public Sub New()         InitializeComponent()          Dim layer As ElementLayer = MyMap.Layers("elementLayer")         ' TODO: Set coordinates         Dim envelope = New Envelope(0, 0, 0, 0)          Dim rectangle = New Rectangle         rectangle.Width = 3         rectangle.Height = 3         rectangle.Fill = New SolidColorBrush(Colors.Red)         ElementLayer.SetEnvelope(rectangle, envelope)         layer.Children.Add(rectangle)          Dim textBlock = New TextBlock()         textBlock.Text = "Hello world"         ElementLayer.SetEnvelope(textBlock, envelope)         layer.Children.Add(textBlock)     End Sub  End Class

View solution in original post

0 Kudos
1 Reply
DenisT
by
Deactivated User
Set Id for the ElementLayer in XAML:
<esri:ElementLayer ID="elementLayer" />

code behind sample:
Imports ESRI.ArcGIS.Client Imports ESRI.ArcGIS.Client.Geometry  Partial Public Class MainPage     Inherits UserControl      Public Sub New()         InitializeComponent()          Dim layer As ElementLayer = MyMap.Layers("elementLayer")         ' TODO: Set coordinates         Dim envelope = New Envelope(0, 0, 0, 0)          Dim rectangle = New Rectangle         rectangle.Width = 3         rectangle.Height = 3         rectangle.Fill = New SolidColorBrush(Colors.Red)         ElementLayer.SetEnvelope(rectangle, envelope)         layer.Children.Add(rectangle)          Dim textBlock = New TextBlock()         textBlock.Text = "Hello world"         ElementLayer.SetEnvelope(textBlock, envelope)         layer.Children.Add(textBlock)     End Sub  End Class
0 Kudos