@@ -783,6 +783,9 @@ $(window).on('load', function() {
783
783
* Adds polylines to the map
784
784
*/
785
785
function processPolylines ( p ) {
786
+
787
+ var lines = Array ( p . length ) ; // array to keep track of loaded geojson polylines
788
+
786
789
if ( ! p || p . length == 0 ) return ;
787
790
788
791
var pos = ( getSetting ( '_polylinesLegendPos' ) == 'off' )
@@ -814,20 +817,19 @@ $(window).on('load', function() {
814
817
}
815
818
}
816
819
817
- line = L . polyline ( latlng , {
820
+ var line = L . polyline ( latlng , {
818
821
color : ( p [ index ] [ 'Color' ] == '' ) ? 'grey' : p [ index ] [ 'Color' ] ,
819
822
weight : trySetting ( '_polylinesWeight' , 2 ) ,
820
823
pane : 'shadowPane'
821
- } ) . addTo ( map ) ;
824
+ } )
825
+
826
+ lines [ index ] = line ;
827
+ line . addTo ( map ) ;
822
828
823
829
if ( p [ index ] [ 'Description' ] && p [ index ] [ 'Description' ] != '' ) {
824
830
line . bindPopup ( p [ index ] [ 'Description' ] ) ;
825
831
}
826
832
827
- polylinesLegend . addOverlay ( line ,
828
- '<i class="color-line" style="background-color:' + p [ index ] [ 'Color' ]
829
- + '"></i> ' + p [ index ] [ 'Display Name' ] ) ;
830
-
831
833
if ( index == 0 ) {
832
834
if ( polylinesLegend . _container ) {
833
835
polylinesLegend . _container . id = 'polylines-legend' ;
@@ -850,8 +852,15 @@ $(window).on('load', function() {
850
852
}
851
853
}
852
854
853
- if ( p . length == index + 1 ) {
855
+ if ( lines . filter ( Boolean ) . length == p . length ) { // only if all polylines loaded
854
856
completePolylines = true ;
857
+
858
+ // Add polylines to the legend - we do this after all lines are loaded
859
+ for ( let j = 0 ; j < p . length ; j ++ ) {
860
+ polylinesLegend . addOverlay ( lines [ j ] ,
861
+ '<i class="color-line" style="background-color:' + p [ j ] [ 'Color' ]
862
+ + '"></i> ' + p [ j ] [ 'Display Name' ] ) ;
863
+ }
855
864
}
856
865
} ;
857
866
} ( i ) ) ;
0 commit comments