Class OffsetBookmark
- java.lang.Object
-
- org.openstreetmap.josm.data.imagery.OffsetBookmark
-
public class OffsetBookmark extends java.lang.Object
Class to save a displacement of background imagery as a bookmark. Known offset bookmarks will be stored in the preferences and can be restored by the user in later sessions.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.List<OffsetBookmark>
allBookmarks
private double
center_lat
private double
center_lon
private double
dx
private double
dy
private java.lang.String
imagery_id
private java.lang.String
imagery_name
Imagery localized name.private java.lang.String
name
private java.lang.String
projection_code
-
Constructor Summary
Constructors Constructor Description OffsetBookmark()
Construct new empty OffsetBookmark.OffsetBookmark(java.lang.String projectionCode, java.lang.String imageryId, java.lang.String imageryName, java.lang.String name, double dx, double dy)
Create a newOffsetBookmark
object using (0, 0) as centerOffsetBookmark(java.lang.String projectionCode, java.lang.String imageryId, java.lang.String imageryName, java.lang.String name, double dx, double dy, double centerLon, double centerLat)
Create a newOffsetBookmark
by specifying all values.OffsetBookmark(java.lang.String projectionCode, java.lang.String imageryId, java.lang.String imageryName, java.lang.String name, EastNorth displacement, ILatLon center)
Create a newOffsetBookmark
object
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static boolean
addBookmark(OffsetBookmark ob)
Adds a bookmark.static void
bookmarkOffset(java.lang.String name, AbstractTileSourceLayer<?> layer)
Add a bookmark for the displacement of that layerstatic OffsetBookmark
fromPropertiesMap(java.util.Map<java.lang.String,java.lang.String> properties)
Creates an offset bookmark from a properties map.static OffsetBookmark
getBookmarkByIndex(int index)
Returns the bookmark at the given index.static OffsetBookmark
getBookmarkByName(ImageryLayer layer, java.lang.String name)
Gets a bookmark that is usable on the given layer by it's name.static java.util.List<OffsetBookmark>
getBookmarks()
Returns all bookmarks.static int
getBookmarksSize()
Returns the number of bookmarks.LatLon
getCenter()
Get center/reference point of the bookmark.EastNorth
getDisplacement()
Get displacement in EastNorth coordinates of the original projection.EastNorth
getDisplacement(Projection proj)
Get displacement in EastNorth coordinates of a given projection.java.lang.String
getImageryId()
Get the id of the imagery for which this bookmark was created.java.lang.String
getImageryName()
Get the name of the imagery for which this bookmark was created.java.lang.String
getName()
Get the name of this bookmark.java.lang.String
getProjectionCode()
Get the projection code for which this bookmark was created.boolean
hasCenter()
Check if bookmark has a valid center.boolean
isUsable(ImageryLayer layer)
Test if an image is usable for the given imagery layer.static void
loadBookmarks()
Load the global list of bookmarks from preferences.static boolean
removeBookmark(OffsetBookmark ob)
Removes a bookmark.(package private) static void
sanitizeBookmarks(java.util.List<OffsetBookmark> bookmarks)
static void
saveBookmarks()
Stores the bookmarks in the settings.void
setDisplacement(EastNorth displacement)
Update the displacement of this imagery.void
setImageryId(java.lang.String imageryId)
Sets the id of the imageryvoid
setImageryName(java.lang.String imageryName)
Sets the name of the imageryvoid
setName(java.lang.String name)
Set the name of the bookmarkvoid
setProjectionCode(java.lang.String projectionCode)
Set the projection code for which this bookmark was createdjava.util.Map<java.lang.String,java.lang.String>
toPropertiesMap()
Converts the offset bookmark to a properties map.
-
-
-
Field Detail
-
allBookmarks
private static final java.util.List<OffsetBookmark> allBookmarks
-
projection_code
private java.lang.String projection_code
-
imagery_id
private java.lang.String imagery_id
-
imagery_name
private java.lang.String imagery_name
Imagery localized name. Locale insensitiveimagery_id
is preferred.
-
name
private java.lang.String name
-
dx
private double dx
-
dy
private double dy
-
center_lon
private double center_lon
-
center_lat
private double center_lat
-
-
Constructor Detail
-
OffsetBookmark
public OffsetBookmark()
Construct new empty OffsetBookmark. Only used for preferences handling.
-
OffsetBookmark
public OffsetBookmark(java.lang.String projectionCode, java.lang.String imageryId, java.lang.String imageryName, java.lang.String name, double dx, double dy)
Create a newOffsetBookmark
object using (0, 0) as centerThe use of the
OffsetBookmark(String, String, String, String, EastNorth, ILatLon)
constructor is preferred.- Parameters:
projectionCode
- The projection for which this object was createdimageryId
- The id of the imagery on the layer (locale insensitive)imageryName
- The name of the imagery on the layer (locale sensitive)name
- The name of the new bookmarkdx
- The x displacementdy
- The y displacement- Since:
- 13797
-
OffsetBookmark
public OffsetBookmark(java.lang.String projectionCode, java.lang.String imageryId, java.lang.String imageryName, java.lang.String name, EastNorth displacement, ILatLon center)
Create a newOffsetBookmark
object- Parameters:
projectionCode
- The projection for which this object was createdimageryId
- The id of the imagery on the layer (locale insensitive)imageryName
- The name of the imagery on the layer (locale sensitive)name
- The name of the new bookmarkdisplacement
- The displacement in east/north space.center
- The point on earth that was used as reference to align the image.- Since:
- 13797
-
OffsetBookmark
public OffsetBookmark(java.lang.String projectionCode, java.lang.String imageryId, java.lang.String imageryName, java.lang.String name, double dx, double dy, double centerLon, double centerLat)
Create a newOffsetBookmark
by specifying all values.The use of the
OffsetBookmark(String, String, String, String, EastNorth, ILatLon)
constructor is preferred.- Parameters:
projectionCode
- The projection for which this object was createdimageryId
- The id of the imagery on the layer (locale insensitive)imageryName
- The name of the imagery on the layer (locale sensitive)name
- The name of the new bookmarkdx
- The x displacementdy
- The y displacementcenterLon
- The point on earth that was used as reference to align the image.centerLat
- The point on earth that was used as reference to align the image.- Since:
- 13797
-
-
Method Detail
-
isUsable
public boolean isUsable(ImageryLayer layer)
Test if an image is usable for the given imagery layer.- Parameters:
layer
- The layer to use the image at- Returns:
true
if it is usable on the projection of the layer and the imagery name matches.
-
getProjectionCode
public java.lang.String getProjectionCode()
Get the projection code for which this bookmark was created.- Returns:
- The projection.
-
getName
public java.lang.String getName()
Get the name of this bookmark. This name can e.g. be displayed in menus.- Returns:
- The name
-
getImageryId
public java.lang.String getImageryId()
Get the id of the imagery for which this bookmark was created. It is used to match the bookmark to the right layers.- Returns:
- The imagery identifier
- Since:
- 13797
-
getImageryName
public java.lang.String getImageryName()
Get the name of the imagery for which this bookmark was created. It is used to match the bookmark to the right layers if id is missing.- Returns:
- The name
-
getDisplacement
public EastNorth getDisplacement()
Get displacement in EastNorth coordinates of the original projection.- Returns:
- the displacement
- See Also:
getProjectionCode()
-
getDisplacement
public EastNorth getDisplacement(Projection proj)
Get displacement in EastNorth coordinates of a given projection. Displacement will be converted to the given projection, with respect to the center (reference point) of this bookmark.- Parameters:
proj
- the projection- Returns:
- the displacement, converted to that projection
-
getCenter
public LatLon getCenter()
Get center/reference point of the bookmark. Basically this is the place where it was created and is valid. The center may be unrecorded (seehasCenter()
, in which case a dummy center (0,0) will be returned.- Returns:
- the center
-
hasCenter
public boolean hasCenter()
Check if bookmark has a valid center.- Returns:
- true if bookmark has a valid center
-
setProjectionCode
public void setProjectionCode(java.lang.String projectionCode)
Set the projection code for which this bookmark was created- Parameters:
projectionCode
- The projection
-
setName
public void setName(java.lang.String name)
Set the name of the bookmark- Parameters:
name
- The name- See Also:
getName()
-
setImageryName
public void setImageryName(java.lang.String imageryName)
Sets the name of the imagery- Parameters:
imageryName
- The name- See Also:
getImageryName()
-
setImageryId
public void setImageryId(java.lang.String imageryId)
Sets the id of the imagery- Parameters:
imageryId
- The identifier- Since:
- 13797
- See Also:
getImageryId()
-
setDisplacement
public void setDisplacement(EastNorth displacement)
Update the displacement of this imagery.- Parameters:
displacement
- The displacement
-
loadBookmarks
public static void loadBookmarks()
Load the global list of bookmarks from preferences.
-
sanitizeBookmarks
static void sanitizeBookmarks(java.util.List<OffsetBookmark> bookmarks)
-
saveBookmarks
public static void saveBookmarks()
Stores the bookmarks in the settings.
-
getBookmarks
public static java.util.List<OffsetBookmark> getBookmarks()
Returns all bookmarks.- Returns:
- all bookmarks (unmodifiable collection)
- Since:
- 11651
-
getBookmarksSize
public static int getBookmarksSize()
Returns the number of bookmarks.- Returns:
- the number of bookmarks
- Since:
- 11651
-
addBookmark
public static boolean addBookmark(OffsetBookmark ob)
Adds a bookmark.- Parameters:
ob
- bookmark to add- Returns:
true
- Since:
- 11651
-
removeBookmark
public static boolean removeBookmark(OffsetBookmark ob)
Removes a bookmark.- Parameters:
ob
- bookmark to remove- Returns:
true
if this list contained the specified element- Since:
- 11651
-
getBookmarkByIndex
public static OffsetBookmark getBookmarkByIndex(int index)
Returns the bookmark at the given index.- Parameters:
index
- bookmark index- Returns:
- the bookmark at the given index
- Throws:
java.lang.IndexOutOfBoundsException
- if the index is out of range (index < 0 || index >= size()
)- Since:
- 11651
-
getBookmarkByName
public static OffsetBookmark getBookmarkByName(ImageryLayer layer, java.lang.String name)
Gets a bookmark that is usable on the given layer by it's name.- Parameters:
layer
- The layer to use the bookmark atname
- The name of the bookmark- Returns:
- The bookmark if found,
null
if not.
-
bookmarkOffset
public static void bookmarkOffset(java.lang.String name, AbstractTileSourceLayer<?> layer)
Add a bookmark for the displacement of that layer- Parameters:
name
- The bookmark namelayer
- The layer to store the bookmark for
-
toPropertiesMap
public java.util.Map<java.lang.String,java.lang.String> toPropertiesMap()
Converts the offset bookmark to a properties map. The map contains all the information to restore the offset bookmark.- Returns:
- properties map of all data
- Since:
- 12134
- See Also:
fromPropertiesMap(java.util.Map)
-
fromPropertiesMap
public static OffsetBookmark fromPropertiesMap(java.util.Map<java.lang.String,java.lang.String> properties)
Creates an offset bookmark from a properties map.- Parameters:
properties
- the properties map- Returns:
- corresponding offset bookmark
- Since:
- 12134
- See Also:
toPropertiesMap()
-
-