mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-03-22 15:17:23 +01:00
feat: add getPin function and improve code formatting in draw-markers
This commit is contained in:
parent
6e26f49423
commit
74952a1071
1 changed files with 7 additions and 19 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { rn } from "../utils";
|
||||
import {rn} from "../utils";
|
||||
|
||||
interface Marker {
|
||||
i: number;
|
||||
|
|
@ -18,10 +18,11 @@ interface Marker {
|
|||
declare global {
|
||||
var drawMarkers: () => void;
|
||||
var drawMarker: (marker: Marker, rescale?: number) => string;
|
||||
var getPin: (shape?: string, fill?: string, stroke?: string) => string;
|
||||
}
|
||||
|
||||
type PinShapeFunction = (fill: string, stroke: string) => string;
|
||||
type PinShapes = { [key: string]: PinShapeFunction };
|
||||
type PinShapes = {[key: string]: PinShapeFunction};
|
||||
|
||||
// prettier-ignore
|
||||
const pinShapes: PinShapes = {
|
||||
|
|
@ -58,19 +59,7 @@ const getPin = (shape = "bubble", fill = "#fff", stroke = "#000"): string => {
|
|||
};
|
||||
|
||||
function markerRenderer(marker: Marker, rescale = 1): string {
|
||||
const {
|
||||
i,
|
||||
icon,
|
||||
x,
|
||||
y,
|
||||
dx = 50,
|
||||
dy = 50,
|
||||
px = 12,
|
||||
size = 30,
|
||||
pin,
|
||||
fill,
|
||||
stroke,
|
||||
} = marker;
|
||||
const {i, icon, x, y, dx = 50, dy = 50, px = 12, size = 30, pin, fill, stroke} = marker;
|
||||
const id = `marker${i}`;
|
||||
const zoomSize = rescale ? Math.max(rn(size / 5 + 24 / scale, 2), 1) : size;
|
||||
const viewX = rn(x - zoomSize / 2, 1);
|
||||
|
|
@ -92,10 +81,8 @@ const markersRenderer = (): void => {
|
|||
const rescale = +markers.attr("rescale");
|
||||
const pinned = +markers.attr("pinned");
|
||||
|
||||
const markersData: Marker[] = pinned
|
||||
? pack.markers.filter((m: Marker) => m.pinned)
|
||||
: pack.markers;
|
||||
const html = markersData.map((marker) => markerRenderer(marker, rescale));
|
||||
const markersData: Marker[] = pinned ? pack.markers.filter((m: Marker) => m.pinned) : pack.markers;
|
||||
const html = markersData.map(marker => markerRenderer(marker, rescale));
|
||||
markers.html(html.join(""));
|
||||
|
||||
TIME && console.timeEnd("drawMarkers");
|
||||
|
|
@ -103,3 +90,4 @@ const markersRenderer = (): void => {
|
|||
|
||||
window.drawMarkers = markersRenderer;
|
||||
window.drawMarker = markerRenderer;
|
||||
window.getPin = getPin;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue