Select to view content in your preferred language

Slide between layers

4611
11
03-04-2011 12:26 PM
JayKappy
Frequent Contributor
Looking for an example of a slide bar that moves from one layer to another...increases and decreases the transparency from one to the other....

Say from Streets to Aerials.....

THanks
0 Kudos
11 Replies
JayKappy
Frequent Contributor
I am a bit confused because I have a single one working on each layer in my layerlist....
I have a mixture of dynamic layers, graphic layers, wms layers etc....
I have two base layers (streets and Aerials)
I dotn want to put the streets and aerials layer list....I want to put them in the header with a slide bar that allows teh user to slide between the two increase and decreasing the opacity....
So At one side layer one will be seen...at the other end the other layer will be seen...in the middle they both will be seen....

Do I create another <esri:map and define the two layers that will be effected with the slider?
I cant see this as a solution because then I have another map that would have to be over the other one....

DO I have to change the Maximum on the Slider?
How do I point to 2 specific services, while continuing to draw the other layers and graphics...create another map service?

Anything to help me clarify this woudl be appreciated....
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Do I create another <esri:map and define the two layers that will be effected with the slider?

You can just add your 2 layers to the map and when the slider value changed (from 0.0 to 1.0), initialize the opacity of your first layer with the slider value and the opacity of your second layer with 1-value.
0 Kudos
JayKappy
Frequent Contributor
You can just add your 2 layers to the map and when the slider value changed (from 0.0 to 1.0), initialize the opacity of your first layer with the slider value and the opacity of your second layer with 1-value.


So I keep the original map and then create another one? 

Or are you saying add to the same map...
THen in VB I change the opacity based on the slider value?

I can effect one layer like this....but looking to move between 2...and return the value of the Slider....I guess now I just need to grab that value and change the opacity on the two layers?????

But again in my example below I am pointing to a specific layer....I assume that I need to just point the MyMap .... and then in VB code change the opacity of the 2 layers????

