Wednesday, August 22, 2012

custom workflow from featureinfo in GXP GeoEXT ExtJS

In a series of articles I would like to share some experiences with open source tooling we frequently use at GeoCat to fullfill customer wishes. I'd like to start with an article on the GXP library by OpenGeo. Developers at OpenGeo use this library in their famous products OpenGeoSuite, GeoNode and more to build interactive webbased mapviewers. The library is based on OpenLayers, ExtJS and GeoExt and can be used to build/configure a full interactive mapviewer including feature-query and edit in minutes. Download a copy from Github: https://github.com/opengeo/gxp.

At GeoCat we use the library if customers have very specific viewer demands which can not be met by a generic product like Geonetwork or Geonode. Today i did a small customisation which i think might be usefull to share with you, since a situation like this happens often. A customer wanted to display a list of coupled records from a non-geospatial table linked to a geometry a user clicked on in the map.

First challenge was to find an 'exit-point' from the default GXP workflow, in this case feature-info. I use exit point, because at that point you leave generic GXP workflow (display a record in a popup) and enter a customised workflow (open additional popups, ajax-requests and more). I wanted to convert the value of an attribute in the featureinfo result to a hyperlink, which starts up customised workflow. One way to set up such a hyperlink on an attribute is by addind a feature-template for that layer to geoserver and add the hyperlink in the template. Next choose html as display format for featureinfo (there is even another way available: one could add the hyperlink itself to the database, eg SELECT '<a href=' || www || '>click here</a>' AS link FROM ....). But in this case I added a ExtJS customRenderers on WMSGetFeaturinfo's itemConfig configuration. Such a renderer can override the default 'print as string' of a PropertyGrid to print about anything (like an image, hyperlink, ajax-lookup)



{
    ptype: "gxp_wmsgetfeatureinfo",
    outputConfig: {
        width: 400,
        height: 200
    },
    itemConfig: {
        customRenderers: {
            yourfieldname: function(value) {
                return '<a href='+value+'>Click here</a>';
            }
        }
    }
}

In stead of a hyperlink we'll need a javascript function call, to in this case load customised content and place it in a panel.



return '<button onclick="getPanelContent(' + value + ')"';



To retrieve the content from the PostGres database, i used PHP to generate JSON. Be sure to activate PostGres extension in PHP.ini.



<?php

$dbh = pg_connect("host=localhost dbname=postgis user=postgres port=5432");
$sql = "SELECT * FROM dummy where id =" + $_POST["id"];
$result = pg_query($dbh, $sql);   
$data = array();
while ($row=pg_fetch_object($result))
{
$data [] = $row;
}
echo json_encode($data);

?>


To retrieve the JSON I used an Ext.JSONStore with a load event that pushes the JSON result as a set of Ext.propertyGrids to a Panel with Accordion Layout (this is how GXP displays a usual getfeatureinfo result).



var store;

Ext.onReady(function(){

 store = new Ext.data.JsonStore({
    url: 'content.php',
    fields: [
            'Id','title', 'type'
        ],listeners: {
            load: {
                fn: function(store, records, options){
                 store.each(
                    function(record){
                     Ext.getCmp("accordionPanel").add(
                            new Ext.grid.PropertyGrid({
                            columns: [
                                {id:'Id',header: 'ID',   dataIndex: 'Id'},
                                {header: 'title',   dataIndex: 'title'},
                                {header: 'type',  dataIndex: 'type'}
                            ],
                            source:record,
                            title:record.get('title')
                        })
                     )
                });
                Ext.getCmp("accordionPanel").doLayout();
                }
            }
        }
    });
       
});



Finally only the load needs to be triggered when the button in the featureinfo panel is clicked, the id of the clicked record should be added here as a filter.



function getPanelContent(value){
store.load({params:{id:value}});
}



I hope this GXP customisation was interesting to read. Feel free to send me improvements.
I'll put up a live demo and full code-download soon.

Saturday, January 21, 2012

mapwindow & metadata

Today i looked at the mapwindow/dotspatial project http://mapwindow.org. A plain-functional .Net desktop gis product. The program has a very nice plug-in architecture. Through a vast list of plug-ins quite some advanced geo-actions can be done. My interest lies in metadata, i was hoping for a CSW-search imlementation. Unfortunately it's currently not available (and no work being done), even WMS/WFS is not supported out of the box (basic WMS through a plug-in). However I was quite surprised to find a metadata-plugin in 4.8 (not in 6?). The plug-in works quite nice. A tree structure for the metadata and for every item a clear edit-form appears. The metadata is however very ESRI-FGDC oriented. In the metadataviewer are actually esri-stylesheets used.
So disappointing to find very limited support for iso19115.
I think (through the WMS-plugin) the basis is there for a CSW search plug-in, extending mapwindow in that direction would be nice. A first quick win is in the context-menu for a WMS-layer, 'show metadata' should not result in a warning ('not available') but get the metadata-link from getcapabilities and display the metadata from the WMS-server!
Maybe i'll dive in the code one day and get it done myself...
Good luck dotspatial/mapwindow team....!

Saturday, December 31, 2011

Changing jobs: Nieuwland -> GeoCat

With the turn of 2011 to 2012 i had the oppertunity to change jobs. This year i start at Geocat bv (http://www.geocat.net). Geocat is the project lead in the open source project geonetwork (http://geonetwork-opensource.org/), a geo-metadata catalog server. Also they (or we) developed an esri-extension to publish data from ArcGIS to GeoServer, Mapserver, PostGis and GeoNetwork (or any CSW-server), GeoCat Bridge. The extension is sold all over europe, in the US and in Canada. Extra opportunities to visit the open source communities abroad. GeoCat also customises OpenLayers/ExtJS clients for customers in a variety of industries.

Aside the international oppertunities i'm looking forward to working in a fully opensource atmosphere amongst at least 4 great colleagues. I wish everybody a great 2012.

Tuesday, September 13, 2011

OpenLayers 2.11

Just upgraded to OpenLayers 2.11, unfortunately my scale control broke down, appeared to be because of new language-keys in i18n Use these new keys in Lang/language.js 'permalink': "Permanente verwijzing", 'graticule': 'Arcering', 'overlays': "Overlays", 'baseLayer': "Achtergrondkaart", 'scale': "Schaal = 1 : ${scaleDenom}", see: http://trac.osgeo.org/openlayers/ticket/3364 And somehow my bbox-strategy doesn't refresh anymore... I have to look into that further.

Sunday, July 03, 2011

Geoserver 2.1 and Inspire View Service Requirements

We currently host Inspire View Services for two customers using GeoServer. Since Geoserver 2.1 the required WMS 1.3 is available, and an Inspire extension is available to add some extra required fields to the capabilities document. However the View Services in Geoserver are not yet fully conformant to the Inspire requirements.

Some points of non-conformance:
- In the keywordlist a reference should be made to which thesaurus the keyword is coming from
- For every layer for every available CRS a bbox should be provided in that CRS
- In the top layer a authority url should be provided, referencing the publishing organisations website
- In every layer a identfier should be available referencing the
dataset (which is also mentioned in the metadata for data and
metadata for services records)

Note that this only applies to scenario 1 (where a metadata for service record is available). And only 1 language supported (which is also default language).

The dutch government proposed a 'workaround' to be able to use products like Geoserver and still be compliant. The capabilities document can be manually altered and saved anywere on the web. In the metadata for service record a hyperlink should be included to the altered capabilities document (however i don't know of any viewer supporting this workaround)

examle of altered capabilities document

Most of these short-comings also exist in the deegree project. Although the developers convinced me they're nearly there.