Commit dac4f4da authored by Antonella Giachino's avatar Antonella Giachino
Browse files

- Managed opacity

- Managed double click on heatmap (like cluster) for lower values
- Optimized error maangement on creation of map
parent ea9e25c4
......@@ -99,14 +99,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
scope.filterDataset(scope.values[layer.name],scope.reformatSelections(newValue));
// apply filtered data
$scope.createLayerWithData(layer.name, scope.values[layer.name], false);
$scope.createLayerWithData(layer.name, scope.values[layer.name], false, false);
}else{
// restore unfiltered data
angular.copy(scope.savedValues[layer.name], scope.values[layer.name]);
delete scope.savedValues[layer.name];
// apply unfiltered data
$scope.createLayerWithData(layer.name, scope.values[layer.name], false);
$scope.createLayerWithData(layer.name, scope.values[layer.name], false, false);
}
}
}
......@@ -261,7 +261,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
}
// apply (filtered) data
$scope.createLayerWithData(layerName, $scope.values[layerName], false);
$scope.createLayerWithData(layerName, $scope.values[layerName], false, false);
}
$scope.getOptions =function(){
......@@ -329,7 +329,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
if (!$scope.ngModel.content.mapId){
$scope.ngModel.content.mapId = 'map-' + $scope.ngModel.id;
}
//set default indicator (first one) for each layer
for (l in $scope.ngModel.content.layers){
var columns = $scope.getColumnSelectedOfDataset($scope.ngModel.content.layers[l].dsId);
......@@ -345,7 +344,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
}
$scope.createLayerWithData = function(label, data, isCluster){
$scope.createLayerWithData = function(label, data, isCluster, isHeatmap){
//prepare object with metadata for desiderata dataset columns
var geoColumn, selectedMeasure = null;
var columnsForData, isHeatmap;
......@@ -356,7 +355,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
if (!layerDef) return;
columnsForData = $scope.getColumnSelectedOfDataset(layerDef.dsId) || [];
isHeatmap = (layerDef.heatmapConf && layerDef.heatmapConf.enabled) ? true : false;
//remove old layer
var previousLayer = $scope.getLayerByName(label);
......@@ -374,6 +372,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
layerDef.layerID = layerID;
var featuresSource = cockpitModule_mapServices.getFeaturesDetails(geoColumn, selectedMeasure, layerDef, columnsForData, data);
if (featuresSource == null){
//creates a fake layer for internal object (becasue isn't the first loop anymore)
layer = {};
layer.name = layerDef.name;
layer.dsId = layerDef.dsId;
$scope.addLayer(layerDef.name, layer); //add layer to internal object
return;
}
......@@ -392,6 +395,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
blur: layerDef.heatmapConf.blur,
radius: layerDef.heatmapConf.radius,
weight: cockpitModule_mapThematizerServices.setHeatmapWeight
// gradient:['#00f', '#0ff', '#0f0', '#ff0', '#ff8d10', '#ff10f5', '#f00', '#00f', '#0ff', '#0f0', '#ff0', '#ff8d10', '#ff10f5', '#f00']
});
} else {
layer = new ol.layer.Vector({source: featuresSource,
......@@ -405,6 +409,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
layer.setZIndex(layerDef.order*1000);
layer.modalSelectionColumn = layerDef.modalSelectionColumn;
layer.hasShownDetails = layerDef.hasShownDetails;
if ($scope.map)
$scope.map.addLayer(layer); //add layer to ol.Map
else{
......@@ -451,9 +456,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
for (l in $scope.ngModel.content.layers){
var layerDef = $scope.ngModel.content.layers[l];
var isCluster = (layerDef.clusterConf && layerDef.clusterConf.enabled) ? true : false;
if (isCluster){
var isHeatmap = (layerDef.heatmapConf && layerDef.heatmapConf.enabled) ? true : false;
if (isCluster){
var values = $scope.values[layerDef.name];
$scope.createLayerWithData(layerDef.name, values, true); //return to cluster view
$scope.createLayerWithData(layerDef.name, values, true, false); //return to cluster view
}
if (isHeatmap){
var values = $scope.values[layerDef.name];
$scope.createLayerWithData(layerDef.name, values, false, true); //return to cluster view
}
}
}
......@@ -516,9 +526,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
for (l in $scope.ngModel.content.layers){
var layerDef = $scope.ngModel.content.layers[l];
var isCluster = (layerDef.clusterConf && layerDef.clusterConf.enabled) ? true : false;
if (isCluster){
var isHeatmap = (layerDef.heatmapConf && layerDef.heatmapConf.enabled) ? true : false;
if (isCluster || isHeatmap){
var values = $scope.values[layerDef.name];
$scope.createLayerWithData(layerDef.name, values, false);
$scope.createLayerWithData(layerDef.name, values, false, false);
}
}
});
......@@ -553,6 +564,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
var selectedMeasure = null;
var columnsForData = [];
var isCluster = (layerDef.clusterConf && layerDef.clusterConf.enabled) ? true : false;
var isHeatmap = (layerDef.heatmapConf && layerDef.heatmapConf.enabled) ? true : false;
var columnsForData = $scope.getColumnSelectedOfDataset(layerDef.dsId) || [];
......@@ -574,7 +586,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//get the dataset columns values
cockpitModule_datasetServices.loadDatasetRecordsById(layerDef.dsId, undefined, undefined, undefined, undefined, model).then(
function(allDatasetRecords){
$scope.createLayerWithData(layerDef.name, allDatasetRecords, isCluster);
$scope.createLayerWithData(layerDef.name, allDatasetRecords, isCluster, isHeatmap);
$scope.hideWidgetSpinner();
},function(error){
console.log("Error loading dataset with id [ "+layerDef.dsId+"] ");
......@@ -610,7 +622,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
var tmpLayer = $scope.layers[0].layer;
cockpitModule_mapServices.updateCoordinatesAndZoom($scope.ngModel, $scope.map, tmpLayer, false);
}
$scope.map = new ol.Map({
target: 'map-' + $scope.ngModel.id,
layers: [ $scope.baseLayer ],
......@@ -673,7 +684,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
$scope.getLayerVisibility = function(n){
var l = $scope.getLayerByName(n);
if (!l) return; //do nothing
if (!l || !l.getVisible) return; //do nothing
return l.getVisible();
}
......@@ -793,7 +804,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
}
$scope.selectPropValue = function(dsId, prop, modalSelectionColumn){
if (!modalSelectionColumn){
if (!modalSelectionColumn && prop.fieldType !== "MEASURE"){
$scope.doSelection(prop.alias, $scope.props[prop.name].value, null, null, null, null, dsId);
}
}
......
......@@ -89,11 +89,11 @@ function mapWidgetEditControllerFunction(
}
}
}
$scope.addField = function(columns){
columns.unshift({});
}
$scope.checkDs = function(column){
for(var i in $scope.confrontationDs.metadata.fieldsMeta){
var confrontField = $scope.confrontationDs.metadata.fieldsMeta[i];
......@@ -109,7 +109,7 @@ function mapWidgetEditControllerFunction(
}
return false;
}
$scope.updateDsList = function(column, dsId){
for(var j in $scope.newModel.content.columnSelectedOfDataset[dsId]){
if($scope.newModel.content.columnSelectedOfDataset[dsId][j].name == column.name){
......@@ -132,7 +132,7 @@ function mapWidgetEditControllerFunction(
}
}
}
$scope.hasShownDetails = function(layer){
layer.hasShownDetails = false;
var columnsList = $scope.newModel.content.columnSelectedOfDataset[layer.dsId];
......@@ -142,9 +142,9 @@ function mapWidgetEditControllerFunction(
return;
}
}
}
$scope.setModalColumn = function(column, layer){
var columnsList = $scope.newModel.content.columnSelectedOfDataset[layer.dsId];
layer.modalSelectionColumn = column.alias;
......@@ -153,9 +153,9 @@ function mapWidgetEditControllerFunction(
columnsList[i].properties.modal = false;
}
}
}
$scope.deleteColumn = function(layer,column){
layer.splice(layer.indexOf(column),1);
}
......@@ -246,7 +246,7 @@ function mapWidgetEditControllerFunction(
}
$mdDialog.hide();
}
$scope.selectLayer = function(layer, e){
e.preventDefault();
e.stopImmediatePropagation();
......@@ -266,7 +266,8 @@ function mapWidgetEditControllerFunction(
locals: { }
})
}
$scope.colorPickerOptions = {format:'hex'};
// $scope.colorPickerOptions = {format:'hex'};
$scope.colorPickerOptions = {format:'rgb'};
$scope.setIconType = function(layer,type) {
if (!layer.markerConf) layer.markerConf={};
layer.markerConf.type = type;
......@@ -457,7 +458,7 @@ function mapWidgetEditControllerFunction(
if($scope.newModel.content.layers.length == 1){ // force target if only one layer is defined
$scope.newModel.content.layers[0].targetDefault = true;
}
$scope.addToDatasets();
mdPanelRef.close();
angular.copy($scope.newModel,model);
......
......@@ -104,7 +104,7 @@
<md-checkbox ng-model="column.properties.showMap" aria-label="Checkbox 2" ng-if="column.fieldType=='MEASURE'"/>
</td>
<td style="display: flex;justify-content: center;">
<md-switch ng-model="column.properties.modal" class="noMargin" ng-change="setModalColumn(column,layer)" aria-label="modal"></md-switch>
<md-switch ng-if="column.fieldType == 'ATTRIBUTE'" ng-model="column.properties.modal" class="noMargin" ng-change="setModalColumn(column,layer)" aria-label="modal"></md-switch>
</td>
<td class="multiTableAction">
<md-icon style="cursor: pointer" md-font-icon="fa fa-sliders" ng-if="column.fieldType === 'MEASURE'" ng-click="getThresholds($event,column)"></md-icon>
......
......@@ -17,8 +17,7 @@
<li ng-repeat="prop in layerConfig track by $index" ng-if="prop.properties.showDetails">
<p>
<strong>{{prop.aliasToShow}}:</strong>
<span class="clickable" ng-cloak ng-click="selectPropValue(layerConfig.dsId, prop, layerConfig.modalSelectionColumn)">{{props[prop.name].value}}</span>
<!-- <span class="clickable" ng-cloak ng-click="selectPropValue(prop.alias, props[prop.name].value)">{{props[prop.name].value}}</span> -->
<span ng-class="{'clickable' : prop.fieldType=='ATTRIBUTE'}" ng-cloak ng-click="selectPropValue(layerConfig.dsId, prop, layerConfig.modalSelectionColumn)">{{props[prop.name].value}}</span>
</p>
<p ng-if="props[prop.name].showWarning" class="warningMessage"><i class='fa fa-warning'></i> The value is within the Alarm range!</p>
</li>
......
......@@ -7,20 +7,20 @@
sbiModule_messaging,
cockpitModule_template,
cockpitModule_mapThematizerServices,
$q,
$mdPanel,
$q,
$mdPanel,
$rootScope,
$location){
var ms = this; //mapServices
ms.getFeaturesDetails = function(geoColumn, selectedMeasure, config, configColumns, values){
if (values != undefined){
var geoFieldName;
var geoFieldValue;
var geoFieldValue;
var geoFieldConfig;
var featuresSource = new ol.source.Vector();
for(var c=0; c < configColumns.length; c++){
var conf = configColumns[c];
if (conf.name === geoColumn){
......@@ -28,7 +28,7 @@
break;
}
}
for(var k=0; k < values.metaData.fields.length; k++){
var field = values.metaData.fields[k];
if (field.header === geoColumn){
......@@ -36,7 +36,7 @@
break;
}
}
if (geoFieldName){
var lon;
var lat;
......@@ -48,55 +48,73 @@
var row = values.rows[r];
geoFieldValue = row[geoFieldName].trim();
if (!geoFieldConfig.properties.coordType){
//retrocompatibility management
//retrocompatibility management (just string type)
geoFieldConfig.properties.coordType = 'string';
geoFieldConfig.properties.coordFormat = 'lon lat';
}
if (geoFieldConfig.properties.coordType == 'json'){
var jsonConf = JSON.parse(geoFieldValue);
if (jsonConf.type.toUpperCase() == 'POINT'){
jsonConf.coordinates = [jsonConf.coordinates];
isSimpleMarker = true;
if (IsJsonString(geoFieldValue)){
var jsonConf = JSON.parse(geoFieldValue);
if (jsonConf.type.toUpperCase() == 'POINT'){
jsonConf.coordinates = [jsonConf.coordinates];
isSimpleMarker = true;
}
else
isSimpleMarker = false;
jsonConf.properties = geoFieldConfig.properties;
geometry = ms.getGeometry(null, jsonConf, geoFieldConfig);
}else{
console.log("Location got from dataset hasn't a valid json format. Please check it: ["+geoFieldValue+"]");
sbiModule_messaging.showInfoMessage(sbiModule_translate.load('sbi.cockpit.map.jsonInvalid').replace("{0}",geoColumn).replace("{1}",geoFieldValue.substring(0,20)+'...'), 'Title', 0);
return null;
}
else
isSimpleMarker = false;
jsonConf.properties = geoFieldConfig.properties;
geometry = ms.getGeometry(null, jsonConf, geoFieldConfig);
}else{
if (geoFieldConfig.properties.coordType == 'string' && IsJsonString(geoFieldValue)){
console.log("Location is set as STRING but its value has a JSON format. Please check the configuration: ["+geoFieldValue+"]");
sbiModule_messaging.showInfoMessage(sbiModule_translate.load('sbi.cockpit.map.stringInvalid').replace("{0}",geoColumn).replace("{1}",geoFieldValue.substring(0,20)+'...'), 'Title', 0);
return null;
}
isSimpleMarker = true;
geometry = ms.getGeometry(geoColumn, geoFieldConfig, geoFieldValue);
}
//set ol objects
feature = new ol.Feature(geometry)
if (!selectedMeasure) selectedMeasure = config.defaultIndicator;
if (!selectedMeasure) selectedMeasure = config.defaultIndicator;
//get config for thematize
if (selectedMeasure){
if (!cockpitModule_mapThematizerServices.getCacheSymbolMinMax().hasOwnProperty(config.name+"|"+selectedMeasure)){
cockpitModule_mapThematizerServices.loadIndicatorMaxMinVal(config.name+"|"+ selectedMeasure, values);
}
}
}
ms.addDsPropertiesToFeature(feature, row, configColumns, values.metaData.fields);
//at least add the layer owner
feature.set("parentLayer", config.layerID);
feature.set("isSimpleMarker", isSimpleMarker);
feature.set("sourceType", (config.markerConf && config.markerConf.type ) ? config.markerConf.type : "simple");
featuresSource.addFeature(feature);
}
return featuresSource;
}
}
return new ol.source.Vector();
}
function IsJsonString(str) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}
ms.getSimpleCoordinates = function(geocol, config, value){
var coord;
if (Array.isArray(value))
if (Array.isArray(value))
coord = value;
else{
if (value.indexOf(" ") > 0){
......@@ -111,13 +129,13 @@
if (coord.length != 2){
sbiModule_messaging.showInfoMessage(sbiModule_translate.load('sbi.cockpit.map.lonLatError').replace("{0}",geocol).replace("{1}",value.substring(0,20)+'...'), 'Title', 0);
console.log("Error getting longitude and latitude from column value ["+ geocol +"]. Check the dataset and its metadata.");
return null;
return null;
}
}
//setting lon, lat values with correct order (LON, LAT)
switch(config.properties.coordFormat) {
case "lon lat":
case "lon lat":
lon = (typeof coord[0] === 'string') ? parseFloat(coord[0].trim()) : coord[0];
lat = (typeof coord[1] === 'string') ? parseFloat(coord[1].trim()) : coord[1];
break;
......@@ -125,19 +143,19 @@
lon = (typeof coord[1] === 'string') ? parseFloat(coord[1].trim()) : coord[1];
lat = (typeof coord[0] === 'string') ? parseFloat(coord[0].trim()) : coord[0];
break;
default:
default:
lon = (typeof coord[0] === 'string') ? parseFloat(coord[0].trim()) : coord[0];
lat = (typeof coord[1] === 'string') ? parseFloat(coord[1].trim()) : coord[1];
}
return [lon, lat];
return [lon, lat];
}
ms.getGeometry = function(geocol, config, value){
ms.getGeometry = function(geocol, config, value){
var geometry;
var coordinates = [];
var transform = ol.proj.getTransform('EPSG:4326', 'EPSG:3857');
if (config.properties.coordType.toUpperCase() == "STRING"){
coordinates = transform(ms.getSimpleCoordinates(geocol, config, value));
}else{
......@@ -146,15 +164,15 @@
var coordinate;
if (Array.isArray(coords[i])){
if (Array.isArray(coords[i][0])){
for (var j in coords[i]){
for (var j in coords[i]){
coordinate = transform(ms.getSimpleCoordinates(geocol, config, coords[i][j]));
coordinates.push(coordinate);
}
}else{
coordinate = transform(ms.getSimpleCoordinates(geocol, config, coords[i]));
coordinate = transform(ms.getSimpleCoordinates(geocol, config, coords[i]));
coordinates.push(coordinate);
}
} else{
var coordinate = transform(ms.getSimpleCoordinates(geocol, config, coords));
coordinates = coordinate; //point has already an array
......@@ -163,13 +181,13 @@
}
});
}
switch(config.type.toUpperCase()) {
case "POINT":
geometry = new ol.geom.Point(coordinates);
case "POINT":
geometry = new ol.geom.Point(coordinates);
break;
case "MULTIPOINT":
geometry = new ol.geom.MultiPoint([coordinates]);
geometry = new ol.geom.MultiPoint([coordinates]);
break;
case "MULTIPOLYGON":
geometry = new ol.geom.MultiPolygon([[coordinates]]);
......@@ -183,19 +201,19 @@
case "MULTILINESTRING":
geometry = new ol.geom.MultiLineString([coordinates]);
break;
// case "CIRCLE":
// geometry = new ol.geom.Circle([coordinates],?);
// case "CIRCLE":
// geometry = new ol.geom.Circle([coordinates],?);
// break;
// case "LINEARRING":
// geometry = new ol.geom.LinearRing([coordinates]);
// break;
default:
geometry = new ol.geom.Point(coordinates);
default:
geometry = new ol.geom.Point(coordinates);
break;
}
return geometry;
}
ms.getColumnConfigByProp = function(configColumns, propName, propValue){
for(var c=0; c < configColumns.length; c++){
var conf = configColumns[c];
......@@ -203,10 +221,10 @@
return conf;
}
}
return null;
}
ms.addDsPropertiesToFeature = function (f, row, cols, meta){
//add columns value like properties
for (c in row){
......@@ -224,10 +242,10 @@
f.set(header, prop);
}
}
ms.getHeaderByColumnName = function(cn, fields) {
var toReturn = cn;
for (n in fields){
if (fields[n] && fields[n].name === cn){
return fields[n].header;
......@@ -235,7 +253,7 @@
}
return toReturn;
}
ms.updateCoordinatesAndZoom = function(model, map, l, setValues){
var coord;
var zoom;
......@@ -246,13 +264,13 @@
source = l.getSource().getSource(); //cluster case
else
source = l.getSource();
if (source.getFeatures().length>0){
if (source.getFeatures()[0].getGeometry().getType().toUpperCase() == 'POINT')
coord = source.getFeatures()[0].getGeometry().getCoordinates();
else if (source.getFeatures()[0].getGeometry().getType().toUpperCase() == 'MULTIPOLYGON')
coord = source.getFeatures()[0].getGeometry().getCoordinates()[0][0][0];
else
else
coord = source.getFeatures()[0].getGeometry().getCoordinates()[0][0];
}
if(source.getFeatures().length>35){
......@@ -260,28 +278,28 @@
}else{
zoom = 5;
}
//update coordinates and zoom within the template
model.content.currentView.center = coord;
model.content.currentView.zoom = zoom;
if (setValues){
map.getView().setCenter(coord);
map.getView().setZoom(zoom);
}
}
}
}