Skip to content
Open
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
55 changes: 55 additions & 0 deletions src/leaflet.legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,57 @@
}
}

class StarSymbol extends GeometricSymbol {
_drawSymbol() {
var ctx = (this._ctx = this._canvas.getContext("2d"));

var linelWeight = this._legend.weight || 3;
var rot=Math.PI/2*3;
var outerRadius = this._control.options.symbolWidth / 2;
var innerRadius = outerRadius / 2;
var x = this._control.options.symbolWidth / 2;
var y = this._control.options.symbolHeight / 2;
var step=Math.PI/this._legend.sides;
ctx.beginPath();
ctx.moveTo(cx,cy-outerRadius)
for(i=0;i<this._legend.sides;i++){
x=cx+Math.cos(rot)*outerRadius;
y=cy+Math.sin(rot)*outerRadius;
ctx.lineTo(x,y)
rot+=step

x=cx+Math.cos(rot)*innerRadius;
y=cy+Math.sin(rot)*innerRadius;
ctx.lineTo(x,y)
rot+=step
}
ctx.lineTo(cx,cy-outerRadius);
ctx.closePath();
}
}

class PolygonRSymbol extends GeometricSymbol {
_drawSymbol() {
var ctx = (this._ctx = this._canvas.getContext("2d"));
var linelWeight = this._legend.weight || 3;
var x0 = this._control.options.symbolWidth / 2;
var y0 = this._control.options.symbolHeight / 2;
var r = Math.min(x0, y0) - linelWeight;
var a = 360 / this._legend.sides;
var rot1 = 360/(this._legend.sides*2);
ctx.beginPath();
for (var i = 0; i <= this._legend.sides; i++) {
var x1 = x0 + r * Math.cos(((a * i + (90 - a / 2) + rot1) * Math.PI) / 180);
var y1 = y0 + r * Math.sin(((a * i + (90 - a / 2) + rot1) * Math.PI) / 180);
if (i == 0) {
ctx.moveTo(x1, y1);
} else {
ctx.lineTo(x1, y1);
}
}
}
}

class ImageSymbol extends LegendSymbol {
constructor(control, container, legend) {
super(control, container, legend);
Expand Down Expand Up @@ -259,6 +310,10 @@
legendSymbol = new RectangleSymbol(this, symbolContainer, legend);
} else if (legend.type === "polygon") {
legendSymbol = new PolygonSymbol(this, symbolContainer, legend);
} else if (legend.type === "star") {
legendSymbol = new starSymbol(this, symbolContainer, legend);
} else if (legend.type === "polygonR") {
legendSymbol = new PolygonRSymbol(this, symbolContainer, legend);
} else if (legend.type === "polyline") {
legendSymbol = new PolylineSymbol(this, symbolContainer, legend);
} else {
Expand Down