diff --git a/README.md b/README.md index b515bbd..080c3c7 100644 --- a/README.md +++ b/README.md @@ -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); ``` diff --git a/example/index.html b/example/index.html index 57cd4db..219db20 100755 --- a/example/index.html +++ b/example/index.html @@ -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], diff --git a/leaflet-polygon.fillPattern.js b/leaflet-polygon.fillPattern.js index c807adc..dde0064 100755 --- a/leaflet-polygon.fillPattern.js +++ b/leaflet-polygon.fillPattern.js @@ -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) { @@ -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); diff --git a/leaflet.d.ts b/leaflet.d.ts new file mode 100644 index 0000000..234d078 --- /dev/null +++ b/leaflet.d.ts @@ -0,0 +1,7 @@ +import { PolylineOptions } from "leaflet"; + +declare module "leaflet" { + interface PolylineOptions { + fillImage?: string | undefined; + } +}