Skip to content

Commit

Permalink
New QGISExtension: LocationService to call external services for elev…
Browse files Browse the repository at this point in the history
…ation and address for given coordinate.

Configurable with project.json file.
Data from this service is displayed in FeatureInfo window.
  • Loading branch information
uprel committed Jan 17, 2016
1 parent 8309bb6 commit dac340e
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 15 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ It turns your QGIS project into Web GIS application with tools to view, navigate
* user authorization with optional guest access
* server side (database for storing info about projects, base layers, external layers (WMS,WFS) and users; user authentication, specific project settings)
* QGIS server proxy (caching and validating requests)
* layer context menu with Zoom to layer extent, Open attribute data, Data Export (SHP, DXF, CSV)
* layer context menu with Zoom to layer extent, Open attribute data, Data Export* (SHP, DXF, CSV)
* geolocation button
* Google StreetView integration
* using external location services for address and elevation
* legend in layer tree
* separating project settings and code
* user Interface changes

**[Longer Description](http://level2.si/index.php/2015/06/14/whats-new-in-extended-qgis-web-client/)**

*Only PostGIS layers

##Documentation
Read **[Wiki](../../wiki)**

Expand Down
4 changes: 3 additions & 1 deletion admin/languages/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ var TR = {
mapBasic: 'Karte',
mapSatellite: 'Satellit',
mapHybrid: 'Hybrid',
mapTerrain: 'Gelände'
mapTerrain: 'Gelände',
fiLocation: 'Position',
fiElevation: 'über dem Meeresspiegel'
};
4 changes: 3 additions & 1 deletion admin/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ var TR = {
mapBasic: 'Map',
mapSatellite: 'Satellite',
mapHybrid: 'Hybrid',
mapTerrain: 'Terrain'
mapTerrain: 'Terrain',
fiLocation: 'Location',
fiElevation: 'above sea level'
};
4 changes: 3 additions & 1 deletion admin/languages/sl.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ var TR = {
mapBasic: 'Osnovna karta',
mapSatellite: 'Satelit',
mapHybrid: 'Hibridni prikaz',
mapTerrain: 'Topografska karta'
mapTerrain: 'Topografska karta',
fiLocation: 'Lokacija',
fiElevation: 'nadmorska višina'
};
125 changes: 118 additions & 7 deletions client/site/js/FeatureInfoDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,60 @@ function showFeatureInfo(evt) {
xmlDoc.async = "false";
xmlDoc.loadXML(evt.text);
}

//start locationservices
var text = "";
var locationText = "";
var locationUnits = map.getLonLatFromPixel(evt.xy);
var locationObj = new QGIS.LocationService({location: locationUnits});
var popupItems = [];

if (projectData.locationServices != null) {

text = "</br>";
locationText = "<h2>" + TR.fiLocation + "</h2>";
//locationText += '<table><tbody>';

popupItems.push(
{
xtype: 'box',
html: locationText
}, {
id: "fi_location",
//margins: '5 5 5 5',
xtype: 'box',
html: '<tr><td>' + locationObj.locationToString() + '</td></tr>'
});

for (var l = 0; l < projectData.locationServices.length; l++) {
locationObj.getService({
name: projectData.locationServices[l].name,
key: projectData.locationServices[l].key,
provider: projectData.locationServices[l].provider
});

popupItems.push({
id: "fi_"+projectData.locationServices[l].name,
//margins: '5 5 5 5',
xtype: 'box',
html: '</br>'
});
}
}

locationObj.on("elevation", updateElevation);
locationObj.on("address", updateAddress);

// open AttributeTree panel
featureInfoResultLayers = [];
highLightGeometry = [];
parseFIResult(xmlDoc);
featureInfoResultLayers.reverse();
highLightGeometry.reverse();
if (featureInfoResultLayers.length > 0) {
//if (featureInfoResultLayers.length > 0) {
if (hoverPopup) {removeHoverPopup();}
if (clickPopup) {removeClickPopup();}
var text = "";

if (identificationMode == 'topMostHit') {
text += featureInfoResultLayers[0];
featureInfoHighlightLayer.addFeatures(highLightGeometry[0]);
Expand All @@ -57,25 +101,42 @@ function showFeatureInfo(evt) {
featureInfoHighlightLayer.addFeatures(highLightGeometry[i]);
}
}


popupItems.push({
id: "fi_qgis",
xtype: 'box',
//margins: '3 0 3 3',
html: text
});

//new way GeoExt Popup
clickPopup = new GeoExt.Popup({
title: clickPopupTitleString[lang],
location: map.getLonLatFromPixel(evt.xy),
location: locationUnits,
map: map,
autoScroll: true,
bodyStyle:'padding:5px',
html: text,
//layout: 'accordion',
items: popupItems,
maximizable: true,
collapsible: true,
listeners: {
beforeshow: function() {

var maxHeight = geoExtMap.getHeight() * 0.8;
var minWidth = 200;

if ((geoExtMap.getWidth() * 0.2) > minWidth) {
this.setWidth(geoExtMap.getWidth() * 0.2);
} else {
this.setWidth(minWidth);
}

if (this.getHeight()> maxHeight) {
this.setHeight(maxHeight);
}
}
}
}
});
clickPopup.show();

Expand All @@ -95,7 +156,7 @@ function showFeatureInfo(evt) {
// clickPopup.events.fallThrough = false;
// map.addPopup(clickPopup); //*/
changeCursorInMap("default");
}
//}
} else {
closePopupClick = false;
}
Expand Down Expand Up @@ -454,3 +515,53 @@ function getFeatures(layerName, node) {
}
}
}

