File tree Expand file tree Collapse file tree 2 files changed +23
-8
lines changed Expand file tree Collapse file tree 2 files changed +23
-8
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,12 @@ iD.BackgroundSource = function(data) {
27
27
return best ;
28
28
} ;
29
29
30
+ source . area = function ( ) {
31
+ if ( ! data . polygon ) return Number . MAX_VALUE ; // worldwide
32
+ var area = d3 . geo . area ( { type : 'MultiPolygon' , coordinates : [ data . polygon ] } ) ;
33
+ return isNaN ( area ) ? 0 : area ;
34
+ } ;
35
+
30
36
source . imageryUsed = function ( ) {
31
37
return source . id || name ;
32
38
} ;
@@ -133,6 +139,10 @@ iD.BackgroundSource.None = function() {
133
139
return 'None' ;
134
140
} ;
135
141
142
+ source . area = function ( ) {
143
+ return - 1 ;
144
+ } ;
145
+
136
146
return source ;
137
147
} ;
138
148
@@ -147,5 +157,9 @@ iD.BackgroundSource.Custom = function(template) {
147
157
return 'Custom (' + template + ')' ;
148
158
} ;
149
159
160
+ source . area = function ( ) {
161
+ return - 2 ;
162
+ } ;
163
+
150
164
return source ;
151
165
} ;
Original file line number Diff line number Diff line change @@ -13,14 +13,13 @@ iD.ui.Background = function(context) {
13
13
// Can be 0 from <1.3.0 use or due to issue #1923.
14
14
if ( opacityDefault === 0 ) opacityDefault = 1.0 ;
15
15
16
+
16
17
function background ( selection ) {
17
18
18
19
function sortSources ( a , b ) {
19
- return a . best ( ) ? - 1
20
- : b . best ( ) ? 1
21
- : a . id === 'none' ? 1
22
- : b . id === 'none' ? - 1
23
- : d3 . ascending ( a , b ) ;
20
+ return a . best ( ) && ! b . best ( ) ? - 1
21
+ : b . best ( ) && ! a . best ( ) ? 1
22
+ : d3 . descending ( a . area ( ) , b . area ( ) ) || d3 . ascending ( a . name ( ) , b . name ( ) ) || 0 ;
24
23
}
25
24
26
25
function setOpacity ( d ) {
@@ -87,8 +86,7 @@ iD.ui.Background = function(context) {
87
86
. filter ( filter ) ;
88
87
89
88
var layerLinks = layerList . selectAll ( 'li.layer' )
90
- . data ( sources , function ( d ) { return d . name ( ) ; } )
91
- . sort ( sortSources ) ;
89
+ . data ( sources , function ( d ) { return d . name ( ) ; } ) ;
92
90
93
91
var enter = layerLinks . enter ( )
94
92
. insert ( 'li' , '.custom_layer' )
@@ -120,10 +118,13 @@ iD.ui.Background = function(context) {
120
118
label . append ( 'span' )
121
119
. text ( function ( d ) { return d . name ( ) ; } ) ;
122
120
121
+
123
122
layerLinks . exit ( )
124
123
. remove ( ) ;
125
124
126
- layerList . style ( 'display' , layerList . selectAll ( 'li.layer' ) . data ( ) . length > 0 ? 'block' : 'none' ) ;
125
+ layerList . selectAll ( 'li.layer' )
126
+ . sort ( sortSources )
127
+ . style ( 'display' , layerList . selectAll ( 'li.layer' ) . data ( ) . length > 0 ? 'block' : 'none' ) ;
127
128
}
128
129
129
130
function update ( ) {
You can’t perform that action at this time.
0 commit comments