Skip to content

Commit

Permalink
issue planetfederal#230 strategies to fetch preview map images for TM…
Browse files Browse the repository at this point in the history
…S and WMS
  • Loading branch information
justb4 committed Mar 28, 2014
1 parent 7bc2605 commit 7ab722b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 23 deletions.
23 changes: 16 additions & 7 deletions src/script/plugins/AddLayers.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ gxp.plugins.AddLayers = Ext.extend(gxp.plugins.Tool, {
*/
layerPreviewHeight: 20,

/** api: config[owsPreviewStrategies]
* ``Array``
* String array with the order of strategies to obtain preview images for OWS services, default is ['attributionlogo', 'getlegendgraphic'].
*/
owsPreviewStrategies: ['attributionlogo', 'getlegendgraphic'],


/** private: property[selectedSource]
* :class:`gxp.plugins.LayerSource`
* The currently selected layer source.
Expand Down Expand Up @@ -563,7 +570,7 @@ gxp.plugins.AddLayers = Ext.extend(gxp.plugins.Tool, {
// Let LayerSource provide a URL to a preview image, if none use 'preview-notavailable' CSS.
var previewImageURL = source.getPreviewImageURL(record, layerPreviewWidth, layerPreviewHeight);
if (previewImageURL) {
data.previewImage = '<div style="width:' + layerPreviewWidth + 'px; height:'+ layerPreviewHeight + 'px; background-image: url(' + previewImageURL + '); background-size:' + layerPreviewWidth + 'px '+ layerPreviewHeight + 'px;background-repeat: no-repeat;" >&nbsp;</div>';
data.previewImage = '<div style="width:' + layerPreviewWidth + 'px; height:'+ layerPreviewHeight + 'px; background-image: url(' + previewImageURL + '); background-repeat: no-repeat;" >&nbsp;</div>';
// data.previewImage = '<img class="layerpreview" width="'+ layerPreviewWidth +'" height="'+ layerPreviewHeight + '" src="' + previewImageURL + '"/>';
} else {
data.previewImage = '<div style="width:' + layerPreviewHeight + 'px; height:'+ layerPreviewHeight + 'px" class="preview-notavailable">&nbsp;</div>';
Expand Down Expand Up @@ -751,22 +758,24 @@ gxp.plugins.AddLayers = Ext.extend(gxp.plugins.Tool, {
},
"urlselected": function(newSourceDialog, url, type) {
newSourceDialog.setLoading();
var ptype;
var config = {url: url};
switch (type) {
case 'TMS':
ptype = "gxp_tmssource";
config.ptype = "gxp_tmssource";
break;
case 'REST':
ptype = 'gxp_arcrestsource';
config.ptype = 'gxp_arcrestsource';
break;
case 'WMS':
ptype = 'gxp_wmssource';
config.ptype = 'gxp_wmssource';
config.owsPreviewStrategies = this.owsPreviewStrategies;
break;
default:
ptype = 'gxp_wmscsource';
config.ptype = 'gxp_wmscsource';
}

this.target.addLayerSource({
config: {url: url, ptype: ptype},
config: config,
callback: function(id) {
// add to combo and select
var record = new sources.recordType({
Expand Down
4 changes: 0 additions & 4 deletions src/script/plugins/TMSSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ gxp.data.TMSCapabilitiesReader = Ext.extend(Ext.data.DataReader, {
),
title: data.title,
name: data.title,
// JvdB: Added abstract, was returned but not in record def+data.
abstract: data.abstract,
tileMapUrl: this.meta.baseUrl
}));
}
Expand All @@ -91,8 +89,6 @@ gxp.data.TMSCapabilitiesReader = Ext.extend(Ext.data.DataReader, {
),
title: tileMap.title,
name: tileMap.title,
// JvdB: Added abstract, was returned but not in record def+data.
abstract: data.abstract,
tileMapUrl: url
}));
}
Expand Down
65 changes: 53 additions & 12 deletions src/script/plugins/WMSSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ gxp.plugins.WMSSource = Ext.extend(gxp.plugins.LayerSource, {
*/
requiredProperties: ["title", "bbox"],

/** api: config[owsPreviewStrategies]
* ``Array``
* String array with the order of strategies to obtain preview images for OWS services, default is ['attributionlogo', 'getlegendgraphic'].
*/
owsPreviewStrategies: ['attributionlogo', 'getlegendgraphic'],

/** private: method[constructor]
*/
constructor: function(config) {
Expand Down Expand Up @@ -222,20 +228,55 @@ gxp.plugins.WMSSource = Ext.extend(gxp.plugins.LayerSource, {
* Create a preview image URL or encoded image for given record.
*/
getPreviewImageURL: function (record, width, height) {
var layerURL = record.data.layer.url;
var layerName = record.data.name;
var layerFormat = record.data.formats && record.data.formats.length > 0 ? record.data.formats[0] : 'image/png';
// Old stuff we may someday use when being able to request via a GetMap
// var layerFormat = record.data.formats && record.data.formats.length > 0 ? record.data.formats[0] : 'image/png';
// the minimum scale value at which the layer should display, e.g. 50000000
var layerMinScale = record.data.minScale;
// var layerMinScale = record.data.minScale;
// the maximum scale value at which the layer should display, e.g. 10000000
var layerMaxScale = record.data.maxScale;
var mapProjection = this.target.map.projection;
var bounds = OpenLayers.Bounds.fromArray(record.data.llbbox);
var scaledBounds = bounds.scale(0.5);
var bbox = scaledBounds.toString();
// var bounds =
var url = layerURL + 'REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=' + width + '&HEIGHT=' + height + '&LAYER=' + layerName;
// var url = layerURL + 'REQUEST=GetMap&VERSION=1.1.1&SRS=EPSG:4326&BBOX=' + bbox + '&FORMAT=' + layerFormat + '&WIDTH=' + width + '&HEIGHT=' + height + '&LAYERS=' + layerName;
// var layerMaxScale = record.data.maxScale;
// var mapProjection = this.target.map.projection;
// var bounds = OpenLayers.Bounds.fromArray(record.data.llbbox);
// var layerScale = layerMinScale;
// if (layerMinScale > 0 ) {
/*
As an example, suppose that a map is to be rendered on to a display with a known actual resolution of 100 dots per inch (square)
and the linear distance of the coordinate system of the map is 200 meters per pixel. The actual scale (denominator)
of the map to be rendered is computed as:
100dpi = 1/100 inches
1/100 inches × 25.4mm/inch = 0.254mm
0.254mm × 1000mm/m = 0.000254m
200m ÷ 0.000254m = 787401.5748
(actual pixel size in inches) (actual pixel size)
(actual pixel size in meters) (actual scale denominator)
The actual scale denominator is translated into the “standard” scale denominator as:
0.28mm ÷ 0.254mm = 1.102362205 (multiplier for scale conversion)
787401.5748×1.102362205=868001.736 (standardscaledenominator)
*/
//layerScale = (layerMinScale + layerMaxScale) / 2;
//var distance = OpenLayers.Util.distVincenty();
//var bounds = bounds.scale(0.25);
//layerScale = (layerMinScale > 0 ? '&SCALE=' + (layerMinScale + layerMaxScale)/2 : '');

// }
// var layerScaleStr = (layerMinScale > 0 ? '&SCALE=' + (layerMinScale + layerMaxScale)/2 : '');
// var bounds =
// var url = layerURL + 'REQUEST=GetMap&VERSION=1.1.1&SRS=EPSG:4326&BBOX=' + bbox + '&FORMAT=' + layerFormat + '&WIDTH=' + width + '&HEIGHT=' + height + '&LAYERS=' + layerName+layerScaleStr;

var url;
if (this.owsPreviewStrategies.indexOf('attributionlogo') >= 0 && record.data.attribution && record.data.attribution.logo && record.data.attribution.logo.href) {
// Use attribution logo a preview image
url = record.data.attribution.logo.href;
}

if (!url && this.owsPreviewStrategies.indexOf('getlegendgraphic') >= 0 ) {
// Use getlegend graphic as preview image
var layerURL = record.data.layer.url;
var layerName = record.data.name;
url = layerURL + 'REQUEST=GetLegendGraphic&VERSION=1.1.1&FORMAT=image/png&WIDTH=' + width + '&HEIGHT=' + height + '&LAYER=' + layerName;
}

// May be null: i.e. show no preview image
return url;
},

Expand Down

0 comments on commit 7ab722b

Please sign in to comment.