Re: [OpenMap Users] polygon with holes

From: Don Dietrick <dietrick_at_bbn.com>
Date: Fri, 16 Jun 2006 15:34:22 -0400

Thanks for the code, Tore!

- Don

On Jun 15, 2006, at 9:16 AM, Tore Halset wrote:

> Hello.
>
> I have had some problems with polygons with holes resulting in
> horizontal lines.
>
> http://openmap.bbn.com/mailArchives/openmap-users/2006-03/4724.html
>
> I created a simple OMGraphic that *seem to fix* the problem in my
> application. It probably does not work for selection, labeling and
> the other stuff that I am not using in my application.
>
> Regards,
> - Tore.
>
> public class OMPolyWithHoles extends OMGraphic {
>
> private OMPoly exteriour = null;
>
> private List<OMPoly> holes = null;
>
> public OMPolyWithHoles() {
> }
>
> public OMPolyWithHoles(int numberOfHoles) {
> this();
> holes = new ArrayList<OMPoly>(numberOfHoles);
> }
>
> public void setExteriour(OMPoly exteriour) {
> this.exteriour = exteriour;
> }
>
> public void addHole(OMPoly hole) {
> if (holes == null) {
> holes = new ArrayList<OMPoly>(2);
> }
> holes.add(hole);
> }
>
> /**
> * Prepare the poly for rendering.
> *
> * _at_param proj
> * Projection
> * _at_return true if generate was successful
> */
> public boolean generate(Projection proj) {
> boolean r = exteriour.generate(proj);
> if (!r) {
> return false;
> }
> for (OMPoly hole : getHoles()) {
> r = hole.generate(proj);
> if (!r) {
> return false;
> }
> }
> createShape();
> return r;
> }
>
> protected List<OMPoly> getHoles() {
> if (holes == null) {
> return Collections.emptyList();
> }
> return holes;
> }
>
> /**
> * Since OMPoly has the option to not create a Shape, this
> method is here to
> * create it if it is asked for. The OMPoly needs to be generated.
> */
> protected void createShape() {
>
> GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
> path.append(exteriour.getShape(), false);
>
> for (OMPoly hole : getHoles()) {
> path.append(hole.getShape(), false);
> }
>
> setShape(path);
> }
>
> public void render(Graphics gr) {
> Shape shp = getShape();
> Graphics2D g2 = (Graphics2D) gr;
> setGraphicsForFill(gr);
> g2.fill(shp);
> setGraphicsForEdge(gr);
> g2.draw(shp);
> }
>
> --
> [To unsubscribe to this list send an email to "majdart_at_bbn.com"
> with the following text in the BODY of the message "unsubscribe
> openmap-users"]

--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Fri Jun 16 2006 - 15:34:42 EDT

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:07 EDT