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'm having a map which is rendered through OpenLayers using GeoServer. The map contains various attribute data field like link_no, X_coord, Y_coord etc.

I want to highlight the link using link_no. I internally use WMS layer to render the map.

I got the following code from this wiki for highlighting purpose:

// define a blank Vector layer and add it to the map
var highlight_style = { fillColor:'#99CCFF', strokeColor:'#3399FF', fillOpacity:0.7 };
hilites = new OpenLayers.Layer.Vector("Highlighted",
            {isBaseLayer:false, features:[], visibility:true, style:highlight_style}
        );
map.addLayer(hilites);

// define the WFS server which will fill requests
var wfs_url = '/cgi-bin/mapserv?map=/maps/spraywatch2/wms/mapfile.map&SERVICE=WFS&VERSION=1.0.0';
/* highlightFeatures() makes the WFS request, then highlight_them() callback does the real work
* Args for WFS filter: typename, attribute, value
*/
function highlightFeatures(typename,attribute,value) {
var wfsurl = wfs_url + '&REQUEST=getfeature&typename=' + typename +
       '&Filter=<Filter><PropertyIsEqualTo><PropertyName>'+attribute+'</PropertyName><Literal>'+value+'</Literal></PropertyIsEqualTo></Filter>';
OpenLayers.loadURL(wfsurl,'',null,highlight_them);
}
function highlight_them(response) {
                      // use the GML parser to turn the XML into a list of Feature objects
                      var features = new OpenLayers.Format.GML().read(response.responseText);
                      // have the Vector layer purge its feature list, replace them with the new ones
                      hilites.destroyFeatures();
                      hilites.addFeatures(features);
                      hilites.setVisibility(true);
                   }

Now what exactly is the typename, attribute and value parameters in the function highlightFeatures ? My aim is to highlight a particular link using a function call like this as explained in the wiki:

highlightFeatures('parcels','parcel_id','123456')

The above function call was an example given in the wiki link.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Typename - this is the name of the feature type you are trying to retrieve Attribute - this is the field of the feature you want to query against (I think this would be link_no in your example) Value - this is the value of link_no for the feature(s) you want to highlight.

You mention in your question that you're got a WMS layer set up, but it's not clear whether you've also set up a corresponding WFS layer to query against. The example you give assumes you have a WMS layer for displaying all your features, but it also requires a WFS layer which is what you need to query when you are highlighting a feature.

share|improve this answer
    
I have set up two layers as shown in the following link. In my code which I have stated in my question, I create a Vector layer. Isn't that sufficient? –  Sibi Nov 12 '12 at 11:10
    
Sorry, I probably wasn't very clear. On the client side of things that's sufficient - I was talking more about how things are set up on the server. You need to have a WFS set up on the server for you to query against. How this is set up will determine what you need to set your parameters to in the highlightFeatures method. –  pecoanddeco Nov 12 '12 at 11:17
    
WFS is set up in my server. My wfs_url in the code is var wfs_url = 'http://localhost:8080/geoserver/Alexandria/wfs'; But this results in a response from the server as bad request. Any idea where i'm going wrong? –  Sibi Nov 12 '12 at 11:26
add comment

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.