21 Replies Latest reply on Mar 13, 2012 10:10 AM by geonetadmin

    Constrain InfoWindow to window size

    andrewb
      Is there a way to constrain the InfoWindow, when visible, to the size of the browser window?  If a user clicks a point that is close to the top of the browser window, the InfoWindow expands past the top of the page.
      [ATTACH=CONFIG]12103[/ATTACH]

      Ideally I'd like to shift the map south so that the entire InfoWindow displays.
      [ATTACH=CONFIG]12104[/ATTACH]

      Any ideas?
        • Re: Constrain InfoWindow to window size
          geonetadmin
          Original User: jenniferdnery

          This is the current behavior of InfoWindow, it does not pan the map or open from bottom to fit the application. If you wish to change this, you can download source from: http://esrisilverlight.codeplex.com/

          You can also probably change the size of element inside DataTemplate or use ScrollViewer.
          • Re: Constrain InfoWindow to window size
            andrewb
            What I ended up doing is building an envelope that compensated for the width & height of the infoWindow.  If the anchor point of the infowindow fell outside the envelope then the map would pan to center the anchor on the page.  If the anchor point of the infoWindow fell inside the envelope, then the map does not pan since the infoWindow will completely show.  Every time the extent of the map changes, the envelope refreshes.  Seems to work perfectly.
            • Re: Constrain InfoWindow to window size
              geonetadmin
              Original User: brunno14

              Is there a way to constrain the InfoWindow, when visible, to the size of the browser window?  If a user clicks a point that is close to the top of the browser window, the InfoWindow expands past the top of the page.
              [ATTACH=CONFIG]12103[/ATTACH]

              Ideally I'd like to shift the map south so that the entire InfoWindow displays.
              [ATTACH=CONFIG]12104[/ATTACH]

              Any ideas?


              Hi..

              Could you please post the code showing how you did this InfoWindow?

              I'm having some problems to implement this control...

              Thanks.
              • Re: Constrain InfoWindow to window size
                andrewb
                Hi..

                Could you please post the code showing how you did this InfoWindow?

                I'm having some problems to implement this control...

                Thanks.


                Are you having problems implementing a simple infoWindow?  If so, then check this out:http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#InfoWindowSimple

                • Re: Constrain InfoWindow to window size
                  geonetadmin
                  Original User: brunno14

                  Are you having problems implementing a simple infoWindow?  If so, then check this out:http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#InfoWindowSimple



                  I saw this sample, the problem is that I'm trying to implement the InfoWindow in a User Control, in a different page than the MapPage.

                  Here's a piece of code of my User Control:

                      <Grid x:Name="LayoutRoot" Background="White">
                          <Grid.Resources>
                  
                              <DataTemplate x:Name="MyFeatureLayerInfoWindowTemplate">
                                  <StackPanel Orientation="Horizontal">
                                      <TextBlock Text="TEST" Foreground="Black" FontSize="12" />
                                  </StackPanel>
                              </DataTemplate>           
                  
                          </Grid.Resources>
                          <esri:InfoWindow x:Name="MyInfoWindow"
                                           Padding="2"
                                           CornerRadius="20" 
                                           Background="LightSalmon"
                                           ContentTemplate="{StaticResource MyFeatureLayerInfoWindowTemplate}" />
                     
                      </Grid>
                  


                  And in the click event of the graphic, that should show the InfoWindow, I put the following code:

                          void graphic_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
                          {
                              Graphic gra = sender as Graphic;
                              MyInfoWindow MyInfo = new MyInfoWindow();
                              MyInfo.MyInfoWindow.Content = gra.Attributes;
                              MyInfo.MyInfoWindow.Anchor = gra.Geometry as MapPoint;
                  
                              MyInfo.MyInfoWindow.Map = CurrentPage.myMap;
                              MyInfo.MyInfoWindow.IsOpen = true;
                          }
                  


                  I put a breakpoint inside the click event, and when I click in the graphic, it hits the breakpoint, but no InfoWindow appears...

                  Am I missing something?

                  Thanks.
                  • Re: Constrain InfoWindow to window size
                    andrewb
                    Is the geometry of your graphic a point (MapPoint)?  Make sure you are returning map coords.  Also, not sure if this could be a problem, but you aren't specifying the ContentTemplate of your infoWindow... 
                    You need:  MyInfoWindow.ContentTemplate = TryCast(LayoutRoot.Resources("InfoWindowTemplate"),system.windows.datatemplate)
                    (sorry, I am a VB.NET guy :p)
                    • Re: Constrain InfoWindow to window size
                      geonetadmin
                      Original User: brunno14

                      While debugging I can see the values, and it shows the following:

                      Point[X=-46.6344223022461, Y=-23.5520210266113, WKID=4326]

                      The values are right, so this wouldn't be a problem, right?

                      And I'm specifying the ContentTemplate of my InfoWindow in the XAML code:

                      <esri:InfoWindow x:Name="MyInfoWindow"
                                               Padding="2"
                                               CornerRadius="20"
                                               Background="LightSalmon"
                                               ContentTemplate="{StaticResource MyFeatureLayerInfoWindowTemplate}" />


                      Do I need to specify it again in my code?

                      I'm new to this stuff, sorry for the inconvenience :p
                      • Re: Constrain InfoWindow to window size
                        andrewb
                        I have the ContentTemplate defined in my codebehind and my XAML.  I don't know if it's necessary, but that's what I have.

                        Couple more things to try:
                        1. Is  the infoWindow opening BEHIND the map?  check the zIndex
                        2.  Is your map contained inside a Grid with multiple rows/columns?  I had a lot of problems with opening an InfoWindow when the map was inside a specific grid cell.(http://forums.arcgis.com/threads/23081-How-do-I-control-the-Infowindow-height?p=100995)
                        • Re: Constrain InfoWindow to window size
                          geonetadmin
                          Original User: brunno14

                          Ok. I've set the ContentTemplate in code-behind. No changes.

                          1- I don't think my InfoWindow is opening behind the map. There's no zIndex set in myMap and looks like there's no zIndex property in the InfoWindow aswell.

                          2- Yes, my map is contained inside a Grid. I saw the thread you refer, but in my case the infowindow doesnt even appear, while in the other cases the infowindow is appearing in the wrong position...

                          Thanks for trying to help me.
                          • Re: Constrain InfoWindow to window size
                            andrewb
                            Ok. I've set the ContentTemplate in code-behind. No changes.

                            1- I don't think my InfoWindow is opening behind the map. There's no zIndex set in myMap and looks like there's no zIndex property in the InfoWindow aswell.

                            2- Yes, my map is contained inside a Grid. I saw the thread you refer, but in my case the infowindow doesnt even appear, while in the other cases the infowindow is appearing in the wrong position...

                            Thanks for trying to help me.


                            Try setting a breakpoint in your MouseDown event and see if myinfowindow.isopen returns true.  If it is true, then check the anchorpoint property and see if it falls within the extnent of your map.
                            • Re: Constrain InfoWindow to window size
                              geonetadmin
                              Original User: brunno14

                              Try setting a breakpoint in your MouseDown event and see if myinfowindow.isopen returns true.  If it is true, then check the anchorpoint property and see if it falls within the extnent of your map.


                              OK.

                              The IsOpen property returns true.

                              Under the Anchor property, theres an Extent property with the following values:

                              XMax  -46.6654243469238
                              XMin   -46.6654243469238

                              YMax -23.5543193817139
                              YMin  -23.5543193817139

                              And the height and width properties are 0.0, is it normal?

                              In the Extent property of myMap, there are the following values:

                              XMax -5188689.952898005
                              XMin  -5195560.7625789493

                              YMax -2697750.5551072815
                              YMin  -2701171.6058885315

                              Height  3421.05078125
                              Width  6870.8096809443086

                              Is there anything wrong?

                              Thanks
                              • Re: Constrain InfoWindow to window size
                                andrewb
                                OK.

                                The IsOpen property returns true.

                                Under the Anchor property, theres an Extent property with the following values:

                                XMax  -46.6654243469238
                                XMin   -46.6654243469238

                                YMax -23.5543193817139
                                YMin  -23.5543193817139

                                And the height and width properties are 0.0, is it normal?

                                In the Extent property of myMap, there are the following values:

                                XMax -5188689.952898005
                                XMin  -5195560.7625789493

                                YMax -2697750.5551072815
                                YMin  -2701171.6058885315

                                Height  3421.05078125
                                Width  6870.8096809443086

                                Is there anything wrong?

                                Thanks


                                Based on your anchor point, it looks like you are somewhere in Brazil?  But.... Is your map in a different spatial reference?  The coords between the infowindow and the map extent don't seem to line up.  The infowindow is opening, but somewhere else in the world!  Make sure your map spatial ref is in [LEFT] WKID=4326[/LEFT]
                                • Re: Constrain InfoWindow to window size
                                  geonetadmin
                                  Original User: brunno14

                                  Based on your anchor point, it looks like you are somewhere in Brazil?  But.... Is your map in a different spatial reference?  The coords between the infowindow and the map extent don't seem to line up.  The infowindow is opening, but somewhere else in the world!  Make sure your map spatial ref is in [LEFT] WKID=4326[/LEFT]


                                  This seems to be the problem.

                                  I want to show the InfoWindow when user clicks in a graphic, that is an image... This graphic has a spatial reference different than the map...

                                                              Graphic graphic = new Graphic();
                                                              graphic.Geometry = new MapPoint(X, Y, new SpatialReference(4326));
                                                              graphic.Symbol = myImage;
                                  


                                  the spatial ref of myMap is 102100...

                                  If I change the graphic's spatial ref to 102100, it appears in the middle of the ocean, but if I set to 4326 it appears in the right place...

                                  What should I do?
                                  • Re: Constrain InfoWindow to window size
                                    andrewb
                                    What is the source of your point-graphic data?  If it's a feature class (shapefile, GeoDB, etc.) You can either project the source data from 4326 to 102100 or you can define 4326 as the spatial reference for your data frame and let ArcGIS project it on the fly.

                                    Alternatively, you can use a GeometryService to project your graphics coords from 4326 to 102100 right in ArcGIS Server.  See:  http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Project
                                    Use the geometry of your graphic (in 4326) as the input, and use the output(in 102100) as the anchor point of your info window.



                                    • Re: Constrain InfoWindow to window size
                                      geonetadmin
                                      Original User: brunno14

                                      What is the source of your point-graphic data?  If it's a feature class (shapefile, GeoDB, etc.) You can either project the source data from 4326 to 102100 or you can define 4326 as the spatial reference for your data frame and let ArcGIS project it on the fly.

                                      Alternatively, you can use a GeometryService to project your graphics coords from 4326 to 102100 right in ArcGIS Server.  See:  http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Project
                                      Use the geometry of your graphic (in 4326) as the input, and use the output(in 102100) as the anchor point of your info window.





                                      I'm using a GeometryService now and my graphics coords are in 102100, just like myMap...

                                      But no changes :/

                                      My InfoWindow doesnt show up...

                                      I dont know what I'm doing wrong :/
                                      • Re: Constrain InfoWindow to window size
                                        andrewb
                                        I was just looking back at some of the previous posts and I see you said you are trying to implement the infoWindow inside a userControl which is not the same page as your map.  Have you tried to use it inside the same page as your map?  Maybe see if you can get it to work in there.  If you can, then maybe that'll give you some hints.  I've never tried to implement the infoWindow on a page that's not the same as my map.  I'm not sure why you would want to.
                                        • Re: Constrain InfoWindow to window size
                                          geonetadmin
                                          Original User: brunno14

                                          I was just looking back at some of the previous posts and I see you said you are trying to implement the infoWindow inside a userControl which is not the same page as your map.  Have you tried to use it inside the same page as your map?  Maybe see if you can get it to work in there.  If you can, then maybe that'll give you some hints.  I've never tried to implement the infoWindow on a page that's not the same as my map.  I'm not sure why you would want to.


                                          Let me explain why I need to implement the InfoWindow inside an UserControl....

                                          In my project, I have the MainPage, which contains the map and a toolbar... At this moment, theres no graphics on my map, just the map...

                                          When I click in an option in my toolbar, it shows a "pop up" with some options that I have to choose... The pop up is in a different page (another .xaml) than the map...

                                          In this pop up, there's a button, and when I click on it, it creates a GraphicsLayer, adds the new GraphicsLayer in the Layers property of my Map, create the graphics and add those graphics to the GraphicsLayer...

                                          This works fine...

                                          The problem is that I need to display an InfoWindow when user clicks in any of those graphics...

                                          Is there another way to do this?
                                          • Re: Constrain InfoWindow to window size
                                            andrewb
                                            You don't need to implement the infowindow inside your usercontrol, you can do it right on the same page as the map (the MainPage). 

                                            Is your graphicslayer defined in your XAML or is it done via codebehind?
                                            • Re: Constrain InfoWindow to window size
                                              geonetadmin
                                              Original User: brunno14

                                              You don't need to implement the infowindow inside your usercontrol, you can do it right on the same page as the map (the MainPage). 

                                              Is your graphicslayer defined in your XAML or is it done via codebehind?


                                              via code-behind....
                                              • Re: Constrain InfoWindow to window size
                                                andrewb
                                                For ha-ha's, try changing from the MouseDown event to the MouseUp event.
                                                • Re: Constrain InfoWindow to window size
                                                  geonetadmin
                                                  Original User: brunno14

                                                  No changes....

                                                  I will try to move the InfoWindow to the map page and see if I can get this working...

                                                  thanks for your help :D