mapcentia / geocloud2

The GC2 framework helps you build a spatial data infrastructure quickly and easily. Powered using open source components for a scalable solution focused on freedom rather than fees.
https://www.osgeo.org/projects/gc2-vidi/
GNU Affero General Public License v3.0
147 stars 67 forks source link

fix WMS passthrough #148

Closed giovanniborella closed 1 day ago

giovanniborella commented 3 days ago

bbox, width, height was not passed through to the final url, parse_url did nothing to the path element because QUERY_STRING was not a complete url - but just the query.

mapcentia commented 3 days ago

It's $_SERVER["QUERY_STRING"], which is passed to parse_url:

parse_url("LAYERS=public.wms&TRANSPARENT=TRUE&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&FORMAT=image%2Fpng&SRS=EPSG%3A3857&BBOX=1169005.4148614,7370812.4847207,1189077.300755,7376022.145929&WIDTH=4201&HEIGHT=1090")

Which yields:

Array
(
    [path] => LAYERS=public.wms&TRANSPARENT=TRUE&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&FORMAT=image%2Fpng&SRS=EPSG%3A3857&BBOX=1169005.4148614,7370812.4847207,1189077.300755,7376022.145929&WIDTH=4201&HEIGHT=1090
)
mapcentia commented 3 days ago

But I found an issue: bbox is passed through from GC2 and Vidi, but SRS/CRS is not. BBOX from GC2/Vidi is EPSG:3857, but the WMS source often has UTM EPSG. So, SRS/CRS must all be passed through from GC2/Vidi.

mapcentia commented 3 days ago

Something like this will do it, I guess:

                if ($source = $this->getWmsSource($db, $postgisschema, $layers)) {
                    parse_str(parse_url($_SERVER["QUERY_STRING"])['path'], $query);
                    $query = array_change_key_case($query, CASE_UPPER);
                    // Use parameters from WMS source if set and use those from query for not set parameters
                    $mergedQuery = array_merge($query, $source['query']);
                    // Always use these from the query
                    $mergedQuery['BBOX'] = $query['BBOX'];
                    $mergedQuery['WIDTH'] = $query['WIDTH'];
                    $mergedQuery['HEIGHT'] = $query['HEIGHT'];
                    $mergedQuery['VERSION'] = $query['VERSION'];
                    // Set SRS or CRS (WMS version 1.1.0 and 1.3.0)
                    $bits = explode('.', $query['VERSION']);
                    if ((int)$bits[1] < 3) {
                        $mergedQuery['SRS'] = $query['SRS'];
                    } else {
                        $mergedQuery['CRS'] = $query['CRS'];
                    }
                    // Set REQUEST TO GetMap
                    $mergedQuery['REQUEST'] = 'GetMap';
                    $url = $source['scheme'] . "://" . $source['host'] . $source['path'] . '?' . http_build_query($mergedQuery);
                    $useWmsSource = true;
                }
giovanniborella commented 1 day ago

maybe we are lookin at this from 2 different points of view - when getting the layer from vidi using an url like:

https://mapgoviditest.geopartner.dk/api/wms/kredsloeb/public?&labels=true&config=?&service=WMS&request=GetMap&layers=public.test_cc&styles=&format=image%2Fpng&transparent=true&version=1.1.1&width=256&height=256&srs=EPSG%3A3857&bbox=1305544.4431108106,7402008.945079902,1305697.317167381,7402161.81913647

then the resulting $url in the script you posted will evaluate to something like this: https://cloudconnectapi.geopartner.dk/prod/service/wms?LABELS=true&CONFIG=&TOKEN=9ca5d0f5-9ea5-49d0-aa90-d5d9f8cd0896&TRANSPARENT=TRUE&STYLE=default&SERVICE=WMS&FORMAT=image%2Fpng&APIKEY=8ac1f487-32dc-44cd-ab9a-9667ae109c96&LAYERS=Samlet_tif&REQUEST=GetMap

lacking the parameters for getting the relevant image from external service.

the layer is setup with a wmssource.

using mapcache the layer works fine - but directly, it fails

mapcentia commented 1 day ago

The URL has two ? - that's not valid. So this is a bug in Vidi I guess

giovanniborella commented 1 day ago

i'm looking at this block of code: https://github.com/mapcentia/vidi/blob/dc3f4d0040f69d1fad8e3afa4e5e5de0597000cf/public/js/gc2/geocloud.js#L689-L702

or this: https://github.com/mapcentia/vidi/blob/dc3f4d0040f69d1fad8e3afa4e5e5de0597000cf/controllers/gc2/wms.js#L12-L30

giovanniborella commented 1 day ago

this pr should still be merged