Loading Dynamic KML from web service

5529
8
10-19-2011 08:25 AM
DavidErickson
New Contributor
I am attempting to use ArcGIS API for Javascript to view KML from a dynamic REST webservice of a 3rd party app server that I control.  To test this I have downloaded the html source for the KMLLayer example and am modifying the kmlUrl variable to hit my service.
http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/layers_kml.htm...

var kmlUrl = 'http://localhost:6040/service/query/etc/1.kml';
var kml = new esri.layers.KMLLayer(kmlUrl);
map.addLayer(kml);

The data does not appear.  However, if I download the URL to a static KML file and upload that to a public file webhosting (in this case my public DropBox) and then adjust the code to pull from the static URL hosting location, it works just fine.

Could the localhost or high number port be causing the problem?
Could any HTTP response headers mess up the KMLLayer constructor?  The webserver is setting the content type to "application/vnd.google-earth.kml+xml", which I believe is correct.

Thanks in advance for help,
Dave
0 Kudos
8 Replies
derekswingley1
Frequent Contributor
Could the localhost <snip> be causing the problem?


Yes, using localhost is the problem. Your KML file has to be publicly accessible to be used with the JS API. This is documented in the Working with KML Layers topic:
To add a KML file(.kml or .kmz) to a map, the KML must be available via a publicly accessible URL. Locally hosted or KML files inside a firewall are not supported.


The reason behind this requirement is that the KMLLayer class relies on a service hosted on ArcGIS.com to convert the actual KML to JSON. You can see this happening with firebug or chrome dev tools...here's the URL that's genereated from the simple KML layer sample: 
http://utility.arcgis.com/sharing/kml?url=http://dl.dropbox.com/u/2654618/kml/Wyoming.kml&model=simple&folders=&outSR={"wkid":4326}&callback=dojo.io.script.jsonp_dojoIoScript2._jsonpCallback
0 Kudos
DavidErickson
New Contributor
Thanks for the quick reply.
This is going to be deployed behind a firewall, so is there a JSON or XML format I could supply to the Javascript API directly?    Making JSON is just as easy for us as KML, we'd just like to make the interaction between the client-side Javascript map and the 3rd party web services to be as simple as possible.

Otherwise I guess I can do it purely in Javscript like
http://forums.arcgis.com/threads/41640-Programmatically-adding-multiple-points-to-the-map
, but then I'd have to learn how to get description bubbles, etc working.

Many thanks again
0 Kudos
derekswingley1
Frequent Contributor
...is there a JSON or XML format I could supply to the Javascript API directly?


Yes, take a look at the feature layer from feature collection sample. That shows how you can create a JSON object and pass it to the FeatureLayer constructor to get a feature layer you can add to your map.
0 Kudos
TimothyGreenwell
New Contributor

[/HR]


Thanks for the information above.  It clears a lot up.  Are there any products/extensions put out by ESRI that would allow us to host this ourselves?  Our network can never be publicly accessible.  Another 2D API handles this adequately but we'd prefer to be ESRI across the board.  Plus, the net link capability would be very useful.

Thanks
TG
0 Kudos
derekswingley1
Frequent Contributor

[/HR]Are there any products/extensions put out by ESRI that would allow us to host this ourselves?  Our network can never be publicly accessible.  Another 2D API handles this adequately but we'd prefer to be ESRI across the board.  Plus, the net link capability would be very useful.


ArcGIS.com does have subscriptions which is a way to keep your data private:  http://help.arcgis.com/en/arcgisonline/help/index.html#/Overview/010q0000007m000000/ There is also an option to host a copy of ArcGIS Online on your network:  http://www.esri.com/software/arcgis/portal-for-arcgis/index.html
0 Kudos
ChrisLatko
New Contributor
So is ArcGIS Online from the ArcGIS Portal the only way to do this? All I need is the kml utility which is located at http://utility.arcgis.com/sharing/kml

I need to add this functionality to my 9.3.1 Server inside my firewall.

Any advice?

Thanks!

Chris
0 Kudos
derekswingley1
Frequent Contributor
So is ArcGIS Online from the ArcGIS Portal the only way to do this? All I need is the kml utility which is located at http://utility.arcgis.com/sharing/kml


Those are your two options:  put your kml on a public server and use the service on arcgis.com or host your own arcgis portal. We don't provide the KML service as something you can host on your intranet.
0 Kudos
stevemclaughlin
New Contributor III
Those are your two options:  put your kml on a public server and use the service on arcgis.com or host your own arcgis portal. We don't provide the KML service as something you can host on your intranet.


What exactly do you mean by 'host you own arcgis portal',  I've installed a local arcgis mapserver, is it part of that package?
0 Kudos