7 Replies Latest reply on Mar 10, 2011 9:00 AM by Vishwanath Bannur

    Problem with gmap zoom

    Marcelo Leiras Newbie

      Hi,

      i'm using gmap in my apliccation, but i'm having a problem with the zoom.
      Look at a piece of my code:

      <rich:gmap zoom="#{myBean.zoomMapa}" binding="#{myBean.mapaRastreamento}" oninit="loadPoints()"/>
      


      Wen i change the zoom of the map on the page, the new value of zoom is not passed to the attribute "myBean.zoomMapa". Is it possible? How can i do that?
      One solution could be create a javascript function that returns the correct zoom value, like this:

       function getZoom() {
       return map.getZoom();
       }
      


      But i don't know how to call this function from myBean and get the return value.
      Any sugestions?


      Thanks a lot, and sorry about my english.

        • 1. Re: Problem with gmap zoom
          Sergey Smirnov Master

          zoom attribute is read-only. When you change zoom on the client, it does not update the bean on the server.
          If you want to synchronize them, you need to do it explicitly. Use a4j:jsFunction that is called from the gmap callback function. Refer to the gmap manual how to add your callback function on zoom changes

          • 2. Re: Problem with gmap zoom
            Marcelo Leiras Newbie

            Sergey,

            where should be my function that is activated when the zoom changes?
            On the client or on the server side?
            Do you have some example?


            Thank you for your help.

            • 3. Re: Problem with gmap zoom
              Sergey Smirnov Master

              gmap itself is a pure client-side widget. It has no idea about the server side. So, all function are on the client.

              • 4. Re: Problem with gmap zoom
                Marcelo Leiras Newbie

                Please take a look at my current code.

                I added an event to the map that fires wen the zoom changes:

                GEvent.addListener(map, "zoomend", function() {
                 zoomChanged();
                });
                


                And here are my JSFunctions

                 function getCurrentZoom() {
                 return map.getZoom();
                 }
                
                 function zoomChanged() {
                 alert('Zoom Changed : '+getCurrentZoom());
                 }
                


                So, when i change the zoon, apears the message "Zoom Chenged : zoomValue".

                Now i need to pass the zoom value to my bean.
                I tryed to do this:

                 <a4j:jsFunction name="zoomChanged">
                 <a4j:actionparam name="xxx" value="getCurrentZoom()" assignTo="#{myBean.zoomMapa}" />
                 </a4j:jsFunction>
                


                and delete the piece of code

                 function zoomChanged() {
                 alert('Zoom Changed : '+getCurrentZoom());
                 }
                


                but it did not work.
                The value assigned to "myBean.zoomMapa" was the String "getCurrentZoom()", and not the zoon value.
                Any sugestions?



                • 5. Re: Problem with gmap zoom
                  Sergey Smirnov Master

                   

                  <a4j:actionparam name="xxx" noEscape="true" value="getCurrentZoom()" assignTo="#{myBean.zoomMapa}" />


                  • 6. Re: Problem with gmap zoom
                    Marcelo Leiras Newbie

                    I found another solution:

                    GEvent.addListener(map, "zoomend", function() {
                     zoomChanged(map.getZoom());
                     });
                    


                    <a4j:jsFunction name="zoomChanged">
                    <a4j:actionparam name="zc1" assignTo="#{myBean.zoomMapa}" />
                    </a4j:jsFunction>
                    


                    Thank you very much for the help!

                    • 7. Re: Problem with gmap zoom
                      Vishwanath Bannur Newbie

                      Hi Marcelo,

                       

                      May I know where this event 'GEvent.addListener(map, "zoomend", function()' you kept in code?

                      I have kept like this as below and am getting JS error as map is undifined.

                       

                      <a4j:outputPanel>

                                          <script>

                                   

                                          GEvent.addListener(this.map, "zoomend", function() {

                                                     zoomChanged();

                                                    });

                        </script>

                      </a4j:outputPanel>