Serving Network KML

Hi All,
Just wondering if anyone has created a flow for serving KML data as a network link. I have have tried by modifying a basic web page example and replacing the html with KML code but it didn't work. I'm not sure if this is the correct way to do it or if I am completely on the wrong path.

@dmac101, if your kml data is stored in files you could do the following...
Create an end point that serves the files...

  • Http in -->
    • URL - "/kml/:filename"
  • function node -->
     msg.filename = '/folder/' + msg.req.params.filename
     return msg;
    
  • file in node -->
    • Leave file name blank (will use msg.filename set in previous function)
  • Http out/response node
    Set header Content-type to application/vnd.google-earth.kml+xml

Then you can access the kml files like this...

http://noderedip/kml/mykmlfile.kml

Where noderedip is the IP of the node red, mykmlfile.kml is the file name.

More info here

Similar solution here

Thanks Steve-Mcl. I was looking more at dynamically creating the KML and serving it.

I have tried this but when I link to it using GE, the link icon remains red and nothing is displayed.
If i browse to the address with a web browser I see the following

Simple placemark Attached to the ground. Intelligently places itself at the height of the underlying terrain. -122.0822035425683,37.42228990140251,0 `

[{"id":"87cd83c2.e4414","type":"template","z":"474c1029.4ec3f","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"plain","template":"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n  <Placemark>\n    <name>Simple placemark</name>\n    <description>Attached to the ground. Intelligently places itself \n       at the height of the underlying terrain.</description>\n    <Point>\n      <coordinates>-122.0822035425683,37.42228990140251,0</coordinates>\n    </Point>`\n  </Placemark>\n</kml>","output":"str","x":560,"y":280,"wires":[["8698588b.c4d728"]]}]

Do you realise the flow you posted a single template node with hard coded xml/kml?

Also, I have no idea what "but when I link to it using GE, the link icon remains red and nothing is displayed" means? Is this in node-red? in node-red dashboard?

NOTE: your original question was about "Serving Network KML" not "dynamically creating the KML and serving it" which would have meant I wouldnt have bother describing loading of KML files etc - however, serving dynamic data (KML or whatever) and serving file data are preyty much the same task (just one doesn't load a file)

so if you want more help, please describe in detail your issue & dont assume we know what you mean by "the link icon remains red" - provide screen shots to clarify if necessary.

Yes i did realise. my approach is to start small to get it working and expand from there. If i started too complex it makes debugging significantly more challenging.
In google Earth the icon located in "Places" for a network links is either "Green" (has connectivity) or "Red" (cannot reach) In my case it is staying 'Red" so it cannot reach the address of node red. ie "MyExternalIP:1880/kml.

Apologies for my incorrect use of terms, I am still learning.
My end goal is to have an address or number addresses that i can link Google Earth to using network links that are generating KML on the fly.
I have a number of ideas, one of which is essentially a telemetry system that displays data in GE. for this i would be updating based on focus and change the icon colour based on alarm status, but provide all input data when clicking on the icon. Another project I am considering is to create rain radar overlay for Australia by pulling the images from the BOM website and turning them into a kml overlay.
Initially i just want to take the first step and be able to serve up the kml as a link and expand from there. Any help would be greatly appreciated

The best way to learn is to try.

Http in (URL set to /mykml) -->
Template node (with kml code in)-->
Http out node

Then open your browser and test it by entering http://localhost:1880/mykml (assuming you are running node-red in local host 1880)

Then once you have that working, build on it.

Read about how to set headers for kml

Read about how to build a js object and send it through an XML node to dynamically generated kml.

Try sending valid kml through an XML node then into a debug node - see what happens to the XML - then try building that js object using change nodes and function nodes. Then change some of the values dynamically. Then feed your object through an XML node - see if you can generate valid kml

Play, read, test, try & post specific questions when you have exhausted your forum and web searches.

And lastly, happy learning

I have tried the following code.
When I point my web browser to the address it downloads a kml.
If i load that kml into google earth it works, but if i reference the same address as a network link in GE it doesn't connect. I have had a look around for information on setting the header for kml and i think that i have it correct in the response node, but not confident. [{"id":"474c1029.4ec3f","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"b0568e69.ab35f","type":"http in","z":"474c1029.4ec3f","name":"test","url":"/kml.kml","method":"get","upload":false,"swaggerDoc":"","x":340,"y":260,"wires":[["87cd83c2.e4414"]]},{"id":"8698588b.c4d728","type":"http response","z":"474c1029.4ec3f","name":"host kml","statusCode":"","headers":{"content-type":"application/vnd.google-earth.kml+xml"},"x":790,"y":260,"wires":[]},{"id":"87cd83c2.e4414","type":"template","z":"474c1029.4ec3f","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"plain","template":"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n <Placemark>\n <name>Simple placemark</name>\n <description>Attached to the ground. Intelligently places itself \n at the height of the underlying terrain.</description>\n <Point>\n <coordinates>-122.0822035425683,37.42228990140251,0</coordinates>\n </Point>\n \n","output":"str","x":560,"y":280,"wires":[["8698588b.c4d728"]]}]`

Hi, please edit your post - your flow is not importable.

```
code here
```

As for GE (Google earth?) Not accessing you endpoint - is this not because you don't expose the end point to the internet?

E.g. your node-red is likely localhost or 192.168.x.y private addresses that are not accessable from the internet.

Hi Steve-Mcl,
I have this running on AWS with the security group set to allow traffic on port 1880 from any IP address.

[{"id":"b0568e69.ab35f","type":"http in","z":"474c1029.4ec3f","name":"test","url":"/kml.kml","method":"get","upload":false,"swaggerDoc":"","x":340,"y":260,"wires":[["87cd83c2.e4414"]]},{"id":"8698588b.c4d728","type":"http response","z":"474c1029.4ec3f","name":"host kml","statusCode":"","headers":{"content-type":"application/vnd.google-earth.kml+xml"},"x":790,"y":260,"wires":[]},{"id":"87cd83c2.e4414","type":"template","z":"474c1029.4ec3f","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"plain","template":"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n  <Placemark>\n    <name>Simple placemark</name>\n    <description>Attached to the ground. Intelligently places itself \n       at the height of the underlying terrain.</description>\n    <Point>\n      <coordinates>-122.0822035425683,37.42228990140251,0</coordinates>\n    </Point>`\n  </Placemark>\n</kml>","output":"str","x":560,"y":280,"wires":[["8698588b.c4d728"]]}]

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.