Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whole layer transparency or OMPoly-with-holes #59

Open
ianrenton opened this issue Dec 14, 2023 · 2 comments
Open

Whole layer transparency or OMPoly-with-holes #59

ianrenton opened this issue Dec 14, 2023 · 2 comments

Comments

@ianrenton
Copy link

ianrenton commented Dec 14, 2023

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:

  1. 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
  2. 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?

OpenMap 5.1.15.

Thanks

@dfdietrick
Copy link
Contributor

dfdietrick commented Dec 14, 2023 via email

@ianrenton
Copy link
Author

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:

image

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants