I use OSM to display boundaries of the county. It works most of the time just fine, but in some cases the counties are larger and don't fit in the map.
How do I adjust zoom level before start the rendering?
var map = L.map("mapCnty").setView([31.2506372, -102.3385429], 5);
map.attributionControl.setPrefix();
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
attribution: \'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors\'
}).addTo(map);
function drawCountyBoundary(county, state) {
url = "https://nominatim.openstreetmap.org/search.php?county=" + county + "&state=" + state + "&polygon_geojson=1&format=jsonv2";
fetch(url).then(function(response) {
return response.json();
})
.then(function(json) {
map.flyTo([json[0].lat, json[0].lon], 9);
setTimeout(function(){
geojsonFeature = json[0].geojson;
L.geoJSON(geojsonFeature).addTo(map);
}, 1900);
});
}
drawCountyBoundary("Cibola", "NM");