Making a Photo Tour based on a Floor Plan

Brooke Simmons - http://www.experienceburgundy.com/

There has recently been a lot of debate on the forums about virtual tours. Their greatest advantage is that they give the consumer as honest a view as possible of a property, but one disadvantage is that they often require users to download platform-dependent software in order to see them. I myself am in Linux most of the time (rather than Windows), and I run Firefox, and some types of software (e.g., Quicktime and Windows Media Player) just aren't available to me.

So, working with another rental owner, I made a floor-plan-based photo tour of a small Paris apartment. It's not animated in the same way that true virtual tours are, but it does give the potential client a sense of perspective that a set of individual photos just doesn't have. The big advantage here is that this photo tour only uses javascript, which is not only a standard feature on every major browser and operating system, but is also much simpler to code compared to typical virtual tour methods.

The finished product can be seen here: http://www.experienceparis.com/fp.php

Essentially, you click on the blue triangles superimposed on the floor plan, and the image taken from that vantage point pops up to the right of the floor plan, and the triangle you just clicked on turns red to show you you're looking at that photo.

Here is a detailed description of how I did this. You can adjust this to fit your particular case. Clicking on any number will take you to the step-by-step instructions:

  1. Using a graphics program, place little blue triangles at each spot on the floor plan where a picture was taken -- and rotate each triangle so that it faces approximately the same direction the photographer was facing when taking the picture.

  2. Make a copy of the blue-triangle floor plan, but with red triangles instead.

  3. Use an image slicer (usually built in to your graphics program) to make the red-triangled image into a mosaic of smaller images, so that each little red triangle is its own image. The idea here is that you want to be able to click each triangle separately and change the triangle from blue to red when you do so, so you can't just click on one large image and hope to do that -- you have to break it up into parts. It'll look whole when it's done, and the image slicer will save not just the individual images, but also an html file for you so that you don't have to manually put them all back together again.

  4. Run the same image slice routine on the blue-triangled image, and if your image slicer has the option, add javascript functions (onMouseOver/onMouseOut or onClick) to each little triangle, setting it so that when the mouse either hovers over or clicks on the blue triangle, the image changes to the red-triangled image you just saved. You'll get lots of little images and an html file from this one, too.

  5. In an HTML or text editor (Dreamweaver, Editpad, Textpad, etc.), open up the html files that your image slicer generated for the blue-triangled images, and add some simple javascript code to it, building somewhat on the code already generated by your image slicer.

  6. Use css or tables to display the floor plan to the left of an image called "blank.gif", which is a 1x1 blank gif image, and just a placeholder for all the other images.

  7. In your HTML/text editor, add a bit of javascript to the html file you've been working on, that will pop up your photos in place of blank.gif whenever you click on or hover over the blue triangles.

  8. You're done!

