Add serverType option to ol.source.ImageWMS constructor
This commit is contained in:
@@ -28,6 +28,7 @@ var layers = [
|
|||||||
'LAYERS': 'ch.swisstopo.pixelkarte-farbe-pk1000.noscale',
|
'LAYERS': 'ch.swisstopo.pixelkarte-farbe-pk1000.noscale',
|
||||||
'FORMAT': 'image/jpeg'
|
'FORMAT': 'image/jpeg'
|
||||||
},
|
},
|
||||||
|
serverType: 'mapserver',
|
||||||
extent: extent
|
extent: extent
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
@@ -42,6 +43,7 @@ var layers = [
|
|||||||
'National parks / geo.admin.ch</a>'
|
'National parks / geo.admin.ch</a>'
|
||||||
})],
|
})],
|
||||||
params: {'LAYERS': 'ch.bafu.schutzgebiete-paerke_nationaler_bedeutung'},
|
params: {'LAYERS': 'ch.bafu.schutzgebiete-paerke_nationaler_bedeutung'},
|
||||||
|
serverType: 'mapserver',
|
||||||
extent: extent
|
extent: extent
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ var layers = [
|
|||||||
source: new ol.source.ImageWMS({
|
source: new ol.source.ImageWMS({
|
||||||
url: 'http://demo.opengeo.org/geoserver/wms',
|
url: 'http://demo.opengeo.org/geoserver/wms',
|
||||||
params: {'LAYERS': 'topp:states'},
|
params: {'LAYERS': 'topp:states'},
|
||||||
|
serverType: 'geoserver',
|
||||||
extent: [-13884991, 2870341, -7455066, 6338219]
|
extent: [-13884991, 2870341, -7455066, 6338219]
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ var layers = [
|
|||||||
})],
|
})],
|
||||||
crossOrigin: 'anonymous',
|
crossOrigin: 'anonymous',
|
||||||
params: {'LAYERS': 'ch.bafu.schutzgebiete-paerke_nationaler_bedeutung'},
|
params: {'LAYERS': 'ch.bafu.schutzgebiete-paerke_nationaler_bedeutung'},
|
||||||
|
serverType: 'mapserver',
|
||||||
url: 'http://wms.geo.admin.ch/'
|
url: 'http://wms.geo.admin.ch/'
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -516,6 +516,9 @@
|
|||||||
* @property {ol.Extent|undefined} extent Extent.
|
* @property {ol.Extent|undefined} extent Extent.
|
||||||
* @property {boolean|undefined} hidpi Use the `ol.Map#devicePixelRatio` value when
|
* @property {boolean|undefined} hidpi Use the `ol.Map#devicePixelRatio` value when
|
||||||
* requesting the image from the remote server. Default is `true`.
|
* requesting the image from the remote server. Default is `true`.
|
||||||
|
* @property {ol.source.wms.ServerType|undefined} serverType The type of the remote WMS
|
||||||
|
* server: `mapserver`, `geoserver` or `qgis`. Only needed if `hidpi` is `true`.
|
||||||
|
* Default is `undefined`.
|
||||||
* @property {boolean|undefined} useOverlay If `true`, will use
|
* @property {boolean|undefined} useOverlay If `true`, will use
|
||||||
* `GETDYNAMICMAPOVERLAYIMAGE`.
|
* `GETDYNAMICMAPOVERLAYIMAGE`.
|
||||||
* @property {ol.proj.ProjectionLike} projection Projection.
|
* @property {ol.proj.ProjectionLike} projection Projection.
|
||||||
|
|||||||
@@ -38,6 +38,12 @@ ol.source.ImageWMS = function(options) {
|
|||||||
imageUrlFunction: imageUrlFunction
|
imageUrlFunction: imageUrlFunction
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {ol.source.wms.ServerType|undefined}
|
||||||
|
*/
|
||||||
|
this.serverType_ = options.serverType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
@@ -92,6 +98,11 @@ ol.source.ImageWMS.prototype.getImage =
|
|||||||
var height = (extent[3] - extent[1]) / resolution;
|
var height = (extent[3] - extent[1]) / resolution;
|
||||||
var size = [width * pixelRatio, height * pixelRatio];
|
var size = [width * pixelRatio, height * pixelRatio];
|
||||||
|
|
||||||
|
if (goog.isDef(this.serverType_) && pixelRatio > 1) {
|
||||||
|
var param = ol.source.wms.getDpiParam(this.serverType_, pixelRatio);
|
||||||
|
goog.object.extend(this.params_, param);
|
||||||
|
}
|
||||||
|
|
||||||
this.image_ = this.createImage(
|
this.image_ = this.createImage(
|
||||||
extent, resolution, pixelRatio, size, projection);
|
extent, resolution, pixelRatio, size, projection);
|
||||||
return this.image_;
|
return this.image_;
|
||||||
|
|||||||
@@ -1,9 +1,20 @@
|
|||||||
goog.provide('ol.source.wms');
|
goog.provide('ol.source.wms');
|
||||||
|
|
||||||
|
goog.require('goog.asserts');
|
||||||
goog.require('goog.object');
|
goog.require('goog.object');
|
||||||
goog.require('goog.uri.utils');
|
goog.require('goog.uri.utils');
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @enum {string}
|
||||||
|
*/
|
||||||
|
ol.source.wms.ServerType = {
|
||||||
|
MAPSERVER: 'mapserver',
|
||||||
|
GEOSERVER: 'geoserver',
|
||||||
|
QGIS: 'qgis'
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} baseUrl WMS base URL.
|
* @param {string} baseUrl WMS base URL.
|
||||||
* @param {Object.<string, string|number>} params Request parameters.
|
* @param {Object.<string, string|number>} params Request parameters.
|
||||||
@@ -12,8 +23,7 @@ goog.require('goog.uri.utils');
|
|||||||
* @param {ol.proj.Projection} projection Projection.
|
* @param {ol.proj.Projection} projection Projection.
|
||||||
* @return {string} WMS GetMap request URL.
|
* @return {string} WMS GetMap request URL.
|
||||||
*/
|
*/
|
||||||
ol.source.wms.getUrl =
|
ol.source.wms.getUrl = function(baseUrl, params, extent, size, projection) {
|
||||||
function(baseUrl, params, extent, size, projection) {
|
|
||||||
var baseParams = {
|
var baseParams = {
|
||||||
'SERVICE': 'WMS',
|
'SERVICE': 'WMS',
|
||||||
'VERSION': '1.3.0',
|
'VERSION': '1.3.0',
|
||||||
@@ -40,3 +50,23 @@ ol.source.wms.getUrl =
|
|||||||
|
|
||||||
return goog.uri.utils.appendParamsFromMap(baseUrl, baseParams);
|
return goog.uri.utils.appendParamsFromMap(baseUrl, baseParams);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.source.wms.ServerType} serverType Server name.
|
||||||
|
* @param {number} pixelRatio Pixel ratio.
|
||||||
|
* @return {Object.<string, string>}
|
||||||
|
*/
|
||||||
|
ol.source.wms.getDpiParam = function(serverType, pixelRatio) {
|
||||||
|
var param = {};
|
||||||
|
if (serverType == ol.source.wms.ServerType.MAPSERVER) {
|
||||||
|
param['MAP_RESOLUTION'] = 90 * pixelRatio;
|
||||||
|
} else if (serverType == ol.source.wms.ServerType.GEOSERVER) {
|
||||||
|
param['FORMAT_OPTION'] = 'dpi:' + 90 * pixelRatio;
|
||||||
|
} else if (serverType == ol.source.wms.ServerType.QGIS) {
|
||||||
|
param['DPI'] = 90 * pixelRatio;
|
||||||
|
} else {
|
||||||
|
goog.asserts.fail();
|
||||||
|
}
|
||||||
|
return param;
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user