[OpenLayers-Users] Re: How to apply a Search Function

Diego M. oo_O2_oo at hotmail.com
Sun Feb 12 05:24:50 EST 2012


*I keep trying to review my code bit it seems logic to me !
I have no idea why all features are loaded when I search for one !*


var filter = new OpenLayers.Filter.Comparison({ 
                 type: OpenLayers.Filter.Comparison.LIKE, 
                 matchCase:false, 
                 property: "name", 
                 value: "searchText" 
             });

var strategy = new OpenLayers.Strategy.BBOX({ 
 		            ratio: 1 // makes for easier comparison to map bounds 
 		        });
var wfsprotocol = new OpenLayers.Protocol.WFS.v1_1_0({ 
                   url: "http://192.168.50.195:8080/geoserver/wfs", 
                   featureType: "Initial_view", 	
		   featureNS: "http://mapmap.org", 
		   srsName: "EPSG:3857", 
                   version: "1.1.0", 
                   extractAttributes: true, 
                   isBaseLayer: false, 
                   visibility: true 
               });
	var vessels = new OpenLayers.Layer.Vector("The Vessels", { 
styleMap: new OpenLayers.StyleMap(style),
maxExtent: new OpenLayers.Bounds(-180, -90,
180,90)transform(geographic,mercator), 
sphericalMercator: true,
strategies: [strategy],				   
protocol: wfsprotocol
			   });
map.addLayers([gmap, google_satellite, google_hybrid, google_physical,
vessels]); 


wfsprotocol.read ({ 
filter:filter, 
callback: processTheQuery, 
scope: strategy
         });

function processTheQuery(request) { 
     if (request.data && request.data.bbox) { 
           var b = request.data.bbox; 
           sExt = new OpenLayers.Bounds(b[0],b[1],b[2],b[3]); 
     }else { 
           var fts = request.features; 
           if (fts.length>0) { 
               sExt = fts[0].geometry.getBounds().clone(); 
               for(var i=1;i<fts.length;i++) { 
                  sExt.extend(fts[i].geometry.getBounds()); 
               }  } } 

     vessels.destroyFeatures();
     vessels.addFeatures(request.features); 
     map.zoomToExtent(sExt); 

} 


--
View this message in context: http://osgeo-org.1560.n6.nabble.com/How-to-apply-a-Search-Function-tp4364140p4461600.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list