Skip to content

markerPlacement support 'vertex-firstlast' #2532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions packages/maptalks/src/renderer/geometry/PointRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Rectangle from '../../geometry/Rectangle';
import LineString from '../../geometry/LineString';
import Polygon from '../../geometry/Polygon';
import Point from '../../geo/Point';
import {WithNull} from "../../types/typings";
import { WithNull } from "../../types/typings";

// 有中心点的图形的共同方法
const CenterPointRenderer = {
Expand All @@ -19,7 +19,7 @@ const CenterPointRenderer = {
export type CenterPointRendererType = typeof CenterPointRenderer;

declare module '../../geometry/Marker' {
interface Marker extends CenterPointRendererType {}
interface Marker extends CenterPointRendererType { }
}

/**
Expand Down Expand Up @@ -131,6 +131,23 @@ const PolyRenderer = {
points = l ? [curretPoint] : [];
const previous = l > 1 ? l - 2 : l - 1;
rotations = l ? [[coords[previous] ? map._prjToPointAtRes(coords[previous], glRes) : curretPoint, curretPoint]] : [];
} else if (placement === 'vertex-firstlast') {
points = [];
rotations = [];
const coords = this._getPrjCoordinates();
const l = coords.length;
if (l) {
//first
const point0 = map._prjToPointAtRes(coords[0], glRes)
points = [point0];
if (l > 1) {
rotations = [[point0, map._prjToPointAtRes(coords[1], glRes)]];
const point1 = map._prjToPointAtRes(coords[l - 1], glRes);
points.push(point1);
const previous = l > 1 ? l - 2 : l - 1;
rotations.push([map._prjToPointAtRes(coords[previous], glRes), point1]);
}
}
} else {
const center = this.getCenter();
if (!center) {
Expand Down
2 changes: 1 addition & 1 deletion packages/maptalks/src/symbol/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export type MarkerCommonSymbol = {
markerDy?: SymbolNumberType;
markerHorizontalAlignment?: 'left' | 'middle' | 'right';
markerVerticalAlignment?: 'top' | 'middle' | 'bottom';
markerPlacement?: 'point' | 'vertex' | 'line' | 'vertex-first' | 'vertex-last';
markerPlacement?: 'center' | 'point' | 'vertex' | 'line' | 'vertex-first' | 'vertex-last' | 'vertex-firstlast';
markerRotation?: number;
}

Expand Down