Technical documentation of Geoportal API

  • FR
  • UK

Index / Documentation / Technical documentation

Ajout de couches vecteur

Adding a KML, GPX or OSM layer 
Adding a WFS layer 
Changing the design of vector layers via the API 
Changing the default behavior of the API

The method for adding layers is explained here.

This chapter details the mandatory and optional parameters allow the addition of vector layers.

Adding a KML, GPX or OSM layer

Examples of use:

Optional layer parameters specific to this type of layers:

In addition to the optional layer parameters ./add_layers.html}here, we find:

  • projection: layer's projection (See internalProjection). Defaults to the map's projection (through its base layer). It is advised not to overload this option ;
  • preFeatureInsert : callback to do something with a feature just before it is appended to its layer.Defaults to Geoportal.Popup.Anchored.setPointerCursorForFeature : this function changes the mouse pointer when it is over the KML object ;
  • onFeatureInsert : callback for creating a popup for a feature:
    • KML : Defaults to Geoportal.Popup.Anchored.createPopUpForKMLFeature: uses description and, if any, name fields of the KML resource
    • GPX : Defaults to Geoportal.Popup.Anchored.createPopUpForGPXFeature: uses the fields present desc, cmt, and ele name of GPX;
    • OSM / WFS : Defaults to Geoportal.Popup.Anchored.createPopUpForGMLFeature: uses the fields present in the objects;
  • formatOptions : options related to reading the file:
    • internalProjection : map's projection (though the base layer) ;
    • extractAttributes : indicator reading information from the file. Defaults to true. When false (default value for OpenLayers), the popup is empty ;
    • extractStyles : indicator reading styles file. Defaults to true. When false, it is up to the developer to support styles ;

    The three following parameters are specific to GPX:

    • extractWaypoints : reads Waypoints. Defaults to true;
    • extractTracks : reads Tracks. Defaults to true;
    • extractRoutes : reads routes. Defaults to true ;

The two parameters that follow are specific OSM format:

  • checkTags : tag verification. Defaults to false;
  • areaTags : list of tags, only applies if checkTags is true. Defaults to null;


The data in the files are loaded into application memory. extractAttributes parameter may be turned off if activated to lower the memory usage. The same remark applies these parameters:

  • extractWaypoints, extractTracks et extractRoutes for GPX files.
  • checkTags et areaTags for OSM files.

It has been benchmarked that above 200 features, the application slows down.

When large GPX or KML datasets are to be handled, it is advised to use WFS or a combinaison of WMS/WFS.

When large OSM datasets are to be handled, it is advised to use the OSM API or a combinaison of WMS/OSM API.

Adding a WFS layer

Examples of use:

Example of adding a WFS layer without loader / with the loader.

The screenshot below is based on the following code fragment

specific service settings for wfs layers :

  • mandatory parameters:
    • typename: Array containing the names of layers to display
  • optionnal parameters:
    • filter:
    • version :

specific layer settings for wfs layers :

In addition to the optional parameters of layers here, we find:

  • mandatory parameters:
    • projection: layer's projection. Example : 'EPSG:4326'.
  • optionnal parameters:
    • units: 'm' or 'degrees'
    • ratio: determines the size of the application server-side relative to the size of the map of the window. []


First of all, reading thi FAQis of help !

Here are some benchmarks made with a WFS service :

Taille de la réponse GetFeatureNombre d'objetsChargement

Various limits are a combinaison of different factors :

  • Geometry size : OpenLayers FAQ says 2500 coordinates, we can load more but it is really the number of coordinates per feature that is the limit at loading time;
  • Feature type : when rendering polygons are really painfull;
  • Number of features : above 200, the panning slows dependant on the two previous factors ...
  • Response size : it seems that Javascript string object length is "limited". This limitation depends on the browser (for instance, Firefox 2 cannot load more than 1Mb into a String object). See over there for more information. []

    As a matter of facts, one has to :

  • limit display range to limit the number of features ;
  • use maxFeatures parameter to limit the number of features ;
  • use multi-scale databases or play with Geoportal.Layer.Aggregate to simulate this ;
  • implement SuperOverlays in OpenLayers for vector data;
  • combine WMS with GetFeatureInfo and GetFeature;
  • switch to 2D Web ActionScript API when ready ...

Exemple de WFS version 2.0.0 : utilisation du JSON-P pour appel Cross-Domain

The API gives access to the WFS service version 2.0.0. From OpenLayers 2.11, a protocol OpenLayers.Protocol.Script allows to use JSONP request to get data from a WFS service located on a different domain without having to configure any proxy.

The above screenshot is based on the code following fragment.

Changing the design of vector layers via the API

First disable the styles defined in the file by adding the parameter "formatOptions":


Then, create an instance of the OpenLayers.StyleMap class with a parameter an object that contains the styles.

var myStyle= new OpenLayers.StyleMap({
             "default"  : new OpenLayers.Style ({
                 strokeColor : "black",
                  strokeWidth: 2
             "select" : new OpenLayers.Style ( {
                 strokeColor : "red",
                 strokeWidth : 2

Then add this to styleMap layer through the layer parameter "styleMap" which will be set to the style name created.

Examples of changes in style from one layer KML, WFS ou GPX ou OSM

Changing the default behavior of the API

In order to customize the display and behavior of the popups, one has to overload the following options preFeatureInsert, onFeatureInsert, onSelect, onUnselect and, possibly, hover.

These attributes are set to the name of a callback function that takes as input the object in question.

Example using the parameters onSelect: when we click on one of the objects of the layer "territories", a wikipedia window opens.

Example using the parameters preFeatureInsert.