Skip to content

Commit

Permalink
Add triangle-down/triangle-up marker shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Hurnaus committed Mar 19, 2018
1 parent ee03337 commit e160e2a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ L.shapeMarker also extends the [path class](http://leafletjs.com/reference.html#
}).addTo(map);
```

### Available shapes

* diamond
* square
* triangle (= triangle-up)
* triangle-up
* triangle-down
* circle
* x

### Additional methods
| Method | Returns | Description |
| ------------- |--------------|--------------|
Expand Down
34 changes: 19 additions & 15 deletions source/SVG.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
L.SVG.include({
_updateShape: function (layer) {
_updateShape: function _updateShape(layer) {

var p = layer._point;
var s = layer._radius;
var shape = layer.options.shape;

if(shape === "diamond"){
var d = "M "+ (p.x-s)+ " "+ (p.y)+ ", L " + (p.x) +" "+ (p.y-s)+ ", L" + (p.x+s) + " " + (p.y)+ ", L" + (p.x) + " " + (p.y+s) +", L" + (p.x-s) + " " + (p.y);
if (shape === "diamond") {
var d = "M " + (p.x - s) + " " + (p.y) + ", L " + (p.x) + " " + (p.y - s) + ", L" + (p.x + s) + " " + (p.y) + ", L" + (p.x) + " " + (p.y + s) + ", L" + (p.x - s) + " " + (p.y);
this._setPath(layer, d);
}
if (shape === "square") {
var d = "M " + (p.x - s) + " " + (p.y - s) + ", L " + (p.x + s) + " " + (p.y - s) + ", L" + (p.x + s) + " " + (p.y + s) + ", L" + (p.x - s) + " " + (p.y + s) + ", L" + (p.x - s) + " " + (p.y - s);
this._setPath(layer, d);
}
if(shape === "square"){
var d = "M "+ (p.x-s)+ " "+ (p.y-s)+ ", L " + (p.x+s) +" "+ (p.y-s)+ ", L" + (p.x+s) + " " + (p.y+s)+ ", L" + (p.x-s) + " " + (p.y+s) +", L" + (p.x-s) + " " + (p.y-s);
if (shape === "triangle" || shape === "triangle-up") {
var d = "M" + (p.x - s) + " " + (p.y + s) + " L" + (p.x) + " " + (p.y - s) + " L" + (p.x + s) + " " + (p.y + s) + " Z";
this._setPath(layer, d);
}
if(shape === "triangle"){
var d = "M"+ (p.x-s)+ " "+ (p.y+s)+ " L" + (p.x) +" "+ (p.y-s)+ " L" + (p.x+s) + " " + (p.y+s)+ " Z";
if (shape === "triangle-down") {
var d = "M" + (p.x - s) + " " + (p.y - s) + " L" + (p.x) + " " + (p.y + s) + " L" + (p.x + s) + " " + (p.y - s) + " Z";
this._setPath(layer, d);
}
if(shape === "circle"){
if (shape === "circle") {
this._updateCircle(layer)
}
if(shape === "x"){
var s = s/2
if (shape === "x") {
s = s / 2;
var d = 'M' + (p.x + s) + ',' + (p.y + s) +
'L' + (p.x - s) + ',' + (p.y - s) +
'M' + (p.x - s) + ',' + (p.y + s) +
'L' + (p.x + s) + ',' + (p.y - s);
'L' + (p.x - s) + ',' + (p.y - s) +
'M' + (p.x - s) + ',' + (p.y + s) +
'L' + (p.x + s) + ',' + (p.y - s);
this._setPath(layer, d);
}
}
})
});
12 changes: 5 additions & 7 deletions source/markerTypes/shapeMarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ L.ShapeMarker = L.Path.extend({

_updateBounds: function () {
var r = this._radius,
r2 = this._radiusY || r,
w = this._clickTolerance(),
p = [r + w, r2 + w];
r2 = this._radiusY || r,
w = this._clickTolerance(),
p = [r + w, r2 + w];
this._pxBounds = new L.Bounds(this._point.subtract(p), this._point.add(p));
},

Expand All @@ -63,7 +63,7 @@ L.ShapeMarker = L.Path.extend({
_empty: function () {
return this._size && !this._renderer._bounds.intersects(this._pxBounds);
},

toGeoJSON: function () {
return L.GeoJSON.getFeature(this, {
type: 'Point',
Expand All @@ -76,8 +76,6 @@ L.ShapeMarker = L.Path.extend({

// @factory L.shapeMarker(latlng: LatLng, options? ShapeMarker options)
//
L.shapeMarker = function (latlng, options) {
L.shapeMarker = function shapeMarker(latlng, options) {
return new L.ShapeMarker(latlng, options);
};


0 comments on commit e160e2a

Please sign in to comment.