This article is more than 1 year old

Virtual Earth puts human face on data

Lightweight programming, minus Google

The data set is returned to the method in the web service and, whilst this is happening, the text "Searching..." is displayed on the web page to provide feedback for the user.

If the transfer of data was successful, the function onSuccess is called.

    function onSuccess(result)
    {
        if (!layer)
        {
            layer = new VEShapeLayer();
            map.AddShapeLayer(layer);
            map.ShowAllShapeLayers();
        }
        
        layer.DeleteAllShapes();
        
        document.getElementById('SearchingText').innerHTML
            = 'Processing results...';
        
        for (var count=0; count < result.length; count++)
        {
            document.getElementById('SearchingText').innerHTML
                = 'Processing result ' + (count + 1)
                + ' of ' + result.length + '.';
            AddPoint(result[count].Name, result[count].Latitude,
                     result[count].Longitude);
        }

        document.getElementById('SearchingText').innerHTML
            = result.length + ' matches found.';
    }

The first five lines after the function name inquire if a layer is present: if there isn't, one is pulled in. Then any existing shapes superimposed upon the layer are erased.

Feedback ("Processing results...") for the web page user is provided again, and then a loop is entered that processes the returned data set row by row and adds a point for each location. Once each row has been processed, the number of matches found is displayed on the web page.

The mashup is now complete: data has been selected by the user, has been returned by the database and is displayed graphically on a Virtual Earth map.

The code needed to make this mashup work was easy to write using Visual Studio 2008. So are we trying to get you to use Visual Studio 2008? No. We don't care. The point isn't that it's any easier in any other code development tool of your choosing, but that it's easy to create mashups that provide useful interactive web-based tools.

If you are already writing web services, adding a mashup on top is trivial. Code for the web service ran to a mere 77 lines, not counting comments or lines containing a single bracket. (Although these are, of course, vital for the readability of code, they aren't exactly a taxing part of code writing and so they were ignored for the line count). The web page code was fractionally shorter at 75 lines, counted on the same basis.

So go on: create a mashup in your lunch break. You know it makes sense.®

More about

TIP US OFF

Send us news


Other stories you might like