next up previous
Next: A command interpreter for Up: Part 1: PR Quadtrees Previous: Data dictionaries and notes

Drawing a spatial map using CanvasPlus

We have developed a Java applet to visualize what you are doing. Mapping commands will interact with the visual map you are building, and two commands will be able to print out what the map looks like. Everything you need to build the map properly is discussed below.

To create a new visual map and set the size:

CanvasPlus canvas = new CanvasPlus(``MeeshQuest'');
canvas.setFrameSize(spatialWidth, spatialHeight);

To initialize the map and make sure it looks correct, we need to add a white background and canvas.addRectangle(0, 0, spatialWidth, spatialHeight, Color.WHITE, false);rectangular bounds to the map since the map gives us a small border. The rectangle should be black and unfilled.

canvas.addRectangle(0, 0, spatialWidth, spatialHeight, Color.WHITE, true);
canvas.addRectangle(0, 0, spatialWidth, spatialHeight, Color.BLACK, false);

To add a named point to the map (despite the fact that cities have color and radius attributes we will always be drawing them as black points):

canvas.addPoint(``name'', x, y, Color.BLACK);

To remove a point works the same way:

canvas.removePoint(``name'', x, y, Color.BLACK);

To add other shapes (line segments, circles, rectangles, etc) the syntax is similar. See the javadoc for CanvasPlus. For example, to add a blue, unfilled circle:

canvas.addCircle(x, y, radius, Color.BLUE, false);

You will also be required to add a cross (a horizontal and a vertical line partitioning a rectangular section into 4 equal sections) where your PR Quadtree is partitioned (i.e. at each internal node). The cross should follow the rules of the PR Quadtree correctly. A cross should exist for each internal node of the PR Quadtree. The cross should be black, centered at the internal node's spatial center, and the radius of the cross should not exceed the spatial bounds of the internal node.

Examples will be provided for all visual components of the project.

To save a map to an image file:

canvas.save(``filename'');

Important: After calling the save method, CanvasPlus is still running. Remember to call the map's dispose() method when you are finished processing all the input. Otherwise your program will keep running.

The drawing packages are provided for your benefit. You are encouraged to use them when testing your PR Quadtree. In that case, you could simply call the CanvasPlus draw() method to open a window displaying the current map.


next up previous
Next: A command interpreter for Up: Part 1: PR Quadtrees Previous: Data dictionaries and notes
MM Hugue 2019-05-28