miguelcobain / ember-leaflet

:fire: :leaves: Easy and declarative mapping for ember

Home Page:https://miguelcobain.github.io/ember-leaflet/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Initially set bounds on set of points

MichalBryxi opened this issue · comments

I think this is pretty common requirement to zoom onto (set bounds) a list of N (all) points. So here's one of the possible solutions I came up with:

import L, { LatLngBounds } from 'leaflet';

function bounds(locations: [[]]): LatLngBounds {
  let ret = L.polyline(locations).getBounds();
  return ret;
}

export default class Map extends Component<Signature> {
  let locations = [
    [49.1, 11.2],
    [35.2, 10.5],
    ...
  ];

  <template>
      <LeafletMap
        @bounds={{bounds this.locations}}
        as |layers|
     >
      ...
    </LeafletMap>
  </template>
}

This is not really a bug report, just a hint to some future bypassers. Happy to open PR if there is a good place to put it in the documentation.