mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-05-04 15:36:40 +07:00
finally saving things
This commit is contained in:
parent
e0f5d0238a
commit
47e4f4a97d
22 changed files with 277 additions and 38 deletions
src/modules
|
@ -168,16 +168,17 @@ export class Editor {
|
|||
this.changeMode(MODES.NONE);
|
||||
};
|
||||
|
||||
setData = ({ route, stickers, format = 'old', owner }) => {
|
||||
setData = ({ route, stickers, version = 1, owner }) => {
|
||||
console.log('setting?', stickers);
|
||||
if (route) {
|
||||
this.poly.setPoints(route);
|
||||
}
|
||||
|
||||
if (stickers) {
|
||||
stickers.map(({ latlng, ang: angle, style }) => this.stickers.createSticker({
|
||||
latlng,
|
||||
angle: parseStickerAngle({ angle, format }),
|
||||
sticker: parseStickerStyle({ style, format }),
|
||||
stickers.map(sticker => this.stickers.createSticker({
|
||||
latlng: sticker.latlng,
|
||||
angle: parseStickerAngle({ sticker, version }),
|
||||
sticker: parseStickerStyle({ sticker, version }),
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -185,7 +186,11 @@ export class Editor {
|
|||
this.owner = owner;
|
||||
}
|
||||
|
||||
this.map.map.fitBounds(this.poly.poly.getBounds());
|
||||
if (!route || route.length <= 1) return;
|
||||
|
||||
const bounds = this.poly.poly.getBounds();
|
||||
|
||||
if (Object.values(bounds)) this.map.map.fitBounds(bounds);
|
||||
};
|
||||
|
||||
startEditing = () => {
|
||||
|
@ -194,5 +199,10 @@ export class Editor {
|
|||
|
||||
stopEditing = () => {
|
||||
this.poly.poly.disableEdit();
|
||||
}
|
||||
};
|
||||
|
||||
dumpData = () => ({
|
||||
route: this.poly.dumpData(),
|
||||
stickers: this.stickers.dumpData(),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -152,4 +152,6 @@ export class Poly {
|
|||
};
|
||||
|
||||
clearArrows = () => this.arrows.clearLayers();
|
||||
|
||||
dumpData = () => this.latlngs;
|
||||
}
|
||||
|
|
|
@ -9,9 +9,11 @@ export class Sticker {
|
|||
constructor({
|
||||
latlng, deleteSticker, map, lockMapClicks, sticker, angle = 2.2
|
||||
}) {
|
||||
this.latlng = latlng;
|
||||
this.angle = angle;
|
||||
this.isDragging = false;
|
||||
this.map = map;
|
||||
this.sticker = sticker;
|
||||
|
||||
this.deleteSticker = deleteSticker;
|
||||
this.lockMapClicks = lockMapClicks;
|
||||
|
@ -37,7 +39,7 @@ export class Sticker {
|
|||
className: 'sticker-container',
|
||||
});
|
||||
|
||||
this.sticker = marker(latlng, { icon: mark });
|
||||
this.marker = marker(latlng, { icon: mark });
|
||||
|
||||
this.setAngle(angle);
|
||||
|
||||
|
@ -56,7 +58,7 @@ export class Sticker {
|
|||
this.preventPropagations(e);
|
||||
|
||||
this.isDragging = true;
|
||||
this.sticker.disableEdit();
|
||||
this.marker.disableEdit();
|
||||
|
||||
this.lockMapClicks(true);
|
||||
|
||||
|
@ -75,7 +77,7 @@ export class Sticker {
|
|||
this.preventPropagations(e);
|
||||
|
||||
this.isDragging = false;
|
||||
this.sticker.enableEdit();
|
||||
this.marker.enableEdit();
|
||||
|
||||
window.removeEventListener('mousemove', this.onDrag);
|
||||
window.removeEventListener('mouseup', this.onDragStop);
|
||||
|
@ -97,8 +99,6 @@ export class Sticker {
|
|||
};
|
||||
|
||||
setAngle = angle => {
|
||||
// $(active_sticker.container).css('left',6+x-parseInt(active_sticker.ctrl.css('left'))).css('top',6+y-parseInt(active_sticker.ctrl.css('top')));
|
||||
//
|
||||
const rad = 44;
|
||||
const mrad = 76;
|
||||
const x = ((Math.cos(angle + 3.14) * rad) - 30);
|
||||
|
@ -114,7 +114,7 @@ export class Sticker {
|
|||
this.stickerDelete.style.top = ay;
|
||||
|
||||
this.stickerArrow.style.transform = `rotate(${angle + 3.14}rad)`;
|
||||
}
|
||||
};
|
||||
|
||||
generateStickerSVG = sticker => (
|
||||
`
|
||||
|
@ -122,5 +122,11 @@ export class Sticker {
|
|||
<use xlink:href="${stickers}#sticker-${sticker}" x="0" y="0" width="64" height="64" />
|
||||
</svg>
|
||||
`
|
||||
)
|
||||
);
|
||||
|
||||
dumpData = () => ({
|
||||
angle: this.angle,
|
||||
latlng: this.latlng,
|
||||
sticker: this.sticker,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ export class Stickers {
|
|||
// };
|
||||
|
||||
createSticker = ({ latlng, sticker, angle = 2.2 }) => {
|
||||
console.log('creating', latlng, sticker, angle);
|
||||
const marker = new Sticker({
|
||||
latlng,
|
||||
angle,
|
||||
|
@ -30,8 +31,8 @@ export class Stickers {
|
|||
});
|
||||
this.stickers.push(marker);
|
||||
|
||||
marker.sticker.addTo(this.map);
|
||||
marker.sticker.enableEdit();
|
||||
marker.marker.addTo(this.map);
|
||||
marker.marker.enableEdit();
|
||||
};
|
||||
|
||||
deleteStickerByReference = ref => {
|
||||
|
@ -39,7 +40,7 @@ export class Stickers {
|
|||
|
||||
if (index < 0) return;
|
||||
|
||||
this.map.removeLayer(ref.sticker);
|
||||
this.map.removeLayer(ref.marker);
|
||||
this.stickers.splice(index, 1);
|
||||
};
|
||||
|
||||
|
@ -49,5 +50,7 @@ export class Stickers {
|
|||
this.deleteStickerByReference(sticker);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
dumpData = () => this.stickers.map(sticker => sticker.dumpData());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue