Select to view content in your preferred language

How to change the template of SimpleMarkerSymbol?

1638
6
04-07-2011 08:40 PM
DanDong
Deactivated User
Hi all,

I am using this method to add symbol on the map. Basically, it is binding size and color attributes to the graphic. The attributes value are gained from combox in the user_interface. The user can choose the size and color of the symbol.

<esri:SimpleMarkerSymbol x:Key="AddSymbolStar" Style="Cross" 
                       Size="{Binding Attribute[Size]}"
                       Color="{Binding Attribute[Color]}" >                
</esri:SimpleMarkerSymbol>


drawMode = DrawMode.Point;
GraphicsLayer graphicsLayer = MyMap.Layers["MyAddSymbolLayer"] as GraphicsLayer;

ESRI.ArcGIS.Client.Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
                    {
                        Geometry = e.MapPoint,
                        Symbol = LayoutRoot.Resources["AddSymbolStar"] as ESRI.ArcGIS.Client.Symbols.Symbol
                    };
graphic.Attributes["Size"] = AddSymbolSizeCombo.SelectedItem.ToString();
MessageBox.Show("size" + graphic.Attributes["Size"]);

graphic.Attributes["Color"] = AddSymbolColorCombo.SelectedItem.ToString();
MessageBox.Show("color" + graphic.Attributes["Color"]);
graphicsLayer.Graphics.Add(graphic);
MessageBox.Show(graphicsLayer.Graphics.Count.ToString());


But weird thing is after I click on the map, the three message boxes all have values (size16, colorRed, 1), but there is no cross symbol appear on the map....

I am not sure whether this binding attribute method can be only used in control template, cuz last time when I try to use the same method to add text on the map, I changed the control template of textblock. So....any suggestions? Thank you very much!!
0 Kudos
6 Replies
DominiqueBroux
Esri Frequent Contributor

I am not sure whether this binding attribute method can be only used in control template


Yes, it's only working in control template because the DataContext of the 'Symbol' is not set to a specific graphic. You can use the same symbol for many graphics.
So in your case you have to redefine the ControlTemplate of the MarkerSymbol (as you did for TextSymbol).
0 Kudos
DanDong
Deactivated User
Yes, it's only working in control template because the DataContext of the 'Symbol' is not set to a specific graphic. You can use the same symbol for many graphics.
So in your case you have to redefine the ControlTemplate of the MarkerSymbol (as you did for TextSymbol).


Hi Dominique, thank you very much for the answer. I go through the components which can subclass the markersymbol, but I am not able to find one with size and color properties (I found rectangle, eclipse, radiobutton, button...). In the other thread I asked to change the symbol of textsymbol, I actually use textblock. But this case I am kinda lost which one I should use (the one has size and color properties). Do you have any suggestion? Thank you!
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I go through the components which can subclass the markersymbol, but I am not able to find one with size and color properties (I found rectangle, eclipse, radiobutton, button...).


You will find lots of samples of custom marker symbols here :
http://help.arcgis.com/en/webapi/silverlight/samples/SymbolGalleryWeb/start.htm

You can use any UIElement even if the UIElement have no size or color properties.
As your are storing these graphic properties int the attributes, you can bind some properties of hen UI elements of your symbol to these attributes, e.g.:

<Polygon Points="0,0 12,0 12,6 8,10 12,14 12,20 0,20 0,14 4,10 0,6 0,0" Fill="{Binding Attributes[Color]}" />
0 Kudos
JenniferNery
Esri Regular Contributor
0 Kudos
DanDong
Deactivated User
Thank you Dominique and Jennifer! That symbol gallery is really excellent dictionary!! I am truly surprised! This symbol gallery really do me a big favor 😄

I do have another small question. Let's see if I want to use the below symbol, a pin symbol, a combobox in the user interface will let user choose size of the symbol (like size 12). I can understand the path of the rectangle is to draw a pin shape. But I dont know where I can change the size of it. I am hoping there is a property that I can bind the size attribute or some size number(length or width) attribute which will be received from user interaction. Thank you 🙂

