leaflet
Version:
JavaScript library for mobile-friendly interactive maps
94 lines (78 loc) • 1.71 kB
JavaScript
/*
* L.Path is the base class for all Leaflet vector layers like polygons and circles.
*/
L.Path = L.Layer.extend({
options: {
stroke: true,
color: '#3388ff',
weight: 3,
opacity: 1,
lineCap: 'round',
lineJoin: 'round',
// dashArray: null
// dashOffset: null
// fill: false
// fillColor: same as color by default
fillOpacity: 0.2,
fillRule: 'evenodd',
// className: ''
interactive: true
},
beforeAdd: function (map) {
// Renderer is set here because we need to call renderer.getEvents
// before this.getEvents.
this._renderer = map.getRenderer(this);
},
onAdd: function () {
this._renderer._initPath(this);
this._reset();
this._renderer._addPath(this);
},
onRemove: function () {
this._renderer._removePath(this);
},
getEvents: function () {
return {
zoomend: this._project,
moveend: this._update,
viewreset: this._reset
};
},
redraw: function () {
if (this._map) {
this._renderer._updatePath(this);
}
return this;
},
setStyle: function (style) {
L.setOptions(this, style);
if (this._renderer) {
this._renderer._updateStyle(this);
}
return this;
},
bringToFront: function () {
if (this._renderer) {
this._renderer._bringToFront(this);
}
return this;
},
bringToBack: function () {
if (this._renderer) {
this._renderer._bringToBack(this);
}
return this;
},
getElement: function () {
return this._path;
},
_reset: function () {
// defined in children classes
this._project();
this._update();
},
_clickTolerance: function () {
// used when doing hit detection for Canvas layers
return (this.options.stroke ? this.options.weight / 2 : 0) + (L.Browser.touch ? 10 : 0);
}
});