remove shadowOffset, add shadowAnchor

This commit is contained in:
mourner 2012-07-20 21:14:24 +03:00
parent b30df4a0fd
commit 0cadad7a1d
2 changed files with 11 additions and 9 deletions

View File

@ -52,7 +52,7 @@ Icon API was improved to be more flexible, but one of the changes is backwards-i
* Converted `Icon` properties to options, changed constructor signature to `Icon(options)`. * Converted `Icon` properties to options, changed constructor signature to `Icon(options)`.
* Moved default marker icon options to `L.Icon.Default` class (which extends from `L.Icon`). * Moved default marker icon options to `L.Icon.Default` class (which extends from `L.Icon`).
* Added `Icon` `className` option to assign a custom class to an icon. * Added `Icon` `className` option to assign a custom class to an icon.
* Added `Icon` `shadowOffset` option to set the position of shadow relative to the icon. * Added `Icon` `shadowAnchor` option to set the anchor of the shadow.
* Made all `Icon` options except `iconUrl` optional (if not specified, they'll be chosen automatically or implemented using CSS). Anchor is centered by default (if size is specified), and otherwise can be set through CSS using negative margins. * Made all `Icon` options except `iconUrl` optional (if not specified, they'll be chosen automatically or implemented using CSS). Anchor is centered by default (if size is specified), and otherwise can be set through CSS using negative margins.
#### Other breaking API changes #### Other breaking API changes
@ -95,7 +95,7 @@ Icon API was improved to be more flexible, but one of the changes is backwards-i
* Made controls implementation easier (now more magic happens under the hood). * Made controls implementation easier (now more magic happens under the hood).
* Added `LatLngBounds` `pad` method that returns bounds extended by a percentage (by [@jacobtoye](https://github.com/jacobtoye)). [#492](https://github.com/CloudMade/Leaflet/pull/492) * Added `LatLngBounds` `pad` method that returns bounds extended by a percentage (by [@jacobtoye](https://github.com/jacobtoye)). [#492](https://github.com/CloudMade/Leaflet/pull/492)
* Moved dragging cursor styles from JS code to CSS. * Moved dragging cursor styles from JS code to CSS.
### Bug fixes ### Bug fixes
#### General bugfixes #### General bugfixes

View File

@ -7,6 +7,7 @@ L.Icon = L.Class.extend({
popupAnchor: (Point) (if not specified, popup opens in the anchor point) popupAnchor: (Point) (if not specified, popup opens in the anchor point)
shadowUrl: (Point) (no shadow by default) shadowUrl: (Point) (no shadow by default)
shadowSize: (Point) shadowSize: (Point)
shadowAnchor: (Point)
*/ */
className: '' className: ''
}, },
@ -42,17 +43,18 @@ L.Icon = L.Class.extend({
_setIconStyles: function (img, name) { _setIconStyles: function (img, name) {
var options = this.options, var options = this.options,
size = L.point(options[name + 'Size']), size = L.point(options[name + 'Size']),
anchor = L.point(options.iconAnchor), anchor;
offset = L.point(options.shadowOffset);
if (name === 'shadow') {
anchor = L.point(options.shadowAnchor || options.iconAnchor);
} else {
anchor = L.point(options.iconAnchor);
}
if (!anchor && size) { if (!anchor && size) {
anchor = size.divideBy(2, true); anchor = size.divideBy(2, true);
} }
if (name === 'shadow' && anchor && offset) {
anchor = anchor.add(offset);
}
img.className = 'leaflet-marker-' + name + ' ' + options.className; img.className = 'leaflet-marker-' + name + ' ' + options.className;
if (anchor) { if (anchor) {
@ -131,4 +133,4 @@ L.Icon.Default.imagePath = (function () {
return src.split(leafletRe)[0] + '/images'; return src.split(leafletRe)[0] + '/images';
} }
} }
}()); }());