Skip to content

Commit

Permalink
Map / Avoid JSON parse error on context having layer with filter. Clear
Browse files Browse the repository at this point in the history
queue on context load.

Context layer can contain a JSON extension which could be formatted and
XML formatting may add extra space which needs to be clean up for proper
JSON string:

```xml
       <ows-context:Layer name="surval_parametre_point" group="/Human Activities" hidden="false" opacity="1"
                           showLayerInfo="true">
            <ows:Title>Surval données par paramètre (point)</ows:Title>
            <ows-context:Server service="urn:ogc:serviceType:WMS" version="1.3.0">
                <ows-context:OnlineResource xlink:href="https://sextant.ifremer.fr/services/wms/environnement_marin"/>
            </ows-context:Server>
            <ows-context:Extension>{"uuid":"cf5048f6-5bbf-4e44-ba74-e6f429af51ea","label":"Surval données par paramètre
                (point)","filters":{"qParams":{"ft_LIEU_LIBELLE_s":{"type":"terms","values":{"001-P-003 - Zuydcoote
                filière":true}}}},"wfsUrl":"https://sextant.ifremer.fr/services/wfs/environnement_marin"}
            </ows-context:Extension>
        </ows-context:Layer>
```

Clear map queue on load - may have side effect when loading differents
maps quickly.

Avoid JS error if server layer is not defined (which should not be the
case unless custom context with new layer types was created).
  • Loading branch information
fxprunayre committed Jun 2, 2023
1 parent b5acf0a commit eb37fb0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
this.queue = queue;
this.errors = errors;

var clear = function (map) {
var type = (map && map.get && map.get("type")) || "viewer";
if (queue[type]) {
queue[type].queue.length = 0;
queue[type].errors.length = 0;
}
};

var getMapType = function (map) {
var type = (map && map.get && map.get("type")) || "viewer";
if (queue[type] === undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@
"gnViewerSettings",
"gnSearchSettings",
"gnOwsContextService",
"gnWmsQueue",
"$rootScope",
"gnMapsManager",
"gnMap",
function (
gnViewerSettings,
gnSearchSettings,
gnOwsContextService,
gnWmsQueue,
$rootScope,
gnMapsManager,
gnMap
Expand Down Expand Up @@ -91,6 +93,7 @@

scope.reset = function () {
$rootScope.$broadcast("owsContextReseted");
gnWmsQueue.clear(scope.map);
var mapViewerConfig = gnMap.getMapConfig()["map-" + gnMapsManager.VIEWER_MAP];
if (gnViewerSettings.defaultContext) {
loadContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@
// load extension content (JSON)
var extension =
layer.extension && layer.extension.any
? JSON.parse(layer.extension.any)
? // Formatted XML may contains extra space and line feed
JSON.parse(layer.extension.any.replaceAll("\\n^ +", " "))
: {};

var loadingId = extension.label ? extension.label : layer.name;
Expand Down Expand Up @@ -710,8 +711,11 @@
* @param {numeric} index of the layer in the tree
*/
this.createLayer = function (layer, map, bgIdx, index, style) {
var server = layer.server[0];
var res = server.onlineResource[0];
var res = { href: "" };
if (layer.server) {
var server = layer.server[0];
res = server.onlineResource[0];
}
var createOnly = angular.isDefined(bgIdx) || angular.isDefined(index);

if (layer.name && layer.name.match(reT)) {
Expand Down

0 comments on commit eb37fb0

Please sign in to comment.