I recently moved from 1.3.6 to 1.4.1 and came across a compile error.  I 
believe I had a local copy of GMap2 (1.3.x) and made modifications to make the 
following work.

Now I would like to propose a change but not sure who I need to talk.  
Specifically, I would like to request to change GOverlay.getJSConstructor() 
from protected to public (and all subsequent derived classes)

I am need to send javascript back to the browser which basically rebounds the a 
GMap2...the following is my code snippet:

<raw>
    private String getJSRebound() {
        StringBuffer buf = new StringBuffer();
        buf.append("var bounds = new GLatLngBounds();\n");
        buf.append("var map = " + map.getJSinvoke("map"));
        buf.append("bounds.extend( map.getCenter() ); \n");

        int idx = 0;

        for (GOverlay overlay : map.getOverlays()) {
            if (overlay instanceof GMarker) {
                GMarker marker = (GMarker) overlay;
                GLatLng point = marker.getLatLng();
                buf.append("bounds.extend( " + point.getJSconstructor()
                        + " );\n");
            }

            if (overlay instanceof GGeoXml) {
                GGeoXml xml = (GGeoXml) overlay;

                String var = "xml" + idx++;
                
                // this is broken with 1.4.1
                // getJSconstructor has been made protected

                buf.append("var " + var + " = " + xml.getJSconstructor()
                        + "; \n");

                buf.append("GEvent.addListener(" + var
                        + ", 'load', function(){ \n");
                buf.append("    bounds.extend( " + var
                        + ".getDefaultBounds().getSouthWest() ); \n");
                buf.append("    bounds.extend( " + var
                        + ".getDefaultBounds().getNorthEast() ); \n");
                buf.append("map.setZoom( map.getBoundsZoomLevel(bounds) );\n");
                buf.append("}); \n");
            }
        }

        if (idx == 0) {
            GLatLng point = new GLatLng(location.getCentralLatitude(), location
                    .getCentralLongitude(), false);
            buf.append("bounds.extend( " + point.getJSconstructor() + " );\n");
            buf
                    .append("map.setZoom( 
Math.min(map.getBoundsZoomLevel(bounds),8) );\n");
        } else {
            buf.append("map.setZoom( map.getBoundsZoomLevel(bounds) );\n");
        }
        buf.append("map.setCenter( bounds.getCenter() );\n");
        return buf.toString();
    }
</raw>

This method is called in my constructor:

<raw>
    map.add(new HeaderContributor(new IHeaderContributor() {
            private static final long serialVersionUID = 1L;

            public void renderHead(IHeaderResponse response) {
                response.renderOnDomReadyJavascript(getJSRebound());
            }
        }));
</raw>


Without the ability to generated the JS object and keep a reference, I don't 
believe I can accomplish what I need to do...rebound the map within the points 
I have stored.  If someone has a better idea, I am all ears.  If not, the 
accessibliity change would greatly be appreciated.

Thanks
- Doug

Reply via email to