mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 02:56:41 +07:00
fixed marker dragging
This commit is contained in:
parent
3109f49cc4
commit
4e167c9759
8 changed files with 53 additions and 67 deletions
|
@ -30,7 +30,7 @@
|
||||||
"eslint-loader": "^4.0.2",
|
"eslint-loader": "^4.0.2",
|
||||||
"file-saver": "^2.0.0",
|
"file-saver": "^2.0.0",
|
||||||
"gpx-parser-builder": "^1.0.2",
|
"gpx-parser-builder": "^1.0.2",
|
||||||
"leaflet": "^1.6.0",
|
"leaflet": "1.6.0",
|
||||||
"leaflet-editable": "^1.1.0",
|
"leaflet-editable": "^1.1.0",
|
||||||
"leaflet-geometryutil": "^0.9.0",
|
"leaflet-geometryutil": "^0.9.0",
|
||||||
"leaflet-routing-machine": "^3.2.12",
|
"leaflet-routing-machine": "^3.2.12",
|
||||||
|
|
|
@ -21,12 +21,12 @@ class StickerDesc extends React.PureComponent<Props, State> {
|
||||||
};
|
};
|
||||||
|
|
||||||
blockMouse = e => {
|
blockMouse = e => {
|
||||||
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
this.input.focus();
|
this.input.focus();
|
||||||
};
|
};
|
||||||
|
|
||||||
input: HTMLTextAreaElement;
|
input: HTMLTextAreaElement;
|
||||||
// todo: pass here locker for moving markers from Sticker.js
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { value: text } = this.props;
|
const { value: text } = this.props;
|
||||||
|
@ -34,10 +34,10 @@ class StickerDesc extends React.PureComponent<Props, State> {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={classnames('sticker-desc', { is_empty: !text.trim() })}
|
className={classnames('sticker-desc', { is_empty: !text.trim() })}
|
||||||
onMouseDown={this.blockMouse}
|
onMouseDownCapture={this.blockMouse}
|
||||||
onMouseUp={this.blockMouse}
|
onMouseUpCapture={this.blockMouse}
|
||||||
onDragStart={this.blockMouse}
|
onDragStartCapture={this.blockMouse}
|
||||||
onTouchStart={this.blockMouse}
|
onTouchStartCapture={this.blockMouse}
|
||||||
>
|
>
|
||||||
<div className="sticker-desc-sizer">
|
<div className="sticker-desc-sizer">
|
||||||
<span
|
<span
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React, { useEffect, useCallback, useRef, useState } from 'react';
|
import React, { useEffect, useCallback, useRef, useState } from 'react';
|
||||||
import { marker, Marker } from 'leaflet';
|
import { DivIcon, 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';
|
||||||
import { StickerDesc } from '~/components/StickerDesc';
|
import { StickerDesc } from '~/components/StickerDesc';
|
||||||
|
@ -110,7 +110,7 @@ const Sticker: React.FC<IProps> = ({
|
||||||
|
|
||||||
MainMap.enableClicks();
|
MainMap.enableClicks();
|
||||||
},
|
},
|
||||||
[onChange, sticker, MainMap]
|
[onChange, sticker]
|
||||||
);
|
);
|
||||||
|
|
||||||
const onDrag = React.useCallback(
|
const onDrag = React.useCallback(
|
||||||
|
@ -183,7 +183,7 @@ const Sticker: React.FC<IProps> = ({
|
||||||
document.removeEventListener('mousemove', onDrag);
|
document.removeEventListener('mousemove', onDrag);
|
||||||
document.removeEventListener('mouseup', onDragStop);
|
document.removeEventListener('mouseup', onDragStop);
|
||||||
};
|
};
|
||||||
}, [dragging, onDrag]);
|
}, [dragging, onDrag, onDragStop]);
|
||||||
|
|
||||||
// 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(() => {
|
||||||
|
@ -199,7 +199,7 @@ const Sticker: React.FC<IProps> = ({
|
||||||
return () => {
|
return () => {
|
||||||
item.remove();
|
item.remove();
|
||||||
};
|
};
|
||||||
}, [element]);
|
}, [sticker.latlng, element]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!layer) return;
|
if (!layer) return;
|
||||||
|
|
|
@ -5,41 +5,12 @@
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { LatLngLiteral, LayerGroup, Map, LatLng, Marker, marker } from 'leaflet';
|
import { LatLng, LatLngLiteral, LayerGroup, Map, Marker } from 'leaflet';
|
||||||
import { arrowClusterIcon, createArrow, createArrowIcon } from '~/utils/arrow';
|
import { arrowClusterIcon, createArrow } from '~/utils/arrow';
|
||||||
import { MarkerClusterGroup } from 'leaflet.markercluster/dist/leaflet.markercluster-src.js';
|
import { MarkerClusterGroup } from 'leaflet.markercluster/dist/leaflet.markercluster-src.js';
|
||||||
import { angleBetweenPoints, dist2, middleCoord } from '~/utils/geom';
|
import { angleBetweenPoints, dist2, middleCoord } from '~/utils/geom';
|
||||||
|
|
||||||
interface MidPoint {
|
|
||||||
latlng: LatLngLiteral;
|
|
||||||
angle: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
// interface IPrevState {
|
|
||||||
// route: LatLngLiteral[];
|
|
||||||
// markers: Marker[];
|
|
||||||
// midpoints: MidPoint[];
|
|
||||||
// }
|
|
||||||
|
|
||||||
class ArrowsLayer extends LayerGroup {
|
class ArrowsLayer extends LayerGroup {
|
||||||
/*
|
|
||||||
without remove optimization
|
|
||||||
|
|
||||||
first:
|
|
||||||
recalc: 5.469970703125ms
|
|
||||||
remove: 0.203857421875ms
|
|
||||||
add: 53.658935546875ms
|
|
||||||
total: 60.986083984375ms
|
|
||||||
|
|
||||||
last:
|
|
||||||
recalc: 0.010986328125ms
|
|
||||||
remove: 0.220947265625ms
|
|
||||||
add: 0.580078125ms
|
|
||||||
total: 2.721923828125ms
|
|
||||||
|
|
||||||
with remove optimization
|
|
||||||
*/
|
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
}
|
}
|
||||||
|
@ -54,7 +25,7 @@ class ArrowsLayer extends LayerGroup {
|
||||||
|
|
||||||
// Reacreating all the markers
|
// Reacreating all the markers
|
||||||
|
|
||||||
setLatLngs = (route: LatLngLiteral[]): void => {
|
setLatLngs = (route: LatLng[]): void => {
|
||||||
if (!this.map) return;
|
if (!this.map) return;
|
||||||
|
|
||||||
this.arrowLayer.clearLayers();
|
this.arrowLayer.clearLayers();
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
import { DivIcon } from 'leaflet';
|
|
||||||
|
|
||||||
export const DomMarker = DivIcon.extend({
|
|
||||||
initialize: function (options: any) {
|
|
||||||
this.options = options;
|
|
||||||
},
|
|
||||||
|
|
||||||
options: {
|
|
||||||
element: null // a initialized DOM element
|
|
||||||
// same options as divIcon except for html
|
|
||||||
},
|
|
||||||
|
|
||||||
createIcon: function() {
|
|
||||||
const { html, element, className } = this.options;
|
|
||||||
|
|
||||||
this._setIconStyles(element, 'icon');
|
|
||||||
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
38
src/utils/map/DomMarker.ts
Normal file
38
src/utils/map/DomMarker.ts
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
import { DivIcon, DivIconOptions } from 'leaflet';
|
||||||
|
//
|
||||||
|
// export const DomMarker = DivIcon.extend({
|
||||||
|
// initialize: function (options) {
|
||||||
|
// this.options = options;
|
||||||
|
// },
|
||||||
|
//
|
||||||
|
// options: {
|
||||||
|
// element: null // a initialized DOM element
|
||||||
|
// // same options as divIcon except for html
|
||||||
|
// },
|
||||||
|
//
|
||||||
|
// createIcon: function() {
|
||||||
|
// const { element } = this.options;
|
||||||
|
//
|
||||||
|
// this._setIconStyles(element, 'icon');
|
||||||
|
//
|
||||||
|
// return element;
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
export interface DomMarkerProps extends DivIconOptions {
|
||||||
|
element: HTMLElement
|
||||||
|
}
|
||||||
|
|
||||||
|
export class DomMarker extends DivIcon {
|
||||||
|
element: HTMLElement
|
||||||
|
|
||||||
|
constructor({ element, ...props }: DomMarkerProps) {
|
||||||
|
super(props);
|
||||||
|
this.element = element;
|
||||||
|
}
|
||||||
|
|
||||||
|
createIcon(oldicon?: HTMLElement) {
|
||||||
|
this.element.classList.add('icon')
|
||||||
|
return this.element;
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,7 +4,7 @@ import { CLIENT } from '~/config/frontend';
|
||||||
import { DomMarker } from '~/utils/map/DomMarker';
|
import { DomMarker } from '~/utils/map/DomMarker';
|
||||||
import { MainMap } from '~/constants/map';
|
import { MainMap } from '~/constants/map';
|
||||||
|
|
||||||
const createWaypointMarker = (): DomMarker => {
|
const createWaypointMarker = () => {
|
||||||
const element = document.createElement('div');
|
const element = document.createElement('div');
|
||||||
|
|
||||||
return new DomMarker({
|
return new DomMarker({
|
||||||
|
|
|
@ -448,8 +448,6 @@ const composeStickerImage = async (
|
||||||
sticker: string,
|
sticker: string,
|
||||||
scale: number
|
scale: number
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
console.log({ scale });
|
|
||||||
|
|
||||||
const rad = 56;
|
const rad = 56;
|
||||||
const tX = (Math.cos(angle + Math.PI) * rad - 30 - 6) * scale + x;
|
const tX = (Math.cos(angle + Math.PI) * rad - 30 - 6) * scale + x;
|
||||||
const tY = (Math.sin(angle + Math.PI) * rad - 30 - 6) * scale + y;
|
const tY = (Math.sin(angle + Math.PI) * rad - 30 - 6) * scale + y;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue