简体   繁体   English

将MapDotMarkers与JMapViewer结合使用

[英]Using MapDotMarkers with JMapViewer

I have two questions about JMapViewer : 我有两个关于JMapViewer问题:

  • After adding MapDotMarkers to my map, I want to couple each dot with a summary list (a certain Pannel having some text written in it, probably some description about the dot). MapDotMarkers添加到我的地图后,我想将每个点与一个摘要列表结合在一起(某个Pannel中写有一些文本,可能是关于该点的一些描述)。 How can I do that? 我怎样才能做到这一点?

  • What method should I use to make the map visible on my screen? 我应该使用什么方法使map在屏幕map可见?

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. 添加摘要列表的整个解决方案将基于创建自定义MapMarker。 You would need to add new class called for example "SummaryMapMarker" that extends the current MapMarker class. 您将需要添加名为“ SummaryMapMarker”的新类,以扩展当前的MapMarker类。 Please check the existing MapMarkerCircle.java that comes with JMapViewer source code (download from JMapViewer open source). 请检查JMapViewer源代码随附的现有MapMarkerCircle.java(从JMapViewer开源下载)。 Create a copy of MapMarkerCircle, rename it to something like MapMarkerSummary.java and modify it accrordingly to your needs. 创建一个MapMarkerCircle副本,将其重命名为MapMarkerSummary.java之类,然后根据需要进行修改。 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. 然后,您可以使用著名的paint方法在地图上输出任何摘要,这意味着使用Graphics g使用g.drawLine,g.drawString,g.drawRect等绘制线,圆,矩形,文本,图像。 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. 简而言之,整个想法是能够根据屏幕像素(x,y)坐标在屏幕上随意拖动任何东西。 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 (eg map().addMapMarker(new MapMarkerSummary...) ) 完成MapMarkerSummary类后,可以将其添加到主类内的主面板中,就像添加DotMap Marker一样(例如map()。addMapMarker(new MapMarkerSummary ...))

public class MapMarkerSummary extends MapObjectImpl implements MapMarker { 公共类MapMarkerSummary扩展了MapObjectImpl实现的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);
}
// ...

} }

You may check the source file Demo.java downloaded along with the library JMapViewer it contains the answers to your questions. 您可以检查与库JMapViewer一起下载的源文件Demo.java,它包含问题的答案。 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)? 您是否有此文件(Demo.java)?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM