Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ var poly1 = [
[24.5, 121.9],
[24, 121.9]
];
L.polygon(poly1, {fill:'url(image.gif)'}).addTo(map);
L.polygon(poly1, {fillImage:'url(image.gif)'}).addTo(map);
```
2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
[24.5, 121.9],
[24, 121.9]
];
L.polygon(poly1, {fill:'url(image.gif)'}).addTo(map);
L.polygon(poly1, {fillImage:'url(image.gif)'}).addTo(map);

var poly2 = [
[24, 120],
Expand Down
24 changes: 10 additions & 14 deletions leaflet-polygon.fillPattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,16 @@ if (L.Browser.svg) {
path.setAttribute('stroke', 'none');
}

if (options.fill) {
if (typeof(options.fill) == "string" &&
options.fill.match(/^url\(/)) {
// here what we add
this.__fillPattern(layer);
}
else {
path.setAttribute('fill', options.fillColor || options.color);
}
path.setAttribute('fill-opacity', options.fillOpacity);
path.setAttribute('fill-rule', options.fillRule || 'evenodd');
} else {
path.setAttribute('fill', 'none');
if (options.fillImage && typeof(options.fillImage) == "string" &&
options.fillImage.match(/^url\(/)) {
// here what we add
this.__fillPattern(layer);
}
else {
path.setAttribute('fill', options.fillColor || options.color);
}
path.setAttribute('fill-opacity', options.fillOpacity);
path.setAttribute('fill-rule', options.fillRule || 'evenodd');
},

__fillPattern: function(layer) {
Expand All @@ -61,7 +57,7 @@ if (L.Browser.svg) {
this._defs = L.SVG.create('defs');
this._container.appendChild(this._defs);
}
var _img_url = options.fill.substring(4, options.fill.length-1);
var _img_url = options.fillImage.substring(4, options.fillImage.length-1);
var _ref_id = _img_url + (Math.random() * Math.pow(10, 17) + Math.random() * Math.pow(10, 17));
_ref_id += new Date().getUTCMilliseconds();
var _p = document.getElementById(_ref_id);
Expand Down
7 changes: 7 additions & 0 deletions leaflet.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { PolylineOptions } from "leaflet";

declare module "leaflet" {
interface PolylineOptions {
fillImage?: string | undefined;
}
}