I’m in the midst of doing a development project with Bing Maps, using their nifty feature whereby you can create a polygon ‘collection’ in their UI toolset, and then publish this out to a KML file, which you can then import back and overlay back onto the map and be able to display it in all sorts of interesting ways (i.e. in their birdseye mode, 3D Google-earth-style mode, etc.).
Unfortunately, it hasn’t been the smoothest road, and I’m looking to find a support community that can help me through this.
The first hurdle is that you can’t develop on KML using just your own box. I.e., you can’t host the KML file on your local web server or an internally-located dev server. In order make KML overlays work in Bing Maps, the KML file has to be on an internet-accessible machine. This is due to the fact that the sequence works like this – if you want to display a file like “myoverlays.kml” on your map:
1. You specify the KML overlay as a shape in your Bing Maps code, like so:
function EventMapLoad() {
var shapeLayer = new VEShapeLayer();
var shapeSpec = new VEShapeSourceSpecification(VEDataType.ImportXML, http://blog.reevestech.net/wp-content/uploads/arlington-combined.kml, shapeLayer);
map.ImportShapeLayerData(shapeSpec);
}
This will then load that KML file when the page loads.
2. When the page loads, the Bing Maps JS then grabs your KML file off the server, and sends it back to Bing to be transformed into a “collection” markup that the Bing JS can use. If you check your Firebug action when loading a KML file as above, you’ll see a request for something like this:
http://www.bing.com/maps/GeoCommunity.aspx?mapguid=1246652212958&action=importcol&saveimport=v&cid=msftve_1001&mapurl=http%3a%2f%2fblog.reevestech.net%3a8600%2faed%2fkml%2farlington-combined.kml&rim=VEMap._GetMapFromGUID(%271246652212958%27)._lm.RetrieveImportedCallback&rimargs=%27msftve_1001%27&mkt=en-us&maxitems=200
Note that it has my URL in the request. The response you get back from the server is something of a “Collection Markup” or “CML” schema, which is basically the same XML data as the KML, but obviously piped through some XSLT at Bing’s end to make it acceptable for their JS.
3. With that data returned successfully to the client’s browser, the KML should then render on the map area of the user’s machine.
Now, where it gets tricky for me is this: I’m trying to dynamically generate a KML file to be returned when the user goes to the page.
Now, for some reason – the Bing Maps KML parser seems to work when the data is served off of Apache, and works when served statically by Resin — but not when served dynamically from a Resin/Railo ColdFusion server.
I can’t tell why this is, but something in the request is making the Bing Maps KML parser bail out. Below are WGET samples – one where the request is going through Resin statically, the other is where it’s being parsed by the Railo CF servlet. Same exact file, nothing different.
Any clues, anyone?
Read more…