Open ianrenton opened 10 months ago
Hi Ian,
I think you should be able to do something pretty easily at the layer level, something along the lines of getting the OMGraphics rendered into an Image and then adjusting the transparency of the image.
I’m guessing you’re using a layer that extends OMGraphicHandlerLayer using the default StandardRenderPolicy. I think that would cause what you describe, with each OMGraphic being rendered into a java.awt.Graphics2D with the same transparency. If you set a BufferedImageRenderPolicy on the layer that transparency should be set on the image buffer used by that layer’s policy, after all the OMGraphics have been rendered into the image buffer.
That’s off the top of my head, let me know if this works for you. If not I’ll dig into it further.
Hope this helps,
Don
On Dec 14, 2023, at 08:31, Ian Renton @.***> wrote:
Hi, I have a data set consisting of lat/lon polygons of varying "priority", say on a scale of green to red. These polys overlap, so for example a yellow poly might overlap one or more green polys, and a red poly might overlap several green & yellow polys, etc. With zero transparency, this is not a problem - I can just generate OMPolys in "priority" order, letting them overlap however they want. However, I would like to make the overall effect semi-transparent. Unfortunately in OpenMap, setting the transparency of a layer actually sets the transparency of all graphics on it individually. This ends up changing the overall effect, for example, a red polygon that overlaps a green polygon is no longer "pure" red but a combination of colours. I have thought of two ways of resolving this: • Rendering all the polygons to a single buffered image, then projecting the image onto the layer - there is therefore only one graphic on the layer so the transparency is applied to the whole thing • Creating an "OMPoly with holes" so that I can remove areas from "green" polys that are underneath "red" polys (and so on), so that any given lat/lon point, is only inside one shape. I have started to play around with both approaches but neither of them seems particularly easy, so before I get too much further into it... does OpenMap already support a way of doing this? If not, has anyone done anything similar and who may be able to share tips on what the best approach is? Thanks — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>
Hi, thanks for the quick response. I am using an OMGraphicHandlerLayer but I am already using BufferedImageRenderPolicy so I see the problem even with this RP.
A quick worked example:
TestLayer.java
:
import com.bbn.openmap.layer.OMGraphicHandlerLayer;
import com.bbn.openmap.omGraphics.OMGraphicList;
import com.bbn.openmap.omGraphics.OMPoly;
import java.awt.*;
import java.util.Properties;
public class TestLayer extends OMGraphicHandlerLayer {
@Override
public void setProperties(String prefix, Properties properties) {
super.setProperties(prefix, properties);
OMGraphicList list = new OMGraphicList();
OMPoly one = new OMPoly(new double[]{0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0}, OMPoly.DECIMAL_DEGREES, OMPoly.LINETYPE_GREATCIRCLE);
OMPoly two = new OMPoly(new double[]{0.5, 0.5, 1.5, 0.5, 1.5, 1.5, 0.5, 1.5}, OMPoly.DECIMAL_DEGREES, OMPoly.LINETYPE_GREATCIRCLE);
one.setFillPaint(new Color(255,0,0));
two.setFillPaint(new Color(0,0,255));
list.add(one);
list.add(two);
setList(list);
System.out.println("transparency: " + getTransparency());
System.out.println("RenderPolicy: " + getRenderPolicy());
}
}
openmap.properties
:
testLayer.class="TestLayer",
testLayer.transparency=0.5,
testLayer.renderPolicy="rp",
testLayer.rp.class="com.bbn.openmap.layer.policy.BufferedImageRenderPolicy",
testLayer.projectionChangePolicy="pcp",
testLayer.pcp.class="com.bbn.openmap.layer.policy.StandardPCPolicy"
stdout:
transparency: 0.5
RenderPolicy: com.bbn.openmap.layer.policy.BufferedImageRenderPolicy@28ceb987
Visual:
If I set transparency to 1 (fully opaque) the red square renders over the top of the blue, but when transparency is used, I can always see a purple section in the overlap.
I may have misunderstood what's going on here, but it looks to me like the transparency is still being set on the individual graphics before the buffered image is being created. I can interactively change the layer transparency and the purple section disappears when changing transparency 0.5->1, so I think the buffered image is being regenerated with every transparency change, based on semi-transparent graphics.
Hi,
I have a data set consisting of lat/lon polygons of varying "priority", say on a scale of green to red. These polys overlap, so for example a yellow poly might overlap one or more green polys, and a red poly might overlap several green & yellow polys, etc.
With zero transparency, this is not a problem - I can just generate OMPolys in "priority" order, letting them overlap however they want. However, I would like to make the overall effect semi-transparent. Unfortunately in OpenMap, setting the transparency of a layer actually sets the transparency of all graphics on it individually. This ends up changing the overall effect, for example, a red polygon that overlaps a green polygon is no longer "pure" red but a combination of colours.
I have thought of two ways of resolving this:
I have started to play around with both approaches but neither of them seems particularly easy, so before I get too much further into it... does OpenMap already support a way of doing this? If not, has anyone done anything similar and who may be able to share tips on what the best approach is?
OpenMap 5.1.15.
Thanks