RE: [OpenMap Users] OpenStreetMap Layer

From: John McMahon <jmcmahon_at_mobilvox.com>
Date: Fri, 11 Jun 2010 10:24:42 -0400

Hi Don,

Yeah the polys seem to be moving correctly, and I believe that I am calling
generate() everytime.

Here is my code, thanks for taking a look:

public class OmOpenStreetMapLayer extends OMGraphicHandlerLayer
{
        ...
        Private data members
        ...

    /**
     * The OmOpenStreetMapLayer Constructor.
     *
     */
    public OmOpenStreetMapLayer(final String path)
    {
        // Do as little as possible in here because it is called
        // regardless of whether we show the layer
        selectedList = null;
        osmPath = path;

        // Retrieve the data lists
        final OSMParser parser = new OSMParser();
        parser.getData(new File(osmPath));
        bounds = parser.getBounds();
        ways = parser.getWays();
        nodeMap = parser.getNodeMap();
        topLeftLatLong = new LatLong(bounds.getMinlat(),
bounds.getMinlon());
        bottomRightLatLong = new LatLong(bounds.getMaxlat(),
bounds.getMaxlon());
    }

    /**
     * Prepares the layer for projection.
     *
     * _at_return the graphic list
     * _at_see com.bbn.openmap.layer.OMGraphicHandlerLayer#prepare()
     */
    public OMGraphicList prepare()
    {
        // I've also tried calling setList(init()) everytime (not just when
the list is null)
        if (getList() == null)
        {
            setList(init());
        }

        return super.prepare();
    }

    /**
     * Initialize the OSM by parsing the file and setting the ways.
     *
     * _at_return the list
     */
    private OMGraphicList init()
    {
        /*
         * plug the data from the XML file into OMPoly and add it to the map
         */
        final OMGraphicList list = new OMGraphicList();

        // Input the ways into OMGraphics
        OMPoly poly = null;
        for (Way way : ways)
        {
            List<Node> nds = new ArrayList<Node>();

            for (NodeReference ref : way.getNodeRefs())
            {
                nds.add(nodeMap.get(ref.getRef()));
            }
            float[] llPoints = new float[nds.size() * 2];
            int i = 0;
            for (Node nd : nds)
            {
                llPoints[i] = nd.getLat();
                llPoints[i + 1] = nd.getLon();
                i += 2;
            }

            // Set some default rendering values
            poly = new OMPoly(llPoints, OMGraphic.DECIMAL_DEGREES,
                OMGraphic.LINETYPE_RHUMB);
            poly.setStroke(new BasicStroke(1.0f));
            poly.setLinePaint(Color.DARK_GRAY);

            // Get the rendering properties file
            Properties props =
Utility.getProperties("rendering.properties");

            // Iterate through the tags and set OMPoly attributes if
necessary
            List<Tag> tags = way.getTags();
            if (tags != null)
            {
                for (Tag tag : tags)
                {
                    // Base Key
                    String key = tag.getKey() + "." + tag.getValue();

                    String lineColorValue = props.getProperty(key
                            + ".linecolor");
                    String fillColorValue = props.getProperty(key
                            + ".fillcolor");
                    String lineWidthValue = props.getProperty(key +
".width");
                    String lineTypeValue = props.getProperty(key +
".linetype");

                    if (fillColorValue != null)
                    {
                        poly.setFillPaint(Color.decode(fillColorValue));
                    }
                    if (lineColorValue != null)
                    {
                        poly.setLinePaint(Color.decode(lineColorValue));
                    }
                    if (lineWidthValue != null)
                    {
                        poly.setStroke(new BasicStroke(Float
                            .parseFloat(lineWidthValue)));
                    }
                    if (lineTypeValue != null)
                    {
                        // If a line type is set, assume that it is dotted
                        Float width = 2.0f;
                        if (lineWidthValue != null)
                        {
                            width = Float.parseFloat(lineWidthValue);
                        }

                        float[] floatArray = { 10.0f, 5.0f };
                        poly.setStroke(new BasicStroke(width,
                            BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                            1.0f, floatArray, 10.0f));
                    }
                }
            }
            list.add(poly);
        }
        return list;
    }
...
Getters and setters
...

Thanks,
John

-----Original Message-----
From: Don Dietrick [mailto:dfdietrick_at_gmail.com]
Sent: Thursday, June 10, 2010 11:29 PM
To: John McMahon
Cc: openmap_at_bbn.com; openmap-users_at_bbn.com
Subject: Re: [OpenMap Users] OpenStreetMap Layer

Hi John,

