L.Label: honour opacity option

This commit is contained in:
Yohan Boniface 2015-11-15 19:15:14 +01:00
parent 9d0b13b991
commit d8b7f6fcbe
3 changed files with 17 additions and 1 deletions

View File

@ -52,7 +52,7 @@
var group = new L.FeatureGroup([marker1, marker2]).addTo(map);
group.bindLabel(function (layer) {
return 'Group label: ' + layer.options.description;
});
}, {opacity: 0.7});
</script>
</body>

View File

@ -74,6 +74,20 @@ describe('Label', function () {
expect(spy.calledOnce).to.be(true);
});
it("honours opacity option", function () {
var layer = new L.Marker(center).addTo(map);
layer.bindLabel('Label', {static: true, opacity: 0.57});
expect(layer._label._container.style.opacity).to.eql(0.57);
});
it("can change opacity with setOpacity", function () {
var layer = new L.Marker(center).addTo(map);
layer.bindLabel('Label', {static: true});
expect(layer._label._container.style.opacity).to.eql(1);
layer._label.setOpacity(0.57);
expect(layer._label._container.style.opacity).to.eql(0.57);
});
it("it should use a label with a function as content with a FeatureGroup", function () {
var marker1 = new L.Marker(new L.LatLng(55.8, 37.6), {description: "I'm marker 1."});
var marker2 = new L.Marker(new L.LatLng(54.6, 38.2), {description: "I'm marker 2."});

View File

@ -11,12 +11,14 @@ L.Label = L.PopupBase.extend({
static: false, // Reserved word, use "permanent" instead?
followMouse: false,
clickable: false,
opacity: 1,
// className: '',
zoomAnimation: true
},
onAdd: function (map) {
L.PopupBase.prototype.onAdd.call(this, map);
this.setOpacity(this.options.opacity);
map.fire('labelopen', {popup: this});