Skip to content

Commit

Permalink
Switch to WMS layer in print
Browse files Browse the repository at this point in the history
  • Loading branch information
fredj committed May 26, 2017
1 parent 4d572a2 commit 545023d
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions contribs/gmf/src/directives/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ goog.require('ngeo.CreatePrint');
goog.require('ngeo.FeatureOverlayMgr');
goog.require('ngeo.LayerHelper');
goog.require('ngeo.PrintUtils');
goog.require('ol.Map');
goog.require('ol.layer.Group');


/**
Expand Down Expand Up @@ -133,6 +135,7 @@ gmf.module.directive('gmfPrint', gmf.printDirective);
* @param {ngeox.QueryResult} ngeoQueryResult ngeo query result.
* @param {ngeo.FeatureHelper} ngeoFeatureHelper the ngeo FeatureHelper service.
* @param {angular.$filter} $filter Angular $filter service.
* @param {gmf.Themes} gmfThemes The gmf Themes service.
* @constructor
* @export
* @ngInject
Expand All @@ -142,7 +145,7 @@ gmf.module.directive('gmfPrint', gmf.printDirective);
gmf.PrintController = function($scope, $timeout, $q, $injector, gettextCatalog,
ngeoLayerHelper, ngeoFeatureOverlayMgr, ngeoPrintUtils, ngeoCreatePrint,
gmfPrintUrl, gmfAuthentication, ngeoQueryResult, ngeoFeatureHelper,
$filter) {
$filter, gmfThemes) {


/**
Expand Down Expand Up @@ -361,6 +364,19 @@ gmf.PrintController = function($scope, $timeout, $q, $injector, gettextCatalog,
this.printState = gmf.PrintState.CAPABILITIES_NOT_LOADED;
this.capabilities_ = null;
}.bind(this));


/**
* @type {gmfThemes.GmfOgcServers}
* @private
*/
this.ogcServers_;

gmfThemes.getOgcServersObject().then(function(ogcServersObject) {
this.ogcServers_ = ogcServersObject;
}.bind(this));


};


Expand Down Expand Up @@ -665,7 +681,34 @@ gmf.PrintController.prototype.print = function(format) {
goog.asserts.assertNumber(this.fields.dpi);
goog.asserts.assertString(this.fields.layout);

var spec = this.ngeoPrint_.createSpec(this.map, scale, this.fields.dpi,
// convert the WMTS layers to WMS
var map = new ol.Map({});
map.setView(this.map.getView());
var ol_layers = this.ngeoLayerHelper_.getFlatLayers(this.map.getLayerGroup());
var new_ol_layers = [];
for (var i = 0, ii = ol_layers.length; i < ii; i++) {
var layer = ol_layers[i];
var metadata = layer.get('metadata');
if (metadata) {
var server_name = metadata.ogcServer;
var layer_names = metadata.layers || metadata.printLayers;
if (server_name && layer_names) {
var server = this.ogcServers_[server_name];
goog.asserts.assert(server);
layer = this.ngeoLayerHelper_.createBasicWMSLayer(
server.url,
layer_names,
server.type
);
}
}
new_ol_layers.push(layer);
}
map.setLayerGroup(new ol.layer.Group({
layers: new_ol_layers
}));

var spec = this.ngeoPrint_.createSpec(map, scale, this.fields.dpi,
this.fields.layout, format, customAttributes);

// Add feature overlay layer to print spec.
Expand All @@ -682,6 +725,10 @@ gmf.PrintController.prototype.print = function(format) {
this.handleCreateReportSuccess_.bind(this),
this.handleCreateReportError_.bind(this)
);

// remove temporary map
map.setTarget(null);

};


Expand Down

0 comments on commit 545023d

Please sign in to comment.