Add to Technorati Favorites .................................. - Virtual Earth
..................................
the blog@spencerwilliams.net

The NOAA WebService

January 15, 2008 14:06 by Spencer

I think something cool to add to a map is weather.  Take weather.com's use of Virtual Earth, I like it much more than the old Java timeline player.  I was looking at something done by Peter Bromberg on eggheadcafe.com.  He made some additions to a ASCX User Control that Mikhail Arkhipov created shown on his blog at MSDN.  I liked it.  I wanted it.  I downloaded Peter's project and built it.  It was pretty neat.  After integrating it into my TrailMaps website, I then realized what I didn't like about it - it was a server control.  Virtual Earth works on AJAX calls, so this didn't work for my TrailMaps website.  Or did it?  I needed to call the NOAA webservice after the map had loaded and I had a location.  Peter Bromberg's code translated zip codes into Lat/Long combinations to make it easier to implement, but I already had Lat/Long coordinates, so I reworked some of the code to query on LatLong instead of zipcode.  There was still the problem of the code needing to postback after I grabbed the LatLong from the map.  I had two choices:

1.  Write the code on the client-side to create the control via javascript that I already had on the server-side in C#. OR

2.  Figure out a way to return the ASCX control via javascript webservice calls using the AJAX Toolkit in VS 2008

I went with option 2 because I'm lazy, I liked what the control looked like already, and it's just HTML in the end right?  There has to be a way to get the HTML out of a user control and then grab that via a JS webservice call right?

 There is.  You have to use the System.Web.UI.Page class, but you can get it....you just have to render it first as if you were adding a control to a page.

public static string getWeatherControlHTML(decimal myLat, decimal myLon)
        {
            WeatherControl.WeatherLookup lookup = new WeatherControl.WeatherLookup();
            lookup.MyLat = myLat;
            lookup.MyLon = myLon;

            Page pageHolder = new Page();

            pageHolder.Controls.Add(lookup);

            StringWriter lookupOutput = new StringWriter();
            HttpContext.Current.Server.Execute(pageHolder, lookupOutput, false);

            return lookupOutput.ToString();
        }

Call this function from your webservice webmethod and you've got it.  I also added some animated gif's to simulate "working".  Check it out here and click the Get Weather button to grab the weather.  You can pan around and get weather all over the map, Colorado, New York, wherever the map is centered, those are the coordinates that are sent to the NOAA webservice.  I will warn you, Canadian weather is not supported. 

You can read more about the NOAA webservice:

Overview of the forcast webservice

 


Problem found - elevation

January 13, 2008 13:11 by Spencer

So after playing with the 3D overlay issues in Virtual Earth, I decided to tear out the elevation data before the import.  This "fixed" the problem (see here).  In this example the map is set to 3D mode, the KML overlay is placed over the map, and my reference point (3 trails converging - click the button to the right of the map to go there) is correctly shown on the map.  This works because there is NO elevation data in the KML file, or rather it is zeroed out.  I noticed something else with the overlay issues though, check this out:

 

screenshot of 3D KML overlay with elevation data

This is a screen shot of this map using this KML file after you use the control+down arrow, or the tilt button on the left-hand menu pane on it.  If you notice, in the lower right corner the altitude is given by the mouse cursor's position.  In the KML file, remember that the 3rd number in the comma-delimited string before the next space is the elevation.  Given the elevation data in the KML file, and the elevation data by the altitude display on the VE control, it is very strange that the overlay is approximately 400-500 feet above the maps elevation at every point.  What is also perplexing is that the track that is overlayed DOES seem to show elevation - i.e. it's not a flat line - there is some gradiation/relief in the overlay.


Problems with KML and Virtual Earth

January 12, 2008 10:53 by Spencer

I have been importing different KML files into the webpage I have been working with.  I first tried the 2D setting on the map control.  This works very well.  It wasn't until I played with the 3D capabilities of the VE control that I noticed some issues.  The following is excerpted from my post on the MSDN Virtual Earth Map Control Forum:

 When adding a KML overlay using ImportShapeLayerData the VEDataType.ImportXML type in a 2D rendering of the map works wonderfully.  Hybrid, road, even birds eye - they all work.  However, change the map to 3D style and the KML overlay is skewed and does not appear to be overlayed correctly on the map. 

