Skip to content

Commit

Permalink
issue planetfederal#230 - enhancing AddLayers GUI for Layer previews …
Browse files Browse the repository at this point in the history
…(image loaoding, TMS abstract attr)
  • Loading branch information
justb4 committed Mar 18, 2014
1 parent b3d834d commit 7bc2605
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
37 changes: 27 additions & 10 deletions src/script/plugins/AddLayers.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,24 @@ gxp.plugins.AddLayers = Ext.extend(gxp.plugins.Tool, {
*/
doneText: "Done",

/** api: config[layerNameText]
* ``String``
* Text for Layer Name in the Layer Card (i18n).
*/
layerNameText: "Name",

/** api: config[layerAbstractText]
* ``String``
* Text for Layer Abstract in the Layer Card (i18n).
*/
layerAbstractText: "Abstract",

/** api: config[layerQueryableText]
* ``String``
* Text for Layer "isQuerable" in the Layer Card (i18n).
*/
layerQueryableText: "Queryable",

/** api: config[search]
* ``Object | Boolean``
* If provided, a :class:`gxp.CatalogueSearchPanel` will be added as a
Expand Down Expand Up @@ -466,14 +484,7 @@ gxp.plugins.AddLayers = Ext.extend(gxp.plugins.Tool, {
},

createColumnModel: function() {
// http://localhost:8080/geoserver/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&LAYER=topp:states
// '<td><img class="align-left thumbnail" caption="thumbnail" src="http://geo.zaanstad.nl/geonetwork/srv/nl/resources.get?id=480&fname=bruggen_s.png&access=public"></td>' +
// {layer.url.params.LAYERS}
var tplLayerURL ='<tpl for="."><tpl for="layer">{url}</tpl></tpl>';
var tplLayerName ='<tpl for="."><tpl for="layer"><tpl for="params">{LAYERS}</tpl></tpl></tpl>';
var tplReqURL = tplLayerURL +'REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH='+ this.layerPreviewWidth +'&HEIGHT='+ this.layerPreviewHeight +'&LAYER=' + tplLayerName;
// var previewImage = '<img class="layerpreview" width="'+ this.layerPreviewWidth +'" height="'+ this.layerPreviewHeight + '" src="' + tplReqURL +'">';
var previewImage = '<img class="layerpreview" width="'+ this.layerPreviewWidth +'" height="'+ this.layerPreviewHeight + '" src="{previewImage}">';
// For use in previewImage.
var layerPreviewWidth = this.layerPreviewWidth, layerPreviewHeight = this.layerPreviewHeight;
var self = this;

Expand Down Expand Up @@ -508,7 +519,7 @@ gxp.plugins.AddLayers = Ext.extend(gxp.plugins.Tool, {
'<td style="vertical-align:middle;">' +
'{previewImage}' +
'</td>' +
'<td style="vertical-align:top; white-space: normal!important;"><p style="margin-top:4px;"><strong>Name: </strong>{name}<br><strong>Abstract: </strong>{abstract}</p></td>' +
'<td style="vertical-align:top; white-space: normal!important;"><p style="margin-top:4px;"><strong>' + this.layerNameText + ': </strong>{name}<br/><strong>' + this.layerAbstractText + ': </strong>{abstract}<br/><strong>' + this.layerQueryableText + ': </strong>{queryable}</p></td>' +
'</tr>' +

'</table>' +
Expand Down Expand Up @@ -548,9 +559,12 @@ gxp.plugins.AddLayers = Ext.extend(gxp.plugins.Tool, {
var data = record.data;
data.id = record.id;
var source = self.target.layerSources[record.store.sourceId];

// 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 = '<img class="layerpreview" onerror="this.style.display=\'none\'" width="'+ layerPreviewWidth +'" height="'+ layerPreviewHeight + '" src="' + 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 = '<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 @@ -745,6 +759,9 @@ gxp.plugins.AddLayers = Ext.extend(gxp.plugins.Tool, {
case 'REST':
ptype = 'gxp_arcrestsource';
break;
case 'WMS':
ptype = 'gxp_wmssource';
break;
default:
ptype = 'gxp_wmscsource';
}
Expand Down
6 changes: 6 additions & 0 deletions src/script/plugins/TMSSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ gxp.data.TMSCapabilitiesReader = Ext.extend(Ext.data.DataReader, {
recordType || meta.fields || [
{name: "name", type: "string"},
{name: "title", type: "string"},
// JvdB: Added abstract, was returned but not in record def+data.
{name: "abstract", type: "string"},
{name: "tileMapUrl", type: "string"}
]);
}
Expand Down Expand Up @@ -67,6 +69,8 @@ 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 @@ -87,6 +91,8 @@ 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
15 changes: 13 additions & 2 deletions src/script/plugins/WMSSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ gxp.plugins.WMSSource = Ext.extend(gxp.plugins.LayerSource, {
/** api: config[version]
* ``String``
* If specified, the version string will be included in WMS GetCapabilities
* requests. By default, no version is set.
* requests. By default, no version 1.1.1 (JvdB, to ensure some MD works and no axis ordering issues) is set.
*/
version: "1.1.1",

/** api: config[requiredProperties]
* ``Array(String)`` List of config properties that are required for each
Expand Down Expand Up @@ -223,8 +224,18 @@ gxp.plugins.WMSSource = Ext.extend(gxp.plugins.LayerSource, {
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';
// the minimum scale value at which the layer should display, e.g. 50000000
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;
return url;
},

Expand Down

0 comments on commit 7bc2605

Please sign in to comment.