<esri:MarkerSymbol x:Key="esriDefaultMarker_97" OffsetX="3.696875" OffsetY="6.53335">
    <esri:MarkerSymbol.ControlTemplate>
      <ControlTemplate>
        <Grid RenderTransformOrigin="0.5,0.5" Width="7.39375" Height="13.0667">
          <Grid.RenderTransform>
            <TransformGroup>
              <ScaleTransform ScaleX="1" ScaleY="1" />
            </TransformGroup>
          </Grid.RenderTransform>
          <Canvas HorizontalAlignment="Left" VerticalAlignment="Top">
            <Rectangle Fill="#00FFFFFF" Width="7.39375" Height="13.0667" Canvas.Left="0" Canvas.Top="0" />
            <Path Fill="Black" Data="F1 M 7.39375,7.85751C 7.35681,8.14526 6.87167,8.30762 5.93833,8.34457C 5.37833,8.36984 4.95542,8.38831 4.66958,8.39999C 4.38375,8.41165 4.20972,8.44861 4.1475,8.51083C 4.08528,8.57303 4.03229,8.77866 3.98854,9.12769C 3.94479,9.47672 3.91028,9.94971 3.885,10.5466C 3.86167,11.2933 3.83493,11.8689 3.80479,12.2733C 3.77465,12.6778 3.74792,12.9422 3.72458,13.0667C 3.62931,12.7672 3.55833,11.9272 3.51167,10.5466C 3.44944,9.27695 3.35611,8.5983 3.23167,8.51083C 3.14417,8.42526 2.55889,8.36304 1.47583,8.32413C 0.530833,8.3125 0.0388891,8.15695 1.48912e-007,7.85751C 0.138056,7.64749 0.272222,7.38986 0.4025,7.08456C 0.532778,6.7793 0.6475,6.4147 0.746667,5.99081C 0.972222,5.11972 1.085,4.42944 1.085,3.92001C 1.085,2.86221 0.878889,2.07178 0.466667,1.54874C 0.455,1.51181 0.424375,1.46851 0.374792,1.41895C 0.325208,1.36935 0.272222,1.31979 0.215833,1.27017C 0.159445,1.22061 0.109375,1.17053 0.0656253,1.12C 0.0218752,1.06943 1.48912e-007,1.01303 1.48912e-007,0.950806C 1.48912e-007,0.678589 0.548333,0.442352 1.645,0.242065C 2.06694,0.154572 2.44903,0.0923157 2.79125,0.0554199C 3.13347,0.0184631 3.43292,0 3.68958,0C 4.29236,0 4.97972,0.0748291 5.75167,0.224579C 6.84639,0.448151 7.39375,0.690277 7.39375,0.950806C 7.39375,1.0636 7.32521,1.16956 7.18813,1.26871C 7.05104,1.36792 6.96403,1.46121 6.92708,1.54874C 6.52847,2.09708 6.32917,2.88748 6.32917,3.92001C 6.32917,4.62973 6.42931,5.31998 6.62958,5.99081C 6.84153,6.79971 7.09625,7.42191 7.39375,7.85751 Z " />
          </Canvas>
        </Grid>
      </ControlTemplate>
    </esri:MarkerSymbol.ControlTemplate>
  </esri:MarkerSymbol>
0 Kudos
DominiqueBroux
Esri Frequent Contributor

I am hoping there is a property that I can bind the size attribute or some size number(length or width) attribute which will be received from user interaction


You can bind the scaletransform to the size of your symbol:
             <ScaleTransform ScaleX="{Binding Attributes[Size]}" ScaleY="{Binding Attributes[Size]}" />

Note : you may have to normalize the initial symbol in order to define what a symbol of size 1 is.
0 Kudos