Anonymous user  |  Log in  |  Create Account


Bounds and zoom range
Return to the code gallery
Autor: subgurim
Publicado: 10/5/2009
Leído: 58863 veces
Comentarios (0)
Valoracion: 3.748637


/**** Explicación / Description  ****/
Using this code you can delimite teh bounds an the zoom range you want for your map.


/**** Código de servidor / Server code  ****/
        if (!IsPostBack)
        {
            int minResolution = 7;
            int maxResolution = 11;

            GMap1.addCustomInsideJavascript(string.Format("limitZoomRange({0}, {1}, {2});", GMap1.GMap_Id, minResolution, maxResolution));

            GLatLngBounds allowedBounds = new GLatLngBounds(new GLatLng(38, -3), new GLatLng(40, 0));
            GMap1.addListener(GListener.Event.move,
                              string.Format("function() {{limitBoundsRange({0}, {1});}}", GMap1.GMap_Id, allowedBounds));


            GMap1.setCenter(allowedBounds.getCenter(), minResolution);
            GMap1.addGMapUI(new GMapUI());
        }


/**** Código HTML / HTML Code  ****/
            <cc1:GMap ID="GMap1" runat="server" />



/**** Código Javascript / Javascript Code  ****/
        <script type="text/javascript">

        function limitZoomRange(map, minResolution, maxResolution) {
            var mt = map.getMapTypes();

            for (var i = 0; i < mt.length; i++) {
                mt[i].getMinimumResolution = function() { return minResolution; }
                mt[i].getMaximumResolution = function() { return maxResolution; }
            }
        }

        function limitBoundsRange(map, allowedBounds) {

            if (allowedBounds.contains(map.getCenter())) {
                return;
            }
            var C = map.getCenter();
            var X = C.lng();
            var Y = C.lat();

            var AmaxX = allowedBounds.getNorthEast().lng();
            var AmaxY = allowedBounds.getNorthEast().lat();
            var AminX = allowedBounds.getSouthWest().lng();
            var AminY = allowedBounds.getSouthWest().lat();

            if (X < AminX) { X = AminX; }
            if (X > AmaxX) { X = AmaxX; }
            if (Y < AminY) { Y = AminY; }
            if (Y > AmaxY) { Y = AmaxY; }
            map.setCenter(new GLatLng(Y, X));
        }
   
    </script>



Powered by Subgurim.NET