Are the points of the polys moving (pixel-wise) when you zoom in and
out? If you have a political boundary layer running underneath your
layer, are your OMGraphics behaving properly and moving to their
proper position geospatially relative to the borders?

You want to make sure that your are calling generate(Projection) on
the OMGraphics before the prepare() method returns.

I'm happy to take a quick look at your layer code if you send it to me.

- Don


On Thu, Jun 10, 2010 at 3:20 PM, John McMahon <jmcmahon_at_mobilvox.com> wrote:
> Hi Don,
>
>
>
> Thank you, you’ve been very helpful.
>
>
>
> It’s been going quite well except, sometimes, I feel like changing the
> projection does not update the OMPolys.  For example, when the layer is
> created from a zoomed-out position, zooming in causes the lines to become
> jagged and distorted.  When the layer is created from a zoomed-in position
> to start with, everything is fine (I can zoom out and zoom back in with no
> distortion).
>
>
>
> How do I get the OMPolys to completely redraw themselves to show more
detail
> as I zoom in?
>
>
>
> Inside the prepare() method, I am already wiping out the OMGraphicList and
> re-creating it from scratch. What else do I need to do?
>
>
>
> Thanks,
>
>
>
> John
>
>
>
> From: Don Dietrick [mailto:dfdietrick_at_gmail.com]
> Sent: Friday, May 21, 2010 9:14 AM
>
> To: John McMahon
> Cc: openmap_at_bbn.com; openmap-users_at_bbn.com
> Subject: Re: [OpenMap Users] OpenStreetMap Layer
>
>
>
> Hi John,
>
>
>
> I think the entries at the end of the file define the roads that use the
> points.  The osm files I have have modes:
>
>
>
>   <node id="163546" timestamp="2008-06-23T14:51:54" user="Dean Earley"
> lat="50.7928559" lon="-1.0995028" />
>
>   <node id="163547" timestamp="2006-12-05T03:17:47" user="Dean Earley"
> lat="50.7940994" lon="-1.0983414" />
>
>
>
> and then later:
>
>
>
>  <way id="12166070" timestamp="2007-11-12T20:52:19">
>
>     <nd ref="110314881" />
>
>     <nd ref="110314568" />
>
>     <tag k="highway" v="residential" />
>
>   </way>
>
>
>
> where the nd references tie back to the node entries.  The tags of the
ways
> would let you determine how you want to render them.
>
>
>
> I'd create OMPoly objects (without fill paint, using OMColor.clear or not
> setting it at all)
>
>
>
>
>
> On Fri, May 21, 2010 at 7:39 AM, John McMahon <jmcmahon_at_mobilvox.com>
wrote:
>
> Hi Don,
>
> Thanks for your reply! It's been very helpful, but I had a question.
>
> When I parse the OSM file, I'm basically left with a bunch of Lat/Long
> points (with tags explaining what they are).  From there am I suppose to
> just use OMLines (or anything in the omGraphics package) to "connect the
> dots" in order to show roadways and boundries?  Are there any examples of
> this in the source code?
>
> Thanks for any help you can offer,
>
> John
>
>
> -----Original Message-----
> From: Don Dietrick [mailto:dfdietrick_at_gmail.com]
> Sent: Tuesday, May 18, 2010 8:10 PM
> To: John McMahon
> Cc: openmap_at_bbn.com; openmap-users_at_bbn.com
> Subject: Re: [OpenMap Users] OpenStreetMap Layer
>
> Hi John,
>
> Thats certainly one way to do it, if the osm files are small enough to fit
> into memory.
>
> If you want to render an osm directly,  you would create a new layer by
> extending OMGraphicHandlerLayer, and override the prepare() method to
create
> and return an OMGraphicList for display.  You would parse the osm file and
> create OMGraphic objects to add to that list.
>
> For larger files, (and a faster-responding map), you would want to create
> image tiles.  openstreetmap.org has details on how to create your own tile
> set from the osm files.  If you have those, you can use the
> com.bbn.openmap.layer.image.MapTileLayer to display them (it's in the beta
> version available via svn on the website).
>
> Hope this helps,
>
> Don
>
>
> On May 18, 2010, at 5:19 PM, John McMahon wrote:
>
>> Hello All,
>>
>> I would like to create an OpenStreetMap layer for OpenMap, and I was
> wondering if anyone had done this before and what it requires.  I have
> OpenStreetMap data in the form of an .osm XML file.  Will I just have to
> parse that XML file and create a class that extends OMGraphicHanderLayer?
>>
>> I am fairly new to both OpenMap and OpenStreetMap, so any help would be
> appreciated.
>>
>> Thanks,
>> John
>
>

--
[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 11 2010 - 10:43:32 EDT

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