public class JXMapViewer extends JPanel implements DesignMode
GeoPosition
. The centerPosition property represents
the current center point of the map. If the user pans the map then the centerPosition point will
change but the addressLocation will not. Calling recenterToAddressLocation() will move the map
back to that center address. The center property represents the same point as the centerPosition
property, but as a Point2D in pixel space instead of a GeoPosition in lat/long space. Note that
the center property is a Point2D in the entire world bitmap, not in the portion of the map currently
visible. You can use the getViewportBounds() method to find the portion of the map currently visible
and adjust your calculations accordingly. Changing the center property will change the centerPosition
property and vice versa. All three properties are bound.SLMapServerInfo
,
Serialized FormJPanel.AccessibleJPanel
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
PROPERTYNAME
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
JXMapViewer()
Create a new JXMapViewer.
|
Modifier and Type | Method and Description |
---|---|
void |
calculateZoomFrom(Set<GeoPosition> positions)
Calculates a zoom level so that all points in the specified set will be visible on screen.
|
Point2D |
convertGeoPositionToPoint(GeoPosition pos)
Converts the specified GeoPosition to a point in the JXMapViewer's local coordinate space.
|
GeoPosition |
convertPointToGeoPosition(Point2D pt)
Converts the specified Point2D in the JXMapViewer's local coordinate space to a GeoPosition on the map.
|
protected void |
drawMapTiles(Graphics g,
int zoom,
Rectangle viewportBounds)
Draw the map tiles.
|
GeoPosition |
getAddressLocation()
Gets the current address location of the map.
|
Point2D |
getCenter()
Gets the current pixel center of the map.
|
GeoPosition |
getCenterPosition()
A property indicating the center position of the map
|
Image |
getLoadingImage()
A property for an image which will be display when an image is still loading.
|
Painter<? super JXMapViewer> |
getOverlayPainter()
Gets the current map overlay
|
TileFactory |
getTileFactory()
Get the current factory
|
Rectangle |
getViewportBounds()
Returns the bounds of the viewport in pixels.
|
int |
getZoom()
Gets the current zoom level
|
boolean |
isDesignTime()
Indicates whether the component is being used at design time, such as in a visual editor like NetBeans' Matisse
|
boolean |
isDrawTileBorders()
Indicates if the tile borders should be drawn.
|
boolean |
isHorizontalWrapped() |
boolean |
isNegativeYAllowed() |
boolean |
isRestrictOutsidePanning() |
protected void |
paintComponent(Graphics g) |
void |
recenterToAddressLocation()
Re-centers the map to have the current address location be at the center of the map, accounting for the map's
width and height.
|
void |
setAddressLocation(GeoPosition addressLocation)
Gets the current address location of the map
|
void |
setCenter(Point2D center)
Sets the new center of the map in pixel coordinates.
|
void |
setCenterPosition(GeoPosition geoPosition)
A property indicating the center position of the map
|
void |
setDesignTime(boolean b)
Indicate that the component is being used at design time, such as in a visual editor like NetBeans' Matisse
|
void |
setDrawTileBorders(boolean drawTileBorders)
Set if the tile borders should be drawn.
|
void |
setHorizontalWrapped(boolean horizontalWrapped) |
void |
setLoadingImage(Image loadingImage)
A property for an image which will be display when an image is still loading.
|
void |
setOverlayPainter(Painter<? super JXMapViewer> overlay)
Sets the map overlay.
|
void |
setRestrictOutsidePanning(boolean restrictOutsidePanning) |
void |
setTileFactory(TileFactory factory)
Set the current tile factory (must not be
null ) |
void |
setZoom(int zoom)
Set the current zoom level
|
void |
zoomToBestFit(Set<GeoPosition> positions,
double maxFraction)
Zoom and center the map to a best fit around the input GeoPositions.
|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public JXMapViewer()
protected void paintComponent(Graphics g)
paintComponent
in class JComponent
public void setDesignTime(boolean b)
setDesignTime
in interface DesignMode
b
- indicates if the component is being used at design timepublic boolean isDesignTime()
isDesignTime
in interface DesignMode
protected void drawMapTiles(Graphics g, int zoom, Rectangle viewportBounds)
g
- Graphicszoom
- zoom level to draw atviewportBounds
- the bounds to draw withinpublic void setOverlayPainter(Painter<? super JXMapViewer> overlay)
overlay
- the map overlay to usepublic Painter<? super JXMapViewer> getOverlayPainter()
public Rectangle getViewportBounds()
public void setZoom(int zoom)
zoom
- the new zoom levelpublic int getZoom()
public GeoPosition getAddressLocation()
public void setAddressLocation(GeoPosition addressLocation)
addressLocation
- the new address locationpublic void recenterToAddressLocation()
public boolean isDrawTileBorders()
public void setDrawTileBorders(boolean drawTileBorders)
drawTileBorders
- new value of this drawTileBorderspublic void setCenterPosition(GeoPosition geoPosition)
geoPosition
- the new property valuepublic GeoPosition getCenterPosition()
public TileFactory getTileFactory()
public void setTileFactory(TileFactory factory)
null
)factory
- the new property valuepublic Image getLoadingImage()
public void setLoadingImage(Image loadingImage)
loadingImage
- the new property valuepublic Point2D getCenter()
public void setCenter(Point2D center)
center
- the new center of the map in pixel coordinatespublic void calculateZoomFrom(Set<GeoPosition> positions)
positions
- A set of GeoPositions to calculate the new zoom frompublic void zoomToBestFit(Set<GeoPosition> positions, double maxFraction)
positions
- A set of GeoPositions to calculate the new zoom frommaxFraction
- the maximum fraction of the viewport that should be coveredpublic boolean isRestrictOutsidePanning()
public void setRestrictOutsidePanning(boolean restrictOutsidePanning)
restrictOutsidePanning
- set if panning is restricted or notpublic boolean isHorizontalWrapped()
public void setHorizontalWrapped(boolean horizontalWrapped)
horizontalWrapped
- true if horizontal wrap is enabledpublic Point2D convertGeoPositionToPoint(GeoPosition pos)
pos
- a GeoPosition on the mappublic GeoPosition convertPointToGeoPosition(Point2D pt)
pt
- a point in the local coordinate space of the mappublic boolean isNegativeYAllowed()
Copyright © 2013. All Rights Reserved.