[Users] how to include a download button for downloadind a vector layer with lines/pol draw by user

nacho barandalla nachobarandalla at hotmail.com
Wed Dec 19 15:23:07 CET 2012



Thanks Alexandre,

Finally I did it drawing the features in a kml vector layer and exporting with the following  function (with LayerManager):


Define vector layer:

    var vector = new OpenLayers.Layer.Vector("vector", {
             projection: map.displayProjection,
             strategies: [new OpenLayers.Strategy.Fixed()],
             protocol: new OpenLayers.Protocol.HTTP({
                 url: "placemark_floating.kml",
                format: new OpenLayers.Format.KML({
                     extractStyles: true,
                     extractAttributes: true,
                     kmlns: "http://www.opengis.net/kml/2.2"
                 })
             })
         });


Draw features:

   action = new GeoExt.Action({
        text: "Dibuja polígono",
        control: new OpenLayers.Control.DrawFeature(
            vector, OpenLayers.Handler.Polygon
        ),
        map: map,
        // button options
        toggleGroup: "draw",
        allowDepress: true,
        tooltip: "draw polygon",
        // check item options
        group: "draw"
    });
    actions["draw_poly"] = action;
    toolbarItems.push(action);
    toolbarItems.push("-");
    
 


Export function:


   var button2 = new Ext.Button({
            text: 'Guardar dibujo',
            enableToggle: false,
            handler: 
          
          function ()
          //alert ('probando')
          
          {
                 GeoExt.ux.data.Export.KMLExport(map,[vector], null);
             }
          
      });      



Thanks for your help

Nacho B


Date: Wed, 21 Nov 2012 08:49:24 -0500
From: adube at mapgears.com
To: users at geoext.org
Subject: Re: [Users] how to include a download button for downloadind a vector layer with lines/pol draw by user


  
    
  
  
    Hi,

      

        If you mean "export the features as text" then you need to pick
      a format in which you want to export your data, for example
      GeoJSON, KML, etc.  Here's a live example doing it in KML :

      

http://dev.geoext.org/geoext/sandbox/redlining/ux/FeatureEditing/examples/ControlerOnlyExample.html

      

        Start by drawing a feature (any first 3 tools).  A popup will
      appear in which there's an export button at the bottom left of the
      bottom toolbar.  You could also use the one in the map toolbar. 
      Here's the code that actualy does the KML writing :

      

http://dev.geoext.org/geoext/sandbox/redlining/ux_externals/layermanager/ux/data/Export.js

      

        Feel free to use any portion of this widget.

      

      HTH,

      

      Alexandre

      

      

      On 12-11-21 03:19 AM, nacho barandalla wrote:

    
    
      
      
        Hi everyone,

         

        I'm not sure this is the channel to send doubts to the
        community....anyway, let's go! (If not, im sorry and please tell
        me the correct way to do it.)

         

        My question is how to include a download button for downloadind
        a vector layer with lines/pol draw by user. explain:

         

        I have a map developed with geoext with several functions. 

        With the drawing controls, user is able to draw polygon and
        lines and stores it in a vector layer (called vector1). I need
        to give the user the possibility to download that vector
        layer containing its own draw, but I have no idea how to do it!

        The idea is to create a json layer and browse to save it in
        local user pc....

         

        Some help or idea please?

         

        Thanks a lot

         

         

        My code is:

         

         

            var vector = new OpenLayers.Layer.Vector("vector1");

            map.addLayers([vector]);

         

           var ctrl, toolbarItems = [], action, actions = {};

            action = new GeoExt.Action({

                text: "Dibuja polígono",

                control: new OpenLayers.Control.DrawFeature(

                    vector, OpenLayers.Handler.Polygon

                ),

                map: map,

                // button options

                toggleGroup: "draw",

                allowDepress: true,

                tooltip: "draw polygon",

                // check item options

                group: "draw"

            });

            actions["draw_poly"] = action;

            toolbarItems.push(action);

        

         

        Thank again!

         

      
      

      
      

      _______________________________________________
Users mailing list
Users at geoext.org
http://www.geoext.org/cgi-bin/mailman/listinfo/users

    
    

    

    -- 
Alexandre Dubé
Mapgears
www.mapgears.com

  


_______________________________________________
Users mailing list
Users at geoext.org
http://www.geoext.org/cgi-bin/mailman/listinfo/users 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.geoext.org/pipermail/users/attachments/20121219/ea21699a/attachment-0001.htm 


More information about the Users mailing list