public MapView addCoordinateLine ( final CoordinateLine coordinateLine ) { if ( ! getInitialized ( ) ) { if ( logger . isWarnEnabled ( ) ) { logger . warn ( MAP_VIEW_NOT_YET_INITIALIZED ) ; } } else { // sync on the coordinatesLines map as the cleaner thread accesses this as well synchronized ( coordinateLines ) { final String id = requireNonNull ( coordinateLine ) . getId ( ) ; if ( ! coordinateLines . containsKey ( id ) ) { if ( logger . isDebugEnabled ( ) ) { logger . debug ( "adding coordinate line {}" , coordinateLine ) ; } final JSObject jsCoordinateLine = ( JSObject ) jsMapView . call ( "getCoordinateLine" , id ) ; coordinateLine . getCoordinateStream ( ) . forEach ( ( coord ) - > jsCoordinateLine . call ( "addCoordinate" , coord . getLatitude ( ) , coord . getLongitude ( ) ) ) ; final javafx . scene . paint . Color color = coordinateLine . getColor ( ) ; jsCoordinateLine . call ( "setColor" , color . getRed ( ) * 255 , color . getGreen ( ) * 255 , color . getBlue ( ) * 255 , color . getOpacity ( ) ) ; final javafx . scene . paint . Color fillColor = coordinateLine . getFillColor ( ) ; jsCoordinateLine . call ( "setFillColor" , fillColor . getRed ( ) * 255 , fillColor . getGreen ( ) * 255 , fillColor . getBlue ( ) * 255 , fillColor . getOpacity ( ) ) ; jsCoordinateLine . call ( "setWidth" , coordinateLine . getWidth ( ) ) ; jsCoordinateLine . call ( "setClosed" , coordinateLine . isClosed ( ) ) ; jsCoordinateLine . call ( "seal" ) ; final ChangeListener < Boolean > changeListener = ( observable , newValue , oldValue ) -> setCoordinateLineVisibleInMap ( id ) ; coordinateLine . visibleProperty ( ) . addListener ( changeListener ) ; // store the listener as we must unregister on removeCooridnateLine coordinateLineListeners . put ( id , new CoordinateLineListener ( changeListener ) ) ; // store a weak reference to be able to remove the line from the map if the caller forgets to do so coordinateLines . put ( id , new WeakReference <> ( coordinateLine , weakReferenceQueue ) ) ; setCoordinateLineVisibleInMap ( id ) ; } } } return this ; }
add a CoordinateLine to the map . If it was already added nothing happens . The MapView only stores a weak reference to the object so the caller must keep a reference in order to prevent the line to be removed from the map . This method must only be called after the map is initialized otherwise a warning is logged and the coordinateLine is not added to the map .