Geoportal Extension for OpenLayers API Reference

Module: Styling

Gp.Styling

A simple specification for styling GeoJSON / GPX / KML data.

See:
TODO
  • ...

Example

feature.getStyle(); // null
feature.getProperties(); // {"stroke": "#ff0000", "stroke-width": 2}
Styling.defineStyleFromProperties(feature);
feature.getStyle(); // [Object Style]

feature.getStyle(); // [Object Style]
feature.getProperties(); // {}
Styling.definePropertiesFromStyle(feature);
feature.getProperties(); // {"stroke": "#ff0000", "stroke-width": 2}

var style = feature.getStyle(); // [Object Style]
var tag = Styling.setTag(style, "GPX");

ex. output GeoJSON:
```json
 "properties": {
  "stroke": "#ff0000",
  "stroke-width": 2
 }
```

Methods

innerdefinePropertiesFromStyle(feature)

OpenLayers/Formats/Styling.js, line 799

A l'écriture du format.

feature style --> feature properties --> tag styling

Le style natif est récupéré pour chaque feature :

// Ex.
var style = feature.getStyle();

Ensuite, le style natif est transformé en properties pour chaque feature :

// Ex.
var stroke = style.getStroke();
var oColorStroke = Color.rgbaToHex(stroke.getColor());
feature.set("stroke", oColorStroke.hex); // #000000
feature.set("stroke-opacity", oColorStroke.opacity); // 0.8

Et, chaque properties des features sont ecrites dans le format du fichier
(opération native sous OpenLayers) :

Ex. avec le format GeoJSON :

"properties": {
   "stroke": "#000000",
   "stroke-opacity": 0.8
}
Name Type Description
feature *

...

innerdefineStyleFromProperties(feature){*}

OpenLayers/Formats/Styling.js, line 406

A la lecture du format :

tag styling ---> feature properties ---> feature style

Les balises de 'styling' du fichier sont ajoutées dans les properties de chaque features
(opération native sous OpenLayers):

Ex. avec le format GeoJSON :

"properties": {
   "stroke": "#000000",      -> feature.get("stroke");
   "stroke-width": 13,       -> feature.get("stroke-width");
   "stroke-opacity": 0.8,    -> feature.get("stroke-opacity");
   "fill": "#a03737",        -> feature.get("fill");
   "fill-opacity": 0.5       -> feature.get("fill-opacity");
}

Ensuite, les properties des features sont transformées dans le style natif :

// Ex.
feature.setStyle(new Style({
 fill : new FillStyle({
     color : Color.hexToRgba(feature.get("fill"), feature.get("fill-opacity") || 1)
 }),
 stroke : new StrokeStyle({
     color : Color.hexToRgba(feature.get("stroke"), feature.get("stroke-opacity"))
     width : feature.get("stroke-width")
 })
}));
Name Type Description
feature *

...

Returns:
- ...

innerdefineStyleFunctionByDefault(defaultStyle){function}

OpenLayers/Formats/Styling.js, line 680

...

Name Type Description
defaultStyle Object

...

Returns:
function

innerdefineTagFromStyle(style, format){String}

OpenLayers/Formats/Styling.js, line 856

A partir d'un style natif, on le transforme en balise de 'styling' dans le format demandé,
que l'on peut ensuite inserer dans le fichier.

style ---> tag styling

Name Type Description
style *

...

format String

...

TODO
Returns:
stringify into the format (json / xml)

innergetListTags(){Array}

OpenLayers/Formats/Styling.js, line 358

All styling tags

Returns:
styling tags
Example
"type", // type de geometrie
"fill",
"fill-opacity",
"stroke",
"stroke-opacity",
"stroke-width",
"circle-fill",
"circle-fill-opacity",
"circle-stroke",
"circle-stroke-opacity",
"circle-stroke-width",
"circle-radius",
"marker-symbol",
"marker-color",
"marker-size"