Skip to content

Commit

Permalink
owscontext: set map projection from context
Browse files Browse the repository at this point in the history
  • Loading branch information
fgravin committed Jul 4, 2017
1 parent c0fa1c6 commit 7010e89
Showing 1 changed file with 12 additions and 16 deletions.
Expand Up @@ -114,36 +114,32 @@
map.removeLayer(layersToRemove[i]);
}

// set the General.BoundingBox
// -- set the Map view (extent/projection)
var bbox = context.general.boundingBox.value;
var ll = bbox.lowerCorner;
var ur = bbox.upperCorner;
var projection = bbox.crs;

if (projection == 'EPSG:4326') {
ll.reverse();
ur.reverse();
}
var extent = ll.concat(ur);
// reproject in case bbox's projection doesn't match map's projection
extent = ol.proj.transformExtent(extent,
projection, map.getView().getProjection());
gnViewerSettings.initialExtent = extent;

extent = gnMap.secureExtent(extent, map.getView().getProjection());
// save this extent for later use (for example if the map
// is not currently visible)
map.set('lastExtent', extent);

// store the extent into view settings so that it can be used later in
// case the map is not visible yet
gnViewerSettings.initialExtent = extent;
if(map.getView().getProjection().getCode() != projection) {
var view = new ol.View({
extent: extent,
projection: projection
});
map.setView(view);
}

// $timeout used to avoid map no rendered (eg: null size)
$timeout(function() {
map.getView().fit(extent, map.getSize(), { nearest: true });
}, 0, false);

// save this extent for later use (for example if the map
// is not currently visible)
map.set('lastExtent', extent);

// load the resources & add additional layers if available
var layers = context.resourceList.layer;
if (additionalLayers) {
Expand Down

0 comments on commit 7010e89

Please sign in to comment.