December 22, 2004

Building a map application with Calc

Author: Dmitri Popov

OpenOffice.org's Calc isn't only about rows and columns. If you look long enough at the empty spreadsheet, you will soon realise that it looks like a map grid, and, indeed, with a bit of imagination you can use Calc to create a simple yet handy mapping application. This how-to guides you through building a Calc-n-map -- an application for marking points of interest on a city map.

First of all you'll need to find a map in any Calc-supported graphics format. The easiest way to get a map is to use a dedicated Web site like Maporama, which features an easy-to-use interface and numerous options and map styles. Find the map you want to use and save it to your hard disk by right-clicking on the map and choosing the Save Image As... option (in Mozilla Firefox).

Launch Calc and create a new spreadsheet, and adjust the cell size (by default it's set to 2.27cm x 0.45cm) to make the spreadsheet look more "map-like." Select the whole sheet by pressing Ctrl-Alt, right-click on a column header, choose Column Width..., and set it to 1.00 cm. Then right-click on a row header, choose Row Height..., and set it also to 1.00 cm.

You might also want to change the name of the current sheet to something more meaningful -- for example, the name of the map. To do this, right-click on the sheet's tab, choose Rename Sheet..., and enter a descriptive name.

If you plan to print your maps, then should adjust the page settings too. Go to Format > Page..., where you can change the default page settings for orientation, table alignment (tick both Vertical and Horizontal check boxes to centre the map), header/footer, and so on.

Now you are ready to insert the map using the Insert > Picture > From File... command. Since you are going to use the map as a background you have to reduce its transparency to make it easier to use. To adjust transparency enter the desired value in the Transparency field.

The last thing you have to do is to send the map to the background so you can use the spreadsheet's cells for adding map points and entering additional info. To send the map to the background you can use the To background button on the Graphics object bar. Alternatively, you can right-click on the map and choose To Background from the Arrange menu.

Your map is now ready to be populated with various points of interest. In a real mapping application you can add a point of interest by simply dragging the appropriate icon to a location on the map. Using a couple of tricks we can add a similar functionality to our Calc-n-map application. First of all, you will need to find a set of suitable icons. I like the free sample icons from IconExperience. You can use any icons you like as long as they are in a format supported by OOo and you don't infringe on someone's copyright.

To create a "draggable" icon collection, use the Gallery tool. Click on the Gallery button or choose Tools > Gallery to open the Gallery pane.

Click on the New Theme button and enter a descriptive name for it -- for example Map points. Click on the Files tab, press the Find Files... button, and locate the folder containing the icon set. Click the Add all button to add the icons and OK when done.

You can now drag icons in the Map points theme into the map. As with a real map, you can add a legend, which explains what every icon signifies.

Better yet, you can use Calc's features to attach additional notes to the map points on the map. For example, if you add a bookstore to your map, you can use notes to enter its exact address, telephone number, and hours. For a hotspot it could be the pricing, signal quality, and provider.

To attach additional info to a map point you can use either the Callouts or Notes tools. Each tool has its advantages and drawbacks, and you might want to use them both. Callouts can be freely moved, support text formatting, and can be customised, but using them requires more steps, and callouts cannot be hidden. As for notes, they are easy to add and can be hidden, but they can only be attached to a cell, and they offer no formatting options.

To add a note, click on the cell you want to add the note to (obviously, this should be a cell close to the desired map point) and choose the Insert > Note... item. Then all you have to do is enter text into it. The cell with a note attached to it is marked with a tiny red dot in the upper right corner. The note appears every time you move the mouse over the cell, but if you prefer to make the note visible, right-click on the cell and choose Show Note.

Callouts give you more flexibility than notes. They are not anchored to a particular cell and you can change their attributes, such as colour, shadow, and type. Callouts also come in different shapes and provide text formatting options, so you are not confined to the default text style and size.

To add a callout click on the Drawing Functions button on the Main tool bar and choose the desired callout. Place the cursor in the desired location on the map and drag it while holding the right mouse button down to create a new callout. To change its appearance, right-click on it and choose the Area... item. You might want to change the background colour and add shadow.

If you want to change the callout's line to an arrow, right-click on it, choose the Line... item and click on the Line tab. In the Arrow styles section choose the desired arrow style from the Style drop-down menu.

That's all there is to it. Knowing the basics, you can expand and improve your Calc-n-map application even further.

Click Here!