Commit Graph

24 Commits

Author SHA1 Message Date
Dave Leaver
27263b7afa Control.Layers: Only add layer events to layers when we are on the map. Fixes #5421 (#5422) 2017-03-28 23:10:29 +02:00
ghybs
9e4f79d1e5 Fix(#5328): Layers Control can now become scrollable even if collapsed: false (#5348)
* Fix(#5328): Layers Control scrollable even if collapsed: false

the `expand()` method was called only when expanding the Layers Control through user action.
In the case of option `collapsed: false`, no event listener is attached (no user action expected to expand), therefore the control height is no longer adjusted compared to map container's height, whereas the only time it is done is at initialization, when the control is not yet inserted into the DOM, hence it does not have an actual height to check against.
Therefore added a hook on `addTo()` in order to run `expand()` AFTER the control has been insterted into the DOM.
The same issue happens when later adding more base layers / overlays to the Layers Control: it not collapsed, we should run again the height check (e.g. through the `expand()` method) to make sure we make it scrollable if necessary.
Therefore called `expand()` after each `_addLayer()`.
Actually checking first if the control is on map and if option `collapsed: false` in order to prevent calling `expand()` for nothing.

* Test(ControlLayers): 2 tests for collapsed: false being scrollable

(for issue #5328).
CAUTION: unlike most other tests, had to actually insert the map container into the DOM (i.e. `document.body`) for these tests to be useful, otherwise the height remains at 0.
This may lead to memory leak and tests hanging if done on too many tests (see Leaflet.markercluster tests issue, e.g. https://github.com/Leaflet/Leaflet.markercluster/pull/577)
2017-02-21 14:33:01 +01:00
Per Liedman
2253672051 Only collapse layer control if collapsed: true (#5131)
Close #5126
2016-11-23 10:49:59 +01:00
Iván Sánchez Ortega
4e979514c3 Add a 'sortLayers' option to L.Control.Layers (#4711)
* Add a 'sortLayers' option to L.Control.Layers

* Add a sortFunction option to L.Control.Layers

* Fix default sort function; modify test
2016-11-17 12:52:29 +01:00
Per Liedman
a656a0b9ec Add unit test 2016-11-11 15:54:05 +01:00
Jan Pieter Waagmeester
02078c2b39 Make sure L.Control.removeLayer() doesn't raise an error if a layer not in the control is removed from it (#4487) 2016-04-22 16:11:22 +02:00
Jan Pieter Waagmeester
0bed05d537 Use array in L.Control.Layers to preserve layer order fixes #2086 2016-04-02 20:48:31 +02:00
Daniel Ritz
0af11b064e Fix attribution text not removed when Layer is removed from map
Symptom: Switching between layers with different attributions does
not remove the attribution from the previously selected layer.

Control.Attribution keeps track of its attributions with a counter for
each text. The problem described in #4285 is that each time the layer
is added to the map, the counter is increased by two. It's because
Layer calls Control.Attribution.addAttribution() twice, once from
addLayer() and the second time via the whenReady() callback _layerAdd().
This was not caught by the tests since the callback was never fired
(missing map.setView() call).

Fixes #4285
2016-03-01 13:46:40 +01:00
Iván Sánchez Ortega
663978227d Unit tests for #4257, attributionControl layeradd/layerremove 2016-02-18 21:31:00 +01:00
Iván Sánchez Ortega
63970e9b6c Better cleanup of L.Control.Layers, fixes #4213 (plus unit tests) 2016-02-09 15:43:03 +01:00
Vladimir Agafonkin
cfdbd10431 enforce indentation in specs 2015-09-25 13:55:37 +03:00
Yohan Boniface
08674721bc Fix baselayerchange event argument (fix #3677) 2015-07-27 15:41:07 +02:00
John Firebaugh
87c7d1d563 No-op Control#remove if not on a map (fixes #2877) 2014-11-13 11:25:49 -08:00
John Firebaugh
0b86fa3266 Remove control from existing map in onAdd (fixes #3020) 2014-11-13 10:49:43 -08:00
Vladimir Agafonkin
91c039b7aa jshinting and major clean up of specs code, ref #2151 2013-11-07 23:54:33 +02:00
Tom MacWright
a2f7d7e834 Use mocha 2013-04-03 14:50:09 -07:00
John Firebaugh
01332ebead Omit "should" in spec descriptions
The rationale is this: the spec string describes the expected
behavior unconditionally. The code examples, on the other hand,
set up an expectation that is tested with the call to the expect
method. The code examples can violate the expectation, but the
spec string does not. The value of the spec string is as clearly
as possible describing the behavior. Including “should” in that
description adds no value. (From http://rubyspec.org/style_guide/)
2013-02-19 12:41:48 -08:00
Tom MacWright
0a2000166a Fix semicolons, breaking, whitespace, duplicate var statements. 2013-02-19 11:18:15 -05:00
Vladimir Agafonkin
5d41efe616 fix removeAttrubution, cover the control with tests, close #1410 2013-02-19 17:47:38 +02:00
Vladimir Agafonkin
0c5f401220 Merge pull request #1159 from moonlite/master
First stab at a fix for Issue 623
2012-11-29 06:44:25 -08:00
Tom Hughes
0b2a31c1fe Update the Layers control when layers are added or removed 2012-11-24 00:33:57 +00:00
Mattias Bengtsson
c0135a219d Added a bunch of tests and fixed some bugs those exposed.
Also don't try to automatically adjust zoom. Leave that to the
layer control for now and wait for a setBaseLayer / switchLayer
or something instead.
2012-11-19 04:36:13 +01:00
John Firebaugh
0b4d2b0c44 Add Map#whenReady
Fixes #1063
2012-10-12 12:54:13 -07:00
John Firebaugh
5ee7113fe4 Add a baselayerchange event 2012-10-12 12:19:21 -07:00