zoomToMarkers - PdMarker JavaScript Library

Oct 22, 2008 at 4:28 AM
Hello, before using GoogleMap control, I'm acessing Google Maps only by JavaScript functions.
I'm used the PdMarker JavaScript library (http://www.pixeldevelopment.com/pdmarker.asp)
to easily develop the integration with Google Maps.

The library has some interesting functions like zoomToMarkers
that adjusts the zoom to show all markers in the map.
I made some changes in the function to work with
.Net control, but a error occur after execute function.
I'm using Firefox with Web Developer extension
to easily view JavaScript errors.

The changed function is showed below. When I
call this function in a javascript onclick event in a button,
the error "a is undefined Source-file: http://maps.google.com/intl/pt-BR_ALL/mapfiles/133d/maps2.api/main.js"
happens. The line show a error in google maps code.

Does someone already used this javascript library?
If someone need this feature and can help to solve
this problem, or if has any other solution, I appreciate.

function zoomToMarkers(slopPercentage, heightOffsetPct) {
    var map = <%=GoogleMap1.ClientID %>_Map;
    var count = 0;
    var thePoint, x, y, minX, maxX, minY, maxY, span;
    var marker = map.Markers[0];

    while (marker != null)
    {
            x = marker.Latitude; y = marker.Longitude;
            if (count == 0)
            {
                minX = x;
                maxX = x;
                minY = y;
                maxY = y;
            }
            else
            {
                if (x < minX) minX = x;
                if (x > maxX) maxX = x;
                if (y < minY) minY = y;
                if (y > maxY) maxY = y;
            }
        marker = map.Markers[++count];
    }
    if (count == 1)
        map.setCenter(new GLatLng(x,y), map.getZoom());
    else if (count > 1)
    {
        var center = new GLatLng((minX + maxX) / 2, (minY + maxY) / 2)
        span = new GSize(Math.abs(maxX - minX), Math.abs(maxY - minY));
        slopWid = 0;
        slopHgt = 0;
        if (typeof slopPercentage != "undefined")
        {
            slopWid = span.width * slopPercentage / 200;
            slopHgt = span.height * slopPercentage / 200;
            span.width  *= 1 + slopPercentage / 100;
            span.height *= 1 + slopPercentage / 100;
        }
        deltaHgt = 0;
        if (typeof heightOffsetPct != "undefined")
        {
            deltaHgt = span.height * heightOffsetPct / 100;
            center = new GLatLng(center.lat() + deltaHgt, center.lng());
        }
        // needs slop
        var bounds = new GLatLngBounds(new GLatLng(minX-slopHgt, minY-slopWid), new GLatLng(maxX+slopHgt, maxY+slopWid)); // sw, ne
        var zoom = map.getBoundsZoomLevel(bounds);
        map.setCenter(center, zoom);
    }
}

the sample function below works ok

function addMarker() {
    var map = <%=GoogleMap1.ClientID %>_Map;
    map.setCenter(new GLatLng(-21.816408,-42.203217), map.getZoom());
    map.addMarker({Latitude: -21.816408, Longitude: -42.203217});
    window.alert(map.Markers[0].Text);
}

Thanks.