Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OWC Context (POC) #90

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions src/Formats/OWC.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import Logger from "../Utils/LoggerByDefault";
import Schema from "./OWC/Schema";

/**
* @classdesc
*

Check failure on line 6 in src/Formats/OWC.js

View workflow job for this annotation

GitHub Actions / build

Trailing spaces not allowed
* Construction d'un fichier JSON de context OWC
* {@link https://www.ogc.org/fr/publications/standard/owc/}
*

Check failure on line 9 in src/Formats/OWC.js

View workflow job for this annotation

GitHub Actions / build

Trailing spaces not allowed
* @constructor
* @alias Gp.Formats.OWC
*
* @param {Object} [options] - options du format OWC
* @example
* // appel via les services
* Gp.Services.getContext({
* data : [{
* name : "PLAN.IGN",
* service : "TMS",
* }],
* configuration : {
* type : "service", // ou service|json|object
* url : "[url du service de recherche]" // data: "file.json" ou data: {}
* },
* onSuccess : (response) => {}
* onFailure : (error) => {}
* });
*

Check failure on line 28 in src/Formats/OWC.js

View workflow job for this annotation

GitHub Actions / build

Trailing spaces not allowed
* // appel direct de la classe
* var owc = new OWC({
* // conf tech issue de geoportal-configuration
* data : {...},
* // nom du template de transformation
* template : "geoportal-configuration",

Check failure on line 34 in src/Formats/OWC.js

View workflow job for this annotation

GitHub Actions / build

Trailing spaces not allowed
* // version du template
* version : 1.0,

Check failure on line 36 in src/Formats/OWC.js

View workflow job for this annotation

GitHub Actions / build

Trailing spaces not allowed
* });
* owc.setVersion();
* owc.setData();
* owc.setTemplate();
* var context = owc.build();
*/
class OWC {

Check failure on line 43 in src/Formats/OWC.js

View workflow job for this annotation

GitHub Actions / build

Block must be padded by blank lines
/**
* constructor
* @param {*} options

Check failure on line 46 in src/Formats/OWC.js

View workflow job for this annotation

GitHub Actions / build

Trailing spaces not allowed
*/
constructor(options) {

Check failure on line 48 in src/Formats/OWC.js

View workflow job for this annotation

GitHub Actions / build

Missing space before function parentheses

Check failure on line 48 in src/Formats/OWC.js

View workflow job for this annotation

GitHub Actions / build

Block must not be padded by blank lines

Check failure on line 49 in src/Formats/OWC.js

View workflow job for this annotation

GitHub Actions / build

Trailing spaces not allowed
this.logger = Logger.getLogger();
this.logger.trace("[Constructeur OWC ()]");

// options par defaut
this.options = {};

// et on ajoute les options en paramètre aux options par défaut
for (var opt in options) {
if (options.hasOwnProperty(opt)) {
if (options[opt]) {
this.options[opt] = options[opt];
}
}
}

this.setTemplate(this.options.template);
this.setVersion(this.options.version);
this.setData(this.options.data);
this.setAdditional(this.options.additional);

return this;
}

/**
* Nom du template de conversion vers le context
* @param {*} template
*/
setTemplate (template) {
this.template = template || "";
}

/**
* Format d'entrée en JSON
* @param {*} data
*/
setData (data) {
this.data = data || {};
}

/**
* Version du tempate de conversion
* @param {*} version
*/
setVersion (version) {
this.version = Number(version) || 1.0;
}

/**
* Données additionnelles
* @param {*} data
*/
setAdditional (data) {
this.additional = data || {};
}

/**
* build
* @returns {Object} -
* @fixme on ne traite qu'une seule donnée !
* @todo les données additionnelles !
*/
build () {
var map = Schema.get(this.template, this.version);
if (! map) {
throw "[run OWC::build()] Erreur de récuperation du schema !"
}

var newSchema = Schema.transform(this.data, map);
if (! newSchema) {
throw "[run OWC::build()] Erreur de transformation de schema !";
}

return newSchema;
}

}

export default OWC;
252 changes: 252 additions & 0 deletions src/Formats/OWC/Schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
/** Liste des properties de type classe : context et resource */
const classType = {
"typeName:context" : {
"lang": "",
"title": "",
"subtitle": "",
"updated": "",
"publisher": "",
"date": "",
"generator": "",
"authors": [],
"contributors": [],
"categories": [],
"links": [],
"bbox": []
},
"typeName:resource" : {
"title": "",
"abstract": "",
"name": "", // added !
"service": "", // added !
"updated": "",
"publisher": "",
"date": "",
"active": true,
"opacity": 1, // added !
"visibility": true, // added !
"authors": [],
"contributors": [],
"offerings": [],
"categories": [],
"links": [],
"minscaledenominator": 0,
"maxscaledenominator": 0,
}
};

/**
* Liste des properties de type data :
* - offering
* - operation
* - content
* - style
*/
const dataType = {
"typeName:offering" : {
"code": "",
"operations": [],
"contents": [],
"styles": []
},
"typeName:operation": {
"code": "",
"method": "",
"type": "",
"href": "",
"request": {},
"result": {}
},
"typeName:content": {
"code": "",
"title": "",
"href": "",
"content": ""
},
"typeName:style": {
"name": "",
"title": "",
"abstract": "",
"default": "",
"legendURL": "",
"content": ""
}
};

/** Liste des services */
const offeringServiceExtension = [
"WMS",
"WMTS",
"TMS",
"WFS"
];

/** Liste des données de type fichier */
const offeringInlineExtension = [
"KML",
"GPX",
"GEOJSON"
];

/** Liste des namespaces */
const namespaces = {
"Core" : "http://www.opengis.net/spec/owc-geojson/1.0/req/core",
"WMS" : "http://www.opengis.net/spec/owc-geojson/1.0/req/wms",
"WMTS" : "http://www.opengis.net/spec/owc-geojson/1.0/req/wmts",
"WFS" : "http://www.opengis.net/spec/owc-geojson/1.0/req/wfs",
"TMS" : "http://www.opengis.net/tms/1.0",
"KML" : "http://www.opengis.net/spec/owc-geojson/1.0/req/kml",
"GPX" : "",
"GEOJSON" : ""
};

/**
* Transforme une emprise en geometrie geojson
* @param {*} bbox
* @returns {Object} geometry
*/
const bbox2polygon = (bbox) => {
const bottomLeft = [bbox.left, bbox.bottom];
const topLeft = [bbox.left, bbox.top];
const topRight = [bbox.right, bbox.top];
const bottomRight = [bbox.right, bbox.bottom];

return {
"type" : "Polygon",
"coordinates" : [[bottomLeft, bottomRight, topRight, topLeft, bottomLeft]]
};
};

/**
* Liste des templates de transformations vers le context owc:
* - config
* - search
* - cartes.gouv.fr
*/
var TEMPLATES = [
{
version : 1.0,
name : "test",
schema : (data) => {
return {
person: {
name: data.person.name
},
pets: {
...data.person.pets
}
};
}
},
{
version : 1.0,
name : "config",
schema : (data) => {
// data utiles
var key = data.key;
var service = data.serviceParams.id.split(":")[1] || null;
var name = data.name;
var version = data.serviceParams.version;
var server = data.serviceParams.serverUrl.full;
var format = data.formats[0].name;
var proj = data.defaultProjection;
var styles = data.styles;
// type d'offre
var offering = null;
if (service && offeringServiceExtension.includes(service)) {
switch (service) {
case "WMS":
offering = [{
"code": namespaces.WMS,
"operations": [
{
"code": "GetCapabilities",
"method": "GET",
"type": "application/xml",
"href": server + "?SERVICE=WMS&VERSION=" + version + "&REQUEST=GetCapabilities",
"request": {},
"result": {}
},
{
"code": "GetMap",
"method": "GET",
"type": format,
"href": server + "?SERVICE=WMS&VERSION=" + version + "&REQUEST=GetMap&SRS=" + proj + "&BBOX=414475,4567125,451575,4588025&WIDTH=600&HEIGHT=400&LAYERS=" + name + "&FORMAT=" + format + "&STYLES=",
"request": {},
"result": {}
},
{
"code": "GetLegendGraphic",
"method": "GET",
"type": format,
"href": server + "?SERVICE=WMS&VERSION=" + version + "&REQUEST=GetLegendGraphic&WIDTH=20&HEIGHT=20&LAYER=" + name + "&FORMAT=" + format,
"request": {},
"result": {}
}
],
"contents": [],
"styles": styles
}];
break;

default:
break;
}
}
return {
"type": "FeatureCollection",
"id": "http://www.opengis.net/owc/1.0/" + key,
"geometry": bbox2polygon(data.globalConstraint.bbox),
"properties": {
"lang": "fr-FR",
"title": "",
"subtitle": "",
"updated": "",
"generator": "cartes.gouv.fr",
"authors": [{ "name": "cartes.gouv.fr" }],
"contributors": [],
"categories": [],
"links": [
{
"rel": "profile",
"href": namespaces.Core,
"title": "This file is compliant with version 1.0 of OGC Context"
}
]
},
"features": [{
"type": "Feature",
"id": server + "/" + name,
"geometry": bbox2polygon(data.globalConstraint.bbox),
"properties": {
"title": data.title,
"updated": "",
"content": data.description,
"authors": [],
"contributors": [],
"categories": [],
"links": data.metadata,
"offerings": offering || [],
"minscaledenominator": data.globalConstraint.minScaleDenominator || 0,
"maxscaledenominator": data.globalConstraint.maxScaleDenominator || 0,
}
}]
};
}
}
];

var Schema = {
get : (name, version) => {
return TEMPLATES.find((el) => {
if (el.name === name && el.version === version) {
return true;
}
});
},
transform : (data, map) => {
return map.schema(data);
},
};

export default Schema;
Loading
Loading