Skip to content

Commit

Permalink
Merge pull request #156 from bartvde/issue-156
Browse files Browse the repository at this point in the history
when loading map config retrieve layerInfo over XHR
  • Loading branch information
bartvde committed Feb 6, 2015
2 parents fec82ec + acd6b18 commit 00b8ab6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
17 changes: 9 additions & 8 deletions examples/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,19 @@
} else {
layer = new ol.layer.Tile(options);
}
return load(layer, styleName).then(function() {
return load.call(self, layer, styleName).then(function() {
self.map.addLayer(layer);
if (fitExtent === true) {
self.map.getView().fitExtent(layer.getExtent(), self.map.getSize());
}
});
};
function describeFeatureType(layer) {
this.describeFeatureType = function(layer, url) {
var id = layer.get('id');
var self = this;
return $http({
method: 'GET',
url: layer.get('server').path + 'wfs',
url: url ? url : layer.get('server').path + 'wfs',
params: {
'SERVICE': 'WFS',
'VERSION': '1.0.0',
Expand All @@ -201,14 +202,14 @@
if (layerInfo.timeAttr !== null) {
layer.set('timeAttribute', layerInfo.timeAttr);
} else {
return getTimeAttribute(layer);
getTimeAttribute(layer);
}
var parts = id.split(':');
layerInfo.typeName = id;
layerInfo.featurePrefix = parts[0];
angular.extend(layer.get('layerInfo'), layerInfo);
layer.set('layerInfo', angular.extend(layer.get('layerInfo') || {}, layerInfo));
});
}
};
function getStyleName(layer, styleName) {
var promise;
if (layer.get('server').canStyleWMS && styleName === undefined) {
Expand Down Expand Up @@ -285,7 +286,7 @@
if (layer.get('timeAttribute')) {
promise = $q.when('');
}
else if (layer.get('server').timeEndpoint) {
else if (layer.get('server') && layer.get('server').timeEndpoint) {
var url = layer.get('server').timeEndpoint(layer);
$http.get(url).success(function(data) {
layer.set('timeAttribute', data.attribute);
Expand All @@ -298,7 +299,7 @@
return promise;
}
function load(layer, styleName) {
return $q.all(loadCapabilities(layer, styleName), describeFeatureType(layer), getStyleName(layer, styleName));
return $q.all(loadCapabilities(layer, styleName), this.describeFeatureType(layer), getStyleName(layer, styleName));
}
}

Expand Down
23 changes: 17 additions & 6 deletions lib/mapstory/MapConfig.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
exports.MapConfig = function() {
return {
read: function(data, mapManager, timeInfo) {
read: function(data, mapManager) {
// old style GXP
if (data.tools) {
data = this.transform(data);
Expand Down Expand Up @@ -58,7 +58,7 @@ exports.MapConfig = function() {
layerConfig.params = params;
layerConfig.params.VERSION = '1.1.1';
// TODO require dependency explicitly?
if (layer.capability) {
if (layer.capability) {
layerConfig.latlonBBOX = layer.capability.bbox['EPSG:4326'].bbox;
layerConfig.times = storytools.core.time.maps.readCapabilitiesTimeDimensions(layer.capability, true);
}
Expand Down Expand Up @@ -89,12 +89,13 @@ exports.MapConfig = function() {
if (layer.type === 'OSM') {
lyr = new ol.layer.Tile();
lyr.setSource(new ol.source.OSM());
mapManager.map.addLayer(lyr);
mapManager.map.getLayers().insertAt(i, lyr);
} else if (layer.type === 'WMS') {
var cfg = {id: layer.id, name: layer.id, title: layer.title, times: layer.times};
if (layer.singleTile === true) {
lyr = new ol.layer.Image({id: layer.id, title: layer.title, times: layer.times});
lyr = new ol.layer.Image(cfg);
} else {
lyr = new ol.layer.Tile({id: layer.id, title: layer.title, times: layer.times});
lyr = new ol.layer.Tile(cfg);
}
if (layer.latlonBBOX) {
lyr.setExtent(
Expand All @@ -116,7 +117,17 @@ exports.MapConfig = function() {
params: layer.params
}));
}
mapManager.map.addLayer(lyr);
if (layer.times && !layer.layerInfo) {
/*jshint -W083 */
angular.bind({counter: i, layer: lyr}, function() {
var me = this;
mapManager.describeFeatureType(lyr, layer.url.replace('wms', 'wfs')).then(function(result) {
mapManager.map.getLayers().insertAt(me.counter, me.layer);
});
})();
} else {
mapManager.map.getLayers().insertAt(i, lyr);
}
}
}
}
Expand Down

0 comments on commit 00b8ab6

Please sign in to comment.