Thanks

                <Slider x:Name="MySlider"
                VerticalAlignment="Top" 
                Minimum="0"
                Maximum="1"
                        Margin="0,40,0,0" MouseLeftButtonUp="GiveMeValue" 
               Value="{Binding ElementName=MyMap, Path=Layers[BaseLayerImage].Opacity, Mode=TwoWay}" />


    Private Sub GiveMeValue(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
        Dim Test As String = MySlider.Value
        MessageBox.Show(Test)
    End Sub
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Or are you saying add to the same map...

Yes, you don't need a second map to do that.

THen in VB I change the opacity based on the slider value?

Yes, easier by code (on event ValueChanged), else you would need a converter returning 1-value.
0 Kudos
JayKappy
Frequent Contributor
I did this and its workign....I can change to ValueChanged....just used MouseLeftButtonUp for testing....

1. Why do I need this?  Path=Layers[BaseLayerImage].Opacity, mean its specifying a specific layer?

2. ONE LAST question....how would i do this with 3 layers?


                <Slider x:Name="MySlider"
                VerticalAlignment="Top" 
                Minimum="0"
                Maximum="1"
                        Margin="0,40,0,0" MouseLeftButtonUp="MultiLayerOpacity" 
               Value="{Binding ElementName=MyMap, Path=Layers[BaseLayerImage].Opacity, Mode=TwoWay}" />


    Private Sub MultiLayerOpacity(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
        Dim Test As String = MySlider.Value
        'MessageBox.Show(Test)

        Dim DynamicLayer1 As ArcGISDynamicMapServiceLayer = TryCast(MyMap.Layers("StreetMapLayer"), ArcGISDynamicMapServiceLayer)
        DynamicLayer1.Opacity = Test

        Dim DynamicLayer2 As ArcGISDynamicMapServiceLayer = TryCast(MyMap.Layers("BaseLayerImage"), ArcGISDynamicMapServiceLayer)
        DynamicLayer2.Opacity = 1 - Test

    End Sub
0 Kudos
DominiqueBroux
Esri Frequent Contributor
1. Why do I need this? Path=Layers[BaseLayerImage].Opacity, mean its specifying a specific layer?

Since it's now done by code, you don't need to do it in xaml as well.

 
2. ONE LAST question....how would i do this with 3 layers?

It's depending on the logic you need (how one slider can manage 3 layers).
We can imagine to extent the maximum value to 2.0 and manage a smooth transition between layer1 and layer2 when the slider is between 0 and 1, and a smooth transition between layers 2 and 3 when the slider is between 1 and 2. There is no specific difficulties to do that by code.
0 Kudos
JayKappy
Frequent Contributor
..........................................................................
0 Kudos
JayKappy
Frequent Contributor
Yea I dont think this is workign right....I am going between StreetLayer and Aerials. I turn off Aerials and slide this slider and the StreetLayer does not change....I think its because I still have that line in the xaml file
If I remove the line in Red below it does not work. with it in there it only effects the opacity of which ever layer is specified.....what is wrong and why cant I remove it?


One last thing...in VB when I use the "MouseLeftButtonUp" I set these parameters....What parameters do I use if I am using a "ValueChanged"
MouseButtonEventArgs has to be changed to WHAT?

Private Sub MultiLayerOpacity(ByVal sender As Object, ByVal e As MouseButtonEventArgs)

Is my VB code completly wrong?
I cant even turn off the layer from within my VB....

Dim DynamicLayer2 As ArcGISDynamicMapServiceLayer = TryCast(Me.MyMap.Layers("Aerials"), ArcGISDynamicMapServiceLayer)
DynamicLayer2.Visible = False


                <Slider x:Name="MySlider" 
                        VerticalAlignment="Center" Minimum="0" Maximum="1" Width="50"
                        Margin="0,0,0,0" MouseLeftButtonUp="MultiLayerOpacity" 
                        Value="{Binding ElementName=MyMap, Path=Layers[Aerials].Opacity, Mode=TwoWay}" />

    Private Sub MultiLayerOpacity(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
        Dim Test As String = MySlider.Value

        Dim DynamicLayer1 As ArcGISDynamicMapServiceLayer = TryCast(MyMap.Layers("StreetMapLayer"), ArcGISDynamicMapServiceLayer)
        DynamicLayer1.Opacity = 1 - Test

        Dim DynamicLayer2 As ArcGISDynamicMapServiceLayer = TryCast(MyMap.Layers("Aerials"), ArcGISDynamicMapServiceLayer)
        DynamicLayer2.Opacity = Test

    End Sub


If I do this I get the messagebox value
    Private Sub MultiLayerOpacity(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
        Dim Test As String = MySlider.Value

        If Test > 0 Then
            MessageBox.Show("Yo")
            Dim DynamicLayer2 As ArcGISDynamicMapServiceLayer = TryCast(MyMap.Layers("Aerials"), ArcGISDynamicMapServiceLayer)
            DynamicLayer2.Opacity = Test
        End If
    End Sub


If I do this I dont....so somethign has to be wrong with the syntax or setting of the opacity
    Private Sub MultiLayerOpacity(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
        Dim Test As String = MySlider.Value

        If Test > 0 Then
            Dim DynamicLayer2 As ArcGISDynamicMapServiceLayer = TryCast(MyMap.Layers("Aerials"), ArcGISDynamicMapServiceLayer)
            DynamicLayer2.Opacity = Test
            MessageBox.Show("Yo")
        End If

    End Sub
0 Kudos
JayKappy
Frequent Contributor
I can get this to work with my map service...but tryign to use ESRIs and it wont work.....
Is it somethign to do with the ArcGISTiledMapServiceLayer??????????


These wont work for some reason....
<esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer" Visible="True"
          Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />

And

<esri:ArcGISTiledMapServiceLayer ID="Aerials" Visible="True"  
          Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer" />
0 Kudos