fixed sticker text issues

This commit is contained in:
Fedor Katurov 2020-01-10 14:45:17 +07:00
parent afc9654200
commit 0314edd550
2 changed files with 14 additions and 9 deletions

View file

@ -1,4 +1,4 @@
import React from 'react'; import React, { useEffect } from 'react';
import { marker, Marker } from 'leaflet'; import { marker, Marker } from 'leaflet';
import { IStickerDump } from '~/redux/map/types'; import { IStickerDump } from '~/redux/map/types';
import { STICKERS } from '~/constants/stickers'; import { STICKERS } from '~/constants/stickers';
@ -6,7 +6,7 @@ import { StickerDesc } from '~/components/StickerDesc';
import classNames from 'classnames'; import classNames from 'classnames';
import { DomMarker } from '~/utils/DomMarker'; import { DomMarker } from '~/utils/DomMarker';
import { createPortal } from 'react-dom'; import { createPortal } from 'react-dom';
import { MapContainer } from '~/constants/map'; import { MapContainer, MainMap } from '~/constants/map';
interface IProps { interface IProps {
map: MapContainer; map: MapContainer;
@ -154,22 +154,27 @@ const Sticker: React.FC<IProps> = ({
// Initial leaflet marker creation, when element (dom element div) is ready // Initial leaflet marker creation, when element (dom element div) is ready
React.useEffect(() => { React.useEffect(() => {
if (!map) return;
const icon = new DomMarker({ const icon = new DomMarker({
element, element,
className: 'sticker-container', className: 'sticker-container',
}); });
const item = marker(sticker.latlng, { icon, draggable: true }).addTo(map); const item = marker(sticker.latlng, { icon, draggable: true })
setLayer(item); setLayer(item);
return () => { return () => {
item.removeFrom(map);
item.remove(); item.remove();
}; };
}, [element, map, sticker]); }, [element]);
useEffect(() => {
if (!layer) return;
layer.addTo(MainMap);
return () => layer.removeFrom(MainMap)
}, [layer]);
React.useEffect(() => { React.useEffect(() => {
element.className = is_editing ? 'sticker-container' : 'sticker-container inactive'; element.className = is_editing ? 'sticker-container' : 'sticker-container inactive';

View file

@ -30,7 +30,7 @@ const Stickers: React.FC<IProps> = React.memo(
<Sticker <Sticker
map={map} map={map}
sticker={sticker} sticker={sticker}
key={`${index}`} key={`${sticker.set}.${sticker.sticker}.${index}`}
index={index} index={index}
is_editing={is_editing} is_editing={is_editing}
mapSetSticker={mapSetSticker} mapSetSticker={mapSetSticker}