Leaflet fitBounds Starting Position

المشرف العام

Administrator
طاقم الإدارة
I am creating a Leaflet application that uses the code from the Simple CSV template to set the bounds of the map to the selected markers.

The issue I have is that I want to set a start position that isn't the bounds of all of my markers. I would also like the map to return to this start position once the clear function is initiated as well.

Some of the key sections of code can be seen below but the repository is available by the link above.

var addCsvMarkers = function() { hits = 0; total = 0; filterString = document.getElementById('filter-string').value; if (filterString) { $("#clear").fadeIn(); } else { $("#clear").fadeOut(); } map.removeLayer(markers); points.clearLayers(); markers = new L.MarkerClusterGroup(clusterOptions); points.addData(dataCsv); markers.addLayer(points); map.addLayer(markers); try { var bounds = markers.getBounds(); if (bounds) { map.fitBounds(bounds, {maxZoom: 15}); } } catch(err) { // pass } if (total > 0) { $('#search-results').html("Showing " + hits + " of " + total + " Projects"); } return false; }; &

$("#clear").click(function(evt){ evt.preventDefault(); $("#filter-string").val("").focus(); addCsvMarkers(); }); EDIT: Is it possible for the setView that is called in when defining the map to override the fitBounds command?

var map = L.map('map', { zoomControl: false, minZoom: 3, maxZoom: 18 }).setView([54.5, -4], 6);

أكثر...
 
أعلى