[GIS] How to change the color of the layer after searching

openlayers-2

My task is searching a single house from a layer and then zoom to the center. I did this part but i can't clearly identify this house. I am try to do this by adding a fillcolor to the searched area. but i can't.

var point1 = new OpenLayers.Geometry.Point(mins.x, mins.y);
            point1.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913")); 
            point1.style={fillColor: '#FF0000'};// coloring the point
var point2 = new OpenLayers.Geometry.Point(maxs.x, maxs.y);
            point2.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913")); 
            point2.style={fillColor: '#FF0000'};// coloring the point
var bounds = new OpenLayers.Bounds();
            bounds.extend(point1);
            bounds.extend(point2);
            bounds.toBBOX();

            map.zoomToExtent(bounds); 

but it can't change the previous color
eg: see this page https://gis.fatih.bel.tr/webgis/default.aspx

Best Answer

What you have done is to define a bounds, and just zoomed to it.

What you need to do, is to create an geometry (either point or polygon), and add it to an empty vector layer. That it will be displayed as a graphic. You can style it according to your needs.

map.addLayer(wmsLayer);

var pt1=new OpenLayers.Geometry.Point(-2,-2);
var pt2=new OpenLayers.Geometry.Point(-2,2);
var pt3=new OpenLayers.Geometry.Point(2,2);
var pt4=new OpenLayers.Geometry.Point(2,-2);

var ring=new OpenLayers.Geometry.LinearRing([pt1, pt2, pt3, pt4]);
var poly=new OpenLayers.Geometry.Polygon([ring]);

var feat=new OpenLayers.Feature.Vector(poly, {}, {fillColor:'red', fillOpacity:0.4});

polygonLayer.addFeatures([feat]);

See this jsfiddle