public MapView addLabel ( final MapLabel mapLabel ) { if ( ! getInitialized ( ) ) { if ( logger . isWarnEnabled ( ) ) { logger . warn ( MAP_VIEW_NOT_YET_INITIALIZED ) ; } } else { if ( null == requireNonNull ( mapLabel ) . getPosition ( ) ) { if ( logger . isDebugEnabled ( ) ) { logger . debug ( "label with no position was not added: {}" , mapLabel ) ; } return this ; } final String id = mapLabel . getId ( ) ; // synchronize on the mapCoordinateElements map as the cleaning thread accesses this as well synchronized ( mapCoordinateElements ) { // if the label is attached to a Marker, only add it when the marker is already added to the MapView if ( mapLabel . getMarker ( ) . isPresent ( ) && ! mapCoordinateElements . containsKey ( mapLabel . getMarker ( ) . get ( ) . getId ( ) ) ) { return this ; } if ( ! mapCoordinateElements . containsKey ( id ) ) { addMapCoordinateElement ( mapLabel ) ; jsMapView . call ( "addLabel" , id , mapLabel . getText ( ) , mapLabel . getCssClass ( ) , mapLabel . getPosition ( ) . getLatitude ( ) , mapLabel . getPosition ( ) . getLongitude ( ) , mapLabel . getOffsetX ( ) , mapLabel . getOffsetY ( ) ) ; if ( logger . isTraceEnabled ( ) ) { logger . trace ( "add label in OpenLayers map {}" , mapLabel ) ; } setMarkerVisibleInMap ( id ) ; } } } return this ; }
adds a label to the map . If it was already added nothing is changed . If the MapView is not yet initialized a warning is logged and nothing changes . If the label has no coordinate set it is not added and a logging entry is written .