Technical documentation of Geoportal API

  • FR
  • UK

Index / Documentation / Technical documentation

Adding layers

The support of WMTS, KML, GPX, OSM, WMS is provided in the minimum, standard and extended API while the support of WFS is only ensured in the extended API.

Adding these layers can be done in two ways:

Using the loader

The addition of outer layers using the loader is explained here.

Using the method Geoportal.Map.addLayer()

// Case of services "WMS", "WMTS", "WFS" ou "GEORSS" 

viewer.getMap().addLayer(
    "layer_type",
    "layer_name",
    "access_url",
    {service_parameters},
    {layer_parameters}
);

// Case of files "KML", "GPX" ou "OSM"

viewer.getMap().addLayer(
    "layer_type",
    "layer_name",
    "access_url",
    {layer_parameters},
    {popup_parameters}
);

Detail of the parameters used:

layer_type :

"WMS", "WMTS", "WFS", "GEORSS", "KML", "GPX" ou "OSM".

layer_name :

Contains the text displayed in the Layer Manager. This name can be a string or an object to support multi-lingual ;

access_url :

String containing the path to the file or the URL of the service;

service_parameters :

Object containing the information needed to manage the service such as the layer names to add or format of the image returned in the case of WMS.

layer_parameters :

Object containing the information needed to refine the behavior of a layer. Common parameters are:

  • visibility : true (the layer is displayed when loading the map), otherwise false ;
  • opacity: integer included between 0 to 1. Sets the opacity of the layer.
  • minZoomLevel : minimum display zoom (smallest scale). Defaults to 0 (world zoom) ;
  • maxZoomLevel : maximum zoom display (highest scale). Defaults the zoom mapped with the base layers' highest scale ;
  • styleMap : Instance of the OpenLayers.StyleMap class. By default, the API creates a legend for each layer type. In the case of WFS, the API creates an INSPIRE legend: points, lines and polygons are black.
  • view :Object containing the parameters of the layer's management:
    • drop : adds a control for deleting the layer from the layers switcher. Defaults to true ;
    • zoomToExtent : adds a control for zoom to the extent of the KML layer. Defaults to true ;
  • originators: Object used to allocate the ownership of data containing the following properties for each of the distributors:
    • logo: a string identifying the distributor logo. See pictureUrl for more information ;
    • pictureUrl: if defined, it is the image's URL. if not defined, the logo property is used to construct the URL to the image as follows : http://www.geoportail.fr/legendes/logo_ + logo + .gif ;
    • url: the distributor's URL. The web page is opened in a new window ;
    • extent : the geographic extent of the dataset ;
    • attribution : a short text describing the data owner.
  • isBaseLayer: Defauls to false. If set to true, the layer added is defined as base layer.
  • maxExtent: Instance of the OpenLayers.Bounds class. Represents the maximum extent of the layer. It is important to note that it must be expressed in the coordinate system projection. Example: new OpenLayers.Bounds (-180, -90,180,90) for projection EPSG: 4326 '
  • constraints: list of constraints to display the layer only in the specified extents. A constraint object is defined with the following properties:
    • maxExtent: Instance of the OpenLayers.Bounds class. Represents the maximum extent of the layer for this constraint. It is important to note that it must be expressed in the coordinate system projection. Example: new OpenLayers.Bounds (-180, -90,180,90) for projection EPSG: 4326 '
    • maxResolution: the maximum resolution for this constraint.
    • minResolution: the minimum resolution for this constraint.
  • format : reader: OpenLayers.Format.KML, OpenLayers.Format.GPX, OpenLayers.Format.OSM, ...
  • eventListeners: set to an object containing events attached to the map and each event is set to a callback function.

popup_parameters :

Optional object containing the information needed to refine the behavior associated with a popup layer. Common settings for layers KML / GPX / OSM / WFS are:

  • onSelect : callback when a feature is selected ;
    • KML/GPX/OSM: Defaults to Geoportal.Control.selectFeature: displays the form of the object;
    • WFS:Defaults to Geoportal.Control.hoverFeature: displays the form of the object;
  • onUnselect : : callback when a feature is unselected. Defaults to Geoportal.Control.unselectFeature : this function closes the feature's popup and free it ;
  • hover : switcher for managing the selection behavior. By default, the selection occurs when clicking (false) on a KML feature ;
  • preventDefaultBehavior :disable the popup behavior - let the developper add the popup handlers ;