<script type="text/javascript">

var map = null;
var layerid=1;

function GetMap()
{
map = new VEMap('myMap');
map.LoadMap(null,null,'h',null,null,null,null);
var l = new VEShapeLayer();
var veLayerSpec = new VEShapeSourceSpecification(VEDataType.ImportXML, "
http://www.spencerwilliams.net/kml/kmltest2.xml", l);
map.ImportShapeLayerData(veLayerSpec, onFeedLoad, 1);
}

function AddMyLayer(type)
{
var l = new VEShapeLayer();
var veLayerSpec = new VEShapeSourceSpecification(type, txtSource.value, null);
map.ImportShapeLayerData(veLayerSpec, onFeedLoad, 1);
}

function onFeedLoad(feed)
{

}

 

When you look at the map in 2D, zoom into the area where 3 trails meet by clicking the "Go To Position" button on the right side of the map (Click here for this map). 

This is a hiking trail where 3 trails come together.  This placement is correct.  Now change it to 3D view and you will see that the triangle section is nowhere near the previous spot.  I would assume that this has something to do with a 2D KML overlay being placed on a 3D contoured shape, like a paper cutout that doesnt fit around an object.  I thought about this for a while and then looked at the KML.

 

UPDATE - 7-18-2008 : this appears to be fixed as long as you don't zoom in past 20yds in 3d - I'll have to research if there were changes to the rendering of 3D overlays by the virtual earth team


The new VEDataType - ImportXML

January 11, 2008 10:34 by Spencer

There's a new addition to an enumeration folks, VEDataType.ImportXML .  Here's an easy example of how collections are added to a map:
 


function MapLoad()
        {
            map = new VEMap('myMap');
            map.onLoadMap = fnLoadCollection;
            map.LoadMap();
        }

        function fnLoadCollection()
        {
            var l = new VEShapeLayer();
            var veLayerSpec = new VEShapeSourceSpecification(VEDataType.VECollection, "C63B5D9B400AD5!122", l);
            map.ImportShapeLayerData(veLayerSpec, null, true);
        }

Collections are cool,  but they aren't my style.  My style is to own my own data.  Collections are assigned an ID on maps.live.com (after you sign in to save them), and granted you can import XML files (GPX, KML, LOC) but you can't import -> modify -> then export the files to a format that you use.  They go into the black hole that is known as a hosted service.  I like to keep tabs on my data and own it myself.  That being said, I did try this out here.  This shows my collection that is stored on maps.live.com - a geocaching trip my wife and I took to the Greenbelt and Barton Creek.  I DID have to edit the KML file that I imported - more on that later.

The coolest thing about this example?  Mouse-over the waypoint labeled 4-way and click the picture.  Now note where the camera was to take the picture - I was North/Northeast of the trail intersection.  Got that? OK, now click the birds-eye view in the upper-left of the Map Control.  Zoom into that waypoint and see how accurate that is.  I thought it was pretty impressive.


Virtual Earth KML - Take One - Waypoints

January 9, 2008 07:55 by Spencer

So I tried adding KML to the map - first glance, it looks great.  Pretty simple code too:

var map = null;

function MapLoad()
         {
            map = new VEMap('myMap');
            map.LoadMap(null,null,'h',null,VEMapMode.Mode3D,null,null);
            var l = new VEShapeLayer();
            
            var veLayerSpec = new VEShapeSourceSpecification(VEDataType.ImportXML, "
http://www.spencerwilliams.net/kml/kmlmainmap1.xml", 1);
            map.ImportShapeLayerData(veLayerSpec, onFeedLoad, 1);
          }

 function onFeedLoad(feed)
              {
                 
                 
              }

See the example here: http://spencerwilliams.net/trailmaps/default.aspx

I liked how Virtual Earth automatically zoomed the map in to see the two waypoints at the lowest zoom level that they would fit in.  I tried unsuccessfully to change the default pushpin icon.  More on that later.


 
Blog Information Profile for williasp