When extending this class for a simple layer, they only method you need to override is the prepare() method. This is a good class to use to start writing your own layers. Start with overriding the prepare() method, having it return an OMGraphicList containing OMGraphics on the map that are appropriate for the current projection.
The OMGraphicHandlerLayer already has an OMGraphicList variable, so if you extend this class you don't have to manage another one. You can add your OMGraphics to the list provided with getList(). If you create a list of OMGraphics that is reused and simply re-projected when the projection changes, do nothing - that's what happens anyway based on the default ProjectionChangePolicy set for the layer (StandardPCPolicy). You can either create an OMGraphicList in the constructor and set it by calling setList(OMGraphicList), or you can test for a null OMGraphicList returned from getList() in prepare() and create one if it needs to be. If the list isn't null, make sure you still call generate on it. The advantage of waiting to create the list in prepare is that the processing time to create the OMGraphics is delayed until the layer is added to the map. If you create OMGraphics in the constructor, you delay the entire program (maybe startup of the map!) while the OMGraphics are created.
If you let prepare() create a new OMGraphicList based on the new projection, then make sure the ProjectionChangePolicy for the layer is set to a com.bbn.openmap.layer.policy.ResetListPCPolicy, or at least clear out the old graphics at some point before adding new OMGraphics to the list in that method. You just have to do one, not both, of those things. If you are managing a lot of OMGraphics and do not null out the list, you may see your layer appear to lag behind the projection changes. That's because another layer with less work to do finishes and calls repaint, and since your list is still set with OMGraphics ready for the old projection, it will just draw what it had, and then draw again when it has finished working. Nulling out the list will prevent your layer from drawing anything on the new projection until it is ready.
The OMGraphicHandlerLayer has support built in for launching a SwingWorker to do work for you in a separate thread. This behavior is controlled by the ProjectionChangePolicy that is set for the layer. Both the StandardPCPolicy and ListResetPCPolicy launch threads by calling doPrepare() on this layer. The StandardPCPolicy only calls this if the number of OMGraphics on its list is greater than some cutoff value.
useLayerWorker variable is true (default), then doPrepare() will be called when a new ProjectionEvent is received in the projectionChanged method. This will cause prepare() to be called in a separate thread. You can use prepare() to create OMGraphics, the projection will have been set in the layer and is available via getProjection(). You should generate() the OMGraphics in prepare. NOTE: You can override the projectionChanged() method to create/manage OMGraphics any way you want. The SwingWorker only gets launched if doPrepare() gets called.
MouseEvents are not handled by a MapMouseInterpreter, with the layer being the GestureResponsePolicy object dictating how events are responded to. The interpreter does the work of fielding MapMouseEvents, figuring out if they concern an OMGraphic, and asking the policy what it should do in certain situations, including providing tooltips, information, or opportunities to edit OMGraphics. The mouseModes property can be set to the MapMouseMode IDs that the interpreter should respond to.
For OMGraphicHandlerLayers, there are several properties that can be set that dictate important behavior:
layer.projectionChangePolicy=pcp layer.pcp.class=com.bbn.openmap.layer.policy.StandardPCPolicy layer.renderPolicy=srp layer.srp.class=com.bbn.openmap.layer.policy.StandardRenderPolicy # or layer.renderPolicy=ta layer.ta.class=com.bbn.openmap.layer.policy.RenderingHintsRenderPolicy layer.ta.renderingHints=KEY_TEXT_ANTIALIASING layer.ta.KEY_TEXT_ANTIALIASING=VALUE_TEXT_ANTIALIAS_ON layer.mouseModes=Gestures layer.consumeEvents=true
|
|
|
|