Skip to content

Commit 5670acb

Browse files
committed
fix specs
1 parent af11480 commit 5670acb

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
lines changed

packages/maptalks/src/core/util/draw.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { isGradient } from './style';
44
import { isNumber } from './common';
55
import Canvas from '../Canvas';
66
import { ResourceCache } from '../../renderer/layer/LayerAbstractRenderer'
7+
import { BBOX } from './bbox';
78

89
export function drawImageMarker(ctx: CanvasRenderingContext2D, image, point, symbol) {
910
let w = symbol && symbol['markerWidth'];
@@ -22,7 +23,7 @@ export function getImage(resources: ResourceCache, url: string) {
2223
return img || null;
2324
}
2425

25-
export function drawVectorMarker(ctx: CanvasRenderingContext2D, point, symbol, resources: ResourceCache) {
26+
export function drawVectorMarker(ctx: CanvasRenderingContext2D, point, symbol, resources: ResourceCache, bbox?: BBOX) {
2627
const strokeAndFill = translateMarkerLineAndFill(symbol);
2728
const style = symbol,
2829
markerType = style['markerType'].toLowerCase(),
@@ -44,7 +45,8 @@ export function drawVectorMarker(ctx: CanvasRenderingContext2D, point, symbol, r
4445

4546
const width = style['markerWidth'],
4647
height = style['markerHeight'],
47-
hLineWidth = style['markerLineWidth'] / 2;
48+
lineWidth = style['markerLineWidth'] || 0,
49+
hLineWidth = lineWidth / 2;
4850
if (markerType === 'ellipse') {
4951
//ellipse default
5052
Canvas.ellipse(ctx, point, width / 2, height / 2, height / 2, lineOpacity, fillOpacity);
@@ -85,6 +87,14 @@ export function drawVectorMarker(ctx: CanvasRenderingContext2D, point, symbol, r
8587
} else {
8688
throw new Error('unsupported markerType: ' + markerType);
8789
}
90+
if (bbox) {
91+
//record marker bbox if need
92+
const { x, y } = point;
93+
bbox[0] = x - width / 2 - lineWidth;
94+
bbox[1] = y - height / 2 - lineWidth;
95+
bbox[2] = x + width / 2 + lineWidth;
96+
bbox[3] = y + height / 2 + lineWidth;
97+
}
8898
return ctx.canvas;
8999
}
90100

packages/maptalks/src/layer/VectorLayer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import Browser from '../core/Browser';
22
import { isNil, isNumber } from '../core/util';
33
import Extent from '../geo/Extent';
44
import Geometry from '../geometry/Geometry';
5-
import OverlayLayer, { LayerIdentifyOptionsType, OverlayLayerOptionsType } from './OverlayLayer';
5+
import OverlayLayer, { OverlayLayerOptionsType } from './OverlayLayer';
6+
import { LayerIdentifyOptionsType } from './Layer';
67
import Painter from '../renderer/geometry/Painter';
78
import CollectionPainter from '../renderer/geometry/CollectionPainter';
89
import Coordinate from '../geo/Coordinate';

packages/maptalks/src/renderer/geometry/symbolizers/VectorMarkerSymbolizer.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import { Geometry } from '../../../geometry';
1313
import Painter from '../Painter';
1414
import { Extent } from '../../../geo';
1515
import { ResourceCache } from '../../layer/LayerAbstractRenderer';
16+
import { getDefaultBBOX, resetBBOX } from '../../../core/util/bbox';
1617

1718
const MARKER_SIZE: [number, number] = [0, 0];
1819
const TEMP_EXTENT = new PointExtent();
1920
const DEFAULT_ANCHOR = new Point(0, 0);
21+
const TEMP_BBOX = getDefaultBBOX();
2022

2123
export default class VectorMarkerSymbolizer extends PointSymbolizer {
2224
//@internal
@@ -66,14 +68,16 @@ export default class VectorMarkerSymbolizer extends PointSymbolizer {
6668
this.geometry.getLayer().getMask() === this.geometry ||
6769
this._dynamic ||
6870
this.geometry.getLayer().options['cacheVectorOnCanvas'] === false) {
69-
this._drawMarkers(ctx, cookedPoints, resources);
71+
//动态样式或者不缓存,function-type style, or not cache vector on canvas
72+
this._drawMarkersWithDynamic(ctx, cookedPoints, resources);
7073
} else {
7174
this._drawMarkersWithCache(ctx, cookedPoints, resources);
7275
}
7376
}
7477

78+
//rename to _drawMarkersWithDynamic
7579
//@internal
76-
_drawMarkers(ctx: CanvasRenderingContext2D, cookedPoints: any[], resources: ResourceCache) {
80+
_drawMarkersWithDynamic(ctx: CanvasRenderingContext2D, cookedPoints: any[], resources: ResourceCache) {
7781
for (let i = cookedPoints.length - 1; i >= 0; i--) {
7882
let point = cookedPoints[i];
7983
const size = calVectorMarkerSize(MARKER_SIZE, this.style);
@@ -90,13 +94,17 @@ export default class VectorMarkerSymbolizer extends PointSymbolizer {
9094
this.rotations.push(rad);
9195
}
9296

93-
this._drawVectorMarker(ctx, point, resources);
97+
const bbox = this._drawVectorMarker(ctx, point, resources);
9498
if (origin) {
9599
ctx.restore();
96100
this._setBBOX(ctx, extent.xmin, extent.ymin, extent.xmax, extent.ymax);
97101
} else {
98-
const { x, y } = point;
99-
this._setBBOX(ctx, x, y, x + width, y + height);
102+
if (bbox) {
103+
this._setBBOX(ctx, bbox[0], bbox[1], bbox[2], bbox[3]);
104+
} else {
105+
const { x, y } = point;
106+
this._setBBOX(ctx, x, y, x + width, y + height);
107+
}
100108
}
101109
}
102110
}
@@ -203,15 +211,21 @@ export default class VectorMarkerSymbolizer extends PointSymbolizer {
203211

204212
//@internal
205213
_drawVectorMarker(ctx: CanvasRenderingContext2D, point: Point, resources: ResourceCache) {
206-
drawVectorMarker(ctx, point, this.style, resources);
214+
resetBBOX(TEMP_BBOX);
215+
drawVectorMarker(ctx, point, this.style, resources, TEMP_BBOX);
216+
return TEMP_BBOX;
207217
}
208218

209219
getFixedExtent(): PointExtent {
210-
const isDynamic = this.isDynamicSize();
211-
const w = this.style.markerWidth;
212-
const h = this.style.markerHeight;
220+
// const isDynamic = this.isDynamicSize();
221+
// const w = this.style.markerWidth;
222+
// const h = this.style.markerHeight;
223+
// this._fixedExtent = this._fixedExtent || new PointExtent();
224+
// return getVectorMarkerFixedExtent(this._fixedExtent, this.style, isDynamic ? [128, 128 * (w === 0 ? 1 : h / w)] : null);
225+
213226
this._fixedExtent = this._fixedExtent || new PointExtent();
214-
return getVectorMarkerFixedExtent(this._fixedExtent, this.style, isDynamic ? [128, 128 * (w === 0 ? 1 : h / w)] : null);
227+
return getVectorMarkerFixedExtent(this._fixedExtent, this.style, null);
228+
215229
}
216230

217231
translate(): any {

0 commit comments

Comments
 (0)