dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #29974
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15201: GIS, color coded boundaries, work in progress.
Merge authors:
Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 15201 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-05-09 10:28:23 +0200
message:
GIS, color coded boundaries, work in progress.
modified:
dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/app.js
dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/core.js
dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/core/GeoStat/all.js
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/app.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/app.js 2014-05-05 18:42:32 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/app.js 2014-05-08 13:39:44 +0000
@@ -1435,13 +1435,14 @@
text: GIS.i18n.labels,
iconCls: 'gis-menu-item-icon-labels',
handler: function() {
- if (layer.labelWindow) {
- layer.labelWindow.show();
- }
- else {
- layer.labelWindow = GIS.app.LabelWindow(layer);
- layer.labelWindow.show();
- }
+ var window = layer.labelWindow || (layer.labelWidow = GIS.app.LabelWindow(layer));
+
+ if (layer.id === 'boundary') {
+ window.updateLabels();
+ }
+ else {
+ window.show();
+ }
}
};
items.push(item);
@@ -2033,23 +2034,48 @@
}
});
- getLabelConfig = function() {
- return {
+ getLabelConfig = function(isLabel) {
+ var style = {
fontSize: fontSize.getValue(),
strong: strong.getValue(),
italic: italic.getValue(),
color: color.getValue()
- };
+ };
+
+ if (isLabel) {
+ style.label = '\${label}';
+ style.fontFamily = 'arial,sans-serif,ubuntu,consolas';
+ }
+
+ return style;
};
updateLabels = function() {
- if (layer.hasLabels) {
- layer.styleMap = GIS.core.StyleMap(layer.id, getLabelConfig());
-
- var loader = layer.core.getLoader();
- loader.hideMask = true;
- loader.loadLegend();
- }
+ var loader = layer.core.getLoader();
+ loader.hideMask = true;
+
+ if (layer.hasLabels) {
+ layer.hasLabels = false;
+
+ if (layer.id === 'boundary') {
+ layer.core.setFeatureLabelStyle(false);
+ }
+ else {
+ layer.styleMap = GIS.core.StyleMap(layer.id);
+ loader.loadLegend();
+ }
+ }
+ else {
+ layer.hasLabels = true;
+
+ if (layer.id === 'boundary') {
+ layer.core.setFeatureLabelStyle(true);
+ }
+ else {
+ layer.styleMap = GIS.core.StyleMap(layer.id, getLabelConfig(true));
+ loader.loadLegend();
+ }
+ }
};
window = Ext.create('Ext.window.Window', {
@@ -2059,6 +2085,7 @@
width: gis.conf.layout.tool.window_width,
resizable: false,
closeAction: 'hide',
+ updateLabels: updateLabels,
items: {
layout: 'fit',
cls: 'gis-container-inner',
@@ -2119,18 +2146,7 @@
xtype: 'button',
text: GIS.i18n.showhide,
handler: function() {
- if (layer.hasLabels) {
- layer.hasLabels = false;
- layer.styleMap = GIS.core.StyleMap(layer.id);
- }
- else {
- layer.hasLabels = true;
- layer.styleMap = GIS.core.StyleMap(layer.id, getLabelConfig());
- }
-
- var loader = layer.core.getLoader();
- loader.hideMask = true;
- loader.loadLegend();
+ updateLabels();
}
}
],
@@ -8114,7 +8130,8 @@
viewport.favoriteWindow.show();
}
});
- //if (gis.init.user.isAdmin) {
+
+ if (gis.init.user.isAdmin) {
a.push({
text: GIS.i18n.legend,
menu: {},
@@ -8127,7 +8144,7 @@
viewport.legendSetWindow.show();
}
});
- //}
+ }
a.push({
xtype: 'tbseparator',
height: 18,
=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/core.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/core.js 2014-05-05 18:42:32 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/core.js 2014-05-08 13:36:05 +0000
@@ -13,7 +13,6 @@
isSessionStorage: 'sessionStorage' in window && window['sessionStorage'] !== null,
logg: []
};
-inst = GIS.core.instances;
GIS.core.getOLMap = function(gis) {
var olmap,
@@ -186,9 +185,26 @@
selectHandlers,
dimConf = gis.conf.finals.dimension,
defaultHoverWindow,
- eventWindow;
+ eventWindow,
+ isBoundary = layer.id === 'boundary',
+ isEvent = layer.id === 'event';
defaultHoverSelect = function fn(feature) {
+ if (isBoundary) {
+ var style = layer.core.getDefaultFeatureStyle();
+
+ style.fillOpacity = 0.15;
+ style.strokeColor = feature.style.strokeColor;
+ style.strokeWidth = feature.style.strokeWidth;
+ style.label = feature.style.label;
+ style.fontFamily = feature.style.fontFamily;
+ style.fontWeight = feature.style.strokeWidth > 1 ? 'bold' : 'normal';
+ style.labelAlign = feature.style.labelAlign;
+ style.labelYOffset = feature.style.labelYOffset;
+
+ layer.drawFeature(feature, style);
+ }
+
if (defaultHoverWindow) {
defaultHoverWindow.destroy();
}
@@ -626,7 +642,7 @@
onClickSelect: defaultClickSelect
};
- if (layer.id === 'event') {
+ if (isEvent) {
options.onClickSelect = function fn(feature) {
var ignoreKeys = ['label', 'value', 'nameColumnMap', 'psi', 'ps', 'longitude', 'latitude', 'eventdate', 'ou', 'oucode', 'ouname'],
attributes = feature.attributes,
@@ -682,13 +698,6 @@
selectHandlers = new OpenLayers.Control.newSelectFeature(layer, options);
- // workaround
- //selectHandlers.selectStyle = {
- //fillOpacity: 0.5,
- //strokeWidth: 1,
- //strokeColor: '#444'
- //};
-
gis.olmap.addControl(selectHandlers);
selectHandlers.activate();
};
@@ -734,29 +743,24 @@
var defaults = {
fillOpacity: 1,
strokeColor: '#fff',
- strokeWidth: 1
+ strokeWidth: 1,
+ pointRadius: 5,
+ labelAlign: 'cr',
+ labelYOffset: 13
},
select = {
fillOpacity: 0.9,
strokeColor: '#fff',
strokeWidth: 1,
- cursor: 'pointer'
+ pointRadius: 5,
+ cursor: 'pointer',
+ labelAlign: 'cr',
+ labelYOffset: 13
};
- if (id === 'boundary') {
- defaults.fillOpacity = 0;
- defaults.strokeColor = '#000';
- defaults.strokeWidth = 1;
-
- select.fillColor = '#000';
- select.fillOpacity = 0.15;
- select.strokeColor = '#000';
- select.strokeWidth = 1;
- }
-
if (labelConfig) {
- defaults.label = '\${label}';
- defaults.fontFamily = 'arial,sans-serif,ubuntu,consolas';
+ defaults.label = labelConfig.label;
+ defaults.fontFamily = labelConfig.fontFamily;
defaults.fontSize = (labelConfig.fontSize || 13) + 'px';
defaults.fontWeight = labelConfig.strong ? 'bold' : 'normal';
defaults.fontStyle = labelConfig.italic ? 'italic' : 'normal';
@@ -1518,7 +1522,7 @@
scope: this,
disableCaching: false,
success: function(r) {
- var geojson = gis.util.geojson.decode(r),
+ var geojson = gis.util.geojson.decode(r, 'DESC'),
format = new OpenLayers.Format.GeoJSON(),
features = gis.util.map.getTransformedFeatureArray(format.read(geojson)),
colors = ['black', 'blue', 'red', 'green', 'yellow'],
@@ -1537,43 +1541,34 @@
return;
}
- //// get levels, colors, map
- //for (var i = 0; i < features.length; i++) {
- //levels.push(parseFloat(features[i].attributes.level));
- //}
-
- //levels = Ext.Array.unique(levels).sort();
-
- //for (var i = 0; i < levels.length; i++) {
- //levelObjectMap[levels[i]] = {
- //strokeColor: colors[i],
- //strokeWidth: levels.length - i
- //};
-//console.log(levels.length - i);
- //}
-
- //// style
- //for (var i = 0, feature, obj; i < features.length; i++) {
- //feature = features[i];
- //obj = levelObjectMap[feature.attributes.level];
-
- //feature.style = {
- //strokeColor: obj.strokeColor || 'black',
- //strokeWidth: obj.strokeWidth || 1,
- //fillOpacity: 0
- //};
- //}
-
-
-
-
-
-
-
-
-
-
-
+ // get levels, colors, map
+ for (var i = 0; i < features.length; i++) {
+ levels.push(parseFloat(features[i].attributes.level));
+ }
+
+ levels = Ext.Array.unique(levels).sort();
+
+ for (var i = 0; i < levels.length; i++) {
+ levelObjectMap[levels[i]] = {
+ strokeColor: colors[i]
+ };
+ }
+
+ // style
+ for (var i = 0, feature, obj, strokeWidth; i < features.length; i++) {
+ feature = features[i];
+ obj = levelObjectMap[feature.attributes.level];
+ strokeWidth = levels.length === 1 ? 1 : feature.attributes.level == 2 ? 2 : 1;
+
+ feature.style = {
+ strokeColor: obj.strokeColor || 'black',
+ strokeWidth: strokeWidth,
+ fillOpacity: 0,
+ pointRadius: 5,
+ labelAlign: 'cr',
+ labelYOffset: 13
+ };
+ }
layer.core.featureStore.loadFeatures(features.slice(0));
@@ -1598,6 +1593,11 @@
layer.removeFeatures(layer.features);
layer.addFeatures(features);
+ // labels
+ if (layer.hasLabels) {
+ layer.core.setFeatureLabelStyle(true, true);
+ }
+
loadLegend(view);
};
@@ -2400,7 +2400,7 @@
util.geojson = {};
- util.geojson.decode = function(doc) {
+ util.geojson.decode = function(doc, levelOrder) {
var geojson = {};
geojson.type = 'FeatureCollection';
geojson.crs = {
@@ -2411,6 +2411,11 @@
};
geojson.features = [];
+ levelOrder = levelOrder || 'ASC';
+
+ // sort
+ doc.geojson = util.array.sort(doc.geojson, levelOrder, 'le');
+
for (var i = 0; i < doc.geojson.length; i++) {
geojson.features.push({
geometry: {
=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/core/GeoStat/all.js'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/core/GeoStat/all.js 2013-12-22 11:58:26 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/webapp/dhis-web-mapping/app/scripts/mapfish/core/GeoStat/all.js 2014-05-08 13:36:05 +0000
@@ -405,6 +405,47 @@
return;
},
+ getDefaultFeatureStyle: function() {
+ return {
+ fillOpacity: 0,
+ fillColor: '#000',
+ strokeColor: '#000',
+ strokeWidth: 1,
+ pointRadius: 5,
+ cursor: 'pointer'
+ };
+ },
+
+ setFeatureStyle: function(style) {
+ for (var i = 0; i < this.layer.features.length; i++) {
+ this.layer.features[i].style = style;
+ }
+
+ this.layer.redraw();
+ },
+
+ setFeatureLabelStyle: function(isLabel, skipDraw) {
+ for (var i = 0, feature, style, label; i < this.layer.features.length; i++) {
+ feature = this.layer.features[i];
+ style = feature.style;
+
+ if (isLabel) {
+ style.label = feature.attributes.label;
+ style.fontColor = style.strokeColor;
+ style.fontWeight = style.strokeWidth > 1 ? 'bold' : 'normal';
+ style.labelAlign = 'cr';
+ style.labelYOffset = 13;
+ }
+ else {
+ style.label = null;
+ }
+ }
+
+ if (!skipDraw) {
+ this.layer.redraw();
+ }
+ },
+
updateOptions: function(newOptions) {
var oldOptions = OpenLayers.Util.extend({}, this.options);
this.addOptions(newOptions);