function updateElevation(data, location, field, template){

var pan = Ext.getCmp('fi_elevation');
var tem = new Ext.Template(template);

if(data!==undefined) {
if (!(isNaN(data[field]))) {
if(data[field] === parseInt(data[field])) {
//
}
else {
data[field] = data[field].toFixed(elevationPrecision);
}
}
}

var label = tem.apply(data);

pan.update(label);
}

function updateAddress(data, location, field, template, templateMin, factor) {

var pan = Ext.getCmp('fi_address');

var distance = 0;
var results;

if((field=='') || (field==null))
results = data;
else
results = data[field];

if(results.distance != null) {
distance = results.distance;
results.distance = distance*factor;
}
if (distance*factor>minimumAddressRange) {
tem = new Ext.Template(templateMin);
}
else {
tem = new Ext.Template(template);
}

var label = tem.apply(results);

pan.update(label);

}
119 changes: 119 additions & 0 deletions client/site/js/QGISExtensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,125 @@ QGIS.LayerOrderPanel = Ext.extend(Ext.Panel, {
Ext.reg('qgis_layerorderpanel', QGIS.LayerOrderPanel);


/* *************************** QGIS.LocationService **************************** */
/* Created by Uros Preloznik, Level2 www.level2.si */
/* ***************************************************************************** */

QGIS.LocationService = Ext.extend(Ext.util.Observable, {
constructor: function(config){
this.location = config.location; //units

this.addEvents(['elevation', 'address']);

this.listeners = config.listeners;

// Call our superclass constructor to complete construction process.
QGIS.LocationService.superclass.constructor.call(this, config)
},

locationToString: function () {
return this.location.lon.toFixed(coordinatePrecision)+ ", " + this.location.lat.toFixed(coordinatePrecision);

},

locationToWgs: function () {
return this.location.clone().transform(authid, new OpenLayers.Projection("EPSG:4326"));
},

getService: function (config) {

var serviceData = {};
switch (config.name) {
case "elevation" :
switch
(config.provider.toLowerCase()) {
case "mapbox" :
serviceData.url = "https://api.mapbox.com/v4/surface/mapbox.mapbox-terrain-v1.json";
serviceData.resultNode = "results";
serviceData.resultField = "ele";
serviceData.displayTemplate = '<tr><td>{ele}m '+TR.fiElevation + '</td></tr>'
serviceData.params = {
layer: "contour",
fields: "ele",
points: this.locationToWgs().toShortString(),
access_token: config.key
};
break;
case "mapzen" :
serviceData.url = "https://elevation.mapzen.com/height";
serviceData.resultNode = "";
serviceData.resultField = "height";
//serviceData.displayTemplate = "{height}m";
serviceData.displayTemplate = '<tr><td>{height}m '+TR.fiElevation + '</td></tr>'
serviceData.params = {
json: Ext.util.JSON.encode({
range: false,
shape: [{
lat: this.locationToWgs().lat,
lon: this.locationToWgs().lon
}]
}),
api_key: config.key
};
break;
}
break;
case "address" :
switch
(config.provider.toLowerCase()) {
case "mapzen" :
serviceData.url = "https://search.mapzen.com/v1/reverse";
serviceData.resultNode = "features";
serviceData.resultField = "properties";
serviceData.displayTemplate = '<tr><td>{label} ('+measureDistanceResultPrefixString[lang].toLowerCase()+' {distance}m)</td></tr>';
serviceData.displayTemplateMinimum = '<tr><td>{region}, {country}</td></tr>';
serviceData.factor = 1000; //factor to multiply returned distance to get meters
serviceData.params = {
layers: "address",
'point.lat': this.locationToWgs().lat,
'point.lon': this.locationToWgs().lon,
api_key: config.key,
size: 1
};
break;
case "mapbox" :
serviceData.url = "https://api.mapbox.com/geocoding/v5/mapbox.places/"+this.locationToWgs().lon+","+this.locationToWgs().lat+".json";
serviceData.resultNode = "features";
serviceData.resultField = "";
serviceData.displayTemplate = '<tr><td>{place_name}</td></tr>';
serviceData.displayTemplateMinimum = '';
serviceData.factor = 1; //factor to multiply returned distance to get meters
serviceData.params = {
access_token: config.key,
types: "address,neighborhood,place"
};
break;
}
break;

}

Ext.Ajax.request({
url: serviceData.url,
params: serviceData.params,
method: 'GET',
scope: this,
success: function (response) {
var result = Ext.util.JSON.decode(response.responseText);

if (result[serviceData.resultNode].length > 0) {
this.fireEvent(config.name, result[serviceData.resultNode][0],this.locationToString(), serviceData.resultField, serviceData.displayTemplate, serviceData.displayTemplateMinimum, serviceData.factor);
}
},
failure: function (response) {
//return {success: false, message: "not available"};
}
});
}

});
Ext.reg('qgis_location', QGIS.LocationService);

/* ***************************************************************************** */
// fix for Ext.Slider in IE9
Ext.override(Ext.dd.DragTracker, {
Expand Down
11 changes: 8 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
if(!property_exists($settings,"geoNames")) {
$settings->geoNames = null;
}
if(!property_exists($settings,"locationServices")) {
$settings->locationServices = null;
}

if(!property_exists($data,"client_url")) {
$data->client_url = "";
}
Expand Down Expand Up @@ -88,6 +92,7 @@
projectData.search = eval(<?php echo json_encode($settings->search)?>);
projectData.layerSpecifics = eval(<?php echo json_encode($settings->layerSpecifics)?>);
projectData.geoNames = eval(<?php echo json_encode($settings->geoNames)?>);
projectData.locationServices = eval(<?php echo json_encode($settings->locationServices)?>);
projectData.gis_projects = eval(<?php echo json_encode($gis_projects)?>);
projectData.project = '<?php echo $project?>';
projectData.crs = '<?php echo $crs?>';
Expand Down Expand Up @@ -143,7 +148,7 @@

</script>

<script type="text/javascript" src="admin/languages/<?php echo $def_lang?>.js"></script>
<script type="text/javascript" src="admin/languages/<?php echo $def_lang?>.js?v=1.1"></script>

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3&sensor=true"></script>

Expand All @@ -164,9 +169,9 @@
<script type="text/javascript" src="client/site/js/GetUrlParams.js"></script>
<script type="text/javascript" src="client/site/js/TriStateTree.js"></script>
<script type="text/javascript" src="client/site/js/GUI.js?v=1"></script>
<script type="text/javascript" src="client/site/js/QGISExtensions.js"></script>
<script type="text/javascript" src="client/site/js/QGISExtensions.js?v=1.1"></script>
<script type="text/javascript" src="client/site/js/GeoNamesSearchCombo.js"></script>
<script type="text/javascript" src="client/site/js/FeatureInfoDisplay.js"></script>
<script type="text/javascript" src="client/site/js/FeatureInfoDisplay.js?v=1.1"></script>
<script type="text/javascript" src="client/site/js/LegendAndMetadataDisplay.js"></script>
<script type="text/javascript" src="client/site/js/LayerActions.js"></script>
<script type="text/javascript" src="client/site/js/WebgisInit.js?v=1"></script>
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
1.1.0 dev - Application
1.1.0 - Application
4 - Database

0 comments on commit dac340e

Please sign in to comment.