Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am trying to modify the Vector Formats example to only display the GPX in the textarea rather than all the options in the original example but I can't get it working.

My code below currently displays [object Object] is the text area. The next stage would be to save it as a GPX file but I can't even get this part to work. Help appreciated.

    <!-- The magic comes here --> 
    <script type="text/javascript"> 
        function init() { 

            //Set the bounds of the map
            var bounds = new OpenLayers.Bounds(
                        -139554.52234597853, -14571.288749854866,
                        805578.7494653241, 1322557.5275064965
                    );

            // Create the map using the specified 
            // DOM element 
            var map = new OpenLayers.Map("main"); 

            // Add a WMS layer
            // and add to the map 
            var wms = new OpenLayers.Layer.WMS("Ordnance Survey",
                "http://192.168.0.7:8080/geoserver/osgb/wms", 
            {
                layers: 'osgb'

            },
            {
                maxExtent: bounds,
                maxResolution: 5223.159438501372,
                projection: "EPSG:27700",
                units: 'm',
                transitionEffect: 'resize'


            });



                vectors = new OpenLayers.Layer.Vector(
                    "Vector Layer",
                    {
                        //renderers:renderer,
                    }
                );

            editing_toolbar_vector=new OpenLayers.Control.EditingToolbar(vectors);
            // Add layers to the map
            map.addLayers([wms,vectors]);

            map.addControl(editing_toolbar_vector); 

            // Add layer switcher control
            map.addControl(new OpenLayers.Control.LayerSwitcher());

            // Set the centre of the view and the starting zoom level
            map.setCenter(new OpenLayers.LonLat(415526,536854), 6);

            // Add Scale of current map (bottom right)
            map.addControl(new OpenLayers.Control.Scale($('scale')));

            // Add coordinates of mouse to the map (bottom right)
            map.addControl(new OpenLayers.Control.MousePosition({element: $('location')}));

            var options = {
            hover: true,
            onSelect: serialize
            };
            var select = new OpenLayers.Control.SelectFeature(vectors, options);
            map.addControl(select);
            select.activate();

        } 

        //var out_options = {
        //    'internalProjection': map.baseLayer.projection,
        //    'externalProjection': "EPSG:4326"
        //};

        function serialize(feature) {

        var str = new OpenLayers.Format.GPX({
            'internalProjection': new OpenLayers.Projection("EPSG:27700"),
            'externalProjection': new OpenLayers.Projection("EPSG:4326")
        });
            str.write(feature);


            //str = str.replace(/,/g, ', ');
            document.getElementById('output').value = str;
        }
    </script> 
</head> 
<body onload="init()"> 
    <div id="main" style="width: 100%; 
        height: 75%;"></div> 
    <div id="text">Draw route to update the output below.<br>
            <div id="outputarea""><textarea id="output"></textarea></div>
</body> 

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You should write document.getElementById('output').value = str.write(feature);

share|improve this answer
    
Thank you that works. I had since redone my modified version of the vectors example and got it working but the version I posted above I prefer now that it actually works. –  user15965 Mar 11 '13 at 22:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.