I have a WMS layer that is coming from SQL View. I want to be able to zoom to extent of layer when clicking a button (view changes because data keep coming to the DB).

How can I get the rectangle that currently contains the points and zoom to it ? (or an alternative is to make a polyline from the points and zoomtoexctent of it.. but its kinda overkill I think)


If you want to do the work purely in javascript, one option I can think of is to use OpenLayers.Request.GET to get the WMS server's capabilities document, then use OpenLayers.Format.XML to parse the document and get the extent of the layer.

If you are working with a web application that has a server side, it's better do the work on server side. Usually in database you can query the extent on the spatial field, e.g SDO_AGGR_MBR in oracle spatial, and ST_Extent in PostGIS, and usually they have corresponding API method in your server side programming language. Then pass the bounding box value from server side to client side (javascript).

  • I'm using MSSQL 2012 , How can I do it there? – Alophind Jul 8 '13 at 16:43
  • Never used SQL server for spatial data before, but I searched on google and I think this STEnvelop is the function used in SQL Server: msdn.microsoft.com/en-us/library/bb933896.aspx – mfdev Jul 9 '13 at 6:42
  • Try to apply the STEnvelop function on the geometry column of the SQL view that you create the WMS layer from. – mfdev Jul 9 '13 at 6:43
  • Solved it by doing the following : SELECT geometry::EnvelopeAggregate([Point]).STPointN(1).STX geometry::EnvelopeAggregate([Point]).STPointN(1).STY geometry::EnvelopeAggregate([Point]).STPointN(3).STX geometry::EnvelopeAggregate([Point]).STPointN(3).STY AS MaxY FROM [SomeTable] – Alophind Jul 10 '13 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.