sahilrajput.com

Learn Leaflet

My slasher Task: CONTINUE_ON_THIS_THREAD

DOCS: Map > Map Methods

To zoom to a given LatLngBound, I can use:

DOCS: LatLngBounds: Click here

Represents a rectangular geographical area on a map.

var corner1 = L.latLng(40.712, -74.227),
corner2 = L.latLng(40.774, -74.125),
bounds = L.latLngBounds(corner1, corner2);

// A LatLngBound value has coordinates for `top-right` and `bottom-left` points of the bounded rectangular region.
// For e.g,  {_southWest: bottom_left_latLng, _northEast: top_right_latLng }
// { "_southWest": {"lat": 41.050832274225485, "lng": -74.9698495599688}, "_northEast": {"lat": 41.05092210575319, "lng": -74.96973044003121}}


// All Leaflet methods that accept LatLngBounds objects also accept them in a simple Array form (unless noted otherwise), so the bounds example above can be passed like this:
map.fitBounds([
    [40.712, -74.227],
    [40.774, -74.125]
]);

DOCS: Pan

DOCS: LatLng: Click here

Represents a geographical point with a certain latitude and longitude.

var latlng = L.latLng(50.5, 30.5);

// All Leaflet methods that accept LatLng objects also accept them in a simple Array form and simple object form (unless noted otherwise), so these lines are equivalent:
map.panTo([50, 30]);
map.panTo({lng: 30, lat: 50});
map.panTo({lat: 50, lng: 30});
map.panTo(L.latLng(50, 30));

DOCS: Point

Source: Click here

Represents a point with x and y coordinates in pixels.

var point = L.point(200, 300);

// Creates a Point object with the given x and y coordinates. If optional round is set to true, rounds the x and y values.
L.point(<Number> x, <Number> y, <Boolean> round?)

// Expects an array of the form [x, y] instead.
L.point(<Number[]> coords)

// Expects a plain object of the form {x: Number, y: Number} instead.
L.point(<Object> coords)


// All Leaflet methods and options that accept Point objects also accept them in a simple Array form (unless noted otherwise), so these lines are equivalent:
map.panBy([200, 300]);
map.panBy(L.point(200, 300));