Merge pull request #1341 from twpayne/mapguide-clean-ups
Tidy up ol.source.MapGuide and add ratio option
This commit is contained in:
@@ -25,6 +25,7 @@ var map = new ol.Map({
|
|||||||
MAPDEFINITION: mdf,
|
MAPDEFINITION: mdf,
|
||||||
FORMAT: 'PNG'
|
FORMAT: 'PNG'
|
||||||
},
|
},
|
||||||
|
ratio: 2,
|
||||||
extent: bounds
|
extent: bounds
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -632,14 +632,18 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} ol.source.MapGuideOptions
|
* @typedef {Object} ol.source.MapGuideOptions
|
||||||
* @property {string} url The mapagent url
|
* @property {string|undefined} url The mapagent url.
|
||||||
* @property {number} metersPerUnit The meters-per-unit value
|
* @property {number|undefined} metersPerUnit The meters-per-unit value.
|
||||||
* @property {ol.Extent|undefined} extent Extent.
|
* @property {ol.Extent|undefined} extent Extent..
|
||||||
* @property {boolean} useOverlay If true, will use GETDYNAMICMAPOVERLAYIMAGE
|
* @property {boolean|undefined} useOverlay If true, will use
|
||||||
|
* GETDYNAMICMAPOVERLAYIMAGE.
|
||||||
* @property {ol.proj.ProjectionLike} projection Projection.
|
* @property {ol.proj.ProjectionLike} projection Projection.
|
||||||
|
* @property {number|undefined} ratio Ratio. 1 means image requests are the size
|
||||||
|
* of the map viewport, 2 means twice the size of the map viewport, and so
|
||||||
|
* on.
|
||||||
* @property {Array.<number>|undefined} resolutions Resolutions. If specified,
|
* @property {Array.<number>|undefined} resolutions Resolutions. If specified,
|
||||||
* requests will be made for these resolutions only.
|
* requests will be made for these resolutions only.
|
||||||
* @property {Object} params additional parameters
|
* @property {Object|undefined} params Additional parameters.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -14,30 +14,15 @@ goog.require('ol.source.Image');
|
|||||||
* @param {ol.source.MapGuideOptions} options Options.
|
* @param {ol.source.MapGuideOptions} options Options.
|
||||||
*/
|
*/
|
||||||
ol.source.MapGuide = function(options) {
|
ol.source.MapGuide = function(options) {
|
||||||
var imageUrlFunction = goog.isDef(options.url) ?
|
|
||||||
ol.ImageUrlFunction.createFromParamsFunction(
|
|
||||||
options.url,
|
|
||||||
options.params,
|
|
||||||
goog.bind(this.getUrl, this)) :
|
|
||||||
ol.ImageUrlFunction.nullImageUrlFunction;
|
|
||||||
|
|
||||||
/**
|
var imageUrlFunction;
|
||||||
* @private
|
if (goog.isDef(options.url)) {
|
||||||
* @type {number}
|
var params = goog.isDef(options.params) ? options.params : {};
|
||||||
*/
|
imageUrlFunction = ol.ImageUrlFunction.createFromParamsFunction(
|
||||||
this.metersPerUnit_ = options.metersPerUnit;
|
options.url, params, goog.bind(this.getUrl, this));
|
||||||
|
} else {
|
||||||
/**
|
imageUrlFunction = ol.ImageUrlFunction.nullImageUrlFunction;
|
||||||
* @private
|
}
|
||||||
* @type {boolean}
|
|
||||||
*/
|
|
||||||
this.useOverlay_ = options.useOverlay;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {ol.Image}
|
|
||||||
*/
|
|
||||||
this.image_ = null;
|
|
||||||
|
|
||||||
goog.base(this, {
|
goog.base(this, {
|
||||||
extent: options.extent,
|
extent: options.extent,
|
||||||
@@ -45,6 +30,33 @@ ol.source.MapGuide = function(options) {
|
|||||||
resolutions: options.resolutions,
|
resolutions: options.resolutions,
|
||||||
imageUrlFunction: imageUrlFunction
|
imageUrlFunction: imageUrlFunction
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this.metersPerUnit_ = goog.isDef(options.metersPerUnit) ?
|
||||||
|
options.metersPerUnit : 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this.ratio_ = goog.isDef(options.ratio) ? options.ratio : 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.useOverlay_ = goog.isDef(options.useOverlay) ?
|
||||||
|
options.useOverlay : false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {ol.Image}
|
||||||
|
*/
|
||||||
|
this.image_ = null;
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.source.MapGuide, ol.source.Image);
|
goog.inherits(ol.source.MapGuide, ol.source.Image);
|
||||||
|
|
||||||
@@ -63,8 +75,10 @@ ol.source.MapGuide.prototype.getImage =
|
|||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
extent = extent.slice();
|
if (this.ratio_ != 1) {
|
||||||
ol.extent.scaleFromCenter(extent, 1.0); //this.ratio_);
|
extent = extent.slice();
|
||||||
|
ol.extent.scaleFromCenter(extent, this.ratio_);
|
||||||
|
}
|
||||||
var width = (extent[2] - extent[0]) / resolution;
|
var width = (extent[2] - extent[0]) / resolution;
|
||||||
var height = (extent[3] - extent[1]) / resolution;
|
var height = (extent[3] - extent[1]) / resolution;
|
||||||
var size = [width, height];
|
var size = [width, height];
|
||||||
@@ -75,9 +89,9 @@ ol.source.MapGuide.prototype.getImage =
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.Extent} extent The map extents
|
* @param {ol.Extent} extent The map extents.
|
||||||
* @param {ol.Size} size the viewport size
|
* @param {ol.Size} size the viewport size.
|
||||||
* @return {number} The computed map scale
|
* @return {number} The computed map scale.
|
||||||
*/
|
*/
|
||||||
ol.source.MapGuide.prototype.getScale = function(extent, size) {
|
ol.source.MapGuide.prototype.getScale = function(extent, size) {
|
||||||
var mcsW = extent[2] - extent[0];
|
var mcsW = extent[2] - extent[0];
|
||||||
@@ -87,12 +101,11 @@ ol.source.MapGuide.prototype.getScale = function(extent, size) {
|
|||||||
var dpi = 96;
|
var dpi = 96;
|
||||||
var mpu = this.metersPerUnit_;
|
var mpu = this.metersPerUnit_;
|
||||||
var mpp = 0.0254 / dpi;
|
var mpp = 0.0254 / dpi;
|
||||||
var scale = 0.0;
|
if (devH * mcsW > devW * mcsH) {
|
||||||
if (devH * mcsW > devW * mcsH)
|
return mcsW * mpu / (devW * mpp); // width limited
|
||||||
scale = mcsW * mpu / (devW * mpp); //width-limited
|
} else {
|
||||||
else
|
return mcsH * mpu / (devH * mpp); // height limited
|
||||||
scale = mcsH * mpu / (devH * mpp); //height-limited
|
}
|
||||||
return scale;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user