Select to view content in your preferred language

set opacity of polygons independant of each other

3518
4
01-26-2012 11:42 AM
Labels (1)
SteveSouthwick
Occasional Contributor
Hello,

Hopefully one last question. I've got my kml file to load, and I can set the color based on an attibute, but here's my problem...When my KML file is loaded, all of the polygons are filled white.  I can lessen it by setting the whole kml layer opacity to .5, but once the color is applied, the remaning countries are filled with white.  A workaround I came up with is:


        Dim theKmlLayer As ESRI.ArcGIS.Client.Toolkit.DataSources.KmlLayer = CType(Map1.Layers("MyGraphicsLayer"), KmlLayer)

        Dim fillsymbolcolor As New SimpleFillSymbol
        Dim fillsymbolclear As New SimpleFillSymbol
        fillsymbolcolor.Fill = New SolidColorBrush(Color.FromRgb(255, 0, 0))
        fillsymbolclear.Fill = New SolidColorBrush(Color.FromArgb(0, 0, 0, 0))


            theKmlLayer.Opacity = 0.5

            For Each kl As GraphicsLayer In theKmlLayer
                For Each g As Graphic In kl.Graphics
                    If CStr(g.Attributes("name")) = "United States" Then
                        g.Symbol = fillsymbolcolor
                    Else
                    g.Symbol = fillsymbolclear
                    End If
                Next
            Next


but surely there's a way to have the kml file itself come in w/ clear polygons.  If anyone is interested, my kml file is attached.  Ideally, I'd like to KML file to load w/ the polygons not being filled rather than having to loop through every one and apply a clear fill to it. 

Thanks in advance!
0 Kudos
4 Replies
JenniferNery
Esri Regular Contributor
I'm not sure how you want to select your graphic, for simplicity, I've selected just the first graphic from this SDK sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#KmlLayerSimple
Dim l = TryCast(MyMap.Layers("KmlLayer"), KmlLayer)
Dim g = l.Graphics.FirstOrDefault()
Dim s = TryCast(g.Symbol, SimpleFillSymbol)
s.Fill.Opacity -= 0.3
0 Kudos
SteveSouthwick
Occasional Contributor
Thanks for the nudge Jennifer, I'll give it a whirl today and post back if I have any questions.
0 Kudos
SteveSouthwick
Occasional Contributor
Hello Jennifer,

The code you posted doesn't seem to do anything (at least it doesn't in the way I implemented it):

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click

        Dim theKmlLayer As ESRI.ArcGIS.Client.Toolkit.DataSources.KmlLayer = CType(Map1.Layers("MyGraphicsLayer"), KmlLayer)

        Dim fillsymbolcolor As New SimpleFillSymbol
        fillsymbolcolor.Fill = New SolidColorBrush(Color.FromRgb(255, 0, 0))

            For Each kl As GraphicsLayer In theKmlLayer
                For Each g As Graphic In kl.Graphics
                    If CStr(g.Attributes("name")) = "United States" Then
                         g.Symbol = fillsymbolcolor
                    End If
                Next
            Next
        Dim l = TryCast(Map1.Layers("MyGraphicsLayer"), KmlLayer)
        Dim f = l.Graphics.FirstOrDefault
        Dim s = TryCast(f.Symbol, SimpleFillSymbol)
        s.Fill.Opacity = 0.3
    End Sub


and my xmal:
<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" xmlns:esri="http://schemas.esri.com/arcgis/client/2009">
    <Grid>
        <esri:Map Background="White"  Name="Map1" WrapAround="True">
            <esri:Map.Layers>
                <esri:LayerCollection>
                    <esri:ArcGISTiledMapServiceLayer Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
                    <esri:KmlLayer ID="MyGraphicsLayer" Url="C:\junk\SiteMap5.Kml" VisibleLayers="Polygons"/>                  
                </esri:LayerCollection>
            </esri:Map.Layers>
        </esri:Map>
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="12,145,0,0" Name="Button1" VerticalAlignment="Top" Width="75" />
    </Grid>
</Window>


The shapes still have a solid white or red fill (depending on if the shapename is "United States" or not).  Do all imported kml files have a default fill of white?

Any other thoughts or feedback is greatly appreciated.

Thanks!
0 Kudos
SteveSouthwick
Occasional Contributor
ok.  Sorry to clog up the forums.  Seems the problem was with my kml and esri not liking how I defined my style(s):

<name>Countries</name>
<Style id="Clear">
   <LineStyle>
      <color>00ffffff</color>
      <width>2</width>
   </LineStyle>
   <PolyStyle>
      <color>00ffffff</color>
      <colorMode>random</colorMode>
   </PolyStyle>
</Style>
<Placemark>
<name>Canada</name>
<styleUrl>
   #Clear
</styleUrl>
<MultiGeometry>
   .
   .
   .
</MultiGeometry>


Returns a white-filled polygon.  This on the otherhand:

<name>Countries</name>
<Placemark>
<name>Canada</name>
<Style>
   <PolyStyle>
      <color>00ffffff</color>
   </PolyStyle>
   <LineStyle>
      <color>00ffffff</color>
      <width>1</width>
   </LineStyle>
</Style>
<MultiGeometry>
   .
   .
   .
</MultiGeometry>


Returns a clear polygon, which is what I was looking for.  Looks like I've got some reformatting to do....
0 Kudos