diff --git a/web-ui/src/main/resources/catalog/components/common/map/esriService.js b/web-ui/src/main/resources/catalog/components/common/map/esriService.js index f116454f6d3..6b6e777a5b2 100644 --- a/web-ui/src/main/resources/catalog/components/common/map/esriService.js +++ b/web-ui/src/main/resources/catalog/components/common/map/esriService.js @@ -33,8 +33,8 @@ var TITLE_FONT = 'bold ' + FONT_SIZE + 'px sans-serif'; var LABEL_FONT = FONT_SIZE + 'px sans-serif'; - module.service('gnEsriUtils', ['$q', - function($q) { + module.service('gnEsriUtils', ['$q', '$http', '$translate', 'gnUrlUtils', + function($q, $http, $translate, gnUrlUtils) { return { /** * Renders a JSON legend asynchronously to an image @@ -160,6 +160,40 @@ } } return [width, height]; + }, + + /** + * Returns a promise resolving to the capabilities document of an ESRI Rest service. + * @param {String} url + * @return {Promise} capabilities document + */ + getCapabilities: function(url) { + var timeout = 60 * 1000; + var defer = $q.defer(); + + url = gnUrlUtils.append(url, + gnUrlUtils.toKeyValue({ + f: 'json' + })); + + $http.get(url, { + cache: true, + timeout: timeout + }) + .success(function(data, status, headers, config) { + // Check if the response contains a mapName property, + // to verify it's an ESRI Rest Capabilities document. + if (!!data.mapName) { + defer.resolve(data); + } else { + defer.reject($translate.instant('esriCapabilitiesNoValid')); + } + }) + .error(function(data, status, headers, config) { + defer.reject($translate.instant('esriCapabilitiesFailed')); + }); + + return defer.promise; } } } diff --git a/web-ui/src/main/resources/catalog/components/common/map/mapService.js b/web-ui/src/main/resources/catalog/components/common/map/mapService.js index 1c0e0e4c65b..f6fd4befa58 100644 --- a/web-ui/src/main/resources/catalog/components/common/map/mapService.js +++ b/web-ui/src/main/resources/catalog/components/common/map/mapService.js @@ -86,13 +86,10 @@ }; var getLayerInMap = function(map, name, url, style) { if (gnWmsQueue.isPending(url, name, style)) { - return true; + return null; } - if(getTheLayerFromMap(map, name, url, style) != null) { - return true; - } - return null; + return getTheLayerFromMap(map, name, url, style); }; /** @@ -121,6 +118,19 @@ return l; } } + else if (source instanceof ol.source.ImageArcGISRest) { + if (!!name) { + if ((url.indexOf(source.getUrl()) == 0) && + source.getParams().LAYERS == "show:" + name) { + return l; + } + } else { + if (source.getUrl() == url) { + return l; + } + } + + } } return null; }; @@ -1432,19 +1442,41 @@ return defer.promise; }, - addEsriRestFromScratch: function(map, url, name, createOnly, md) { + /** + * @ngdoc method + * @methodOf gn_map.addEsriRestLayer:gnMap + * @name gnMap#addEsriRestLayer + * + * @description + * Here is the method to use when you want to add a ESRIREst layer from + * a url and a name (layer identifier). + * + * Return a promise with ol.Layer as data is succeed, and url/name + * if failure. + * If createOnly, we don't add the layer to the map. + * If the md object is given, we add it to the layer, or we try + * to retrieve it in the catalog + * + * @param {ol.Map} map to add the layer + * @param {string} url of the service + * @param {string} name of the layer (identifier) + * @param {boolean} createOnly or add it to the map + * @param {!Object} md object + */ + addEsriRestLayer: function(map, url, name, createOnly, md) { if (url === '') { var error = "Trying to add an ESRI layer with no service URL. Layer name is " + name + ". Check the metadata or the map."; console.warn(error); return $q.reject(error); } var serviceUrl = url.replace(/(.*\/MapServer).*/, '$1'); - var layer = !!name && parseInt(name).toString() === name + var layer = angular.isNumber(name) ? name : url.replace(/.*\/([^\/]*)\/MapServer\/?(.*)/, '$2'); name = url.replace(/.*\/([^\/]*)\/MapServer\/?(.*)/, '$1 $2'); - var olLayer = getTheLayerFromMap(map, name, url); + // Use the url and the layer identifier to check if the layer exists + var olLayer = getTheLayerFromMap(map, layer, url); if (olLayer !== null) { if(md) { olLayer.set('md', md); @@ -2021,7 +2053,7 @@ opt); break; } - this.addEsriRestFromScratch(map, opt.url, opt.name) + this.addEsriRestLayer(map, opt.url, opt.name) .then(function(layer) { if (title) { layer.set('title', title); diff --git a/web-ui/src/main/resources/catalog/components/viewer/ViewerDirective.js b/web-ui/src/main/resources/catalog/components/viewer/ViewerDirective.js index c750ce68c9e..58aeb9bfb0d 100644 --- a/web-ui/src/main/resources/catalog/components/viewer/ViewerDirective.js +++ b/web-ui/src/main/resources/catalog/components/viewer/ViewerDirective.js @@ -183,7 +183,7 @@ var loadLayerPromise = gnMap[ config.type === 'wmts' ? 'addWmtsFromScratch' : - (config.type === 'esrirest' ? 'addEsriRestFromScratch' : 'addWmsFromScratch') + (config.type === 'esrirest' ? 'addEsriRestLayer' : 'addWmsFromScratch') ]( scope.map, config.url, config.name, undefined, config.md); diff --git a/web-ui/src/main/resources/catalog/components/viewer/owscontext/OwsContextService.js b/web-ui/src/main/resources/catalog/components/viewer/owscontext/OwsContextService.js index e3aced8de14..43a6a82b833 100644 --- a/web-ui/src/main/resources/catalog/components/viewer/owscontext/OwsContextService.js +++ b/web-ui/src/main/resources/catalog/components/viewer/owscontext/OwsContextService.js @@ -649,7 +649,7 @@ if (type === 'wmts') { promise = gnMap.addWmtsFromScratch(map, res.href, name, createOnly); } else if (type === 'arcgis') { - promise = gnMap.addEsriRestFromScratch(map, res.href, name, createOnly); + promise = gnMap.addEsriRestLayer(map, res.href, name, createOnly); } // if it's not WMTS, let's assume it is wms diff --git a/web-ui/src/main/resources/catalog/components/viewer/partials/mainviewer.html b/web-ui/src/main/resources/catalog/components/viewer/partials/mainviewer.html index a40a0d4123b..38297c4b33b 100644 --- a/web-ui/src/main/resources/catalog/components/viewer/partials/mainviewer.html +++ b/web-ui/src/main/resources/catalog/components/viewer/partials/mainviewer.html @@ -178,6 +178,11 @@

{{'AddALayer' | translate}} gn-wms-import-map="map" gn-wms-import-url="addLayerUrl.wfs" services-list-from-catalog="true"> + +
  • " + + "
    " + + "
    " + + "
  • " + + '' + + '' + }; + }]); + + /** + * @ngdoc directive + * @name gn_wmsimport.directive:gnEsriCapTreeElt + * + * @description + * Directive to manage layers from an ESRI REST capabilities + * document. Will call its own template to display the layer. + */ + module.directive('gnEsriRestCapTreeElt', [ + '$compile', + '$translate', + 'gnAlertService', + function($compile, $translate, gnAlertService) { + return { + restrict: 'E', + require: '^gnWmsImport', + replace: true, + scope: { + member: '=' + }, + templateUrl: '../../catalog/components/viewer/wmsimport/' + + 'partials/esrilayer.html', + link: function(scope, element, attrs, controller) { + var el = element; + + scope.toggleNode = function(evt) { + el.find('.fa').first().toggleClass('fa-folder-open-o') + .toggleClass('fa-folder-o'); + el.children('ul').toggle(); + evt.stopPropagation(); + }; + + scope.addLayer = function() { + controller.addEsriRestLayer(scope.member); + }; + } + }; + }]); + module.directive('gnLayerStyles', [ function() { return { diff --git a/web-ui/src/main/resources/catalog/components/viewer/wmsimport/partials/esrilayer.html b/web-ui/src/main/resources/catalog/components/viewer/wmsimport/partials/esrilayer.html new file mode 100644 index 00000000000..79d56d00a05 --- /dev/null +++ b/web-ui/src/main/resources/catalog/components/viewer/wmsimport/partials/esrilayer.html @@ -0,0 +1,25 @@ +
  • + +
  • diff --git a/web-ui/src/main/resources/catalog/components/viewer/wmsimport/partials/wmsimport.html b/web-ui/src/main/resources/catalog/components/viewer/wmsimport/partials/wmsimport.html index 7150b19e08e..cbff714de5c 100644 --- a/web-ui/src/main/resources/catalog/components/viewer/wmsimport/partials/wmsimport.html +++ b/web-ui/src/main/resources/catalog/components/viewer/wmsimport/partials/wmsimport.html @@ -57,4 +57,5 @@ + diff --git a/web-ui/src/main/resources/catalog/locales/en-search.json b/web-ui/src/main/resources/catalog/locales/en-search.json index 0ee2027ff23..42580ed1019 100644 --- a/web-ui/src/main/resources/catalog/locales/en-search.json +++ b/web-ui/src/main/resources/catalog/locales/en-search.json @@ -532,5 +532,8 @@ "displayMousePosition": "Display mouse position (Use 'c' shortcut to copy position to clipboard).", "copyMousePosition": "Copy mouse position to clipboard", "printUnsupportedLayerTypes": "The following layer types are present but cannot be printed", - "rssFeed": "RSS feed" + "rssFeed": "RSS feed", + "esriCapabilitiesFailed": "Error retrieving the ESRI Rest capabilities document.", + "esriCapabilitiesNoValid": "The response is not a valid ESRI Rest capabilities document." + }