From bde959669065eb6a227ca39ceaf36f30c6b2131f Mon Sep 17 00:00:00 2001 From: Frederic Bonifas Date: Wed, 22 Jul 2015 16:47:17 +0200 Subject: [PATCH] =?UTF-8?q?#91:=20possibilit=C3=A9=20d'ajouter=20des=20POI?= =?UTF-8?q?s=20au=20tableau=20d'interactivit=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scripts/controllers/commonmap.js | 88 ++++++---------------------- app/scripts/controllers/main.js | 10 +++- 2 files changed, 26 insertions(+), 72 deletions(-) diff --git a/app/scripts/controllers/commonmap.js b/app/scripts/controllers/commonmap.js index a0899fb6..2e9fb71e 100644 --- a/app/scripts/controllers/commonmap.js +++ b/app/scripts/controllers/commonmap.js @@ -314,24 +314,6 @@ angular.module('accessimapEditeurDerApp') if ($scope.mode === 'interaction') { resetActions(); $('#der').css('cursor', 'crosshair'); - // Add filters to SVG if they don't exist - if (d3.select('filters').empty()) { - var filters = d3.select('#der') - .select('svg') - .append('filters'); - filters.append('filter') - .attr('id', 'f0') - .attr('name', 'Aucune interaction') - .attr('expandable', 'false'); - filters.append('filter') - .attr('id', 'f1') - .attr('name', 'filtre numéro 1') - .attr('expandable', 'true'); - filters.append('filter') - .attr('id', 'f2') - .attr('name', 'filtre numéro 2') - .attr('expandable', 'true'); - } // Make the selected feature blink d3.selectAll('path:not(.notDeletable)') @@ -339,62 +321,27 @@ angular.module('accessimapEditeurDerApp') d3.selectAll('.blink').classed('blink', false); var feature = d3.select(this); feature.classed('blink', true); - var bbox = feature[0][0].getBBox(); - if (feature.select('actions').empty()) { - $scope.$apply(function() { - $scope.interaction = {}; - }); - feature.append('actions') - .append('action') - .attr('filter', $scope.interaction.filter) - .attr('protocol', $scope.interaction.protocol) - .attr('value', function() { - if (feature.attr('name')) { - $scope.$apply(function() { - $scope.interaction.value = feature.attr('name'); - }); - return feature.attr('name'); - } else { - return $scope.interaction.value; - } - }) - .attr('x', bbox.x) - .attr('y', bbox.y) - .attr('width', bbox.width) - .attr('height', bbox.height); - } else { + var featureIid; + featureIid = feature.attr('iid'); + if (!featureIid) { + featureIid = $rootScope.getiid(); + feature.attr('iid', featureIid); + } + + var featurePosition = $scope.interactiveFilters.data.filter(function(row) { + return row.id === 'poi-' + featureIid; + }); + var featureToAdd = $scope.interactiveFilters.data.indexOf(featurePosition[0]) < 0; + + if (featureToAdd) { $scope.$apply(function() { - $scope.interaction.filter = feature.select('actions').select('action').attr('filter'); - $scope.interaction.protocol = feature.select('actions').select('action').attr('protocol'); - $scope.interaction.value = feature.select('actions').select('action').attr('value'); + $scope.interactiveFilters.data.push({'id': 'poi-' + featureIid}); }); } - $scope.$watch('interaction.filter', function() { - d3.selectAll('.blink') - .select('actions') - .select('action') - .attr('filter', $scope.interaction.filter); - }); - $scope.$watch('interaction.protocol', function() { - d3.selectAll('.blink') - .select('actions') - .select('action') - .attr('protocol', $scope.interaction.protocol); - }); - $scope.$watch('interaction.value', function() { - d3.selectAll('.blink') - .select('actions') - .select('action') - .attr('value', $scope.interaction.value); - }); - }); - d3.selectAll('circle') - .on('click', function() { - d3.selectAll('.blink').classed('blink', false); - var feature = d3.select(this); - feature.classed('blink', true); + }); } + if ($scope.mode === 'point') { resetActions(); $('#der').css('cursor', 'crosshair'); @@ -405,7 +352,8 @@ angular.module('accessimapEditeurDerApp') var coordinates = d3.mouse(this); var feature = d3.select('svg') .append('path') - .attr('d', $scope.styleChosen.path(coordinates[0], coordinates[1], $scope.styleChosen.radius)); + .attr('d', $scope.styleChosen.path(coordinates[0], coordinates[1], $scope.styleChosen.radius)) + .attr('iid', $rootScope.getiid()); angular.forEach($scope.styleChosen.style, function(attribute) { var k = attribute.k; var v = attribute.v; diff --git a/app/scripts/controllers/main.js b/app/scripts/controllers/main.js index 10cfa023..59e7f88d 100644 --- a/app/scripts/controllers/main.js +++ b/app/scripts/controllers/main.js @@ -8,8 +8,8 @@ * Controller of the accessimapEditeurDer */ angular.module('accessimapEditeurDerApp') - .controller('MainCtrl', ['$scope', '$location', 'settings', - function($scope, $location, settings) { + .controller('MainCtrl', ['$scope', '$rootScope', '$location', 'settings', + function($scope, $rootScope, $location, settings) { $scope.go = function(path) { $location.path(path).search('mapFormat', $scope.mapFormat).search('legendFormat', $scope.legendFormat); }; @@ -18,4 +18,10 @@ angular.module('accessimapEditeurDerApp') $scope.mapFormat = 'landscapeA4'; $scope.legendFormat = 'landscapeA4'; + $rootScope.iid = 1; + + $rootScope.getiid = function() { + return $rootScope.iid ++; + }; + }]);