Note: If you don't care about turning the triangles red, you can do this much more easily -- you just create an image map rather than slice up the floor plan image. You add the same javascript code, but not having to worry about slicing the image can make things much easier. However, below I'll describe the whole thing -- but keep in mind that there is a way of making steps 3 and 4 easier.

  1. Using a graphics program, place little blue triangles at each spot on the floor plan where a picture was taken -- and rotate each triangle so that it faces approximately the same direction the photographer was facing when taking the picture.

    Note: For all the graphics manipulation described below, I used Paint Shop Pro, which I find to be somewhat friendlier than Photoshop, a whole lot cheaper, and capable of doing nearly everything I need. For the HTML editing, I used Editpad, which is really just a text editor. Dreamweaver would work just as well.

    In the floorplan image, create a new layer; if you like, name it something useful like "Blue Triangles." In Paint Shop Pro, create it as a vector layer.

    Click on the shapes tool and select the triangle shape.

    Choose blue as your background color and solid color as your background fill style; choose transparent as your foreground fill style. Make sure "Create as vector" is checked in the tool options palette.

    In an empty part of the image, create the triangle you want. Make sure it's not equilateral, so that it will be obvious which direction it's pointing!

    Switch to the Object Selection Tool.

    Using the triangle you just created as a template, you can now create and place the other triangles. Click on the triangle to select it; a box should appear around it. Press Ctrl-C to copy the triangle, and Ctrl-G to paste a new one into the same layer. Place the new triangle at the position of your first photo.

    Click and drag the line extending from the selected vector triangle to rotate the triangle to the desired angle.

    Rinse, lather, repeat: Make, place, and rotate enough triangles to mark all the positions from which you have taken photos you're including in the photo tour. A sample end result:



    Top of Page

  2. Make a copy of the blue-triangle floor plan, but with red triangles instead.

    Select the "Blue Triangles" layer.

    Right-click on the layer and choose "Duplicate" -- or, from the Layers menu, choose Duplicate.

    Re-name the "Copy of Blue Triangles" layer to "Red Triangles." (Right-click on the layer and choose Rename.)

    Switch to (or make sure you're using) the Object Selection Tool.

    Expand the Red Triangles layer (click on the "+" sign next to it).

    Hold down the shift key as you click to select all the blue triangles in the layer (either click on the image, or click on the "triangle" entries in the layer toolbar).

    Once all the triangles are selected, click the blue background color (top right of screenshot above) and change it to red. This should change all the blue triangles on that layer to red.

    In preparation for the next step, make sure the Red Triangles layer is visible and the Blue Triangles layer is invisible (click the eye to the right of the layer name to toggle between visible/invisible).

    Top of Page

  3. Use an image slicer (usually built in to your graphics program) to make the red-triangled image into a mosaic of smaller images, so that each little red triangle is its own image.

    Paint Shop Pro has an image slicer built in, which you can access with: "File | Export | Image Slicer...". Making sure that the red triangle layer is selected and the blue triangle layer is deselected, run the image slicer on your floor plan image.

    Note: You can play around with this, since in the end it preserves your original image and creates copies as smaller images. So if you really hate the result, just delete the smaller copies and try again. You won't destroy your original floor plan image.

    First, select "GIF" from the Format box, and click "Apply optimization to whole image". You can click the "Optimize Cell..." button to set the image transparency and color palette, if you want.

    Note: jpegs are standard for photos, but for something like a floor plan where you probably don't have that many colors involved, gif is the way to go.

    Use the slice tool to make rows right above and right below your triangles. Just click and hold at the right horizontal level in the image, and drag the mouse slightly sideways -- the cut will appear as a horizontal line and you can release the mouse when you've got it where you want it. If you make a mistake, either Undo (Ctrl-Z) or use the eraser tool to erase a cut line, or the hand tool to move cut lines.

    When you've got the rows arranged as you like them so that the rows are fairly tight against each triangle, use the slice tool to create columns around the triangles, so that each triangle has a little box around it. (To create columns, drag the mouse vertically rather than horizontally when you're creating the cut line). Work-in-progress for the floor plan is shown to left.

    When you've got all the cut lines where you want them, click the "Save Settings..." button to save the layout of your cut lines. This is an important step! I called the settings "fp_mosaic.jsd".

    Click the "Save As..." button. This is where you save not only the little mosaic images that will come from the slices you've created, but also the HTML file where the code to put the pieces back together into the big image. I suggest choosing a short but descriptive name for the html file, and using the same name as the stem for the image files. I used "fp_on.html" and "fp_on" for the HTML Save As and Image Slice Save As prompts:

    The most important thing about this step is that you save your html files and images in the same directories you intend to store the html files and images when you publish the website, or at least have the same relative directory structure. If you store your html files and images in the same directory, do that here. If, however, you store your html files in C:\MyStuff\html\ and your images in C:\MyStuff\html\images\, make sure you do the same thing with your HTML Save As and your Image Slice Save As. Otherwise, the relative directory paths between the HTML file and the images will be wrong, and while it's not hard to fix, it's a pain in the rear.

    Now you should have a file called "fp_on.html" and a bunch of images that start with "fp_on"..., like fp_on_1x1.gif, etc. We will be using these files in the next step, and we will be using some of the gif files in the finished product.

    Top of Page

  4. Run the same image slice routine on the blue-triangled image, and if your image slicer has the option, add javascript functions (onMouseOver/onMouseOut or onClick) to each little triangle, setting it so that when the mouse either hovers over or clicks on the blue triangle, the image changes to the red-triangled image you just saved.

    In a web browser, load the fp_on.html file from the File menu; the actual menu command depends on your browser. In Firefox, the command is "File | Open File..." (Get Firefox).

    I recommend printing a copy of the floor plan from your browser; if you don't have a printer, sketch a quick diagram with triangles included.

    For each triangle, right-click and either choose Properties or View Image. Locate the file name and note the coordinates of the file on your printed/sketched plan next to the triangle in question. For example, if my top-rightmost triangle image is fp_on_2x2.gif, I would write 2x2 next to the top-rightmost triangle on my printout. This will make the next steps much faster.

    In your original floor plan image with the two sets of triangles, make the Red Triangles layer invisible and the Blue Triangles layer visible (click on the eyes next to the layer names).

    Again, choose "File | Export | Image Slicer..." and this time, click the "Load Settings..." button and load the jsd file you saved (in my case, fp_mosaic.jsd). This should bring up the cut lines already made and the gif image format should now be selected.

    Using the arrow tool, select the first box-surrounded triangle in your image; the box around it should turn green.

    With the triangle cell selected, click the "Rollover Creator..." button.

    Check the "Mouse click" line, and click on the little file icon to the right of that line. Here's where writing down those coordinates comes in handy: select the "fp_on_*.gif" which corresponds to the coordinate of the triangle you're working on. So if I'm working on the 2x2 triangle, I would find the image fp_on_2x2.gif and select that for my mouse click image here.

    Rinse, lather, repeat: Repeat the three steps above for each of the triangles in your image.

    Note: If you want the photos to appear when someone just hovers their mouse over the triangle rather than them having to click on it, do the same thing as above using the "Mouse over" line. For everything that follows, though, I'm going to assume you've chosen the click method.

    Run the Save As... steps described above, except this time name the files "fp_off" instead of "fp_on." You'll be using the fp_off.html file quite a bit in the next steps.

    Open fp_off.html in your browser and check to make sure that each triangle turns red when you click on it. If you missed one, you can go back and add it by re-doing step 4 (this image slice step). For now, the triangles will stay red even when you click on other triangles; that's what we're going to fix with the next step.

    Top of Page

  5. In an HTML or text editor (Dreamweaver, Editpad, Textpad, etc.), open up the html files that your image slicer generated for the blue-triangled images, and add some simple javascript code to it, building somewhat on the code already generated by your image slicer.

    In your HTML/text editor, open fp_off.html (or whatever it is you named it).

    Add the following code to the beginning of the file, somewhere between the <HEAD> and </HEAD> tags:

    <script language="JavaScript"> <!-- function restoreall() { if(document.images) { //document.rtswap.src='images/blank.gif'; } } function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } //--> </script> Ah-hah, but you're not done with that yet. See that code after the "if(document.images)" line? You're going to customize that for your specific floor plan.

    Aside: Don't be afraid of code. It's not that scary. Code is your friend. You can do it.

    Within fp_off.html, search for the first line of code that looks like (the numbers may be different): <A HREF="#" onclick="if(document.images) document.fp_off2.src='images/fp_on_2x2.gif';"> Copy (highlight and press Ctrl-C) the last part of the line (except for the " and the > sign): in the above case you would copy document.fp_off2.src='images/fp_on_2x2.gif';.

    Scroll up to the "if(document.images) {" line, and paste the text into a new line after "if(document.images) {". To paste, put your cursor at the position you want the new text, and press Ctrl-V. Following the above example, that function should now look like:
    function restoreall() { if(document.images) { document.fp_off2.src='images/fp_on_2x2.gif'; //document.rtswap.src='images/blank.gif'; } } Now, in the line you just pasted, change "fp_on_" to "fp_off_" (or whatever you called your blue-triangle sliced/mosaic images). Now the function looks like: function restoreall() { if(document.images) { document.fp_off2.src='images/fp_off_2x2.gif'; //document.rtswap.src='images/blank.gif'; } } Now, go back to the original line you copied: <A HREF="#" onclick="if(document.images) document.fp_off2.src='images/fp_on_2x2.gif';"> And add one bit of text to it: a) before "if(document.images)", add the text " restoreall(); ". Now the line should look like: <A HREF="#" onclick="restoreall(); if(document.images) document.fp_off2.src='images/fp_on_2x2.gif';"> Rinse, lather, repeat: Now that you've done that for the first "onclick" example, do the same thing for each line in the file that has that 'onclick="if(document.images)' text. You should notice as you go along that the coordinates (e.g., the coordinates in the above example are 2x2) of the lines you're copy-pasting and changing correspond to the coordinates of the triangle images that you wrote on your map.

    Once you're done, you should have several lines in the function restoreall() bit of your code. Mine looks like this:

    function restoreall() { if(document.images) { document.fp_off2.src='images/fp_off_2x2.gif'; document.fp_off6.src='images/fp_off_4x2.gif'; document.fp_off10.src='images/fp_off_6x2.gif'; document.fp_off14.src='images/fp_off_8x2.gif'; document.fp_off18.src='images/fp_off_10x2.gif'; document.fp_off19.src='images/fp_off_10x3.gif'; document.fp_off21.src='images/fp_off_10x5.gif'; document.fp_off25.src='images/fp_off_12x2.gif'; document.fp_off29.src='images/fp_off_14x2.gif'; document.fp_off31.src='images/fp_off_14x4.gif'; document.fp_off33.src='images/fp_off_14x6.gif'; //document.rtswap.src='images/blank.gif'; } } Each of those lines (except for the last one) correspond to one of the triangle images. The last line in the function actually corresponds to an image that doesn't exist yet -- we'll be doing that in the next step.

    Now, go to your browser and reload fp_off.html (in some browsers, F5 will refresh the browser, or you can click the refresh button). If nothing happens, hold the shift key down as you click refresh to force a full refresh.

    What you should see now when you click each triangle is that that particular triangle turns red, and any triangle that was just red turns back to blue. Great -- you've gotten the floor plan to look the way you want it to look when people click. Now we have to add the actual photos!

    Top of Page

  6. Use css or tables to display the floor plan to the left of an image called "blank.gif", which is a 1x1 blank gif image, and just a placeholder for all the other images.

    Since we want the floor plan to appear at the left and the photos to appear at the right, we need to tell the browser exactly how to do this.

    (Aside) I should note here that you can do this very well with CSS, and if that's your preferred method, go to it! I personally prefer tables because there's no problems with different browser interpretations, and they're somewhat more basic than CSS, so even really old browsers have no problem with them. So, my example will use tables. If you're going to do it with CSS, skip this step.

    Also, if you would prefer that your photos be displayed below or above the floor plan, you'll also have to modify this step. Displaying below or above the floor plan, though, is a little easier: just insert a <BR CLEAR=ALL> tag between the floor plan table and the image tag I'll be describing below.(End Aside)


    In your HTML/text editor, you will be embedding the HTML code that Paint Shop Pro automatically created within fp_off.html within a little bit of code of your own.

    In fp_off.html, look for the lines:<!-- Begin Table --> near the beginning of the file, and <!-- End Table --> near the end of the file. If you can't find those, look for the lines <TABLE BORDER="0" ...>and</TABLE> instead.

    The code between these two lines should take up most of the file fp_off.html. When I refer to it here, I'm not going to show it all -- I'll instead refer to it as: <!-- Begin Table --> ... <!-- End Table --> Within fp_off.html, insert some simple HTML code: <TABLE BORDER="0"> <TR><TD ALIGN=LEFT> <!-- Begin Table --> ... <!-- End Table --> </TD> <TD ALIGN=CENTER> <IMG NAME="rtswap" SRC="images/blank.gif" BORDER="0"> </TD></TR> </TABLE> Note the position of the original html code within this. Also note that I've assumed two things:
    a) that the path to your image folder is the same as in all my previous examples (images are stored in a directory called images/ which is within the directory where you store your html files); and
    b) that there already exists a file called blank.gif in the images/ directory. If that's not true, use your image program to create a small image (e.g. 1 pixel by 1 pixel), which is either transparent (if you know how to do this) or the same color as your page background (if you don't know how to set image transparency); save it as "blank.gif" in your images directory.

    In your browser, refresh fp_off.html and make sure that your floor plan is now shown on the left side of the screen, and that you see a blank space on the right side. If you're not sure this worked, you can always change the table borders to "1" and see where the borders of each table cell are. Be sure to change them back to "0" when you're done, though.

    That blank.gif image is just a place holder: in the next step, we'll be adding small bits of code that will swap the photos you want to show from each triangle.

    Top of Page

  7. In your HTML/text editor, add a bit of javascript to the html file you've been working on, that will pop up your photos in place of blank.gif whenever you click on or hover over the blue triangles.

    This step will be no problem for you now that you've done step 5, you code master you.

    Speaking of step 5, we'll be modifying the exact same lines of code that we did then.

    First: go to the line within the function restoreall(): //document.rtswap.src='images/blank.gif'; and remove the two slashes right before "document.rtswap."

    Now, here comes the most customized part of this instruction: what are the filenames of each photo that you want to show for each triangle? You will need to go back to that printed/sketched floor plan diagram and jot down the filename of each photo next to the triangle in question.

    Note: for convenience, I named my photos using the mosaic coordinate form and with the prefix "fp_pic". What this means is that, for example, the photo that shows up at the 2x2 mosaic triangle is called fp_pic_2x2.jpg. I could have just as easily called it bedroom_blahblah.jpg. But for this instruction, I'll assume the filenames are fp_pic_*.jpg. You will need to customize this according to your photo names.

    Now, go back to the first line of code that begins with <A HREF="#" onclick="restoreall(); if(document.images) ..."> For me, this first line of code is: <A HREF="#" onclick="restoreall(); if(document.images) document.fp_off2.src='images/fp_on_2x2.gif';"> Since this is the 2x2 coordinate, I know that the photo I want to include is called fp_pic_2x2.jpg. So now, add two bits of text to this line:

    First, after "if(document.images)", add a left curly bracket "{".

    Second, before the last two characters of the line ( the "> characters), add the text "document.rtswap.src='images/fp_pic_2x2.jpg';}". The code should now look like: <A HREF="#" onclick="restoreall();if(document.images) {document.fp_off2.src='images/fp_on_2x2.gif'; document.rtswap.src='images/fp_pic_2x2.jpg';}"> Optionally, you can also remove the textHREF="#" from the line (I did).

    Rinse, lather, repeat: Do this for each line that has the "onclick" function in it -- be sure to match up the correct photo filename with the correct triangle using your sketch/printout of the floor plan!

    In your browser, refresh fp_off.html and make sure the correct photo appears when you click each triangle!

    Top of Page

  8. You're done!

Well done! Now publish your photo tour and be sure to ask your clients what they thought of it!

Here's my finished product.

Back to the Lay My Hat Forums