[OpenLayers-Users] drawing a polygon over selected region

sunny74 sb.ray at hotmail.com
Sun May 9 10:03:39 EDT 2010


Hi Friends,

I am doing a GETfeature over a WFS layer.I am able to get the info of
selected features.
I have 2 questions:

1) When I drag the mouse a box is drawn temporarily and it goes off as soon
as I leave the mouse..
I want to pass the bounds of the selected region drawn to a function which
will draw a rectangle with a particular style over the selected region.How
can I do this?

2)I want to save the details of the features selected i.e within the box in
a GML.
3) Can we have a circle instead of a box for selection?

My code is :

layer = new OpenLayers.Layer.WMS("OpenLayers WMS",
"/Mapserver/mapserv.exe?map=c:/ms4w/apache/htdocs/Shape/newwr1rec.map", {
layers: ["state", "RailwayStations"], transparent: false, format:
"image/png" }, { isBaseLayer: true });
               map.addLayer(layer);

               layer = new OpenLayers.Layer.WFS("MyWFS",
               
"/Mapserver/mapserv.exe?map=c:/ms4w/apache/htdocs/Shape/Rail_wfs.map",
                { typename: "RailwayStations", maxfeatures: 100 },
                { featureClass: OpenLayers.Feature.WFS });
              
                select = new OpenLayers.Layer.Vector("Selection", {
styleMap:
                new
OpenLayers.Style(OpenLayers.Feature.Vector.style["select"])
            });
//                select1 = new OpenLayers.Layer.Vector("Selection1", {
styleMap:
//                new
OpenLayers.Style(OpenLayers.Feature.Vector.style["select"])
//            });
//            
            map.addLayers([layer,select]); 
               map.addControl(new OpenLayers.Control.LayerSwitcher());
               map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
               
               // make a GetFeature request
//               map.events.register('click', map, function(e) {
//                   var url =
"http://localhost:81/cgi-bin/mapserv.exe?map=c:/ms4w/apache/htdocs/Shape/Rail_wfs.map&SERVICE=WFS&VERSION=1.0.0&REQUEST=GETfeature&typename=state";

               //               })

               control = new OpenLayers.Control.GetFeature({
                 
                   protocol: OpenLayers.Protocol.WFS({
                    
                       formatOptions: {
                           outputFormat: "text/xml"
                       },
                       url:
"/Mapserver/mapserv.exe?map=c:/ms4w/apache/htdocs/Shape/Rail_wfs.map",
                       featureType: 'RailwayStations',
                       featurePrefix: 'ms',
                       geometryName: 'msgeometry',
                       maxFeatures: 100
                       
                       }),
                   box: true,
                   multipleKey: "shiftKey"
                   
               });
               control.events.register("featureselected", this, function(e)
{
                   alert(" in fselected");
                   //select.addFeatures([e.feature]);
                   //                  
document.getElementById('featuredetails').innerHTML += "<br>"+
e.feature.attributes.S_Name + "<br>"
                   //                   + e.feature.attributes.S_no;
                   var feats = e.feature;
                   alert(feats);
                   alert(e.feature.attributes);
                   alert(e.feature.geometry);
                   //response += e.feature.attributes.S_Name +
e.feature.attributes.S_no + e.feature.attributes.Distance_K +
e.feature.attributes.Stn_Code;
                   //UpdatePopup(response);

                   //alert(results.attributes.length);
                   //                   OpenLayers.Strategy.Save(e.feature);
                   //alert(feats);
                   //                   while (feats.attributes != null) {
                   //                      
document.getElementById('featuredetails').innerHTML += "<br>" +
feats.attributes.name + "<br>";

                   //                   }
                   //                   for (i = 0; i <
feats.attributes.length; i++) {
                   //                       alert(feats.attributes.first);
                   //                       alert(feats.attributes);
                   //                      
document.getElementById('featuredetails').innerHTML += "<br>" +
feats.attributes[i].name + "<br>";
                   //                   }

                   document.getElementById('featuredetails').innerHTML +=
"<br>" + e.feature.attributes.S_Name + "<br>"
                                        + e.feature.attributes.S_No + "<br>"
                                        + e.feature.attributes.Distance_K +
"<br>"
                                        + e.feature.attributes.Stn_Code;


               });
               map.addControl(control);
               control.activate();



-- 
View this message in context: http://osgeo-org.1803224.n2.nabble.com/drawing-a-polygon-over-selected-region-tp5026619p5026619.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.



More information about the Users mailing list