+
+ protected void drawPositionLocation() {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ if (currentPosition == null)
+ return;
+
+ AffineTransform tr = getMapPane().getWorldToScreenTransform();
+ DirectPosition2D geoCoords = new DirectPosition2D(
+ currentPosition.getLocation().getCoordinate().x,
+ currentPosition.getLocation().getCoordinate().y);
+ tr.transform(geoCoords, geoCoords);
+ geoCoords.setCoordinateReferenceSystem(getMapPane()
+ .getMapContext().getCoordinateReferenceSystem());
+
+ final int halfRefSize = 3;
+ Rectangle rect = new Rectangle((int) Math.round(geoCoords
+ .getX()
+ - halfRefSize), (int) Math.round(geoCoords.getY()
+ - halfRefSize), halfRefSize * 2 + 1,
+ halfRefSize * 2 + 1);
+ Graphics2D g2D = (Graphics2D) getMapPane().getGraphics();
+ if (g2D == null)
+ return;
+ g2D.setColor(Color.WHITE);
+ if (positionProviderDisconnected)
+ g2D.setXORMode(Color.ORANGE);
+ else
+ g2D.setXORMode(Color.RED);
+ g2D.drawRect(rect.x, rect.y, rect.width, rect.height);
+ g2D.drawRect(rect.x - 1, rect.y - 1, rect.width + 2,
+ rect.height + 2);
+ }
+ });
+ }
+
+ private class CustomMapPaneListener extends MapPaneAdapter {
+
+ @Override
+ public void onRenderingStopped(MapPaneEvent ev) {
+ drawPositionLocation();
+ }
+
+ @Override
+ public void onDisplayAreaChanged(MapPaneEvent ev) {
+ drawPositionLocation();
+ }
+
+ @Override
+ public void onRenderingProgress(MapPaneEvent ev) {
+ drawPositionLocation();
+ }
+
+ @Override
+ public void onRenderingStarted(MapPaneEvent ev) {
+ drawPositionLocation();
+ }
+
+ @Override
+ public void onResized(MapPaneEvent ev) {
+ drawPositionLocation();
+ }
+
+ }