Re: [OpenMap Users] A few random questions

From: Don Dietrick <>
Date: Sun, 7 Jun 2015 20:09:45 -0400

Hi Gary,

> On Jun 6, 2015, at 6:31 PM, Gary Briggs <> wrote:
> So, a few things have come up recently and I'm not clear how best to
> achieve these things. Any pointers would be appreciated:
> * Is it possible to make the map update/fully re-render as it's being
> dragged with the mouse, as opposed to only when you let go?
> * Speaking of mouse input: I'm reading the developer guide, and I don't
> really "get" how to actually implement a mouse listener. Examples
> of things I'm currently trying to do:
> - I have a layer that is made up of a series of points [OMPoint],
> connected with edges [OMLine]. I want a user to be able to click
> on the map [or only on a node], and have the nearest node to
> that point be "selected", then drag the mouse around the map [not
> necessarily clicking] and run an algorithm for my graph, highlighting
> the best path along my graph to get from the original point to
> the nearest point to the current mouse position. My algorithm is
> fast-ish, but not quite interactive-real-time fast.
> - I have a map of the world being shown as a shapefile [the one included
> with openmap, actually]. User clicks on a country, I want to
> highlight that country.

These things are kinda related. First, though, I feel like I should explain the hierarchy of mouse event objects a bit better. Java has MouseListeners, which are objects that receive events when the mouse does certain things (clicks, presses, releases, etc). There are MouseMotionListeners, too, that get events when the mouse is simply moved over a component. Any object can implement the methods for those listener interfaces, and attach to any Java component to receive those events. Those listeners will receive those events regardless of who else is listening for those events, so you can have multiple listeners reacting to the same mouse event in an application.

For OpenMap, we tried to organize mouse and mouse motion event notifications to make delivery more organized across all the different layers and components. That’s what MouseModes are - they are a specific MouseListener to the Map that reacts to the mouse events in a certain way - they represent a certain behavior responding to mouse activity over the map. Layers are expected to tell the MouseDelegator (the mouse mode organizer) which MouseModes they want to receive events from. The active MouseMode manages the distribution of the mouse events to the layers, keeping track of what’s going on so that it seems organized.

So, to answer your first question, it’s possible to have the map update itself as it’s being dragged around, and that would be controlled by the MouseMode. But here’s why the current mouse modes aren’t written to do that - when a the map is being updated, a new projection gets sent out to the layers and each one autonomously responds to that update, causing the layers to be repainted. That can sometimes several times for one projection change. The current behavior is intended to reduce the amount of wasted effort the layers would be churning trying to respond to one projection change when the next one would be coming a .01 sec later. But in this case, we’re thinking of the general case.

If you are more in control of your layers, they respond quickly to projection changes and repaint quickly, and you have a background layer that is using tiles, I think you could create a map that would respond well to dragging and update on the fly. You’d just modify the mouse mode so it just changed the projection on the MapBean with every mouse movement including dragging.

For having layers react to mouse events, look at the com.bbn.openmap.layer.learn.InteractionLayer example, or the com.bbn.openmap.layer.DemoLayer. They both utilize the OMGraphicHandlerLayer’s built-in functionality for managing mouse events over OMGraphics. The InteractionLayer is better for understanding which methods are available to override, and you can look at the DemoLayer to see that in action.

For your layer, you’d just override the methods that tell you when the mouse is doing something over the map, and add or modify the OMGraphic rendering attributes responding to those actions (don’t forget to call repaint on the layer to see the changes take place, or call generate(projection) on the OMGraphic if it’s location parameters change).

For the country layer behavior, you would just extend the ShapeLayer, override the selection methods (isSelectable(), select(), deselect()), and change the rendering attributes of that particular OMGraphic. Then, repaint. You might have to keep track of those changes in case the projection changes, that might reset the OMGraphicList being rendered. You’d just have to play around with it.

> * If I had a FORTRAN program that runs at the command-line, and I wanted
> to add features to that program to have it render to a map as it
> runs... how would I go about doing that?
> - Is it a better investment of time to give up on that and find
> something, anything, else to do? This is just a blue-sky idea…

You can use jni to connect the FORTRAN program to java, and have a layer on the java side respond to the input by updating its OMGraphicList, calling generate with the current projection, and then calling repaint on itself. Here’s an example I found of someone using JNI to call java from FORTRAN: <>

It would be an interesting setup. I don’t have much experience with FORTRAN, so I’m not sure if it would be easier to open up a network connection and talk to java that way.

Hope this helps,


[To unsubscribe to this list send an email to ""
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Sun Jun 07 2015 - 20:11:23 EDT

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