Java JMapViewer:如何更改MapPolygon的颜色? [英] Java JMapViewer: How can I change the color of a MapPolygon?

查看:136
本文介绍了Java JMapViewer:如何更改MapPolygon的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个用于在JMapViewer上绘制污染信息的应用程序.我想用MapPolygons做到这一点,但是我没有找到关于它的好的文档.我成功创建了这样的新MapPolygons:

I'm creating an application for drawing pollution information on a JMapViewer. I want to do this with MapPolygons, but I didn't find a good documentation about it. I succeeded to create new MapPolygons like this:

private MapPolygon getPolygon(double lat, double lon, Color col){
    List<Coordinate> coords = new ArrayList<>();

    //add all points to the list...

    MapPolygon poly = new MapPolygonImpl(coords); 
    return poly;
}

我想知道如何更改颜色并删除MapPolygon的边框.没有setColor之类的功能……

I'm wondering how I could change the color and remove the border of the MapPolygon. There is no function setColor or such...

我直接尝试使用构造函数,但这不起作用:

I tried directly with the constructor, but this doesn't work:

MapPolygon poly = new MapPolygonImpl(coords, Color.RED, new BasicStroke(0));

有人知道我如何更改MapPolygon的颜色吗? 谢谢!

Does anybody know how I can change the color of the MapPolygon? Thanks!

推荐答案

由于MapPolygonImpl扩展了MapObjectImpl,所以MapPolygonImplMapObjectImpl继承了setColor()setBackColor(). MapPolygonImpl在其paint()的实现中使用这些颜色.颜色存储在父类的Style属性中,该属性在构造期间通过调用getDefaultStyle()进行初始化.

Because MapPolygonImpl extends MapObjectImpl, MapPolygonImpl inherits setColor() and setBackColor() from MapObjectImpl. MapPolygonImpl uses these colors in its implementation of paint(). The colors are stored in the parent class's Style attribute, initialized by calling getDefaultStyle() during construction.

您可以改变所选Color alpha 组件以实现各种效果;下面的示例使用了12.5%的浅灰色.

You can vary the alpha component of the chosen Color to achieve a variety of effects; the example below uses a 12.5% light gray.

MapPolygonImpl poly = new MapPolygonImpl(coords);
Color color = new Color(0x20202020, true);
poly.setColor(color);
poly.setBackColor(color);
poly.setStroke(new BasicStroke(0));
map.addMapPolygon(poly);

如果现有颜色令人满意,则可以通过将颜色设置为背景色来达到类似的效果.

If the existing color is satisfactory, a similar effect may be achieved by setting the color to the background color.

MapPolygonImpl poly = new MapPolygonImpl(route);
poly.setColor(poly.getBackColor());

这篇关于Java JMapViewer:如何更改MapPolygon的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