user2920851
user2920851

Reputation: 11

Using MapDotMarkers with JMapViewer

I have two questions about JMapViewer:

Upvotes: 1

Views: 1296

Answers (2)

Ali Ghosn
Ali Ghosn

Reputation: 11

Unfortunately, there is no simple way of adding summary list to the map, but, there is a way:

The whole solution of adding summary list will be based on a creating a custom MapMarker. You would need to add new class called for example "SummaryMapMarker" that extends the current MapMarker class. Please check the existing MapMarkerCircle.java that comes with JMapViewer source code (download from JMapViewer open source). Create a copy of MapMarkerCircle, rename it to something like MapMarkerSummary.java and modify it accrordingly to your needs. You can then output any summary on the map using the famous paint method, meaning using Graphics g to draw lines, circles, rectangles, text, images using g.drawLine, g.drawString, g.drawRect, and so on. You can create any custom summary (any really!). Brief, the whole idea is to be able to dray on the screen whatever you want but based on screen pixel (x, y) coordinates. The below is pasted for your reference. Please let me know if you need any further details in case not sufficient. I was able myself to create fancy summary and to add it to the map viewer. Once the class MapMarkerSummary is done, then you can add it to your main panel inside you main class like you add the DotMap Marker (e.g. map().addMapMarker(new MapMarkerSummary...) )

public class MapMarkerSummary extends MapObjectImpl implements MapMarker {

public void paint(Graphics g, Point position, int radio) {
    // ...
    int size_h = radio;
    int size = 64;
    g.setColor(Color.blue);

    g.draw3DRect(position.x - 5, position.y - 5, 400, 120, true);
    g.drawString("20°C", position.x + size - 10, position.y + 25);
    g.drawString("30°C", position.x + size - 10, position.y + 37);
    g.setColor(Color.gray);
    g.drawLine(position.x + size + 18, position.y - 4, position.x + size + 18 ,        position.y + 112);
}
// ...

}

Upvotes: 1

Ali Ghosn
Ali Ghosn

Reputation: 1

You may check the source file Demo.java downloaded along with the library JMapViewer it contains the answers to your questions. You can easily make the map visible in few simple lines, create dot, add tooltip.Please check the source file mentioned above and let me know I you need further help. Do you have this file (Demo.java)?

Upvotes: 0

Related Questions