Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ bin
*.jar
*.war
*.ear

# IntelliJ idea files
.idea/
*.iml
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@ mappanel
========

MapPanel renders OpenstreetMaps using just basic java. Rendering is done from a tileserver and uses some multithreaded tile loading, caching and zooming. Free for everyone to build his own stuff on.

Marking places on the map
=========================
The class `com.roots.map.overlay.OverlayDemo` demonstrates how to mark places, identiefied by latitude and
longitude on the map.

`com.roots.map.overlay.DemoGlassPane` is setup to display marks at two cities - Artyom, Russia and Cologne, Germany.
3 changes: 2 additions & 1 deletion src/com/roots/map/MapPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
import javax.swing.text.html.StyleSheet;
import javax.xml.parsers.SAXParserFactory;

import com.roots.map.overlay.ILatLongToScreenCoordinatesConverter;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
Expand Down Expand Up @@ -129,7 +130,7 @@
* @author stepan.rutz
* @version $Revision$
*/
public class MapPanel extends JPanel {
public class MapPanel extends JPanel implements ILatLongToScreenCoordinatesConverter {

private static final Logger log = Logger.getLogger(MapPanel.class.getName());

Expand Down
18 changes: 18 additions & 0 deletions src/com/roots/map/overlay/DemoGlassPane.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.roots.map.overlay;

import java.awt.*;
import java.awt.geom.Point2D;

public class DemoGlassPane extends PointSetMarkingGlassPane {

public static final Point2D.Double ARTYOM = new Point.Double(132.18381, 43.35514);

public static final Point2D.Double COLOGNE = new Point.Double(6.96202, 50.93575);

public DemoGlassPane(ILatLongToScreenCoordinatesConverter latitudeLongitudeToScreenCoordinatesConverter) {
super(latitudeLongitudeToScreenCoordinatesConverter);

addPointToMark(ARTYOM);
addPointToMark(COLOGNE);
}
}
5 changes: 5 additions & 0 deletions src/com/roots/map/overlay/IGlassPane.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.roots.map.overlay;

public interface IGlassPane {
void repaint();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.roots.map.overlay;

import java.awt.*;

public interface ILatLongToScreenCoordinatesConverter {
Point getScreenCoordinates(Point.Double coords);
}
32 changes: 32 additions & 0 deletions src/com/roots/map/overlay/OverlayDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.roots.map.overlay;

import com.roots.map.MapPanel;

import javax.swing.*;
import java.awt.*;

public class OverlayDemo {
public void run()
{
final JFrame mainFrame = new JFrame("MapPanel with place marks");
final MapPanel mapPanel = new MapPanel(new Point(3636598, 1535138), 14);
mainFrame.add(mapPanel);

final DemoGlassPane glassPane = new DemoGlassPane(mapPanel);

mainFrame.setGlassPane(glassPane);

mainFrame.getGlassPane().setVisible(true);

mainFrame.pack();
mainFrame.setVisible(true);

}

public static void main(final String[] aArgs)
{
final OverlayDemo app = new OverlayDemo();

app.run();
}
}
38 changes: 38 additions & 0 deletions src/com/roots/map/overlay/PointSetMarkingGlassPane.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.roots.map.overlay;

import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.util.List;

public class PointSetMarkingGlassPane extends JComponent implements IGlassPane {
private final ILatLongToScreenCoordinatesConverter latLongToScreenCoordinatesConverter;
private final List<Point.Double> pointsToMark = new LinkedList<Point.Double>();

public PointSetMarkingGlassPane(final ILatLongToScreenCoordinatesConverter aConverter) {
this.latLongToScreenCoordinatesConverter = aConverter;
}

protected void addPointToMark(final Point.Double aPoint)
{
if (aPoint != null)
{
pointsToMark.add(aPoint);
}
}

@Override
protected void paintComponent(final Graphics aGraphics) {
for (final Point.Double pointToMark : pointsToMark)
{
final Point positionInScreenCoords = latLongToScreenCoordinatesConverter.getScreenCoordinates(pointToMark);
drawCircle(aGraphics, positionInScreenCoords, Color.red);
}
}

private void drawCircle(Graphics g, Point point, Color color) {
g.setColor(color);
g.fillOval(point.x, point.y, 10, 10);
}

}