// SWEREF 99 TM with map's pixel origin at (218128.7031, 6126002.9379)
var crs = new L.Proj.CRS('EPSG:3006',
'+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs',
{
origin: [218128.7031, 6126002.9379],
resolutions: [8192, 4096, 2048] // 3 example zoom level resolutions
}
);
var map = L.map('map', {
crs: crs,
continuousWorld: true
});
// define rectangle geographical bounds
var bounds = XXX;
// create an orange rectangle
L.rectangle(bounds, {color: "#ff7800", weight: 1}).addTo(map);
// zoom the map to the rectangle bounds
map.fitBounds(bounds);
How do I define the rectangle geographical bounds (XXX in the code above)? If I defined the bound in SWEREF, it doesn't work. If I unproject them using the crs, I get a lon/lat rotated/transformed vector on a SWEREF map... :-P
You need to unproject all four corners of the rectangle, not only the min/max coordinates of the bounds. This also means you need to add a L.Polygon instead of L.Rectangle.
// SWEREF 99 TM with map's pixel origin at (218128.7031, 6126002.9379) var crs = new L.Proj.CRS('EPSG:3006', '+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs', { origin: [218128.7031, 6126002.9379], resolutions: [8192, 4096, 2048] // 3 example zoom level resolutions } );
var map = L.map('map', { crs: crs, continuousWorld: true });
// define rectangle geographical bounds var bounds = XXX; // create an orange rectangle L.rectangle(bounds, {color: "#ff7800", weight: 1}).addTo(map); // zoom the map to the rectangle bounds map.fitBounds(bounds);
How do I define the rectangle geographical bounds (XXX in the code above)? If I defined the bound in SWEREF, it doesn't work. If I unproject them using the crs, I get a lon/lat rotated/transformed vector on a SWEREF map... :-P
Thanks!