Select to view content in your preferred language

PicutreMarkerSymbol does not work but SimpleMarkerSymbol does

843
3
10-22-2010 01:53 PM
TerryGiles
Frequent Contributor
I thought I'd seen a fix for this last week in the forums but can't find it today!  I'm trying to add a graphic to a graphics layer using an image defined in Resources of my user control but if I use a PictureMarkerSymbol nothing draws whereas a SimpleMarkerSymbol does.  The ESRI Identify sample uses a PictureMarkerSymbol so I know it's possible. 

I have a user control that a user can enter a Lat-Long and the map will zoom to it and (should) add a graphic at the local they entered.  I'm wondering if it's a location issue - my control is /UserControls/ZoomToXY and references a PNG in /UserControls/Images as the source for the PictureMarkerSymbol.  I've tried putting the PNG up a level in the /Images folder but that doesn't seem to solve the problem either. 

Anyone know what I'm missing?  Thanks, Terry


XAML for resources:
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.Resources>
            <esri:PictureMarkerSymbol x:Name="DefaultPictureSymbol" OffsetX="13" OffsetY="22" 
                 Source="/Images/IdentifyMapIcon.png"  />
            <esri:SimpleMarkerSymbol x:Name="SMStest" Color="Red" Size="12" />
        </Grid.Resources>

Code behind:
            //add graphic to map
            GraphicsLayer graphicsLayer = (GraphicsLayer)_Map.Layers[_GraphicsLayer];
            graphicsLayer.ClearGraphics();
            //this does not work
            Graphic graphic = new Graphic() { Geometry = ptMapPoint, Symbol = DefaultPictureSymbol };
            graphicsLayer.Graphics.Add(graphic);
            //using a SimpleMarkerSymbol works
            Graphic graphic2 = new Graphic() { Geometry = ptMapPoint, Symbol = SMStest };
            graphicsLayer.Graphics.Add(graphic2);
0 Kudos
3 Replies
dotMorten_esri
Esri Notable Contributor
Note that "/Images/IdentifyMapIcon.png" is relative to where the .xap file is, not where the hosting html file is.
0 Kudos
TerryGiles
Frequent Contributor
Hi Morten,

Thank you, chaning the path in the XAML fixed it.
        <Grid.Resources>
            <esri:PictureMarkerSymbol x:Name="DefaultPictureSymbol" OffsetX="12" OffsetY="24" 
                 Source="../UserControls/Images/IdentifyMapIcon.png"  />
            <esri:SimpleMarkerSymbol x:Name="SMStest" Color="Red" Size="12" />
        </Grid.Resources>


I'm still a little confused as to how path references work in the XAP. Why does it need the "../UserControls" in the source string - the ZoomToXY.xaml is in the UserControls folder but neither "/Images/IdentifyMapIcon.png" nor "./IdentifyMapIcon.png" work in the controls xaml but it did work in code -

            Graphic graphic = new Graphic() 
                { Geometry = ptMapPoint, 
                  //Symbol = DefaultPictureSymbol

                  
                  Symbol = new PictureMarkerSymbol() 
                        { Source = new BitmapImage(new Uri("Images/IdentifyMapIcon.png", UriKind.Relative)),
                          OffsetX=12, OffsetY=24 }
                };


Thanks again, Terry
0 Kudos
dotMorten_esri
Esri Notable Contributor
The difference lies in whether the xaml is parsed as part of the page (where relative makes sense), or whether it's a piece of code that could have been executed from anywhere.
0 Kudos