1

I am removing open layers and trying to use google maps instead. My javascript creates a layer as under

var options = {
  "projection": new OpenLayers.Projection(DispProjection),
  "strategies": [ new OpenLayers.Strategy.BBOX( {
                    "ratio": 2,
                    "resFactor": 3
                  } )
                ],
  "protocol": new OpenLayers.Protocol.HTTP( {
                "url": "kml.asmx",
                "params": {},
                "format": new OpenLayers.Format.KML( {
                  "extractStyles": true,
                  "extractAttributes": true,
                  "maxDepth": 2
                } )
              } )};

var itslayer = new OpenLayers.Layer.Vector(
    l.name,
    options );

The call to "kml.asmx" is in my .NET code which is a HttpHandler. To transform this code, how do I use the 'protocol' in google maps? I have tried to do this which clearly does not work

var itslayer = new google.maps.KmlLayer("kml.asmx");

Please help.

user2837961
  • 1,505
  • 3
  • 27
  • 67
  • I've never used the `KmlLayer`, but from glancing at their documentation, does the URL need to be the fully qualified path? (example: `http://www.yourserver.com/kml.asmx`) – Paul Richter Feb 26 '14 at 16:04
  • But then why does openlayers use just "kml.asmx"? – user2837961 Feb 26 '14 at 16:32
  • Good question; [take a look at this](https://code.google.com/p/gmaps-api-issues/issues/detail?id=2825). It seems like the google KmlLayer feature assumes you're grabbing an external file, and doesn't automatically prepend the current url. Looking at OpenLayers' source code, they use the URL to make a `OpenLayers.Request.POST()`, which is ultimately an Ajax request (makes sense for how you were using it). Ajax will handle the URL properly in the case of a relative path like yours. I'd put all this as an answer, but like I said I've never used that layer so can't be 100% certain of any of this. – Paul Richter Feb 26 '14 at 17:02
  • I understand that the kmllayer will only take a physical file. This is difficult as I would need to convert a HTTPResponse into a physical file before I can use it and as far as I know you cannot save a file in javascript. Any ideas how to convert httpresponse into a url? – user2837961 Feb 27 '14 at 12:44
  • What happens if you write the fully qualified path? KML is just just xml basically, not a binary format or anything special like that, so I'm thinking google's KML layer might actually be able to make sense of the returned data from your server. [This answer](http://stackoverflow.com/a/16858740/877472) and [this one too](http://stackoverflow.com/a/9228379/877472) make me think it should be possible in this manner. – Paul Richter Feb 27 '14 at 18:51

0 Answers0