11import { merge , getLineUid } from '../util'
22import Line from '../components/line'
33
4- export default function createLines ( lines , markers , isRecentlyCreated = false ) {
4+ const LINES_GROUP_CLASS = 'jvm-lines-group'
5+
6+ export default function createLines ( lines , isRecentlyCreated = false ) {
7+ // Create group for holding lines we're checking if `linesGroup`
8+ // exists or not becuase we may add lines after the map has
9+ // loaded so we will append the futured lines to this group as well.
10+ this . linesGroup = this . linesGroup || this . canvas . createGroup ( LINES_GROUP_CLASS )
11+
12+ const markers = this . params . markers || { }
13+ const { style, elements : _ , ...rest } = this . params . lines
14+
515 let point1 = false , point2 = false
616
7- // Create group for holding lines
8- // we're checking if `linesGroup` exists or not becuase we may add lines
9- // after the map has loaded so we will append the futured lines to this group as well.
10- this . linesGroup = this . linesGroup || this . canvas . createGroup ( 'jvm-lines-group' )
11-
1217 for ( let index in lines ) {
1318 const config = lines [ index ]
1419
1520 for ( let mindex in markers ) {
16- const markerConfig = isRecentlyCreated ? markers [ mindex ] . config : markers [ mindex ]
21+ const markerConfig = isRecentlyCreated
22+ ? markers [ mindex ] . config
23+ : markers [ mindex ]
1724
1825 if ( markerConfig . name === config . from ) {
1926 point1 = this . getMarkerPosition ( markerConfig )
@@ -25,19 +32,23 @@ export default function createLines(lines, markers, isRecentlyCreated = false) {
2532 }
2633
2734 if ( point1 !== false && point2 !== false ) {
28- // Register lines with unique keys
29- this . _lines [ getLineUid ( config . from , config . to ) ] = new Line ( {
30- index : index ,
35+ const options = {
36+ index,
3137 map : this ,
32- // Merge the default `lineStyle` object with the custom `line` config style
33- style : merge ( { initial : this . params . lineStyle } , { initial : config . style || { } } , true ) ,
38+ group : this . linesGroup ,
39+ config,
3440 x1 : point1 . x ,
3541 y1 : point1 . y ,
3642 x2 : point2 . x ,
3743 y2 : point2 . y ,
38- group : this . linesGroup ,
39- config
40- } )
44+ ...rest ,
45+ }
46+
47+ // Register lines with unique keys
48+ this . _lines [ getLineUid ( config . from , config . to ) ] = new Line (
49+ options ,
50+ merge ( { initial : style } , { initial : config . style || { } } , true )
51+ )
4152 }
4253 }
4354}
0 commit comments