Saving graphics drawn on a map

34 views
Skip to first unread message

petaga...@gmail.com

unread,
Mar 25, 2016, 10:17:57 AM3/25/16
to openmap-users
Hello,
I am using v5.1.13.  I am using the drawing layer defined in openmap.properties as:
# Drawing layer
dtlayer.class=com.bbn.openmap.layer.editor.EditorLayer
dtlayer.prettyName=Drawing Layer
dtlayer.editor=com.bbn.openmap.layer.editor.DrawingEditorTool
dtlayer.loaders=lines polys rects circles points
dtlayer.mouseModes=Gestures
dtlayer.distance.class=com.bbn.openmap.tools.drawing.OMDistanceLoader
dtlayer.lines.class=com.bbn.openmap.tools.drawing.OMLineLoader
dtlayer.polys.class=com.bbn.openmap.tools.drawing.OMPolyLoader
dtlayer.rects.class=com.bbn.openmap.tools.drawing.OMRectLoader
dtlayer.circles.class=com.bbn.openmap.tools.drawing.OMCircleLoader
dtlayer.points.class=com.bbn.openmap.tools.drawing.OMPointLoader

Leaving out "dtlayer.file" on purpose.  Noting that http://openmap-java.org/api/com/bbn/openmap/layer/DrawingToolLayer.html states: 
# optional flag to specify file to store and read OMGraphics.  A Save button 
# is available on the palette. If it's not specified and the Save button is # chosen, the user will queried for this location. drawingToolLayer.file=file to read OMGraphics from

I draw a square on my "map panel" and in the dtlayer palette I select from the drop down list "Save map", I get the exception:
Exception in thread "AWT-EventQueue-0" java.lang.Error: Cannot call invokeAndWait from the event dispatcher thread
at java.awt.EventQueue.invokeAndWait(EventQueue.java:1294)
at java.awt.EventQueue.invokeAndWait(EventQueue.java:1287)
at javax.swing.SwingUtilities.invokeAndWait(SwingUtilities.java:1348)
at com.bbn.openmap.util.FileUtils$OpenFileRunnable.invoke(FileUtils.java:114)
at com.bbn.openmap.util.FileUtils.getFilePathToSaveFromUser(FileUtils.java:67)
at com.bbn.openmap.layer.DrawingToolLayer.saveOMGraphics(DrawingToolLayer.java:590)
at com.bbn.openmap.layer.DrawingToolLayer$5.actionPerformed(DrawingToolLayer.java:516)
at com.bbn.openmap.layer.DrawingToolLayer.doIt(DrawingToolLayer.java:462)
at com.bbn.openmap.layer.DrawingToolLayer$1.actionPerformed(DrawingToolLayer.java:421)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
at java.awt.Component.processMouseEvent(Component.java:6525)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3322)
at java.awt.Component.processEvent(Component.java:6290)
at java.awt.Container.processEvent(Container.java:2234)
at java.awt.Component.dispatchEventImpl(Component.java:4881)
at java.awt.Container.dispatchEventImpl(Container.java:2292)
at java.awt.Component.dispatchEvent(Component.java:4703)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
at java.awt.Container.dispatchEventImpl(Container.java:2278)
at java.awt.Window.dispatchEventImpl(Window.java:2739)
at java.awt.Component.dispatchEvent(Component.java:4703)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:751)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:702)
at java.awt.EventQueue$3.run(EventQueue.java:696)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:724)
at java.awt.EventQueue$4.run(EventQueue.java:722)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:721)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)


So I set "dtlayer.file":
# Drawing layer
dtlayer.class=com.bbn.openmap.layer.editor.EditorLayer
dtlayer.prettyName=Drawing Layer
dtlayer.editor=com.bbn.openmap.layer.editor.DrawingEditorTool
# optional flag to specify file to store and read OMGraphics.  A Save button 
# is available on the palette.  If it's not specified and the Save button is 
# chosen, the user will queried for this location.
dtlayer.file=C:/drawimage
dtlayer.loaders=lines polys rects circles points
dtlayer.mouseModes=Gestures
dtlayer.distance.class=com.bbn.openmap.tools.drawing.OMDistanceLoader
dtlayer.lines.class=com.bbn.openmap.tools.drawing.OMLineLoader
dtlayer.polys.class=com.bbn.openmap.tools.drawing.OMPolyLoader
dtlayer.rects.class=com.bbn.openmap.tools.drawing.OMRectLoader
dtlayer.circles.class=com.bbn.openmap.tools.drawing.OMCircleLoader
dtlayer.points.class=com.bbn.openmap.tools.drawing.OMPointLoader

