mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-26 03:26:41 +07:00
stickers with ability to drag them
This commit is contained in:
parent
5f30df6f48
commit
b8434c32e7
19 changed files with 460 additions and 39 deletions
40
src/modules/Stickers.js
Normal file
40
src/modules/Stickers.js
Normal 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);
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue