QGIS Web Client

Installation and Configuration Guide Wednesday June 11, 2014

Last Updated: Wednesday June 11, 2014 Last Change : Wednesday June 11, 2014

  • 1 For the terminally lazy
  • 2 Purpose
  • 3 Installation
  • 4 Configuration of Client
  • 4.1 Per Project Startup Options
  • 4.2 Configuration of search panels
  • 4.3 Configuration of the theme switcher
  • 4.4 Configuring of background layers
  • 4.5 Extending the interface
  • 4.6 Customize languages
  • 5 URL Rewriting
  • 6 Configuration of the search
  • 6.1 PHP Search
  • 6.2 WSGI Search
  • 7 License
  • 8 Developers and Contributors
  • 9 Acknowledgements

1. For the terminally lazy

Edit (if necessary) the needed parameters in install.sh and run:

sudo ./install.sh

2. Purpose

A WMS based webgis client that makes use of QGIS specific WMS extensions (e.g. highlighting, printing, metadata, etc.). QGIS webclient reads the configuration from the WMS GetCapabilities command and builds the layer tree accordingly. Supports legend graphic, feature info requests and printing.

The client builds on existing Web-GIS libraries OpenLayers and GeoExt, as well as ExtJS 3 for the GUI widgets.

All major browsers should be supported.

3. Installation

Requirements (Server):

  • Apache2 - Webserver (Ubuntu: apache2)
  • mod-fcgid (Ubuntu: libapache2-mod-fcgid)
  • QGIS and QGIS Server (best installed from source)

On ubuntu you can meet these requirements by simply doing:

sudo apt-get install libapache2-mod-fcgid

The QGIS Server compilation and installation will be covered in the QGIS manual.

For searching:

  • python-wsgi for searching (Ubuntu: libapache2-mod-wsgi)
  • psycopg2 PostgreSQL db driver (Ubuntu: python-psycopg2)
  • webob - Python module providing WSGI request and response objects (Ubuntu: python-webob)

The client part needs to be git cloned with the following command:

git clone https://github.com/qgis/qgis-web-client.git

4. Configuration of Client

Global Settings for all projects (make a copy from one of the templates provided):

site/js/GlobalOptions.js

Translations (additional languages):

site/js/Translations.js

Project settings and index:

site/index.xml, site/index.php or site/index.html

Stylesheet of project index:

site/gis-project_listing.xsl

Thumbnails for individual projects (if you take the index.xml route):

thumbnails/projectname.png

4.1. Per Project Startup Options

These options are usually defined in the file site/index.xml. The stylesheet then generates the startup URL parameter options. On the client, the file site/js/GetUrlParams.js is responsible for the proper handling of the startup options. The following options are available:

  • lang

An optional language parameter. Normally, this parameter is defined in the file site/js/GlobalOptions.js. Optionally this can be overwritten on a per project base. Allowed values are two-character language codes that must be present in the file site/js/Translations.js or site/js/Translations_custom.js if a custom translations file is used.

  • visibleLayers

A comma-separated list of layers that should be set visible on the project start.

  • visibleBackgroundLayer

Optionally the name of the background layer that should be set visible on project start. You must have background layers enabled in GlobalOptions.js by setting enableBGMaps to true and a background layer must exist with this name. If either of these prerequisites is not met nothing happens and the parameter is simply ignored.

  • format

This optional parameter allows a per project definition of the file format. Valid values are image/png, image/jpeg and image/png;mode=8bit. Defaults to image/png if no format is given per project. For correct specification of image/png;mode=8bit in a URL please encode it correctly: image%2fpng%3b%20mode%3d8bit. If you specify this in site/js/GISProjectListing.js you do not need to encode it.

  • fullColorLayers

An optional comma-separated list of layers that need to be in full color (24bit). This parameter is only relevant if the project default image format is set to image/png or image/png;mode=8bit. If any of the layers in the fullColorLayers parameter list is set visible, the format changes to image/jpeg.

  • maxExtent

The maximum extent of the project. This parameter is used if the 'Full View' navigation button is clicked. If the startExtent parameter is not specified, maxExtent will also be used as the startExtent. The format is: left,bottom,right,top in map units.

  • startExtent

The initial extent on project load if the project should start with a given, but not the maximum extent (e.g. for zooming to a specific project area). Not to be confused with the maxExtent parameter. The format is: left,bottom,right,top in map units.

  • searchtables

An optional list of additional search tables specific to the project. The format is schemaname.tablename. These additional search tables will be used for the search field at the top-right corner of the Webclient-GUI. The default search tables are hard-coded in the file wsgi/search.wsgi, in the searchtables array.

4.2. Configuration of search panels

There are two types of search panels supported, using a direct WMS GetFeatureInfo request or using URL rewriting with a much shorter search URL.

The search panels are configured in site/js/GlobalOptions.js.

The following options are available:

  • mapSearchPanelOutputRegion

SearchPanel search results output configuration (string), possible values: default, right, bottom, popup By default, search results will be shown in left panel, under the search form. Sometimes this is not desired, here you can choose to show the results in one of the other panels, like BottomPanel and RightPanel. These additional panels are hidden by default because their expansion and collapse trigger a map resize->reload cycle that can slow down the application. Example:

  • var mapSearchPanelOutputRegion = 'popup';

4.2.1. Using WMS GetFeatureInfo

var simpleWmsSearch = {
  title: "Search continent",
  query: 'simpleWmsSearch',
  useWmsRequest: true,
  queryLayer: "Country",
  formItems: [
    {
      xtype: 'textfield',
      name: 'name',
      fieldLabel: "Name",
      allowBlank: false,
      blankText: "Please enter a name (e.g. 'africa')"
    }
  ],
  gridColumns: [
    {header: 'Name', dataIndex: 'name', menuDisabled: 'true'}
  ],
  highlightFeature: false,
  highlightLabel: 'name',
  selectionLayer: 'Country',
  selectionZoom: 0,
  doZoomToExtent: true
};
  • title: title of the search tab
  • query: identifier for this search
  • useWmsRequest: enabled for WMS GetFeatureInfo request
  • queryLayer: name of query layer
  • formItems: list of Ext.form.FormPanel item configs
  • xtype: form field type
  • name: name of query layer attribute
  • fieldLabel: visible text for this field
  • blankText: popup text for blank fields
  • gridColumns: list of Ext.grid.GridPanel column configs to show search results
  • highlightFeature (optional): use QGIS WMS highlight instead of QGIS WMS selection if enabled
  • highlightLabel (optional): show this feature attribute as label if highlightFeature is enabled
  • selectionLayer: name of layer for marking selected results (the same as queryLayer) if highlightFeature is not enabled
  • selectionZoom: zoom level for jump-to when selecting results
  • doZoomToExtent (optional): zoom to feature extent when selecting results, overrides selectionZoom

Request URL:

When performing a search query using the above configuration, the following get request will be made:

http://localhost/wms/helloworld?SERVICE=WMS&VERSION=1.1.1& REQUEST=GetFeatureInfo&LAYERS=Country&QUERY_LAYERS=Country& FEATURE_COUNT=10&INFO_FORMAT=text/xml&SRS=EPSG:4326& FILTER=Country:"name"+=+'africa'

4.2.2. Using URL Rewriting

For security and neatness, you may prefer to use rewritten URLs (so that your internal server file paths are not revealed. In that case your options file would contain something like this:

var urlRewriteSearch = {
  title: "Search letter",
  query: 'samplesearch',
  formItems: [
    {
      xtype: 'hidden',
      name: 'query',
      value: 'samplesearch'
    },
    {
      xtype: 'textfield',
      name: 'colour',
      fieldLabel: "Colour",
      allowBlank: false,
      blankText: "Please enter a colour (e.g. 'orange')"
    }
  ],
  gridColumns: [
    {header: 'PKUID', dataIndex: 'pkuid', menuDisabled: 'true'},
    {header: 'Colour', dataIndex: 'colour', menuDisabled: 'true'}
  ],
  highlightFeature: false,
  highlightLabel: 'colour',
  selectionLayer: 'Hello',
  selectionZoom: 1,
  doZoomToExtent: true
};
  • title: title of the search tab
  • query: identifier for this search
  • formItems: list of Ext.form.FormPanel item configs, the query form field is required to match the rewrite rule (value is the same as query)
  • xtype: form field type
  • name: name of query layer attribute
  • fieldLabel: visible text for this field
  • blankText: popup text for blank fields
  • gridColumns: list of Ext.grid.GridPanel column configs to show search results
  • highlightFeature (optional): use QGIS WMS highlight instead of QGIS WMS selection if enabled
  • highlightLabel (optional): show this feature attribute as label if highlightFeature is enabled
  • selectionLayer: name of layer for marking selected results if highlightFeature is not enabled
  • selectionZoom: zoom level for jump-to when selecting results
  • doZoomToExtent (optional): zoom to feature extent when selecting results, overrides selectionZoom

For every search of this type you have to add a URL rewrite rule in the Apache config.

Note

Linebreaks added for formatting - they should be removed in your config file.

RewriteCond %{QUERY_STRING} ^(?:.*)query=samplesearch&*(?:.*)$
RewriteCond %{QUERY_STRING} ^(?:(?:.*)&)?colour=([^&]*)(?:.*)$
RewriteRule ^/wms/(.+)$ /cgi-bin/qgis_mapserv.fcgi?map=/
<path-to-qgis-server-projects>/$1.qgs&SERVICE=WMS&VERSION=1.1.1&
REQUEST=GetFeatureInfo&LAYERS=Hello&QUERY_LAYERS=Hello&FEATURE_COUNT=20&
INFO_FORMAT=text/xml&SRS=EPSG:4326&FILTER=Hello:"colour"\ =\ '%1' [PT]

The first RewriteCond matches the query id of the search panel config. The second RewriteCond extracts the values of the search request parameters.

The RewriteRule composes the actual WMS GetFeatureInfo request to QGIS Server.

Request URL:

http://localhost/wms/helloworld?query=samplesearch&colour=orange

4.2.3. Add search panels to projects

In order for your search panel to appear in the web UI, you must enumerate them in your GlobalOptions.js for example (with url rewriting):

var mapSearchPanelConfigs = {
  "helloworld": [simpleWmsSearch, urlRewriteSearch]
};

Example (no rewriting):

var mapSearchPanelConfigs = {
  "../projects/helloworld.qgs": [simpleWmsSearch, urlRewriteSearch]
};

Search panels are added to a project by adding a new key for the map name with a list of search panel configs to mapSearchPanelConfigs. If there is no search panel configuration for a project, the search will be hidden in the GUI.

The map name is whatever is passed in the get request for your .qgs file. For example if your url includes this:

http://localhost/cgi-bin/qgis_mapserv.fcgi?map=../projects/helloworld.qgs

then your mapSearchPanelConfigs should reflect ../projects/helloworld.qgs as the key for the search list.

4.3. Configuration of the theme switcher

The theme switcher allows to change to a diffent QGIS project (or map theme) without having to leave the application and using the map extent. To enable/disable the theme switcher you have to set the variable var mapThemeSwitcherActive = true; in the site/js/GlobalOptions.js file to true|false. In addition you should place thumbnail images of your map into the directory site/thumbnails where the file name equals the projectname. All thumbnails should be 300x200 pixels in size and in .png format. If your .qgs project is called helloworld.qgs then your thumbnail should be called helloworld.png.

In addition you need to make entries for topics and projects in the file 'site/js/GISProjectListing.js'. Please use the given file as a template. The file is in JSON format and starts with a few central parameters.

4.3.1. Central theme switcher parameters

  • path

The 'path' is the URL part used at the start of the application telling the QGIS Webclient where to find the QGIS projects (see also Apache URL rewriting). This path may be overwritten in some projects if you password-protect them in a separate Apache location.

  • mapserver

This is the path to the WMS server used for WMS requests (e.g. for GetCapabilities, GetFeatureInfo, etc. requests). Again, this parameter may be overwritten in some projects if you want to password-protect the WMS in a separate Apache location.

  • thumbnails

The URL where QGIS web client can find the project thumbnail images.

  • title

The overall title of your Web-GIS. This will be later appended with the name of your project, separated by a dash. It appears in the title bar of the browser window and in the title bar of the web application.

4.3.2. Per topic theme switcher parameters

You can group your projects into topics. A topic only has a single parameter with the name of the topic. In a topic element you can have several project entries in a JSON array called project.

  • name: The name of the topic.

4.3.3. Per project theme switcher parameters

In a topic you can have several project entries. A project can overwrite the global 'path' and 'mapserver' entries.

  • name

The name of the project or map. Will be displayed in the theme switcher below the thumbnail and in the title strings of the application.

  • path

Optional. Overrides the central settings in case you need to password-protect certain projects. The 'path' is the URL part used at the start of the application telling the QGIS Webclient where to find the QGIS projects (see also Apache URL rewriting).

  • mapserver

Optional. Overrides the central settings in case you need to password-protect certain projects. This is the path to the WMS server used for WMS requests (e.g. for GetCapabilities, GetFeatureInfo``, etc. requests).

  • projectpath

The projectpath (directory) or part of the Apache rewrite expression necessary to find the project file. This parameter is mandatory.

  • projectfile

The QGIS project file or part of the Apache rewrite expression necessary to find the project file. This parameter is mandatory. Depending on the Apache rewrite expression you may have to omit the .qgs extension.

  • format

Optional. The image format that QGIS web client should request. Valid values are: image/jpeg, image/png or image/png;mode=8bit. If omitted, the value is taken from site/js/GlobalOptions.js. If it is not defined there either, the value defaults to image/png.

  • visibleLayers

Optional. A comma separated list of layers that should be visible after loading the projects. A future QGIS Webclient version will also read the layer visibility directly from the GetProjectSettings command.

  • fullColorLayers

Optional. A comma separated list of layers that would trigger a format change from image/png to image/jpeg. Per default, the project would use image/png or image/png;mode=8bit but if the user toggles the visibility of a layer with orthophoto data or satellit images, the format will change to image/jpeg.

  • updateInterval

Optional. A prosa text indicating how often the project will get data update. E.g. daily, weekly, monthly, weekly or occasional.

  • lastUpdate

Optional. The date of the last data update, e.g. 2012-10-23.

  • responsible

Optional. The organization and/or person responsible for the project and the data involved.

  • startExtent

Optional. The bounding box (left,bottom,right,top in map units) used when starting the project. If not specified, maxExtent or the extent from GetProjectSettings is used.

  • maxExtent

Optional. The maximum bounding box (left,bottom,right,top in map units) of the project. If not specified the extent from the GetProjectSettings is used.

  • showFeatureInfoLayerTitle

Optional. Boolean (true``|``false). Defines whether the layer title is displayed or not at the top of the popup bubble displaying the feature info results. Influences both the hover and the click popups.

  • tags

Optional. Tags or keywords displayed in the tooltips in the theme switcher. The tags are also used in the search filter used in the theme switcher.

4.4. Configuring of background layers

You can use any OpenLayers.Layer (http://dev.openlayers.org/releases/OpenLayers-2.13.1/doc/apidocs/files/OpenLayers/Layer-js.html) subclass as background layer. This layer must be added to baseLayers. You should do this in customBeforeMapInit() in Customizations.js. Example:

// called before map initialization
function customBeforeMapInit() {
    // define base layer
    var myBaseLayer = new OpenLayers.Layer.WMS("myBaseLayerName",
        "myBaseLayerWmsUrl", {
            layers: "myLayer",
            format: format,
            dpi: screenDpi,
            VERSION: "1.3.0"
        },
        {
            buffer:0,
            singleTile:true,
            ratio:1,
            transitionEffect:"resize",
            isBaseLayer: true, // important!
            projection:authid // requests the base layer in the projection defined in GlobalOptions
        }
    );

    // now add to baseLayers array
    baseLayers.push(myBaseLayer);
}

4.5. Extending the interface

You can add buttons to implements additional functions (editing, advanced identify, etc.). See the example in site/js/Customizations.js.

4.6. Customize languages

In order to provide shorter loading times you can reduce the languages in Translations.js to those you really need. For this purpose the Python script site/js/build/translations.py is shipped with QGIS Web Client.

Write the languages you need into site/js/build/translations.cfg and run the script, i.e. in a shell change to site/js/build and enter python translations.py

A new file site/js/Translations_custom.js is created. Copy this file to your server and adapt qgiswebclient.html accordingly.

5. URL Rewriting

Using a standard installation of QGIS Server, GlobalOptions.js will have a WMS server configuration like var serverAndCGI = "/cgi-bin/qgis_mapserv.fcgi";

A sample URL for QGIS Web Client installed in /var/www/qgis-web-client:

http://localhost/qgis-web-client/qgiswebclient.html?map=/opt/geodata/maps/NaturalEarth.qgs&visibleLayers=HYP_50M_SR_W

With the following rules for Apache mod_rewrite you can shorten the URLs to var serverAndCGI = "/wms"; and http://localhost/maps/NaturalEarth?visibleLayers=HYP_50M_SR_W

Rules in VirtualHost configuration:

# Forbid direct access
RewriteRule ^/cgi-bin/.*$ - [F]

# Search with SearchPanel (e.g. Address)
RewriteCond %{QUERY_STRING} ^(?:.*)query=address&*(?:.*)$
RewriteCond %{QUERY_STRING} ^(?:(?:.*)&)?street=([^&]*)(?:(?:.*)&)+number=([^&]*)(?:.*)$
RewriteRule ^/wms/(.+)$ /cgi-bin/qgis_mapserv.fcgi?map=/opt/geodata/maps/$1.qgs&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&LAYERS=addresses&QUERY_LAYERS=addresses&FEATURE_COUNT=10&INFO_FORMAT=text/xml&SRS=EPSG:21781&FILTER=addresses:"street"\ =\ '%1' AND "number"\ =\ %2 [PT]

# Rewrite /wms/mapname to qgis_mapserv.fcgi?map=mappath/mapname.qgs
RewriteRule ^/wms/(.+)$ /cgi-bin/qgis_mapserv.fcgi?map=/opt/geodata/maps/$1.qgs [QSA,PT]
# Rewrite /maps/mapname to qgis-web-client main page. mapname will be extracted for wms calls in Javascript code.
RewriteRule ^/maps/([^\.]+)$ /qgis-web-client/site/qgiswebclient.html [PT]
# Rewrite /maps/* to qgis-web-client/site (e.g. /maps/gis_icons/mActionZoomNext.png -> /qgis-web-client/site/gis_icons/mActionZoomNext.png)
RewriteRule ^/maps/(.*) /qgis-web-client/site/$1 [PT]

For supporting qgs files in subdirectories (e.g. /maps/subdir/mapnampe) replace last rule with RewriteRule ^/maps/[^/]+/(.*) /qgis-web-client/site/$1 [PT]

For adding zones in different subdirecories (e.g. maps and maps-protected) add the following rules:

RewriteRule ^/wms-protected/(.+)$ /cgi-bin/qgis_mapserv.fcgi?map=/opt/geodata/maps-protected/$1.qgs [QSA,PT]
RewriteRule ^/maps-protected/([^\.]+)$ /qgis-web-client/site/qgiswebclient.html [PT]
RewriteRule ^/maps-protected/(.*) /qgis-web-client/site/$1 [PT]

6. Configuration of the search

Searching is handled by two separate scripts: "search" lists back a hit list while the user is typing in the searchbox. It groups the results and returns a bounding box of the result. getSearchGeom returns the actual wkt geometry for a selected search result.

These scripts are provided in two flavors: PHP and WSGI (Python). The PHP version should run out-of-the-box with just a few lines of configuration. There is no need to alter the DB table structure in order to use PHP search scripts because all needed informations are read from the project file. Another notable difference is that layer names are used instead of table names, this is in order to not disclose internal DB details. The PHP scripts are available under the php folder.

The Python wsgi search scripts provide an advanced, more configurable and more detailed search solution. They draw their results directly from dedicated relations in a PostGIS database. The WSGI scripts are available under the wsgi folder. It is recommended to install the wsgi scripts in a separate directory, e.g. /home/www/wsgi, a place that is not reachable by regular web traffic.

There are two options to highlight a feature that is selected from the search results. If the option enableSearchBoxWmsHighlight in GlobalOptions.js is enabled, the selected feature will be highlighted using QGIS WMS highlight. Otherwise the feature will be added as a vector feature to the highlight layer.

6.1. PHP Search

6.1.1. Available PHP scripts

6.1.1.1. Search

The search.php scripts works as described above. Accepted parameters:

  • map (map name or path)
  • query (search text)
  • searchtables (optional: layer names to search in)

The companion is search_geom.php.

  • map (map name or path)
  • searchtable (layer name)
  • displaytext (the matched string)

6.1.1.2. Unique list

This simple script returns the unique values of a given column of a given PostgreSQL layer. Accepted parameters:

  • map (map name or path)
  • layer (layer name)
  • field (column name)

The script returns a json array of unique values and can be useful to implement select combo boxes for the search panels.

6.1.1.3. Get legend

This script has no wsgi counterpart, it works with recent QGIS Server versions (2.0.1 and newer) and can be used to build a template-based HTML legend instead of the image provided by GetLegendGraphic calls.

To use this feature you must activate it in GlobalOptions.js, search for the commented line below:

var interactiveLegendGetLegendURL = '../php/get_legend.php?map=' + project_map + '&';

Legends generated by this script can be cached for speed, see the paragraph on configuration below.

Accepted parameters:

  • map: (map name or path)
  • layer: (layer name)

6.1.2. PHP configuration file

Configuration for the services is stored in config.php.

Example:

/****************************
 * Map rewrite configuration
 */
// Prefix map name with path
#define('MAP_PATH_REWRITE', '/home/xxx/public_html/QGIS-Web-Client/projects/');
// Append .qgs to the map name
#define('MAP_PATH_APPEND_QGS', true);


/**************************************
 * search configuration
 */
// Configuration for searchable layers
$searchlayers_config = array(
    // Key is layer name
    'Country' => array(
        // SQL for text search: where to search
        'search_column' => 'name'
    )
);

// Default search tables
define('DEFAULT_SEARCH_LAYERS', 'Country');
// Limit search results
define('SEARCH_LIMIT', 100);


/**************************************
 *  Get legend configuration
 */
// Cache expiry time in seconds 0=never cache
define('GET_LEGEND_CACHE_EXPIRY', 60*60);
// Cache directory, defaults to dirname(__FILE__) . '/legend_cache'
define('GET_LEGEND_CACHE_DIRECTORY', null);
// Defaults to current URL + '../cgi-bin/qgis_mapserv.fcgi?'
define('WMS_ONLINE_RESOURCE', null);

/* End configuration */

QGIS Web Client needs to know where to find the scripts, since most configuration is read from the project file, this must be passed in the query string, the file where this parameters are set is GlobalOptions.js see the example below:

// Adds project_map, read value from query string
var project_map = Ext.urlDecode(window.location.search.substring(1)).map;

var searchBoxQueryURL = '../php/search.php?map=' + project_map;
var searchBoxGetGeomURL = '../php/search_geom.php?map=' + project_map;

6.1.3. TODO

Permalinks: the permalinks script is not yet implemented in PHP.

6.2. WSGI Search

6.2.1. Configuration of mod_wsgi

You need to enable mod_wsgi as root. (Ubuntu: a2enmod mod_wsgi).

You need to configure apache with the following lines (e.g. in file /etc/apache2/sites-available/default):

#mod_wsgi
WSGIDaemonProcess gis processes=5 threads=15 display-name=%{GROUP}
WSGIScriptAlias /wsgi/ /home/www/wsgi/
WSGIScriptAliasMatch ^/wsgi/([^/]+) /home/www/wsgi/$1.wsgi

6.2.2. Adaption of the wsgi scripts to your settings and needs

6.2.2.1. DB connection

In the file qwc_connect.py please edit the first line containing the db connection string.

DB_CONN_STRING="host='myhost' dbname='mydb' port='5432' user='myuser' password='secret'"

This connection will be used in all wsgi scripts.

Adapt the parameters according to your server/db. It is highly recommended to connect with a database user having limited rights only (e.g. select rights on relevant tables only).

6.2.2.2. Search type to be used

The search can use PostgreSQL's tsvector data type. "A tsvector value is a sorted list of distinct lexemes, which are words that have been normalized to merge different variants of the same word." from the PostgreSQL doc (http://www.postgresql.org/docs/9.0/interactive/datatype-textsearch.html#DATATYPE-TSVECTOR). Thus tsvector skips all the fill words and reduces nouns to their single form, a behaviour useful for searching texts. However as we are normally dealing with place names here we want them to stay as they are. If you use a language where the single form is a lot different from the plural form but your name contains a plural you will not get a suitable result. If you want to use the tsvector search option you should activate the lines

sql += "searchstring_tsvector @@ to_tsquery(\'not_your_language\', %s)"
data += (querystrings[j]+":*",)

not_your_language is to be replaced with an entry e.g. finnish if you have German place names. Thus plural forms and fillwords are kept as they are. Be aware of side effects! Be sure to fill the field searchstring_tsvector with to_tsvector('not_your_language', 'yourstring').

The use of

sql += "searchstring::tsvector @@ lower(%s)::tsquery"
data += (querystrings[j]+":*",)

is discouraged as it does not find a place name like Stoke-sub-Hamden when you enter Stoke.

If you do not want to use tsvector at all you can enable the full string comparison on the field searchstring (activated by default).

sql += "searchstring ILIKE %s"
data += ("%" + querystrings[j] + "%",)

This method however is slower than tsvector but not relevantly at least if you only have a couple 1000 datasets.

6.2.3. PostgreSQL table setup for searching

CREATE TABLE cadastre.searchtable
(
  searchstring text, --the search string (all lower case), e.g. "zürichstrasse 46, 8610 uster"
  displaytext text NOT NULL, --the display text for the search combobox, e.g. "Zürichstrasse 46, 8610 Uster (address)"
  search_category text, --should have a leading two digit number:, e.g.
                        --"03_parcels", where 03 is the order of the search categories, the number
                        --should be unique across all search tables
  the_geom geometry,    --the actual geometry
  geometry_type text,   --the geometry type as returned by ST_GeometryType(the_geom)
  searchstring_tsvector tsvector, -- be sure to fill this with to_tsvector()
  showlayer varchar(256), -- holds the layer name to be set visible if user chooses a respective result
  CONSTRAINT searchtable_pkey PRIMARY KEY (displaytext)
)
WITH (
  OIDS=FALSE
);
GRANT SELECT ON TABLE cadastre.searchtable TO qwc_user;

-- Index: cadastre.in_cadastre_searchstring_tsvector_gin

CREATE INDEX in_cadastre_searchstring_tsvector_gin
  ON cadastre.searchtable
  USING gin
  (searchstring_tsvector);

The above search table can also be a view or materialized view. One can combine several search tables by specifying the searchtables=searchtable1,searchtable_n parameter when requesting the search.wsgi script. Any searchtable passed to search.wsgi may only contain the letters A to Z, a to z and the underscore. Double quoting the search table throws an error, thus searchtables' names must contain lower characters only.

Using views is generally slower than properly indexed tables, check for yourself what works best.

7. License

The QGIS web client is released under a BSD license.

Copyright (2010-2012), The QGIS Project All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

8. Developers and Contributors

Developers:

  • Jürgen Fischer
  • Marco Hugentobler
  • Pirmin Kalberer
  • Andreas Neumann
  • Alessandro Pasotti
  • Niccolo Rigacci
  • Denis Rouzaud
  • Bernhard Ströbl
  • Tim Sutton
  • Mathias Walker
  • Marco Bernasocchi

Translators:

  • Giovanni Allegri
  • Germán Carrillo
  • Paolo Cavallini
  • Diana Galindo
  • Mayeul Kauffmann
  • Samuel Mesa
  • Alessandro Pasotti
  • Nelson Silva
  • Pavlo Taranov
  • Tudor Bărăscu
  • Uroš Preložnik
  • Klas Karlsson
  • Carl Defevere

9. Acknowledgements

We'd like to thank the OpenLayers, GeoExt and ExtJS teams for providing their base libraries we build upon.



QGIS Web Client

安装和配置指南 2014年6月11日星期三

最后更新:2014年6月11日(星期三) 最后更改:2014年6月11日(星期三)

  • 1对于终极懒惰
  • 2用途
  • 3安装
  • 4客户端配置
  • 4.1每个项目启动选项
  • 4.2搜索面板的配置
  • 4.3主题切换器的配置
  • 4.4配置背景图层
  • 4.5扩展界面
  • 4.6自定义语言
  • 5 URL重写
  • 6搜索配置
  • 6.1 PHP搜索
  • 6.2 WSGI搜索
  • 7许可证
  • 8开发人员和贡献者
  • 9致谢

1。对于终极懒惰

编辑(如有必要) install.sh 中所需的参数,然后运行:

sudo ./install.sh

2。目的

使用QGIS特定WMS扩展(例如,WMS)的基于WMS的webgis客户端。 突出显示,打印,元数据等)。 QGIS webclient读取配置 从WMS GetCapabilities 命令,并相应地构建层树。 支持图例图形,功能信息请求和打印。

客户端基于现有的Web-GIS库OpenLayers和GeoExt 作为GUI小部件的ExtJS 3。

应支持所有主流浏览器

3。安装

要求(服务器):

  • Apache2 - Webserver(Ubuntu:apache2)
  • mod-fcgid(Ubuntu:libapache2-mod-fcgid)
  • QGIS和QGIS Server(最好从源安装)

在ubuntu上,您可以通过简单的方式来满足这些要求:

sudo apt-get install libapache2-mod-fcgid

QGIS Server编译和安装将在QGIS手册中介绍。

用于搜索:

  • python-wsgi进行搜索(Ubuntu:libapache2-mod-wsgi)
  • psycopg2 PostgreSQL数据库驱动程序(Ubuntu:python-psycopg2)
  • webob - 提供WSGI请求和响应对象的Python模块(Ubuntu: python-webob)

客户端部分需要使用以下命令进行git克隆:

git clone https://github.com/qgis/qgis-web-client.git

4。客户端配置

所有项目的全局设置(从其中一个模板复制) 提供):

site / js / GlobalOptions.js

翻译(其他语言):

site / js / Translations.js

项目设置和索引:

site / index.xml,site / index.php或site / index.html

项目索引的样式表:

site / gis-project_listing.xsl

单个项目的缩略图(如果您使用 index.xml 路由):

缩略图/ projectname.png

4.1。每个项目启动选项

这些选项通常在文件 site / index.xml 中定义。然后生成样式表 启动URL参数选项。在客户端,文件 site / js / GetUrlParams.js 负责正确处理启动选项。以下选项可用:

  • lang

可选的语言参数。通常,该参数在文件 site / js / GlobalOptions.js 中定义。 可选地,这可以在每个项目基础上覆盖。允许的值是双字符语言代码 必须存在于文件 site / js / Translations.js site / js / Translations_custom.js 中,如果自定义翻译 文件被使用。

  • visibleLayers

应该在项目开始时设置为可见的层的逗号分隔列表。

  • visibleBackgroundLayer

(可选)应在项目开始时设置的背景图层的名称。您必须启用背景图层 GlobalOptions.js 通过将 enableBGMaps 设置为true,背景图层必须与此名称一起存在。 如果这些先决条件中的任何一个没有得到满足,并且该参数被简单地忽略。

  • 格式

此可选参数允许每个项目定义文件格式。有效值是 image / png image / jpeg image / png; mode = 8bit 。如果没有为每个项目提供格式,则默认为 image / png 。 要正确指定URL中的 image / png; mode = 8bit ,请正确编码: image%2fpng%3b%20mode%3d8bit 。 如果您在 site / js / GISProjectListing.js 中指定,则不需要对其进行编码。

  • fullColorLayers

需要使用全色(24bit)的可选逗号分隔的图层列表。仅此参数 相关的项目默认图像格式设置为 image / png image / png; mode = 8bit 。 如果fullColorLayers参数列表中的任何图层设置为可见,格式将更改为 image / jpeg

  • maxExtent

项目的最大范围。如果单击全景导航按钮,则使用此参数。 如果未指定 startExtent 参数,则 maxExtent 也将用作 startExtent 。 格式为:左,底,右,顶部以地图为单位。

  • startExtent
如果项目应该从给定的开始而不是最大程度开始,项目负载的初始范围 (例如缩放到特定项目区域)。不要与 maxExtent 参数混淆。 格式为:左,底,右,顶部以地图为单位。

  • searchtables

特定于项目的其他搜索表的可选列表。格式为 schemaname.tablename 。 这些附加搜索表将用于WebClient-GUI右上角的搜索字段。 在 searchtables 数组中的 wsgi / search.wsgi 文件中,默认搜索表是硬编码的。

4.2。搜索面板的配置

支持两种类型的搜索面板,使用直接的WMS GetFeatureInfo请求或使用URL重写与更短的搜索URL。

搜索面板在 site / js / GlobalOptions.js 中配置。

以下选项可用:

  • mapSearchPanelOutputRegion

SearchPanel搜索结果输出配置(字符串),可能的值: default,right,bottom,popup 默认情况下,搜索结果将显示在左侧面板下 搜索表单。有时这是不需要的,在这里你可以选择 在其他面板之一中显示结果,如BottomPanel和 RightPanel。这些附加面板默认隐藏,因为 他们的扩展和崩溃触发地图resize-&gt;重新加载循环 可以减缓应用程序。示例:

  • var mapSearchPanelOutputRegion =‘popup’;

4.2.1。使用WMS GetFeatureInfo

var simpleWmsSearch = {
  title: "Search continent",
  query: 'simpleWmsSearch',
  useWmsRequest: true,
  queryLayer: "Country",
  formItems: [
    {
      xtype: 'textfield',
      name: 'name',
      fieldLabel: "Name",
      allowBlank: false,
      blankText: "Please enter a name (e.g. 'africa')"
    }
  ],
  gridColumns: [
    {header: 'Name', dataIndex: 'name', menuDisabled: 'true'}
  ],
  highlightFeature: false,
  highlightLabel: 'name',
  selectionLayer: 'Country',
  selectionZoom: 0,
  doZoomToExtent: true
};
  • title :搜索标签的标题
  • query :此搜索的标识符
  • useWmsRequest :启用WMS GetFeatureInfo请求
  • queryLayer :查询图层的名称
  • formItems :Ext.form.FormPanel项目配置列表
  • xtype :表单字段类型
  • name :查询层属性的名称
  • fieldLabel :此字段的可见文本
  • blankText :空白字段的弹出文本
  • gridColumns :Ext.grid.GridPanel列的列表用于显示搜索结果
  • highlightFeature (可选):如果启用,请使用QGIS WMS高亮显示而不是QGIS WMS选择
  • highlightLabel (可选):如果启用highlightFeature,则将此功能属性显示为标签
  • selectionLayer :如果没有启用highlightFeature,则标记所选结果的层的名称(与queryLayer相同)
  • selectionZoom :选择结果时跳转的缩放级别
  • doZoomToExtent (可选):选择结果时缩放到特征范围,覆盖selectionZoom

请求网址:

使用上述配置执行搜索查询时, 将收到以下获取请求:

http:// localhost / wms / helloworld?SERVICE = WMS&amp; VERSION = 1.1.1&amp; REQUEST = GetFeatureInfo&amp; LAYERS = Country&amp; QUERY_LAYERS = Country&amp; FEATURE_COUNT = 10&amp; INFO_FORMAT = text / xml&amp; SRS = EPSG:4326&amp; FILTER =国家:名称+ = +非洲

4.2.2。使用URL重写

为了安全和整齐,您可能更喜欢使用重写的URL(以便您的 内部服务器文件路径不显示。在这种情况下你的选项文件 将包含以下内容:

var urlRewriteSearch = {
  title: "Search letter",
  query: 'samplesearch',
  formItems: [
    {
      xtype: 'hidden',
      name: 'query',
      value: 'samplesearch'
    },
    {
      xtype: 'textfield',
      name: 'colour',
      fieldLabel: "Colour",
      allowBlank: false,
      blankText: "Please enter a colour (e.g. 'orange')"
    }
  ],
  gridColumns: [
    {header: 'PKUID', dataIndex: 'pkuid', menuDisabled: 'true'},
    {header: 'Colour', dataIndex: 'colour', menuDisabled: 'true'}
  ],
  highlightFeature: false,
  highlightLabel: 'colour',
  selectionLayer: 'Hello',
  selectionZoom: 1,
  doZoomToExtent: true
};
  • title :搜索标签的标题
  • query :此搜索的标识符
  • formItems :Ext.form.FormPanel项目配置列表,查询表单 字段是必须匹配重写规则(值与查询相同)
  • xtype :表单字段类型
  • name :查询层属性的名称
  • fieldLabel :此字段的可见文本
  • blankText :空白字段的弹出文本
  • gridColumns :Ext.grid.GridPanel列的列表用于显示搜索 结果
  • highlightFeature (可选):如果启用,请使用QGIS WMS高亮显示而不是QGIS WMS选择
  • highlightLabel (可选):如果启用highlightFeature,则将此功能属性显示为标签
  • selectionLayer :如果highlightFeature未启用,则标记所选结果的图层名称
  • selectionZoom :选择结果时跳转的缩放级别
  • doZoomToExtent (可选):选择结果时缩放到特征范围,覆盖selectionZoom

对于这种类型的每次搜索,您必须在Apache中添加URL重写规则 config。

Note

Linebreaks added for formatting - they should be removed in your config file.

RewriteCond %{QUERY_STRING} ^(?:.)query=samplesearch&(?:.)$
RewriteCond %{QUERY_STRING} ^(?:(?:.)&)?colour=([^&])(?:.)$
RewriteRule ^/wms/(.+)$ /cgi-bin/qgis_mapserv.fcgi?map=/
<path-to-qgis-server-projects>/$1.qgs&SERVICE=WMS&VERSION=1.1.1&
REQUEST=GetFeatureInfo&LAYERS=Hello&QUERY_LAYERS=Hello&FEATURE_COUNT=20&
INFO_FORMAT=text/xml&SRS=EPSG:4326&FILTER=Hello:"colour"\ =\ '%1' [PT]

第一个RewriteCond匹配搜索面板配置的查询ID。的 第二个RewriteCond提取搜索请求参数的值。

RewriteRule组合到QGIS Server的实际WMS GetFeatureInfo请求。

请求网址:

http:// localhost / wms / helloworld?query = samplesearch&amp; color = orange

4.2.3。将搜索面板添加到项目

为了让您的搜索面板显示在Web UI中,您必须 在您的GlobalOptions.js中列举它们(例如使用url重写):

var mapSearchPanelConfigs = {
  "helloworld": [simpleWmsSearch, urlRewriteSearch]
};

示例(不重写):

var mapSearchPanelConfigs = {
  "../projects/helloworld.qgs": [simpleWmsSearch, urlRewriteSearch]
};

通过为地图名称添加新的键,将搜索面板添加到项目中 具有搜索面板配置列表到 mapSearchPanelConfigs 。如果有 没有搜索面板配置为一个项目,搜索将被隐藏在 GUI。

地图名称是您的 .qgs 文件的get请求中传递的地址。对于 例如,如果您的网址包含以下内容:

http://localhost/cgi-bin/qgis_mapserv.fcgi?map = .. / projects / helloworld.qgs

那么你的 mapSearchPanelConfigs 应该将 ../ projects / helloworld.qgs 反映为 搜索列表的关键。

4.3。主题切换器的配置

主题切换器允许更改为不同的QGIS项目(或地图主题) 而不必离开应用程序并使用地图范围。至 启用/禁用您必须设置变量的主题切换器 var mapThemeSwitcherActive = true; site / js / GlobalOptions.js 文件到 true | false 。另外你应该放置你的缩略图 映射到文件名等于项目名称的目录站点/缩略图。 所有缩略图的尺寸应为300x200像素,格式为 .png 。 如果您的 .qgs 项目称为 helloworld.qgs ,那么您的缩略图应该 被称为 helloworld.png

此外,您还需要为文件中的主题和项目创建条目 ‘site / js / GISProjectListing.js’。请使用给定的文件作为模板。 该文件是JSON格式,并以几个中心参数开始。

4.3.1。中央主题切换台参数

  • 路径

路径是应用开始时使用的URL部分,告诉QGIS Webclient在哪里 找到QGIS项目(另见Apache URL重写)。这条路 如果您在单独的Apache位置进行密码保护,可能会在某些项目中被覆盖。

  • mapserver

这是用于WMS请求的WMS服务器的路径(例如,用于 GetCapabilities GetFeatureInfo 等请求)。 同样,如果要对WMS进行密码保护,则在某些项目中可能会覆盖此参数 在一个单独的Apache位置。

  • 缩略图

QGIS Web客户端可以找到项目缩略图的URL。

  • title
您的Web-GIS的总体标题。这将在后面附加名称 的项目,用破折号分隔。它出现在浏览器的标题栏中 窗口和Web应用程序的标题栏。

4.3.2。每个主题主题切换器参数

您可以将项目分组到主题中。主题只有一个参数 与主题的名称。在主题元素中可以有几个项目 名为project的JSON数组中的条目。

  • name :主题的名称。

4.3.3。每个项目主题切换器参数

在主题中,您可以有多个项目条目。项目可以覆盖全球 ‘path’和’mapserver’条目。

  • name

项目或地图的名称。将在缩略图下方的主题切换器中显示 在应用程序的标题字符串中。

  • 路径

可选。覆盖中央设置,以防您需要密码保护 项目。 路径是应用程序开始时使用的URL部分 QGIS Webclient在哪里可以找到QGIS项目(另见Apache URL重写)。

  • mapserver

可选。覆盖中央设置,以防您需要密码保护 项目。这是用于WMS请求的WMS服务器的路径(例如,对于 GetCapabilities , GetFeatureInfo等等)。</p> <ul> <li> <code> projectpath </code> </li> </ul> <p>需要查找的projectpath(目录)或Apache重写表达式的一部分 项目文件。此参数是必需的。</p> <ul> <li> <code> projectfile </code> </li> </ul> <p> QGIS项目文件或Apache重写表达式的一部分需要查找 项目文件。此参数是必需的。取决于Apache重写表达式 您可能必须省略<code> .qgs </code>扩展名。</p> <ul> <li> <code>格式</code> </li> </ul> <p>可选。 QGIS Web客户端应该请求的图像格式。有效值为:<code> image / jpeg </code>, <code> image / png </code>或<code> image / png; mode = 8bit </code>。如果省略,该值取自<code> site / js / GlobalOptions.js </code>。 如果没有定义,则该值默认为<code> image / png </code> <ul> <li> <code> visibleLayers </code> </li> </ul> <p>可选。加载项目后应该可见的图层的逗号分隔列表。 未来的QGIS Webclient版本也将直接从GetProjectSettings中读取图层的可见性 命令。</p> <ul> <li> <code> fullColorLayers </code> </li> </ul> <p>可选。以逗号分隔的图层列表将触发格式从<code> image / png </code>更改为<code> image / jpeg </code>。 根据默认,项目将使用<code> image / png </code>或<code> image / png; mode = 8bit </code>,但如果用户切换可见性 具有正射影像数据或卫星图像的图层,格式将更改为<code> image / jpeg </code>。</p> <ul> <li> <code> updateInterval </code> </li> </ul> <p>可选。一个普通文字,表明项目将获得数据更新的频率。例如。 <code> daily </code>,<code> weekly </code> <code> monthly </code>,<code> weekly </code>或<code>偶尔</code>。</p> <ul> <li> <code> lastUpdate </code> </li> </ul> <p>可选。上次数据更新的日期,例如<code> 2012-10-23 </code> <ul> <li> <code>负责</code> </li> </ul> <p>可选。组织和/或负责项目的人员 和所涉及的数据。</p> <ul> <li> <code> startExtent </code> </li> </ul> <p>可选。启动项目时使用的边框(左,底,右,顶部在地图单位)。 如果未指定,则使用<code> maxExtent </code>或<code> GetProjectSettings </code>的扩展名。</p> <ul> <li> <code> maxExtent </code> </li> </ul> <p>可选。项目的最大边界框(左,底,右,顶部在地图单位)。 如果未指定,则使用GetProjectSettings的扩展名。</p> <ul> <li> <code> showFeatureInfoLayerTitle </code> </li> </ul> <p>可选。 Boolean(<code> true |``false )。定义图层标题是否显示在顶部 的弹出窗口显示功能信息结果。影响悬停和点击弹出窗口。

  • 标签

可选。在主题切换器中的工具提示中显示的标签或关键字。 标签也用于主题切换器中使用的搜索过滤器。

4.4。配置背景图层

您可以使用任何OpenLayers.Layer( http ://dev.openlayers.org/releases/OpenLayers-2.13.1/doc/apidocs/files/OpenLayers/Layer-js.html )子类作为背景层。此图层必须添加到基础层。您应该在 Customizations.js 中的 customBeforeMapInit()中执行此操作。示例:

// called before map initialization
function customBeforeMapInit() {
    // define base layer
    var myBaseLayer = new OpenLayers.Layer.WMS("myBaseLayerName",
        "myBaseLayerWmsUrl", {
            layers: "myLayer",
            format: format,
            dpi: screenDpi,
            VERSION: "1.3.0"
        },
        {
            buffer:0,
            singleTile:true,
            ratio:1,
            transitionEffect:"resize",
            isBaseLayer: true, // important!
            projection:authid // requests the base layer in the projection defined in GlobalOptions
        }
    );

// now add to baseLayers array
baseLayers.push(myBaseLayer);

}

4.5。扩展接口

您可以添加按钮来实现其他功能(编辑,高级识别等)。 请参阅 site / js / Customizations.js 中的示例

4.6。自定义语言

为了提供更短的加载时间,您可以将 Translations.js 中的语言减少到真正需要的语言。 为此,QGIS Web Client附带了Python脚本 site / js / build / translations.py

写下你的语言 需要进入 site / js / build / translations.cfg 并运行脚本,即在shell更改为 site / js / build 并输入 python translations.py

创建了一个新文件 site / js / Translations_custom.js 。将此文件复制到您的服务器,并相应地修改 qgiswebclient.html

5。网址重写

使用QGIS Server的标准安装, GlobalOptions.js 将具有WMS 服务器配置,如 var serverAndCGI =/cgi-bin/qgis_mapserv.fcgi;

安装在 / var / www / qgis-web-client 中的QGIS Web Client示例URL:

http://localhost/qgis-web-client/qgiswebclient.html?map=/opt/geodata/maps/NaturalEarth.qgs&visibleLayers=HYP_50M_SR_W

使用Apache mod_rewrite 的以下规则可以将URL缩短到 var serverAndCGI =/ wms; http:// localhost / maps / NaturalEarth?visibleLayers = HYP_50M_SR_W < / a>

VirtualHost配置中的规则:

# Forbid direct access
RewriteRule ^/cgi-bin/.*$ - [F]

Search with SearchPanel (e.g. Address)

RewriteCond %{QUERY_STRING} ^(?:.)query=address&(?:.)$ RewriteCond %{QUERY_STRING} ^(?:(?:.)&)?street=([^&])(?:(?:.)&)+number=([^&])(?:.)$ RewriteRule ^/wms/(.+)$ /cgi-bin/qgis_mapserv.fcgi?map=/opt/geodata/maps/$1.qgs&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&LAYERS=addresses&QUERY_LAYERS=addresses&FEATURE_COUNT=10&INFO_FORMAT=text/xml&SRS=EPSG:21781&FILTER=addresses:"street"\ =\ '%1' AND "number"\ =\ %2 [PT]

Rewrite /wms/mapname to qgis_mapserv.fcgi?map=mappath/mapname.qgs

RewriteRule ^/wms/(.+)$ /cgi-bin/qgis_mapserv.fcgi?map=/opt/geodata/maps/$1.qgs [QSA,PT]

Rewrite /maps/mapname to qgis-web-client main page. mapname will be extracted for wms calls in Javascript code.

RewriteRule ^/maps/([^.]+)$ /qgis-web-client/site/qgiswebclient.html [PT]

Rewrite /maps/* to qgis-web-client/site (e.g. /maps/gis_icons/mActionZoomNext.png -> /qgis-web-client/site/gis_icons/mActionZoomNext.png)

RewriteRule ^/maps/(.*) /qgis-web-client/site/$1 [PT]

在子目录中支持qgs文件(例如/ maps / subdir / mapnampe)将最后一个规则替换为 RewriteRule ^ / maps /[^/]+/(.)/ qgis-web-client / site / $ 1 [PT]

为了在不同的子目录中添加区域(例如,地图和地图保护),请添加以下规则:

RewriteRule ^/wms-protected/(.+)$ /cgi-bin/qgis_mapserv.fcgi?map=/opt/geodata/maps-protected/$1.qgs [QSA,PT]
RewriteRule ^/maps-protected/([^.]+)$ /qgis-web-client/site/qgiswebclient.html [PT]
RewriteRule ^/maps-protected/(.) /qgis-web-client/site/$1 [PT]

6。配置搜索

搜索由两个单独的脚本处理:搜索列表 当用户在搜索框中输入时,返回命中列表。它组合 结果并返回结果的边界框。 getSearchGeom 返回 所选搜索结果的实际wkt几何。

这些脚本提供了两种口味: PHP WSGI(Python) PHP 版本应该开箱即用 只需几行配置。没有必要改变DB 表结构,以便使用PHP搜索脚本,因为读取所有需要的信息 项目文件。另一个值得注意的区别是使用图层名称而不是 表名,这是为了不透露内部数据库的细节。 PHP脚本可用 在php文件夹下。

Python wsgi搜索脚本提供了高级的,更可配置的 更详细的搜索解决方案。他们直接从忠诚关系中得出结果 在PostGIS数据库中。 WSGI脚本可用 在 wsgi 文件夹下。建议 将wsgi脚本安装在单独的目录中,例如 / home / www / wsgi ,一个地方 这不能通过常规网络流量访问。

有两个选项来突出显示从搜索结果中选择的功能。如果选项 启用 GlobalOptions.js 中的 enableSearchBoxWmsHighlight ,所选功能将被 使用QGIS WMS突出显示。否则,该功能将作为向量功能添加到 高亮层。

6.1。 PHP搜索

6.1.1。可用的PHP脚本

6.1.1.1。搜索

search.php 脚本如上所述工作。 接受的参数:

  • map (地图名称或路径)
  • 查询(搜索文字)
  • searchtables (可选:要搜索的图层名称)

伴侣是 search_geom.php

  • map (地图名称或路径)
  • searchtable (图层名称)
  • displaytext (匹配的字符串)

6.1.1.2 。唯一列表

这个简单的脚本返回给定PostgreSQL层的给定列的唯一值。 接受的参数:

  • map (地图名称或路径)
  • (图层名称)
  • 字段(列名称)

脚本返回一个唯一值的json数组,可用于实现搜索面板的选择组合框。

6.1.1.3 。获得传奇

这个脚本没有wsgi对应,它适用于最近的QGIS Server版本(2.0.1和更新版本) 并且可以用于构建基于模板的HTML图例,而不是由 GetLegendGraphic 调用提供的图像。

要使用此功能,您必须在 GlobalOptions.js 中激活它,搜索下面的注释行:

var interactiveLegendGetLegendURL = '../php/get_legend.php?map=' + project_map + '&';

此脚本生成的图例可以缓存缓存,请参阅下面的配置部分。

接受的参数:

  • map :(地图名称或路径)
  • layer :(layer name)

6.1.2。 PHP配置文件

服务的配置存储在 config.php 中。

示例:

/****************************
 * Map rewrite configuration
 */
// Prefix map name with path
#define('MAP_PATH_REWRITE', '/home/xxx/public_html/QGIS-Web-Client/projects/');
// Append .qgs to the map name
#define('MAP_PATH_APPEND_QGS', true);

/************************************** * search configuration */ // Configuration for searchable layers $searchlayers_config = array( // Key is layer name 'Country' => array( // SQL for text search: where to search 'search_column' => 'name' ) );

// Default search tables define('DEFAULT_SEARCH_LAYERS', 'Country'); // Limit search results define('SEARCH_LIMIT', 100);

/************************************** * Get legend configuration */ // Cache expiry time in seconds 0=never cache define('GET_LEGEND_CACHE_EXPIRY', 60*60); // Cache directory, defaults to dirname(FILE) . '/legend_cache' define('GET_LEGEND_CACHE_DIRECTORY', null); // Defaults to current URL + '../cgi-bin/qgis_mapserv.fcgi?' define('WMS_ONLINE_RESOURCE', null);

/* End configuration */

QGIS Web Client需要知道从哪里找到脚本,因为大多数 配置是从项目文件中读取的,必须在该文件中传递 查询字符串,这个参数设置的文件是 GlobalOptions.js 参见下面的例子:

// Adds project_map, read value from query string
var project_map = Ext.urlDecode(window.location.search.substring(1)).map;

var searchBoxQueryURL = '../php/search.php?map=' + project_map; var searchBoxGetGeomURL = '../php/search_geom.php?map=' + project_map;

6.1.3。 TODO

永久链接:PHP中尚未实现固定链接脚本。

6.2。 WSGI搜索

6.2.1。配置mod_wsgi

您需要以root身份启用mod_wsgi。 (Ubuntu: a2enmod mod_wsgi )。

您需要使用以下行配置apache(例如,在文件中 / etc / apache2 / sites-available / default ):

#mod_wsgi
WSGIDaemonProcess gis processes=5 threads=15 display-name=%{GROUP}
WSGIScriptAlias /wsgi/ /home/www/wsgi/
WSGIScriptAliasMatch ^/wsgi/([^/]+) /home/www/wsgi/$1.wsgi

6.2.2。将wsgi脚本适应您的设置和需要

6.2.2.1 。 DB连接

在文件 qwc_connect.py 中,请编辑包含数据库连接字符串的第一行。

DB_CONN_STRING =host =‘myhost’dbname =‘mydb’port =‘5432’user =‘myuser’password =‘secret’

此连接将用于所有wsgi脚本。

根据您的服务器/数据库调整参数。强烈推荐 与仅具有有限权限的数据库用户连接(例如,仅对相关表格选择权限)。

6.2.2.2。要使用的搜索类型

搜索可以使用PostgreSQL的tsvector数据类型。 tsvector值是不同词汇的排序列表,它们是已被归一化的词 合并相同单词的不同变体。 从PostgreSQL文档( http://www.postgresql.org/docs/9.0 /interactive/datatype-textsearch.html#DATATYPE-TSVECTOR )。 因此,tsvector跳过所有填充单词,并将名词减少为单个表单,行为有用 用于搜索文本。然而,正如我们通常在这里处理地名一样,我们希望他们保持原样。 如果您使用单一形式与复数形式大不相同的语言,但您的名称包含复数形式 你不会得到一个合适的结果。如果要使用tsvector搜索选项,则应激活线条

sql += "searchstring_tsvector @@ to_tsquery(&#39;not_your_language&#39;, %s)"
data += (querystrings[j]+":",)

not_your_language将替换为条目,例如芬兰语,如果你有德国地名。 因此,复数形式和填充词保持原样。注意副作用! 请务必使用 to_tsvector(’not_your_language’,’yourstring’)填写fieldstring_tsvector。

使用

sql += "searchstring::tsvector @@ lower(%s)::tsquery"
data += (querystrings[j]+":",)
不要劝阻

,因为当您输入Stoke时,找不到Stoke-sub-Hamden的地名。

如果您不想使用tsvector,您可以在字段搜索字符串中启用完整的字符串比较 (默认激活)。

sql += "searchstring ILIKE %s"
data += ("%" + querystrings[j] + "%",)

然而,这种方法比tsvector慢,但是至少如果你只有几个数据集,那么这个方法不是相关的。

6.2.3。 PostgreSQL表设置用于搜索

CREATE TABLE cadastre.searchtable
(
  searchstring text, –the search string (all lower case), e.g. "zürichstrasse 46, 8610 uster"
  displaytext text NOT NULL, –the display text for the search combobox, e.g. "Zürichstrasse 46, 8610 Uster (address)"
  search_category text, –should have a leading two digit number:, e.g.
                        –"03_parcels", where 03 is the order of the search categories, the number
                        –should be unique across all search tables
  the_geom geometry,    –the actual geometry
  geometry_type text,   –the geometry type as returned by ST_GeometryType(the_geom)
  searchstring_tsvector tsvector, – be sure to fill this with to_tsvector()
  showlayer varchar(256), – holds the layer name to be set visible if user chooses a respective result
  CONSTRAINT searchtable_pkey PRIMARY KEY (displaytext)
)
WITH (
  OIDS=FALSE
);
GRANT SELECT ON TABLE cadastre.searchtable TO qwc_user;

– Index: cadastre.in_cadastre_searchstring_tsvector_gin

CREATE INDEX in_cadastre_searchstring_tsvector_gin ON cadastre.searchtable USING gin (searchstring_tsvector);

上述搜索表也可以是视图或物化视图。一个可以结合 几个搜索表通过指定 searchtables = searchtable1,searchtable_n 参数在请求search.wsgi脚本时。任何可搜索表传递给 search.wsgi 只能包含字母A到Z,a到z和下划线。双引号搜索 table抛出一个错误,因此searchtables的名称只能包含较低的字符。

使用视图通常比正确索引的表格慢,请检查自己最有效的方法。

7。许可证

QGIS Web客户端根据BSD许可证发布。

版权所有(2010-2012),QGIS项目 保留所有权利。

允许使用源代码和二进制形式进行重新分发和使用,无论是否进行修改 条件是满足以下条件:

  • 重新分发源代码必须保留上述版权声明,此列表条件 以及免责声明。
  • 以二进制形式重新分发必须复制上述版权声明,此列表条件 以及发行版随附的文档和/或其他资料中的以下免责声明。

本软件由版权所有者和贡献者按原样提供,任何明示或暗示 暗示的保证,包括但不限于暗示的适销性和适用性的保证 对于特定用途是免责的。在任何情况下,版权所有者或贡献者均不承担责任 对于任何直接,间接,偶发,特殊,惩戒性或后果性损害(包括但不限于 限于替代商品或服务的采购;使用,数据或利润损失;或业务中断) 无论何种原因和任何责任理论,无论合同,严格责任或侵权 (包括疏忽或其他)由于使用本软件而导致的任何方式,即使已被告知 这种损害的可能性。

8。开发人员和贡献者

开发人员:

  • JürgenFischer
  • Marco Hugentobler
  • Pirmin Kalberer
  • Andreas Neumann
  • 亚历山德罗·帕索蒂
  • Niccolo Rigacci
  • Denis Rouzaud
  • BernhardStröbl
  • Tim Sutton
  • Mathias Walker
  • Marco Bernasocchi

Translators:

  • Giovanni Allegri
  • GermánCarrillo
  • Paolo Cavallini
  • 黛安娜·加林多
  • Mayeul Kauffmann
  • Samuel Mesa
  • 亚历山德罗·帕索蒂
  • Nelson Silva
  • Pavlo Taranov
  • TudorBărăscu
  • UrošPreložnik
  • Klas Karlsson
  • Carl Defevere

9。致谢

我们要感谢OpenLayers,GeoExt和ExtJS团队提供基础库 我们建立在。




相关问题推荐