Now when I select "Save map" there is NO exception and a file is written out to C:\drawimage.    But then when I try "Reload map from file", nothing happens.  the image I drew and "Save map" with, I expected to be store in C:\drawimage and reloaded and appear on my map.   I set "openmap.Debug=basic editortool dtl" in openmap.properties but no help.  

Not sure what I am doing incorrectly or misunderstanding about this feature in drawing tool palette of "save" and "reload".  

You could modify a layer (the DrawingToolLayer, for example) to 
serialize it's OMGraphicList when it is destroyed. The OMGraphicList 
has support for reading and writing itself. 
You'd have to modify its start up parameters so it knows what file to 
save/read the graphics from. You could do this with properties or 
whatever mechanism you want

I was hoping to avoid having to modify the DrawingToolLayer, and just use the "save map".   

Please let me know what direction I should take if I want to draw graphics on a map using com.bbn.openmap.layer.editor.EditorLayer  and then save to a file, in order to reload at a later point (at the same location it was originally drawn at on a map)

Thanks
Maria Cruz

petaga...@gmail.com

unread,
Mar 25, 2016, 10:56:47 AM3/25/16
to openmap-users
Draw me shocked!   So all of a sudden (swear no changes to properties file etc) setting the filename does save and reload the images drawn.  

BUT... but I still get the exception noted below if I do NOT set a filename in the properties file.  I would like to specify a filename when I want to save, and not just use one filename.
thanks
Maria

Don Dietrick

unread,
Mar 28, 2016, 9:52:30 PM3/28/16
to petaga...@gmail.com, openmap-users
Hi Maria,

I’ve just checked in some changes to three files (DrawingToolLayer, FileUtils and EsriPolylineList) that fix these problems.  DrawingToolLayer/EditorLayer should behave as you expect, now.

I’ll be making a formal release with these updates soon.

If you choose ‘save map’, and don’t enter a file name with a .shp extension, it’ll save the OMGraphics out as serialized objects, all in one file.  If you save them to a Shape file, or chose a name with .shp at the end, it’ll save the OMGraphics to shape files.  This may result in more than one shape file if you have different types of OMGraphics (polylines, polygons or points) all in the layer at save time.  The layer won’t handle importing all three shape files back into one layer, just one at a time.  It’s more of an export function in that case.

Thanks for the bug reports!

- Don

petaga...@gmail.com

unread,
Mar 29, 2016, 12:53:47 PM3/29/16
to openmap-users, petaga...@gmail.com
:(
Did not work for me.  I went to https://github.com/OpenMap-java/openmap.  I did a "Download ZIP", I compiled each of the files and used .class files in my .jar.  Running gives me the following exceptions:

1. Didn't enter a file name with a .shp extension in openmap.properties.  Selected save map as shape file(s):
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.bbn.openmap.layer.DrawingToolLayer$6.actionPerformed(DrawingToolLayer.java:534)


2. don’t enter a file name at all in openmap.properties.  Select save map:
3.  chose a name with .shp at the end in openmap.properties file.  Draw 2 graphics, then Save Map as shape file(s):
at com.bbn.openmap.dataAccess.shape.DbfTableModel.addRecord(DbfTableModel.java:282)
at com.bbn.openmap.dataAccess.shape.EsriShapeExport.addGraphic(EsriShapeExport.java:261)
at com.bbn.openmap.dataAccess.shape.EsriShapeExport.addLine(EsriShapeExport.java:272)
at com.bbn.openmap.dataAccess.shape.EsriShapeExport.export(EsriShapeExport.java:575)
at com.bbn.openmap.dataAccess.shape.EsriShapeExport.export(EsriShapeExport.java:459)
at com.bbn.openmap.layer.DrawingToolLayer$6.actionPerformed(DrawingToolLayer.java:538)




4. chose a name with .shp at the end, in the openmap.properties file.  Draw ONE graphic, use save map and this creates associated shape files:
drawings.dbf
drawings.shp
drawings.shx


5. set a name without .shp at end in openmap.properties.  Use save map.  and this works. 

but I would like to NOT set a name in openmap.properties and be prompted for a file name when I select save map. 

maria

Don Dietrick

unread,
Mar 29, 2016, 2:47:55 PM3/29/16
to petaga...@gmail.com, openmap-users
Hi Maria,

I don’t think you’re picking up the new files in your classpath, the line numbers in the stack exceptions don’t match the code in the repository.  I’d check your build.

- Don
Reply all
Reply to author
Forward
0 new messages