stickers with ability to drag them

This commit is contained in:
Fedor Katurov 2018-08-15 16:18:49 +07:00
parent 5f30df6f48
commit b8434c32e7
19 changed files with 460 additions and 39 deletions

40
src/modules/Stickers.js Normal file
View file

@ -0,0 +1,40 @@
import L from 'leaflet';
import { Sticker } from '$modules/Sticker';
export class Stickers {
constructor({ map }) {
this.map = map;
this.layer = L.layerGroup();
this.stickers = [];
this.layer.addTo(this.map);
}
createOnClick = e => {
if (!e || !e.latlng) return;
const { latlng } = e;
this.createSticker({ latlng });
};
createSticker = ({ latlng }) => {
const sticker = new Sticker({
latlng,
deleteSticker: this.deleteStickerByReference,
});
this.stickers.push(sticker);
sticker.sticker.addTo(this.map);
sticker.sticker.enableEdit();
};
deleteStickerByReference = ref => {
const index = this.stickers.indexOf(ref);
if (index < 0) return;
this.map.removeLayer(ref.sticker);
this.stickers.splice(index, 1);
};
}