<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>Hello everybody,</div>

<div> </div>

<div>im using OpenLayers 2.12 and want to export vector layers (some routes served by geoserver) as kml and gpx files.</div>

<div>Now i found two different api versions:</div>

<div>http://dev.openlayers.org/docs/files/OpenLayers/Format/KML-js.html</div>

<div>which has a lot more functions then</div>

<div>http://dev.openlayers.org/releases/OpenLayers-2.12/doc/apidocs/files/OpenLayers/Format/KML-js.html</div>

<div>which has only the write function to export.</div>

<div> </div>

<div>I wonder which one works, or with which OL version.</div>

<div>Using the first one get the following errors (complete code below):</div>

<div><span style="box-sizing: border-box; color: rgb(255, 0, 0); font-family: Consolas, 'Lucida Console', monospace; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 12px; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">Uncaught TypeError: Cannot read property 'collection' of undefined</span><span style="color: rgb(255, 0, 0); font-family: Consolas, 'Lucida Console', monospace; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 12px; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); display: inline !important; float: none;"> </span></div>

<div>when i try</div>

<div>console.log(format.buildGeometry.multilinestring(record.data.geometry));</div>

<div>or</div>

<div><span style="box-sizing: border-box; color: rgb(255, 0, 0); font-family: Consolas, 'Lucida Console', monospace; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 12px; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">Uncaught TypeError: Object #<Object> has no method 'createElementNS'</span><span style="color: rgb(255, 0, 0); font-family: Consolas, 'Lucida Console', monospace; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 12px; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); display: inline !important; float: none;"> </span></div>

<div>when i try to export a single linestring</div>

<div>
<div>console.log(format.buildGeometry.linestring(record.data.geometry.components[0]));</div>

<div> </div>

<div>Is there something i'm missing or doing wrong? Below is my code snippet.</div>

<div> </div>
</div>

<div>I think the MultiLineString Object should be ok, as it looks like this</div>

<div>
<div class="header monospace" style="box-sizing: border-box; font-family: Consolas, 'Lucida Console', monospace; font-size: 12px; color: rgb(0, 0, 0); padding: 0px 8px 0px 0px; min-height: 0px; white-space: nowrap; -webkit-background-origin: padding; -webkit-background-clip: padding; background-image: none; border: none; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">
<div class="title" style="box-sizing: border-box; font-weight: normal; word-wrap: break-word; white-space: normal; line-height: 13px; color: black;"><span class="console-object-preview" style="box-sizing: border-box; font-style: italic;">constructor {<span class="name" style="box-sizing: border-box; color: rgb(136, 19, 145);">raw</span>: <span class="console-formatted-object" style="box-sizing: border-box; position: relative; display: inline-block; vertical-align: top; color: black;">Object</span>, <span class="name" style="box-sizing: border-box; color: rgb(136, 19, 145);">modified</span>: <span class="console-formatted-object" style="box-sizing: border-box; position: relative; display: inline-block; vertical-align: top; color: black;">Object</span>, <span class="name" style="box-sizing: border-box; color: rgb(136, 19, 145);">data</span>: <span class="console-formatted-object" style="box-sizing: border-box; position: relative; display: inline-block; vertical-align: top; color: black;">Object</span>, <span class="name" style="box-sizing: border-box; color: rgb(136, 19, 145);">hasListeners</span>: <span class="console-formatted-object" style="box-sizing: border-box; position: relative; display: inline-block; vertical-align: top; color: black;">HasListeners</span>, <span class="name" style="box-sizing: border-box; color: rgb(136, 19, 145);">events</span>: <span class="console-formatted-object" style="box-sizing: border-box; position: relative; display: inline-block; vertical-align: top; color: black;">Object</span><span style="box-sizing: border-box;">…</span>}</span></div>
</div>

