[josm-dev] Integrating the map panel on another application

Karl Guggisberg karl.guggisberg at guggis.ch
Mon Jun 29 17:48:01 BST 2009


Hi,

when I write unit tests for JOSM I also set
    Main.proj = new Epsg4326(); // if null nearly every construction of a
Node
                                // fails 
Or  let josm.home point to a directory with a preferences file, i.e.
   System.setProperty("josm.home", "/my/josm/home");

Then I use
   Main.pref.init(false);  // SIC: not true, otherwise whatever prefereces
you have
                           // are deleted 

-- Karl

PS: the structure of JOSM would benefit from something called "dependency
injection". Just my two cents. 

-----Ursprüngliche Nachricht-----
Von: josm-dev-bounces at openstreetmap.org
[mailto:josm-dev-bounces at openstreetmap.org] Im Auftrag von Maria Arias de
Reyna
Gesendet: Montag, 29. Juni 2009 18:30
An: josm-dev at openstreetmap.org
Betreff: [josm-dev] Integrating the map panel on another application

Hi,

I am trying to use the panel map integrated in JOSM (without the menus and
the
toolbars) on another Java Application, where I want to load a couple of osm
files.

I have found the MapViewer and the MapFrame classes, but when I try to
integrate them on my JFrame, it crashes. I know that there are some
preferences loaded on the Main class of JOSM and I am trying to replicate
whatever the Main loads so I can use the map panel on my project.

So far I have found this:

		Main.platform = new PlatformHookUnixoid();
		Main.platform.preStartupHook();
		Main.pref.init(true);

which I think are necessary to load the map.

After that I try:

		map = new MapView();
		frame.add(map);

and it works, showing me an empty map (black), although it says that the
projection could not be read from the preferences and prints an exception:

java.lang.ClassNotFoundException: 
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:169)
	at org.openstreetmap.josm.Main.preConstructorInit(Main.java:258)
	at my.application.Main$Initializer.run(Main.java:125)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
	at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java
:269)
	at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:18
4)
	at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java
:174)
	at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
	at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

When I try to load an osm layer from a file:

		Layer layer = new OsmDataLayer(new DataSet(), "prueba", new
File(""));
		map.addLayer(layer);

It simply crashes, throwing this:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at
org.openstreetmap.josm.gui.MapView.setActiveLayer(MapView.java:374)
	at org.openstreetmap.josm.gui.MapView.addLayer(MapView.java:173)
	at .....my classes....
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
	at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java
:269)
	at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:18
4)
	at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java
:174)
	at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
	at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

I am wondering if someone can help me pointing me how can I separate the map
panel from the rest of the application. If it is possible. I just need a map
that shows osm files, nothing more.

Thanks for your help :)
--
María Arias de Reyna Domínguez
Emergya Consultoría

_______________________________________________
josm-dev mailing list
josm-dev at openstreetmap.org
http://lists.openstreetmap.org/listinfo/josm-dev





More information about the josm-dev mailing list