Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Change a query parameter

wadeziegler
Nimbostratus
Nimbostratus

I have a query paremeter with coordinates that need to be reversed. The name of the parameter needs to change and the coordinates reversed too. What is the best way to do that?

Change from:

https://gis.xxxxxxxx.com/arcgis/apps/webappviewer/index.html?id=yyyyyyyyy&reversedmarker=36.121779,-115.169858&level=20 

To:

https://gis.xxxxxxxx.com/arcgis/apps/webappviewer/index.html?id=yyyyyyyyy&marker=-115.169858,36.121779&level=20 

1 REPLY 1

Hi wadeziegler,

Can you try this?

when HTTP_REQUEST {
    if { [HTTP::query] contains "reversedmarker" } {
        set uri [HTTP::uri]
        set reversedmarkervalue [URI::query $uri reversedmarker]
        set markervalue "[getfield $reversedmarkervalue "," 2],[getfield $reversedmarkervalue "," 1]"
        set newuri [string map [list $reversedmarkervalue $markervalue "reversedmarker" "marker" ] $uri]
        HTTP::uri $newuri
        # for redirect
        # HTTP::redirect https://[HTTP::host]$newuri
        unset uri reversedmarkervalue markervalue newuri
    }
}

or shorter but less readable:

when HTTP_REQUEST {
    if { [HTTP::query] contains "reversedmarker" } {
        HTTP::uri [string map [list "[URI::query [HTTP::uri] reversedmarker]" "[getfield [URI::query [HTTP::uri] reversedmarker] "," 2],[getfield [URI::query [HTTP::uri] reversedmarker] "," 1]" "reversedmarker" "marker"] [HTTP::uri]]
        # for redirect
        # HTTP::redirect https://[HTTP::host][string map [list "[URI::query [HTTP::uri] reversedmarker]" "[getfield [URI::query [HTTP::uri] reversedmarker] "," 2],[getfield [URI::query [HTTP::uri] reversedmarker] "," 1]" "reversedmarker" "marker"] [HTTP::uri]]
    }
}