You can combine both layers' extents and increase a bit the resulting bounding box to make sure all geometries and labels are visible.
In the following code, I i) take first and second layers from the ToC, ii) combine their extents, and iii) scale the resulting bounding box by 10%:
extent = QgsRectangle()
extent.setMinimal()
layers = [ iface.mapCanvas().layers()[0], iface.mapCanvas().layers()[1] ]
for layer in layers:
extent.combineExtentWith( layer.extent() )
extent.scale( 1.1 ) # Increase a bit the extent to make sure all geometries lie inside
iface.mapCanvas().setExtent( extent )
iface.mapCanvas().refresh()
Try something like this
L.control.zoom({
position:'topright'
}).addTo(map);
Sry, for the lack of explanation I ll try to be more comprehensive next time. So, if I understood the question correctly, problem lies in position of zoom in & out control.
On Leaflet doc I've found this [http://leafletjs.com/reference.html#control-options][1]
First, I disabled zoom control when rendering a map (which is topleft by default) Like this:
//disable zoomControl
var map = L.map('map',{zoomControl: false}).setView([40.91, -96.63], 4);
And then I added this block of code
L.control.zoom({
position:'topright'// default is topleft
}).addTo(map);
Here is full block of code that I copied from site above
I just copied script tag
function applyMargins() {
var leftToggler = $(".mini-submenu-left");
if (leftToggler.is(":visible")) {
$("#map .leaflet-control-zoom")
.css("margin-left", 5)
.css("margin-Top", 50)
.removeClass("zoom-top-opened-sidebar")
.addClass("zoom-top-collapsed");
} else {
$("#map .leaflet-control-zoom")
.css("margin-left", 2 + $(".sidebar-left").width())
.css("margin-Top", 5)
.removeClass("zoom-top-opened-sidebar")
.removeClass("zoom-top-collapsed");
}
}
function isConstrained() {
return $(".sidebar").width() == $(window).width();
}
function applyInitialUIState() {
if (isConstrained()) {
$(".sidebar-left .sidebar-body").fadeOut('slide');
$('.mini-submenu-left').fadeIn();
}
}
$(function () {
$('.sidebar-left .slide-submenu').on('click', function () {
var thisEl = $(this);
thisEl.closest('.sidebar-body').fadeOut('slide', function () {
$('.mini-submenu-left').fadeIn();
applyMargins();
});
});
$('.mini-submenu-left').on('click', function () {
var thisEl = $(this);
$('.sidebar-left .sidebar-body').toggle('slide');
thisEl.hide();
applyMargins();
});
////////////////////////////////////////////////
//DISABLING ZOOM CONTROL WHEN LOADING A MAP/////
var map = L.map('map',{zoomControl: false}).setView([40.91, -96.63], 4);
///ZOOM CONTROL POSITION///
/////////////////////////////
L.control.zoom({
position:'bottomright'
}).addTo(map);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
L.control.scale({}).addTo(map);
var locationFilter = new L.LocationFilter().addTo(map);
$(window).on("resize", applyMargins);
applyInitialUIState();
applyMargins();
});
//Bootstrap modal dragging
$(document).ready(function () {
$(".modal-draggable .modal-dialog").draggable({
handle: ".modal-header", cursor: "move"
});
});
Best Answer
The destination is allowed to be a Rectangle instead of a Cartesian3. When using a rectangle, the camera's height (zoom level) will be set such that it can see the corners of the rectangle. Use a larger rectangle for a more zoomed-out look.
For a working example of this, load the Sandcastle Camera Demo and click the pull-down to select "Fly to Rectange". The demo runs this code: