• v0.2.0 Stable

    buddy released this 2 weeks ago | 0 commits to main since this release

    Auto-fit the map to its markers

    New on <leaflet-map>:

    attribute default meaning
    fit-to-markers off when present, ignore lat / lng / zoom and frame every locatable layer instead
    fit-padding 20 pixel gutter kept around the bounds
    fit-max-zoom none cap on how far it zooms in — set this so a single marker doesn't snap to max zoom
    <leaflet-map fit-to-markers fit-padding="40" fit-max-zoom="15">
      <leaflet-tile-layer url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"></leaflet-tile-layer>
      <leaflet-marker lat="34.0537" lng="-118.2427"></leaflet-marker>
      <leaflet-marker lat="34.0083" lng="-118.4987"></leaflet-marker>
      <leaflet-marker lat="34.1341" lng="-118.3215"></leaflet-marker>
    </leaflet-map>
    

    "Locatable" means anything with a getLatLng() (markers, circles) or getBounds()
    (rectangles, image / video overlays). Tile layers and open popups / tooltips are
    skipped.

    Behaviour

    • The only reframe trigger is a component registering — initial page load and
      any child added later. Panning, zooming, opening a popup and removing a marker
      all leave the view exactly where it is.
    • Reframes are coalesced onto a microtask, so page load produces one fitBounds
      call, not one per marker.
    • Panning / zooming still writes the live centre and zoom back to the
      lat / lng / zoom attributes as before — including the view fitBounds()
      lands on. That write-back never re-triggers a fit.
    • setView() still runs once at construction, so the map has a valid view before
      the first frame.

    Also

    • jsr.json / package.json now carry a description, for the JSR package
      score and search.

    Full diff: https://git.buddy.wtf/lib/leaflet-components/compare/v0.1.1...v0.2.0

    Downloads