Permalink
Browse files

Add combo box to use different projection for displaying coordinates,…

… export data and in Location Info window.
  • Loading branch information...
uprel committed Jan 29, 2019
1 parent 382bbdc commit f3a19267b42ed8ffcab6fc9f3e329b01fc2e6896
@@ -42,7 +42,8 @@ function showFeatureInfo(evt) {
var text = "";
var locationText = "<h2>" + TR.fiLocation + "</h2>";
var locationUnits = map.getLonLatFromPixel(evt.xy);
var locationObj = new QGIS.LocationService({location: locationUnits, language: projectData.lang});
var locationProj = projectData.crs == Eqwc.currentMapProjection[0] ? null : Eqwc.currentMapProjection[2];
var locationObj = new QGIS.LocationService({location: locationUnits, language: projectData.lang, projection: locationProj});
var popupItems = [];

if (Eqwc.settings.showCoordinatesIdentify) {
@@ -268,6 +268,7 @@ MyViewportUi = Ext.extend(Ext.Viewport, {
width: 120,
store: 'objIdentificationModes',
valueField: 'value',
editable: false,
mode: 'local',
displayField: 'name',
triggerAction: 'all',
@@ -350,9 +351,28 @@ MyViewportUi = Ext.extend(Ext.Viewport, {
}, {
xtype: 'tbfill'
}, {
xtype: 'tbtext',
text: '',
id: 'rightStatusText'
xtype: 'combo',
id: 'rightStatusText',
hideLabel: true,
editable: false,
mode: 'local',
triggerAction: 'all',
width: 90,
store: projectData.crsComboStore(),
value: projectData.crsComboStore()[0],
listeners: {
"select": function(combo, record, index) {
Eqwc.currentMapProjection = projectData.getProjectionsList().filter(function (val) {
return val[0] === record.data.field1;
})[0];
}
//"render": function(c) {
// new Ext.ToolTip({
// target: c.getEl(),
// html: 'Tooltip content'
// });
//}
}
}, {
xtype: 'tbtext',
text: coordinateTextLabel[lang]
@@ -361,8 +381,9 @@ MyViewportUi = Ext.extend(Ext.Viewport, {
}, {
xtype: 'textfield',
width: 120,
regex: /^\d{6}\.?\d{0,2},\d{6}\.?\d{0,2}$/,
enableKeyEvents: true,
//regex: /^\d{6}\.?\d{0,2},\d{6}\.?\d{0,2}$/,
maskRe: /[0-9]/,
enableKeyEvents: true,
id: 'CoordinateTextField'
}, {
xtype: 'tbtext',
@@ -102,7 +102,7 @@ function buildLayerContextMenu(node) {
hideOnClick: false
},{
itemId: 'useMapCRS',
text: TR.exportUseMapCrs+" ("+projectData.crs+")",
text: TR.exportUseMapCrs,
checked: true,
hideOnClick: false
}]
@@ -212,7 +212,7 @@ function exportHandler(item) {
var myFormat = item.container.menuItemId;

var exportExtent = item.ownerCt.getComponent('currentExtent');
var crs = item.ownerCt.getComponent('useMapCRS').checked ? projectData.crs : projectData.layers[layerId].crs;
var crs = item.ownerCt.getComponent('useMapCRS').checked ? Eqwc.currentMapProjection[0] : projectData.layers[layerId].crs;

exportData(exportLayer, myFormat, exportExtent.checked, crs);
}
@@ -210,19 +210,30 @@ projectData.getProjectionsList = function() {

//first element is map projection
if(Proj4js.defs[projectData.crs]) {
ret.push([projectData.crs,projectData.crs_description,geoExtMap.map.getProjectionObject()]);
ret.push([projectData.crs, projectData.crs_description, new OpenLayers.Projection(projectData.crs)]);
}

for (var i = 0; i < projectData.crs_list.length; ++i) {
var crs = projectData.crs_list[i];
var olProj = new OpenLayers.Projection(crs);
if (crs != projectData.crs && Proj4js.defs[crs]) {
ret.push([crs,olProj.title,olProj]);
ret.push([crs,olProj.proj.title,olProj]);
}
}
return ret;
};

projectData.crsComboStore = function() {
var ret = [];

projectData.getProjectionsList().map(function(currentValue, index, arr) {
var code = currentValue[0];
ret.push(code);
}, ret);

return ret;
};

//plugins
Eqwc.plugins = {};

@@ -1688,6 +1688,7 @@ QGIS.LocationService = Ext.extend(Ext.util.Observable, {
constructor: function(config){
this.location = config.location; //units
this.language = config.language;
this.projection = config.projection;

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

@@ -1698,8 +1699,11 @@ QGIS.LocationService = Ext.extend(Ext.util.Observable, {
},

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

var loc = this.location;
if(this.projection) {
loc = loc.clone().transform(authid, this.projection);
}
return loc.lon.toFixed(coordinatePrecision)+ ", " + this.location.lat.toFixed(coordinatePrecision);
},

locationToWgs: function () {
@@ -643,7 +643,8 @@ function postLoading() {
});

//set EPSG text from OpenLayers
rightStatusText.setText(authid);
//rightStatusText.setText(authid);
Eqwc.currentMapProjection = [projectData.crs, projectData.crs_description, geoExtMap.map.getProjectionObject()];

if (urlParams.startExtent) {
var startExtentParams = urlParams.startExtent.split(",");
@@ -754,23 +755,37 @@ function postLoading() {
//coordinate display
coordinateTextField = Ext.getCmp('CoordinateTextField');
geoExtMap.map.events.register('mousemove', this, function (evt) {
var projectCrs = projectData.crs;
var mapCrs = rightStatusText.getValue();
var mapCrsUnits = Eqwc.currentMapProjection[2].proj.units;
var xy = geoExtMap.map.events.getMousePosition(evt);
var geoxy = geoExtMap.map.getLonLatFromPixel(xy);
var nDeci = 0;
if(mapCrsUnits=='degrees') {
nDeci = 4;
}
var currentScale = geoExtMap.map.getScale();
if (currentScale <= 400) {
nDeci = 1;
nDeci += 1;
if (currentScale <= 100) {
nDeci = 2;
nDeci += 2;
}
}
if(projectCrs != mapCrs) {
geoxy.transform(geoExtMap.map.getProjectionObject(),Eqwc.currentMapProjection[2]);
}
coordinateTextField.setRawValue(geoxy.lon.toFixed(nDeci) + "," + geoxy.lat.toFixed(nDeci));
});

coordinateTextField.on('specialkey', function (textField, evt) {
if (evt.getKey() == evt.ENTER) {
var projectCrs = projectData.crs;
var mapCrs = rightStatusText.getValue();
var coords = textField.getValue().split(",");
var newCenter = new OpenLayers.LonLat(parseFloat(coords[0]), parseFloat(coords[1]));
if(projectCrs != mapCrs) {
newCenter.transform(Eqwc.currentMapProjection[2],geoExtMap.map.getProjectionObject());
}
geoExtMap.map.setCenter(newCenter);
}
//supress arrow keys propagation to underlying OpenLayers
@@ -779,8 +794,13 @@ function postLoading() {
}
});
coordinateTextField.on('change', function (numberField, newValue, oldValue) {
var projectCrs = projectData.crs;
var mapCrs = rightStatusText.getValue();
var coords = newValue.split(",");
var newCenter = new OpenLayers.LonLat(parseFloat(coords[0]), parseFloat(coords[1]));
if(projectCrs != mapCrs) {
newCenter.transform(Eqwc.currentMapProjection[2],geoExtMap.map.getProjectionObject());
}
geoExtMap.map.setCenter(newCenter);
});

0 comments on commit f3a1926

Please sign in to comment.