# Serving Network KML

**URL:** <https://discourse.nodered.org/t/serving-network-kml/29089>\
**Category:** General\
**Created:** [28 June 2020 02:18 UTC](https://discourse.nodered.org/t/serving-network-kml/29089 "2020-06-28T02:18:39Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmac101](https://avatars.discourse-cdn.com/v4/letter/d/b4bc9f/32.png) [@dmac101](https://discourse.nodered.org/u/dmac101)\
**Post date:** [28 June 2020 02:18 UTC](https://discourse.nodered.org/t/serving-network-kml/29089/1 "2020-06-28T02:18:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [29 June 2020 22:02 UTC](https://discourse.nodered.org/t/serving-network-kml/29089/2 "2020-06-29T22:02:43Z")

</div>

@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 --\>

```auto
 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](https://cookbook.nodered.org/http/handle-url-parameters)

Similar solution [here](https://flows.nodered.org/flow/db68bd4934cf46f39e6e453a348bc419)

---

<div class="post-metadata">

**Author:** ![dmac101](https://avatars.discourse-cdn.com/v4/letter/d/b4bc9f/32.png) [@dmac101](https://discourse.nodered.org/u/dmac101)\
**Post date:** [4 July 2020 22:51 UTC](https://discourse.nodered.org/t/serving-network-kml/29089/3 "2020-07-04T22:51:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dmac101](https://avatars.discourse-cdn.com/v4/letter/d/b4bc9f/32.png) [@dmac101](https://discourse.nodered.org/u/dmac101)\
**Post date:** [4 July 2020 23:29 UTC](https://discourse.nodered.org/t/serving-network-kml/29089/4 "2020-07-04T23:29:59Z")

</div>

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 `

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 July 2020 11:29 UTC](https://discourse.nodered.org/t/serving-network-kml/29089/5 "2020-07-05T11:29:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dmac101](https://avatars.discourse-cdn.com/v4/letter/d/b4bc9f/32.png) [@dmac101](https://discourse.nodered.org/u/dmac101)\
**Post date:** [6 July 2020 21:34 UTC](https://discourse.nodered.org/t/serving-network-kml/29089/6 "2020-07-06T21:34:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 July 2020 21:46 UTC](https://discourse.nodered.org/t/serving-network-kml/29089/7 "2020-07-06T21:46:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dmac101](https://avatars.discourse-cdn.com/v4/letter/d/b4bc9f/32.png) [@dmac101](https://discourse.nodered.org/u/dmac101)\
**Post date:** [12 July 2020 09:21 UTC](https://discourse.nodered.org/t/serving-network-kml/29089/8 "2020-07-12T09:21:48Z")

</div>

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"]]}]`

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [12 July 2020 09:42 UTC](https://discourse.nodered.org/t/serving-network-kml/29089/9 "2020-07-12T09:42:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dmac101](https://avatars.discourse-cdn.com/v4/letter/d/b4bc9f/32.png) [@dmac101](https://discourse.nodered.org/u/dmac101)\
**Post date:** [12 July 2020 20:32 UTC](https://discourse.nodered.org/t/serving-network-kml/29089/10 "2020-07-12T20:32:06Z")

</div>

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

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [10 September 2020 20:32 UTC](https://discourse.nodered.org/t/serving-network-kml/29089/11 "2020-09-10T20:32:13Z")

</div>

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