Merge pull request #6264 from ahocevar/view-fit

Remove the requirement to provide a size to ol.View#fit()
This commit is contained in:
Andreas Hocevar
2016-12-18 22:34:51 +01:00
committed by GitHub
14 changed files with 72 additions and 48 deletions

View File

@@ -62,8 +62,7 @@ var zoomtoswitzerlandbest = document.getElementById('zoomtoswitzerlandbest');
zoomtoswitzerlandbest.addEventListener('click', function() {
var feature = source.getFeatures()[0];
var polygon = /** @type {ol.geom.SimpleGeometry} */ (feature.getGeometry());
var size = /** @type {ol.Size} */ (map.getSize());
view.fit(polygon, size, {padding: [170, 50, 30, 150], constrainResolution: false});
view.fit(polygon, {padding: [170, 50, 30, 150], constrainResolution: false});
}, false);
var zoomtoswitzerlandconstrained =
@@ -71,8 +70,7 @@ var zoomtoswitzerlandconstrained =
zoomtoswitzerlandconstrained.addEventListener('click', function() {
var feature = source.getFeatures()[0];
var polygon = /** @type {ol.geom.SimpleGeometry} */ (feature.getGeometry());
var size = /** @type {ol.Size} */ (map.getSize());
view.fit(polygon, size, {padding: [170, 50, 30, 150]});
view.fit(polygon, {padding: [170, 50, 30, 150]});
}, false);
var zoomtoswitzerlandnearest =
@@ -80,16 +78,14 @@ var zoomtoswitzerlandnearest =
zoomtoswitzerlandnearest.addEventListener('click', function() {
var feature = source.getFeatures()[0];
var polygon = /** @type {ol.geom.SimpleGeometry} */ (feature.getGeometry());
var size = /** @type {ol.Size} */ (map.getSize());
view.fit(polygon, size, {padding: [170, 50, 30, 150], nearest: true});
view.fit(polygon, {padding: [170, 50, 30, 150], nearest: true});
}, false);
var zoomtolausanne = document.getElementById('zoomtolausanne');
zoomtolausanne.addEventListener('click', function() {
var feature = source.getFeatures()[1];
var point = /** @type {ol.geom.SimpleGeometry} */ (feature.getGeometry());
var size = /** @type {ol.Size} */ (map.getSize());
view.fit(point, size, {padding: [170, 50, 30, 150], minResolution: 50});
view.fit(point, {padding: [170, 50, 30, 150], minResolution: 50});
}, false);
var centerlausanne = document.getElementById('centerlausanne');

View File

@@ -121,8 +121,7 @@ dragAndDropInteraction.on('addfeatures', function(event) {
style: styleFunction
})
}));
map.getView().fit(
vectorSource.getExtent(), /** @type {ol.Size} */ (map.getSize()));
map.getView().fit(vectorSource.getExtent());
});
var displayFeatureInfo = function(pixel) {

View File

@@ -118,8 +118,7 @@ dragAndDropInteraction.on('addfeatures', function(event) {
source: vectorSource,
style: styleFunction
}));
map.getView().fit(
vectorSource.getExtent(), /** @type {ol.Size} */ (map.getSize()));
map.getView().fit(vectorSource.getExtent());
});
var displayFeatureInfo = function(pixel) {

View File

@@ -89,7 +89,7 @@ exportButton.addEventListener('click', function() {
source.un('tileloadend', tileLoadEnd, canvas);
source.un('tileloaderror', tileLoadEnd, canvas);
map.setSize(size);
map.getView().fit(extent, size);
map.getView().fit(extent);
map.renderSync();
exportButton.disabled = false;
document.body.style.cursor = 'auto';
@@ -104,7 +104,7 @@ exportButton.addEventListener('click', function() {
});
map.setSize([width, height]);
map.getView().fit(extent, /** @type {ol.Size} */ (map.getSize()));
map.getView().fit(extent);
map.renderSync();
}, false);

View File

@@ -53,11 +53,7 @@ function setProjection(code, name, proj4def, bbox) {
projection: newProj
});
map.setView(newView);
var size = map.getSize();
if (size) {
newView.fit(extent, size);
}
newView.fit(extent);
}

View File

@@ -61,5 +61,5 @@ fetch('https://ahocevar.com/geoserver/wfs', {
}).then(function(json) {
var features = new ol.format.GeoJSON().readFeatures(json);
vectorSource.addFeatures(features);
map.getView().fit(vectorSource.getExtent(), /** @type {ol.Size} */ (map.getSize()));
map.getView().fit(vectorSource.getExtent());
});

View File

@@ -28,4 +28,4 @@ var map = new ol.Map({
extent: extent
})
});
map.getView().fit(extent, /** @type {ol.Size} */ (map.getSize()));
map.getView().fit(extent);