Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mapbox fit bounds to country

i just want fit my map to my country. I saw some example from https://www.mapbox.com/mapbox-gl-js/example/fitbounds/ and it's fit to whole Kenya. It's a simple code but i don't know why this function takes two lat and longs. I just google it for what is Keyna lat and long? it's 1.2667° S, 36.8000° E. Why this is different than google's result.

function fit() {
    map.fitBounds([[
        32.958984,
        -5.353521
    ], [
        43.50585,
        5.615985
    ]]);
}

How to fit to my specific area just like this.

like image 363
Neo Teo Avatar asked Dec 17 '15 12:12

Neo Teo


People also ask

How do I use Mapbox boundaries?

To add Mapbox Boundaries to a Mapbox GL JS map, start with the 'add a vector tile source' example and add one of the Boundaries tilesets as a source. The source is added with promoteId to use the mapbox_id property of each feature as the unique identifier in the source.

What is bounds Mapbox?

Represents a rectangular area in pixel coordinates.


2 Answers

If i search for the bounding box of Kenya, i find the following:

http://isithackday.com/geoplanet-explorer/index.php?woeid=23424863

Using those coordinates, it's looks ok:

map.fitBounds([
    [-4.71712, 33.90884], // Northeast
    [4.62933, 41.899059]  // Southwest
]);

Example using Leaflet on Plunker: http://plnkr.co/edit/yRuTxjmQxcoqkVyFbE4q?p=preview

like image 181
iH8 Avatar answered Sep 17 '22 07:09

iH8


.fitBounds takes two latlng arguments, one for the upper-left corner of the mapview and one for the lower-right corner.

If you would like to just center the map on Kenya, you could use:

map.flyTo({center: [Lat, Lng]})
like image 45
phillercode Avatar answered Sep 18 '22 07:09

phillercode