public MapView addMarker ( final Marker marker ) { if ( ! getInitialized ( ) ) { if ( logger . isWarnEnabled ( ) ) { logger . warn ( MAP_VIEW_NOT_YET_INITIALIZED ) ; } } else { if ( null == requireNonNull ( marker ) . getPosition ( ) ) { if ( logger . isTraceEnabled ( ) ) { logger . trace ( "marker with no position was not added: {}" , marker ) ; } return this ; } final String id = marker . getId ( ) ; // synchronize on the mapCoordinateElements map as the cleaning thread accesses this as well synchronized ( mapCoordinateElements ) { if ( ! mapCoordinateElements . containsKey ( id ) ) { addMapCoordinateElement ( marker ) ; jsMapView . call ( "addMarker" , id , marker . getImageURL ( ) . toExternalForm ( ) , marker . getPosition ( ) . getLatitude ( ) , marker . getPosition ( ) . getLongitude ( ) , marker . getOffsetX ( ) , marker . getOffsetY ( ) ) ; if ( logger . isTraceEnabled ( ) ) { logger . trace ( "add marker in OpenLayers map {}" , marker ) ; } setMarkerVisibleInMap ( id ) ; } } marker . getMapLabel ( ) . ifPresent ( this :: addLabel ) ; } return this ; }
adds a marker 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 marker has no coordinate set it is not added and a logging entry is written .