added map fitting

This commit is contained in:
Fedor Katurov 2020-01-13 17:43:38 +07:00
parent 0314edd550
commit bc34cf3876
12 changed files with 93 additions and 78 deletions
src/constants

View file

@ -1,6 +1,12 @@
import { Map } from 'leaflet';
import { Map, LayerGroup, Layer, FeatureGroup } from 'leaflet';
export class MapContainer extends Map {
constructor(props) {
super(props);
this.routeLayer.addTo(this);
this.stickerLayer.addTo(this);
}
disableClicks = () => {
this.clickable = false;
};
@ -9,10 +15,23 @@ export class MapContainer extends Map {
this.clickable = true;
};
getVisibleBounds = () => {
const layers = [this.routeLayer, this.stickerLayer];
for (let i = 0; i < layers.length; i += 1) {
const bounds = layers[i].getBounds();
if (Object.keys(bounds).length == 2) return bounds;
}
};
public clickable = true;
public routeLayer = new FeatureGroup();
public stickerLayer = new FeatureGroup();
}
export const MainMap = new MapContainer(document.getElementById('canvas')).setView(
[55.0153275, 82.9071235],
13
);
console.log('MAP', MainMap);