Hi Chris,
Thanks for the update and for showing the code that worked out for you.
I'm moving away from using the AppObject in OMGraphics directly, and
I'm using the putAttribute()/getAttribute() methods instead, so you
might expect the OMPoly's appObject to be a hashtable in future
releases. If the index attribute isn't available from the
getAttribute(SHAPE_INDEX_ATTRIBUTE) on the OMPolys, it will be for
the next release.
Regards,
Don
On Jan 24, 2007, at 6:05 AM, Chris Hopkins wrote:
>
> Thanks a lot Don! In case anyone was curious, this is the code I wrote
> that performs the aggregation of areas. I wrote it using the
> java.awt.geom package classes and, for now, have stuck it into my own
> extension of the BasicMapPanel. I also realized that the OMPoly
> object's
> have the Integer index set as their appObject and you can look up the
> name of the OMPoly based on that Integer so that worked out well.
> In any
> case, it's working the way we expect now.
>
> - Chris
>
> ------------------------------------------
> package com.cra.openmap.gui;
>
> import java.awt.BasicStroke;
> import java.awt.Color;
> import java.awt.geom.Area;
> import java.awt.geom.GeneralPath;
> import java.awt.geom.PathIterator;
> import java.util.ArrayList;
>
> import com.bbn.openmap.gui.BasicMapPanel;
> import com.bbn.openmap.layer.shape.areas.AreaHandler;
> import com.bbn.openmap.omGraphics.OMGraphic;
> import com.bbn.openmap.omGraphics.OMGraphicList;
> import com.bbn.openmap.omGraphics.OMPoly;
> import com.cra.openmap.layer.MyAreaShapeLayer;
>
> public class OpenMapPanel extends BasicMapPanel
> {
> private AreaHandler areaHandler;
>
> private MyAreaShapeLayer areaShapeLayer;
>
> private final BasicStroke REGION_STROKE = new BasicStroke(2.0f);
>
> public OpenMapPanel()
> {
> super(null);
> }
>
> _at_Override
> public void findAndInit(Object arg0)
> {
> super.findAndInit(arg0);
>
> if (arg0 instanceof MyAreaShapeLayer)
> {
> System.err.println("Got the area handler!!!");
> this.areaShapeLayer = (MyAreaShapeLayer)arg0;
> this.areaHandler = (AreaHandler)this.areaShapeLayer.getAreas();
>
> this.areaShapeLayer.addRegion(createRegion(Color.blue.brighter
> (),
> "Al Anbar", "Karbala'",
> "Baghdad", "Babil", "An Najaf"));
> this.areaShapeLayer.addRegion(createRegion
> (Color.green.brighter(),
> "Ninawa", "Dahuk",
> "Arbil", "As Sulaymaniyah", "At Ta'min", "Salah ad Din",
> "Diyala"));
> this.areaShapeLayer.addRegion(createRegion(Color.red.brighter(),
> "Wasit", "Maysan",
> "Al Qadisiyah", "Dhi Qar", "Al Basrah", "Al Muthanna"));
>
> this.areaShapeLayer.repaint();
> }
> }
>
> private OMPoly createRegion(Color polyColor, String... strings)
> {
> OMPoly regionPoly = null;
>
> if (strings != null && strings.length > 0)
> {
> // Create an AWT Area object from the first political area
> Area area = createAwtAreaFromPoliticalArea(strings[0]);
>
> if (area != null)
> {
> for (int i = 1; i < strings.length; i++)
> {
> Area nextArea = createAwtAreaFromPoliticalArea(strings[i]);
> if (nextArea != null)
> {
> area.add(nextArea);
> }
> }
> }
>
> regionPoly = createOMPolyFromArea(area, polyColor);
> }
>
> return regionPoly;
> }
>
> private OMPoly createOMPolyFromArea(Area area, Color polyColor)
> {
> ArrayList<Float> newpoints = new ArrayList<Float>();
> PathIterator pi = area.getPathIterator(null);
> float[] fpts = new float[6];
> while (!pi.isDone())
> {
> int type = pi.currentSegment(fpts);
> if (type == PathIterator.SEG_MOVETO || type ==
> PathIterator.SEG_LINETO)
> {
> newpoints.add(fpts[0]);
> newpoints.add(fpts[1]);
> }
>
> pi.next();
> }
>
> float[] newfpts = new float[newpoints.size()];
> for (int i = 0; i < newpoints.size(); i++)
> {
> newfpts[i] = newpoints.get(i);
> }
>
> OMPoly newpoly = new OMPoly(newfpts, OMGraphic.RADIANS,
> OMGraphic.LINETYPE_STRAIGHT);
> newpoly.setLinePaint(polyColor);
> newpoly.setStroke(REGION_STROKE);
>
> return newpoly;
> }
>
> private Area createAwtAreaFromPoliticalArea(String string)
> {
> Area newArea = null;
> OMPoly omp = getOMPolyForArea(string);
> if (omp != null)
> {
> newArea = new Area(createGeneralPath(omp.getLatLonArray()));
> }
>
> return newArea;
> }
>
> private GeneralPath createGeneralPath(float[] pts)
> {
> GeneralPath gp = new GeneralPath();
> gp.moveTo(pts[0], pts[1]);
>
> for (int i = 2; i < pts.length; i += 2)
> {
> gp.lineTo(pts[i], pts[i + 1]);
> }
>
> gp.closePath();
>
> return gp;
> }
>
> private OMPoly getOMPolyForArea(String string)
> {
> OMGraphicList omgl = this.areaHandler.getGraphics();
> for (int i = 0; i < omgl.size(); i++)
> {
> OMGraphic omg = omgl.getOMGraphicAt(i);
> if (omg instanceof OMGraphicList)
> {
> OMGraphicList omgl2 = (OMGraphicList)omg;
> for (int j = 0; j < omgl2.size(); j++)
> {
> OMGraphic omg2 = omgl2.getOMGraphicAt(j);
> if (omg2 instanceof OMPoly)
> {
> String name =
> this.areaHandler.getName((Integer)omg2.getAppObject());
> if (name != null && name.equals(string))
> {
> return (OMPoly)omg2;
> }
> }
> }
> }
> }
>
> return null;
> }
> }
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Don Dietrick, dietrick_at_bbn.com
BBN Technologies, Cambridge, MA
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
--
[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 Jan 26 2007 - 10:45:38 EST