This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

[closed] How to get boundary points of different zoom levels through getBounds() method of leaftlet API?

-2

I have written this function to find the corner points according to the 3 different zoom levels.
The problem is that for all the 3 zoom levels, the corner points that I get are "same"!!


    function findCorners ()
    {
        var zoomLevel;
        for (zoomLevel = 7; zoomLevel < 10; zoomLevel++)
        {
            map.setView (centerPoint, zoomLevel);

            var corners        = map.getBounds ();

            // Extracting boundary points
            var northEast      = corners.getNorthEast ();
            var southWest      = corners.getSouthWest ();
            var topLeft        = new L.LatLng (southWest.lat, northEast.lng, true);
            var bottomRight    = new L.LatLng (northEast.lat, southWest.lng, true);

            // For boundary line equation
            var topLeftLng     = toFixedd (topLeft.lng);
            var topLeftLat     = toFixedd (topLeft.lat);
            var bottomRightLng = toFixedd (bottomRight.lng);
            var bottomRightLat = toFixedd (bottomRight.lat);

            var stringCat       = "";
            stringCat           = stringCat.concat (toFixedd (centerPoint.lng) + "," + toFixedd (centerPoint.lat) + "," + zoomLevel + "," + topLeftLng + ",", topLeftLat + ",", + bottomRightLng + "," + bottomRightLat + ",");

            // For map downloading.
            // Attach the northEast and southWest corners too to the above formed string. 
            var bottomLeftLng = toFixedd (southWest.lng);
            var bottomLeftLat = toFixedd (southWest.lat);
            var topRightLng   = toFixedd (northEast.lng);
            var topRightLat   = toFixedd (northEast.lat);

            stringCat         = stringCat.concat (bottomLeftLng + "," + bottomLeftLat + "," + topRightLng + "," + topRightLat);

            arrayCorners.push (stringCat);
        }
        map.setView (centerPoint, 13);
    }

The function for selecting center point is here:

        var map;
        var centerPoint;
        var arrayCenterPoints = new Array ();
        var arrayFileNames    = new Array ();
        var arrayCorners      = new Array ();
        var arrayList         = new Array ();

        function displayMapAndClick ()
        {
            map = L.map ('map', 
                    {
                        dragging: true,
                        scrollWheelZoom: true
                    }).setView ([51.505, -0.09], 13, true);

            L.tileLayer('http://{s}.tile.cloudmade.com/24c8d683cff74bffa7f00e59cd858e00/997/256/{z}/{x}/{y}.png', 
                {
                    attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>',
                    maxZoom: 13,
                }).addTo (map);

            selectCenterPoint ();
        }

        function selectCenterPoint ()
        {
            var popup = L.popup();

            function onMapClick (e) 
            {
                popup
                    .setLatLng  (e.latlng)
                    .setContent ("You clicked the map at: " + e.latlng.toString())
                    .openOn      (map);

                    map.panTo (e.latlng);
                    L.marker (e.latlng).addTo (map).bindPopup ("<b>Center point: </b>" + "<br>" + e.latlng + "<br />").openPopup ();
                    centerPoint = e.latlng; 
            }
            map.on ('click', onMapClick);
        }

       function toFixedd (value) 
       {
        var power         = Math.pow (10, 4 || 0);
        var returnValue = String (Math.round (value * power) / power);
        return returnValue;
       }

Am I on the right track?

asked 11 Oct '12, 11:47

Anisha%20Kaul's gravatar image

Anisha Kaul
293410
accept rate: 0%

closed 11 Oct '12, 23:29

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
82.5k927201273

Reason of the downvote? Not a mind reader am I. @someoneelse

(11 Oct '12, 12:28) Anisha Kaul

@Frederik Is this off-topic too?

(11 Oct '12, 12:53) Anisha Kaul

Source code available on GitHub .