Latest update

# Javascript Convert WMS url to coordinate?

2017-09-19 14:59:27

I'm looking for some hints (Javascript custom function or openlayers 4 function) ...) that can help me to convert a wms response URL parameters to get my click coordinates.

Here an example of url to convert to a click coordinate.

https://ws.mapserver.transports.gouv.qc.ca/swtq?SERVICE=WMS

&VERSION=1.3.0

&REQUEST=GetFeatureInfo

&BBOX=-7859605.72457123640924692,5954835.61684618983417749,-7802662.21180228982120752,5988064.99139707256108522

&CRS=EPSG:3857

&WIDTH=1155

&HEIGHT=674

&LAYERS=histo_stations_meteoroutieres

&STYLES=

&FORMAT=image/png

&QUERY_LAYERS=histo_stations_meteoroutieres

&INFO_FORMAT=text/html

&I=722

&J=403

&FEATURE_COUNT=10

My goal is to recreate a gml from this query based on derived wkt Point.

Your click coordinates are 722,403 px on a window that is 1155x674px with a really world bounding box of -7859605.72457123640924692,5954835.61684618983417749,-7802662.21180228982120752,5988064.99139707256108522.

So simple maths gives you

x = (-7802662.21

• Your click coordinates are 722,403 px on a window that is 1155x674px with a really world bounding box of -7859605.72457123640924692,5954835.61684618983417749,-7802662.21180228982120752,5988064.99139707256108522.

So simple maths gives you

x = (-7802662.2118022898212 - -7859605.72457123640924692) * 722/1155

y = (5988064.99139707256108522 - 5954835.61684618983417749) * 403/674

converting to javascript is left as an exercise for the reader.

But if it was me I'd remember the event coordinates I used to construct the URL in the first place.

2017-09-19 15:02:05