I am creating an app with django, geodjango and Leaflet, I am also using django-geojson and django-leaflet. I manage to insert on a map two features that contain points. But i am getting problems setting the bounds for that map. Since I am adding two sets of points to the map i would like to set the bounds to the combination of both sets. But when I try try to use
var features = L.control.layers(basemaps, overlayMaps).addTo(map);
map.fitBounds(features.getBounds());
I get the following error:
Uncaught TypeError: features.getBounds is not a function
The Idea is that I want to set the bound to the combination of feature_incidence and feature_warnings. This is my code:
var geom_incidence = {{ incidences|geojsonfeature|safe }};
var feature_incidence = L.geoJson(geom_incidence , { pointToLayer:redIcon});
var geom_warnings = {{ mobile_warnings|geojsonfeature|safe }};
var feature_warnings = L.geoJson(geom_warnings, { pointToLayer:blueIcon});
var basemaps = {
"osmHOT" : L.tileLayer('https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© OpenStreetMap contributors, Tiles style by Humanitarian OpenStreetMap Team hosted by OpenStreetMap France'
}),
"Calles": L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
})
};
var overlayMaps = {
"Incidencias": feature_incidence,
"Avisos":feature_warnings
};
var features = L.control.layers(basemaps, overlayMaps).addTo(map);
map.fitBounds(features.getBounds());
feature_incidence.addTo(map);
feature_warnings.addTo(map);
basemaps["Calles"].addTo(map);