<ol class="properties properties-tree monospace" style="box-sizing: border-box; margin: 0px; padding-top: 0px; padding-right: 6px; padding-bottom: 2px; padding-left: 0px !important; list-style: none; min-height: 18px; font-family: Consolas, 'Lucida Console', monospace; font-size: 12px; display: block; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">
        <li class="parent expanded" style="box-sizing: border-box; margin-left: 1px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; -webkit-user-select: text; cursor: default;" title=""><span class="name" style="box-sizing: border-box; color: rgb(136, 19, 145);">data</span><span class="separator" style="box-sizing: border-box;">: </span><span class="value console-formatted-object" style="box-sizing: border-box; position: relative; display: inline-block; vertical-align: top; color: black;" title="Object">Object</span>

        <ol class="children expanded" style="box-sizing: border-box; display: block; margin: 0px; -webkit-padding-start: 12px; list-style: none;">
                <li class="parent expanded" style="box-sizing: border-box; margin-left: 1px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; -webkit-user-select: text; cursor: default;" title=""><span class="name" style="box-sizing: border-box; color: rgb(136, 19, 145);">geometry</span><span class="separator" style="box-sizing: border-box;">: </span><span class="value console-formatted-object" style="box-sizing: border-box; position: relative; display: inline-block; vertical-align: top; color: black;" title="C">C</span>

                <ol class="children expanded" style="box-sizing: border-box; display: block; margin: 0px; -webkit-padding-start: 12px; list-style: none;">
                        <li class="parent" style="box-sizing: border-box; margin-left: 1px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; -webkit-user-select: text; cursor: default;" title=""><span class="name" style="box-sizing: border-box; color: rgb(136, 19, 145);">bounds</span><span class="separator" style="box-sizing: border-box;">: </span><span class="value console-formatted-object" style="box-sizing: border-box; position: relative; display: inline-block; vertical-align: top; color: black;" title="OpenLayers.Bounds.OpenLayers.Class.initialize">OpenLayers.Bounds.OpenLayers.Class.initialize</span></li>
                        <li class="parent expanded" style="box-sizing: border-box; margin-left: 1px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; -webkit-user-select: text; cursor: default;" title=""><span class="name" style="box-sizing: border-box; color: rgb(136, 19, 145);">components</span><span class="separator" style="box-sizing: border-box;">: </span><span class="value console-formatted-array" style="box-sizing: border-box; position: relative; display: inline-block; vertical-align: top; color: black;" title="Array[334]">Array[334]</span>
                        <ol class="children expanded" style="box-sizing: border-box; display: block; margin: 0px; -webkit-padding-start: 12px; list-style: none;">
                                <li class="parent name" style="box-sizing: border-box; margin-left: 1px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; -webkit-user-select: text; cursor: default; color: rgb(136, 19, 145);" title="">[0 … 99]</li>
                                <li class="parent name" style="box-sizing: border-box; margin-left: 1px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; -webkit-user-select: text; cursor: default; color: rgb(136, 19, 145);" title="">[100 … 199]</li>
                                <li class="parent name" style="box-sizing: border-box; margin-left: 1px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; -webkit-user-select: text; cursor: default; color: rgb(136, 19, 145);" title="">[200 … 299]</li>
                                <li class="parent name" style="box-sizing: border-box; margin-left: 1px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; -webkit-user-select: text; cursor: default; color: rgb(136, 19, 145);" title="">[300 … 333]</li>
                                <li style="box-sizing: border-box; margin-left: 12px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; -webkit-user-select: text; cursor: default;" title=""><span class="name dimmed" style="box-sizing: border-box; color: rgb(136, 19, 145); opacity: 0.6;">length</span><span class="separator" style="box-sizing: border-box;">: </span><span class="value console-formatted-number" style="box-sizing: border-box; color: rgb(28, 0, 207);" title="334">334</span></li>
                                <li class="parent" style="box-sizing: border-box; margin-left: 1px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; -webkit-user-select: text; cursor: default;" title=""><span class="name dimmed" style="box-sizing: border-box; color: rgb(136, 19, 145); opacity: 0.6;">__proto__</span><span class="separator" style="box-sizing: border-box;">: </span><span class="value console-formatted-array" style="box-sizing: border-box; position: relative; display: inline-block; vertical-align: top; color: black;" title="Array[0]">Array[0]</span></li>
                        </ol>
                        </li>
                        <li style="box-sizing: border-box; margin-left: 12px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; -webkit-user-select: text; cursor: default;" title=""><span class="name" style="box-sizing: border-box; color: rgb(136, 19, 145);">id</span><span class="separator" style="box-sizing: border-box;">: </span><span class="value console-formatted-string" style="box-sizing: border-box; color: rgb(196, 26, 22); white-space: pre;" title="OpenLayers.Geometry.MultiLineString_2691">"OpenLayers.Geometry.MultiLineString_2691"</span></li>
                </ol>
                </li>
        </ol>
        </li>
</ol>
</div>

<div> </div>

<div>This is my code snippet:</div>

<div>onDownloadRouteClick: function(grid, view, rowIndex, colIndex){<br/>
        var record = grid.getStore().getAt(rowIndex);               // the MultilineString Object seen above<br/>
            var format = new OpenLayers.Format.KML({<br/>
                internalProjection: this.getMappanel().map.baseLayer.projection,<br/>
                externalProjection: new OpenLayers.Projection("EPSG:4326")<br/>
            });<br/>
        console.log(format.buildGeometry.multilinestring(record.data.geometry));</div>

<div> </div>

<div> </div>

<div>Finally (after solving this problem ;) i'm facing the next problem how to get the user friendly download popup. If somebody as experience/ or an example how i can get a downloadable file from the string i would be very thankful :)</div>

<div> </div>

<div>Thanks</div>

<div>Christian</div>

<div> </div>

<div> </div></div></body></html>