mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 02:56:41 +07:00
printing gpx tracks
This commit is contained in:
parent
5604d8716b
commit
f41078b769
4 changed files with 40 additions and 8 deletions
|
@ -14,8 +14,9 @@ const GpxPolyline: FC<IProps> = ({ latlngs, color }) => {
|
||||||
const item = new Polyline([], {
|
const item = new Polyline([], {
|
||||||
color,
|
color,
|
||||||
stroke: true,
|
stroke: true,
|
||||||
opacity: 0.4,
|
opacity: 1,
|
||||||
weight: 9,
|
weight: 9,
|
||||||
|
dashArray: [12,12],
|
||||||
}).addTo(MainMap);
|
}).addTo(MainMap);
|
||||||
setLayer(item);
|
setLayer(item);
|
||||||
|
|
||||||
|
|
|
@ -118,6 +118,7 @@ function* getRenderData() {
|
||||||
yield put(editorSetRenderer({ info: 'Загрузка тайлов', progress: 0.1 }));
|
yield put(editorSetRenderer({ info: 'Загрузка тайлов', progress: 0.1 }));
|
||||||
|
|
||||||
const { route, stickers, provider }: ReturnType<typeof selectMap> = yield select(selectMap);
|
const { route, stickers, provider }: ReturnType<typeof selectMap> = yield select(selectMap);
|
||||||
|
const gpx: ReturnType<typeof selectEditorGpx> = yield select(selectEditorGpx);
|
||||||
const { distance }: ReturnType<typeof selectEditor> = yield select(selectEditor);
|
const { distance }: ReturnType<typeof selectEditor> = yield select(selectEditor);
|
||||||
|
|
||||||
const canvas = <HTMLCanvasElement>document.getElementById('renderer');
|
const canvas = <HTMLCanvasElement>document.getElementById('renderer');
|
||||||
|
@ -137,6 +138,20 @@ function* getRenderData() {
|
||||||
|
|
||||||
yield composeImages({ geometry, images, ctx });
|
yield composeImages({ geometry, images, ctx });
|
||||||
yield composePoly({ points, ctx });
|
yield composePoly({ points, ctx });
|
||||||
|
|
||||||
|
gpx.list.forEach(item => {
|
||||||
|
if (!gpx.enabled || !item.enabled || !item.latlngs.length) return;
|
||||||
|
|
||||||
|
composePoly({
|
||||||
|
points: getPolyPlacement(item.latlngs),
|
||||||
|
ctx,
|
||||||
|
color: item.color,
|
||||||
|
opacity: 0.5,
|
||||||
|
weight: 9,
|
||||||
|
dash: [12, 12],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
yield composeArrows({ points, ctx });
|
yield composeArrows({ points, ctx });
|
||||||
yield composeDistMark({ ctx, points, distance });
|
yield composeDistMark({ ctx, points, distance });
|
||||||
yield composeStickers({ stickers: sticker_points, ctx });
|
yield composeStickers({ stickers: sticker_points, ctx });
|
||||||
|
|
|
@ -10,5 +10,5 @@ export const getStyle = (oElm: any, strCssRule: string): string => {
|
||||||
|
|
||||||
|
|
||||||
export const getRandomColor = () => {
|
export const getRandomColor = () => {
|
||||||
return `hsl(${(Math.floor(Math.random() * 360))}, 100%, 50%)`
|
return `hsla(${(Math.floor(Math.random() * 360))}, 100%, 50%, 0.4)`
|
||||||
}
|
}
|
|
@ -170,9 +170,16 @@ export const composeImages = ({
|
||||||
export const composePoly = ({
|
export const composePoly = ({
|
||||||
points,
|
points,
|
||||||
ctx,
|
ctx,
|
||||||
|
color = 'gradient',
|
||||||
|
weight = CLIENT.STROKE_WIDTH,
|
||||||
|
dash = null,
|
||||||
}: {
|
}: {
|
||||||
points: Point[];
|
points: Point[];
|
||||||
ctx: CanvasRenderingContext2D;
|
ctx: CanvasRenderingContext2D;
|
||||||
|
color?: string;
|
||||||
|
opacity?: number;
|
||||||
|
weight?: number;
|
||||||
|
dash?: number[];
|
||||||
}): void => {
|
}): void => {
|
||||||
if (points.length === 0) return;
|
if (points.length === 0) return;
|
||||||
|
|
||||||
|
@ -181,10 +188,9 @@ export const composePoly = ({
|
||||||
let minY = points[0].y;
|
let minY = points[0].y;
|
||||||
let maxY = points[0].y;
|
let maxY = points[0].y;
|
||||||
|
|
||||||
ctx.strokeStyle = 'red';
|
|
||||||
ctx.lineCap = 'round';
|
ctx.lineCap = 'round';
|
||||||
ctx.lineJoin = 'round';
|
ctx.lineJoin = 'round';
|
||||||
ctx.lineWidth = CLIENT.STROKE_WIDTH + 0.5;
|
ctx.lineWidth = weight + 0.5;
|
||||||
|
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.moveTo(points[0].x, points[0].y);
|
ctx.moveTo(points[0].x, points[0].y);
|
||||||
|
@ -199,11 +205,21 @@ export const composePoly = ({
|
||||||
if (points[i].y > maxY) maxY = points[i].y;
|
if (points[i].y > maxY) maxY = points[i].y;
|
||||||
}
|
}
|
||||||
|
|
||||||
const gradient = ctx.createLinearGradient(minX, minY, minX, maxY);
|
if (color === 'gradient') {
|
||||||
gradient.addColorStop(0, COLORS.PATH_COLOR[0]);
|
|
||||||
gradient.addColorStop(1, COLORS.PATH_COLOR[1]);
|
|
||||||
|
|
||||||
ctx.strokeStyle = gradient;
|
const gradient = ctx.createLinearGradient(minX, minY, minX, maxY);
|
||||||
|
gradient.addColorStop(0, COLORS.PATH_COLOR[0]);
|
||||||
|
gradient.addColorStop(1, COLORS.PATH_COLOR[1]);
|
||||||
|
|
||||||
|
ctx.strokeStyle = gradient;
|
||||||
|
} else {
|
||||||
|
ctx.strokeStyle = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dash) {
|
||||||
|
ctx.setLineDash([12,12]);
|
||||||
|
}
|
||||||
|
|
||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
ctx.closePath();
|
ctx.closePath();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue