[OpenLayers-Users] How do I draw a box, retreive map coordinates, and pass to a python function?

William Hudspeth bhudspeth at edac.unm.edu
Wed Jul 23 07:28:55 PDT 2014


Thanks much Phil....I will take a look and see if I can adapt your code....

Vick


On 07/22/2014 04:00 PM, Phil Scadden wrote:
> okay, here is some outline (what I do for searching). Overview:
> Create a vector layer (selectedLayer) in which drawing occurs.
> Use a drawfeature control to do the drawing.
> When feature added to to drawcontrol, extract the geometry, call 
> server with a callback to handle the response.
>
> the code:
> selectedLayer = new OpenLayers.Layer.Vector("Selected Layer", {
>     wrapDateLine: true,
>     displayOutsideMaxExtent: true,
>     displayInLayerSwitcher: false,
> });
> map.addLayer(selectedLayer); (top layer)
>
>            ctrl= new OpenLayers.Control.DrawFeature(selectedLayer, 
> OpenLayers.Handler.Polygon, {
>                 geodesic: true, // stuff for managing drawing across 
> 180 line
>                 handlerOptions: {
>                     citeCompliant: false
>                 }
>             });
> // you can use different handler other than polygon for other geometries
>    ctrl.events.register("featureadded", this, function (e) {
>         Ext.Ajax.request({ // i am using Ext,  but you can use any 
> ajax wrapper you like
>             url:'mypythoncode',
>             method:'GET',
>             success:function(response){
>                  // process the response
>             },
>             params:{
>                 geometry:serialize(e.feature.geometry) // you need to 
> write serialize to your taste to format the geometry
>                 id: new Date().getTime(); // avoid browser caching
>             }
>         });
>
> That should get you started.
>
> Notice: This email and any attachments are confidential.
> If received in error please destroy and immediately notify us.
> Do not copy or disclose the contents.
>
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users



More information about the Users mailing list