Global Navigation Bar

MapInfo Products Knowledge Base


Product: MapXtreme Java
Version: 2.x
Platform: All Platforms
Category: Code Samples

Summary:
Creating a copy of the MapJ object.

Question:
Is there a way to create a copy of an instance of a MapJ object?

Answer:
The following code sample will copy oldMapJ to newMapJ:

//... assume oldMapJ has already been initialized
MapJ newMapJ = new MapJ();
try {
//Save the original MapJ to a ByteArrayOutputStream
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream os = new ObjectOutputStream(baos);
oldMapJ.saveMapDefinition(os);
os.flush();
os.close();

//Open the original MapJ into the new MapJ
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream is = new ObjectInputStream(bais);
newMapJ.loadMapDefinition(is,null,null,0,null);
is.close();
} catch(Exception e) {
e.printStackTrace();
}




Last Modified: 02/15/2000 03:27:02 PM
Global Navigation Bar