Geoconcept Web - How to select an object on the map using its GCKEY, JSON and PHP

Geoconcept Web - How to select an object on the map using its GCKEY, JSON and PHP

This article is intended to help you dynamically selecting objects on the Geoconcept GIS web interface.

Defined the objects you need as vector objects

To be able to interact with specific objects on your map, first you have to declare them as a vector layer.

To create a new vector layer, go to Administration > Layers > Vector layers > Add...

In the dialog box you have to set:

  1. Use the exact name of the table where the objects you want to be able to query are stored

  2. Select the database where the table is stored

  3. Select the same table name as above in your dropdown menu

It's important that the name in 1 and 3 match.

Make it work/test it with Postman

If you're not already a daily Postman user you may have missed your life as a developer. Anyway, for the newbies, here is what one can read on the wiki about Postman:

Postman is an API platform for developers to design, build, test and iterate their APIs. As of April 2022, Postman reports having more than 20 million registered users and 75,000 open APIs, which it says constitutes the world's largest public API hub. The company is headquartered in San Francisco and maintains an office in Bangalore, where it was founded.

All of this is probably true and the best is that you can use it free of charge by just downloading it on postman.com.

Now that you're finally fully equipped to discuss with your Geoconcept server, here is how it works.

First, find the right URL

First of all, you need to know where to send your request, if you have a standard install, the URL should be looking like this:

https://<your-server-name>.<your-domain-name>/<server instance>/api/ws/portal?wsdl

To be able to communicate with your Geoconcept server you should use a SOAP Envelope such as this one

<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:sch=\"http://geoconcept.com/gc/schemas\">
    <soapenv:Header/>
    <soapenv:Body>
        <sch:update>
            <!--Optional:-->
            <userId>".$userID."</userId>
            <!--Optional:-->
            <projectId>".$projectID."</projectId>
            <!--Optional:-->
            <action>
                ".$builtJSON."
            </action>
        </sch:update>
    </soapenv:Body>
</soapenv:Envelope>

The envelope needs 3 specific pieces of information

  • The user ID: this information specifies for which user the map will be actualized. This information can be found in your database, in the table gw_user.id.

  • The project ID: specifies in which project the information will be found. This information can be found in your database, in the table gw_egw_project.id.

  • The JSON request: which is the action you want your server to take.

How to build a JSON request

To build your first Geoconcept Web JSON request use this template

{
  "display": {
    "level": <scale number>,
    "layers": [
      {
        "layerName": "<layer name>",
        "opacity": 100,
        "visibility": true
      }
    ]
  },
  "features": [
    {
      "layerName": "<name of the table you want to query>",
      "id": [
        <gckey you want to select, can be multiples>
      ],
      "styleId": 341
    }
  ]
}

You have to choose these options:

  • the scale number: which is the zoom factor of your map

  • the layer name: this is the exact name of the layer in Geoconcept Web where the object is displayed

  • the table name: this is the name of the vector layer we created before, we did make match the table name and the layer name to make it easy

  • the gckeys: this is a list of gckey you want to select. One will do the trick, multiple entries will work also

Make it work with a PHP script

You will find below a small PHP function that will be able to request Geoconcept Web to update its map selecting the objects you want by their GCKEY.

function mapUpdateRequest($projectId,$requestUserId,$layersList,$layerName,$gckey,$styleId,$scale){

  $wsdl_url   = "https://yourserver.domain.com/geoconcept-web/api/ws/portal?wsdl" 
  $builtJSON = '
    {
      "display": {
        "level": $scale,
        "layers": [
          $layersList
        ]
      },
      "features": [
        {
          "layerName": "$layerName",
          "id": [
            $gckey
          ],
          "styleId": $styleId
        }
      ]
    }'

  $params     = array(
    'userId'    =>  ''.$requestUserId.'',
    'projectId' =>  ''.$projectId.'',
    'action'    =>  ''.$builtJSON.''
  );
  $client   = new SoapClient($wsdl_url);
  $response = $client->__soapCall("update",array($params));
  return(var_dump($response));
}

That's all for now, let me know if this example was useful to you and reach me out if you need any help with your Geoconcept Web queries.

Did you find this article valuable?

Support D Ʌ V I D ★ S Ξ N Ʌ T Ξ by becoming a sponsor. Any amount is appreciated!