Skip to content

Commit

Permalink
ussue planetfederal#235 : enhancements CSW: missing bounds, multiple …
Browse files Browse the repository at this point in the history
…WMSs per record, abstract info mouse-over
  • Loading branch information
justb4 committed Aug 19, 2014
1 parent b44ff58 commit 147e3f1
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 45 deletions.
17 changes: 12 additions & 5 deletions src/script/plugins/AddLayers.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,14 +462,21 @@ gxp.plugins.AddLayers = Ext.extend(gxp.plugins.Tool, {
output.on({
'addlayer': function(cmp, sourceKey, layerConfig) {
var source = this.target.layerSources[sourceKey];
var bounds = OpenLayers.Bounds.fromArray(layerConfig.bbox,
(source.yx && source.yx[layerConfig.projection] === true));
var mapProjection = this.target.mapPanel.map.getProjection();
var bbox = bounds.transform(layerConfig.srs, mapProjection);
var map = this.target.mapPanel.map;
var mapProjection = map.getProjection();

// Bounds may be empty!
var bbox;
if (layerConfig.bbox) {
var bounds = OpenLayers.Bounds.fromArray(layerConfig.bbox,
(source.yx && source.yx[layerConfig.projection] === true));
bbox = bounds.transform(layerConfig.srs, mapProjection);
layerConfig.bbox = bbox.toArray();
}
layerConfig.srs = mapProjection;
layerConfig.bbox = bbox.toArray();
layerConfig.source = this.initialConfig.catalogSourceKey !== null ?
this.initialConfig.catalogSourceKey : sourceKey;

var record = source.createLayerRecord(layerConfig);
this.target.mapPanel.layers.add(record);
if (bbox) {
Expand Down
14 changes: 10 additions & 4 deletions src/script/plugins/CSWCatalogueSource.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Copyright (c) 2008-2011 The Open Planning Project
*
*
* Published under the GPL license.
* See https://github.com/opengeo/gxp/raw/master/license.txt for the full text
* of the license.
Expand Down Expand Up @@ -36,6 +36,11 @@ gxp.plugins.CSWCatalogueSource = Ext.extend(gxp.plugins.CatalogueSource, {
/** api: ptype = gxp_cataloguesource */
ptype: "gxp_cataloguesource",

/** api: config[outputSchema]
* ``String`` The XML schema to be used for response records. Default is "CSW Summary".
*/
outputSchema : 'http://www.opengis.net/cat/csw/2.0.2',

/** api: method[createStore]
* Create the store that will be used for the CS-W searches.
*/
Expand Down Expand Up @@ -74,7 +79,7 @@ gxp.plugins.CSWCatalogueSource = Ext.extend(gxp.plugins.CatalogueSource, {
},

/** private: method[getFullFilter]
* :arg filter: ``OpenLayers.Filter`` The filter to add to the other existing
* :arg filter: ``OpenLayers.Filter`` The filter to add to the other existing
* filters. This is normally the free text search filter.
* :arg otherFilters: ``Array``
* :returns: ``OpenLayers.Filter`` The combined filter.
Expand Down Expand Up @@ -103,10 +108,10 @@ gxp.plugins.CSWCatalogueSource = Ext.extend(gxp.plugins.CatalogueSource, {
*
* .. list-table::
* :widths: 20 80
*
*
* * - ``queryString``
* - the search string
* * - ``limit``
* * - ``limit``
* - the maximum number of records to retrieve
* * - ``filters``
* - additional filters to include in the query
Expand All @@ -124,6 +129,7 @@ gxp.plugins.CSWCatalogueSource = Ext.extend(gxp.plugins.CatalogueSource, {
var data = {
"resultType": "results",
"maxRecords": options.limit,
"outputSchema": this.outputSchema,
"Query": {
"typeNames": "gmd:MD_Metadata",
"ElementSetName": {
Expand Down
16 changes: 11 additions & 5 deletions src/script/plugins/WMSSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ gxp.plugins.WMSSource = Ext.extend(gxp.plugins.LayerSource, {

/** api: property[requiredProperties]
* ``Array(String)`` List of config properties that are required for a
* complete layer configuration, in addition to ``name``.
* complete layer configuration, in addition to ``name``. Note: bbox may not be present.
*/
requiredProperties: ["title", "bbox"],
requiredProperties: ["title"],

/** api: config[owsPreviewStrategies]
* ``Array``
Expand Down Expand Up @@ -617,8 +617,6 @@ gxp.plugins.WMSSource = Ext.extend(gxp.plugins.LayerSource, {
layer.setName(config.title || layer.name);
layer.addOptions({
attribution: layer.attribution || config.attribution,
maxExtent: maxExtent,
restrictedExtent: maxExtent,
singleTile: singleTile,
ratio: config.ratio || 1,
visibility: ("visibility" in config) ? config.visibility : true,
Expand All @@ -629,9 +627,17 @@ gxp.plugins.WMSSource = Ext.extend(gxp.plugins.LayerSource, {
minScale: config.minscale,
maxScale: config.maxscale,
// JvdB add: to let Feature info widgets know this layer is querable
queryable: original.get("queryable")
queryable: original.get("queryable") || config.queryable
});

if (maxExtent && maxExtent.top) {
layer.addOptions({
maxExtent: maxExtent,
restrictedExtent: maxExtent
}
);
}

// data for the new record
var data = Ext.applyIf({
title: layer.name,
Expand Down
131 changes: 100 additions & 31 deletions src/script/widgets/CatalogueSearchPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,55 @@ gxp.CatalogueSearchPanel = Ext.extend(Ext.Panel, {
});
}
});

var recordRenderer = function (value, metadata, record) {
// Line Splitter Function
// copyright Stephen Chapman, 19th April 2006
// you may copy this code but please keep the copyright notice as well
function splitLine(st, n) {
var b = '';
var s = st;
while (s.length > n) {
var c = s.substring(0, n);
var d = c.lastIndexOf(' ');
var e = c.lastIndexOf('\n');
if (e != -1) d = e;
if (d == -1) d = n;
b += c.substring(0, d) + '\n';
s = s.substring(d + 1);
}
return b + s;
}

function htmlEscape(str) {
return String(str)
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
}
// tooltip template
var qtipTpl = new Ext.XTemplate(
'<h3>Abstract</h3>'
, '<tpl for=".">'
, '<div>{abstract}</div>'
, '</tpl>'
);
var qtipStr = qtipTpl.apply({abstract: 'Unavailable'});
var abstr = record.data.abstract;
if (abstr.length > 0) {
abstr = abstr[0];
abstr = htmlEscape(abstr);
abstr = splitLine(abstr, 50);
abstr = abstr.replace(/\r?\n/g, '<br/>');
qtipStr = qtipTpl.apply({abstract: abstr});
}
abstr = abstr.split('<br/>')[0] + '...';
var tplStr = new Ext.XTemplate('<b>{title}</b><br/>{abstract}').apply({title: value, abstract: abstr});
return '<div ext:qtip=\'' + qtipStr + '\'>' + tplStr + '</div>';
};

this.items = [{
xtype: 'form',
border: false,
Expand Down Expand Up @@ -306,17 +355,21 @@ gxp.CatalogueSearchPanel = Ext.extend(Ext.Panel, {
store: this.sources[this.selectedSource].store,
columns: [{
id: 'title',
xtype: "templatecolumn",
tpl: new Ext.XTemplate('<b>{title}</b><br/>{abstract}'),
sortable: true
// xtype: "templatecolumn",
// tpl: '<div ext:qtip="{abstract}"><b>{title}</b><br/>{abstract}</div>',

// tpl: new Ext.XTemplate('<div ext:qtip="{abstract}"><b>{title}</b><br/>{abstract}</div>'),
sortable: true,
dataIndex: 'title',
renderer: recordRenderer
}, {
xtype: "actioncolumn",
width: 30,
items: [{
getClass: function(v, meta, rec) {
if (this.findWMS(rec.get("URI")) !== false ||
this.findWMS(rec.get("references")) !== false) {
return "gxp-icon-addlayers";
var ows = this.findWMS(rec.get("URI")) || this.findWMS(rec.get("references"));
if (ows !== false) {
return "gxp-icon-addlayers";
}
},
tooltip: this.addMapTooltip,
Expand Down Expand Up @@ -421,7 +474,8 @@ gxp.CatalogueSearchPanel = Ext.extend(Ext.Panel, {
}
}
}
if (url !== null && name !== null) {
if (url !== null && name !== null && name.length > 0) {
url = url.split('?')[0];
return {
url: url,
name: name
Expand All @@ -433,33 +487,48 @@ gxp.CatalogueSearchPanel = Ext.extend(Ext.Panel, {

/** private: method[addLayer]
* :arg record: ``GeoExt.data.LayerRecord`` The layer record to add.
*
* Add a WMS layer coming from a catalogue search.
*
* Add WMS layers coming from a catalogue search.
*/
addLayer: function(record) {
var uri = record.get("URI");
addLayer: function (record) {

var bounds = record.get("bounds");
var bLeft = bounds.left,
bRight = bounds.right,
bBottom = bounds.bottom,
bTop = bounds.top;
var left = Math.min(bLeft, bRight),
right = Math.max(bLeft, bRight),
bottom = Math.min(bBottom, bTop),
top = Math.max(bBottom, bTop);
var wmsInfo = this.findWMS(uri);
if (wmsInfo === false) {
// fallback to dct:references
var references = record.get("references");
wmsInfo = this.findWMS(references);

// Bounds may be empty
var bbox;
if (bounds && bounds != '') {
var bLeft = bounds.left,
bRight = bounds.right,
bBottom = bounds.bottom,
bTop = bounds.top;
var left = Math.min(bLeft, bRight),
right = Math.max(bLeft, bRight),
bottom = Math.min(bBottom, bTop),
top = Math.max(bBottom, bTop);
bbox = [left, bottom, right, top];
}
if (wmsInfo !== false) {
this.fireEvent("addlayer", this, this.selectedSource, Ext.apply({
title: record.get('title')[0],
bbox: [left, bottom, right, top],
srs: "EPSG:4326",
projection: record.get('projection')
}, wmsInfo));

// There may be multiple WMS layers!
var uris = record.get("URI"), i, refsChecked=false;
for (i = 0; i < uris.length; ++i) {

var wmsInfo = this.findWMS([uris[i]]);
if (wmsInfo === false && refsChecked === false) {
// fallback to dct:references
var references = record.get("references");
wmsInfo = this.findWMS(references);
// Do this only once TODO: make elegant
refsChecked = true;
}
if (wmsInfo !== false) {
this.fireEvent("addlayer", this, this.selectedSource, Ext.apply({
title: record.get('title')[0],
bbox: bbox,
srs: "EPSG:4326",
projection: record.get('projection'),
queryable: true
}, wmsInfo));
}
}
}

Expand Down

0 comments on commit 147e3f1

Please sign in to comment.