-
-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ht 38 select task #51
Changes from 16 commits
531473b
e23208c
30f81c6
240cf2b
7ca3186
80f0f6e
18b3d53
883f971
c64d5de
b7e6f5f
50d3e9f
292e0e5
0b34ada
c1a3f55
5aed934
44be3c2
071aff5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,37 +7,92 @@ | |
*/ | ||
angular | ||
.module('taskingManager') | ||
.controller('projectController', ['$location', 'mapService', 'projectService', 'styleService', projectController]); | ||
.controller('projectController', ['$scope', '$location', 'mapService', 'projectService', 'styleService', 'taskService', projectController]); | ||
|
||
function projectController($location, mapService, projectService, styleService) { | ||
function projectController($scope, $location, mapService, projectService, styleService, taskService) { | ||
var vm = this; | ||
vm.project = null; | ||
vm.projectData = null; | ||
vm.taskVectorLayer = null; | ||
vm.map = null; | ||
|
||
// tab and view control | ||
vm.currentTab = ''; | ||
vm.mappingStep = ''; | ||
|
||
//selected task | ||
vm.selectedTask = null; | ||
vm.isSelectTaskMappable = false; | ||
|
||
//interaction | ||
var select = new ol.interaction.Select({ | ||
style: styleService.getSelectedStyleFunction | ||
}); | ||
|
||
activate(); | ||
|
||
function activate() { | ||
//TODO: Set up sidebar tabs | ||
vm.currentTab = 'description'; | ||
vm.mappingStep = 'select'; | ||
mapService.createOSMMap('map'); | ||
vm.map = mapService.getOSMMap(); | ||
|
||
vm.map.addInteraction(select); | ||
select.on('select', function (event) { | ||
$scope.$apply(function () { | ||
var feature = event.selected[0]; | ||
onTaskSelection(feature); | ||
}); | ||
}); | ||
|
||
var id = $location.search().project; | ||
initialiseProject(id); | ||
//TODO: put the project metadata (description instructions on disebar tabs | ||
//TODO: put the project metadata (description and instructions on siedbar tabs) | ||
} | ||
|
||
/** | ||
* Get a project with using it's id | ||
* Sets up a randomly selected task as the currently selected task | ||
*/ | ||
function initialiseProject(id){ | ||
vm.selectRandomTask = function () { | ||
var feature = taskService.getRandomMappableTaskFeature(vm.taskVectorLayer.getSource().getFeatures()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks a lot neater now 👍 |
||
if (feature) { | ||
select.getFeatures().clear(); | ||
select.getFeatures().push(feature); | ||
onTaskSelection(feature); | ||
// padding to makes sure there is plenty of clear space around feature on map to keep visual | ||
// context of feature location | ||
var vPadding = vm.map.getSize()[1] * 0.3; | ||
vm.map.getView().fit(feature.getGeometry().getExtent(), {padding: [vPadding, vPadding, vPadding, vPadding]}); | ||
} | ||
else { | ||
vm.selectedTask = null; | ||
vm.isSelectTaskMappable = false; | ||
vm.mappingStep = 'none-available'; | ||
} | ||
}; | ||
|
||
/** | ||
* clears the currently selected task. Clears down/resets the vm properties and clears the feature param in the select interaction object. | ||
*/ | ||
vm.clearCurrentSelection = function () { | ||
vm.selectedTask = null; | ||
vm.isSelectTaskMappable = false; | ||
vm.currentTab = 'mapping'; | ||
vm.mappingStep = 'select'; | ||
select.getFeatures().clear(); | ||
}; | ||
|
||
/** | ||
* Initilaise a project using it's id | ||
* @param id - id of the project to initialise | ||
*/ | ||
function initialiseProject(id) { | ||
var resultsPromise = projectService.getProject(id); | ||
resultsPromise.then(function (data) { | ||
//project returned successfully | ||
vm.project = data; | ||
addAoiToMap(vm.project.areaOfInterest); | ||
addProjectTasksToMap(vm.project.tasks); | ||
}, function(){ | ||
vm.projectData = data; | ||
addAoiToMap(vm.projectData.areaOfInterest); | ||
addProjectTasksToMap(vm.projectData.tasks); | ||
}, function () { | ||
// project not returned successfully | ||
// TODO - may want to handle error | ||
}); | ||
|
@@ -47,16 +102,18 @@ | |
* Adds project tasks to map as features from geojson | ||
* @param tasks | ||
*/ | ||
function addProjectTasksToMap(tasks){ | ||
function addProjectTasksToMap(tasks) { | ||
//TODO: may want to refactor this into a service at some point so that it can be reused | ||
var source = new ol.source.Vector(); | ||
var vector = new ol.layer.Vector({ | ||
vm.taskVectorLayer = new ol.layer.Vector({ | ||
source: source, | ||
name: 'tasks', | ||
style: styleService.getTaskStyleFunction | ||
}); | ||
vm.map.addLayer(vector); | ||
vm.map.addLayer(vm.taskVectorLayer); | ||
|
||
// read tasks JSON into features | ||
console.log(tasks); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove console.log There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
var format = new ol.format.GeoJSON(); | ||
var taskFeatures = format.readFeatures(tasks, { | ||
dataProjection: 'EPSG:4326', | ||
|
@@ -70,11 +127,12 @@ | |
* Adds the aoi feature to the map | ||
* @param aoi | ||
*/ | ||
function addAoiToMap(aoi){ | ||
function addAoiToMap(aoi) { | ||
//TODO: may want to refactor this into a service at some point so that it can be resused | ||
var source = new ol.source.Vector(); | ||
var vector = new ol.layer.Vector({ | ||
source: source | ||
source: source, | ||
name: 'aoi' | ||
}); | ||
vm.map.addLayer(vector); | ||
|
||
|
@@ -86,5 +144,31 @@ | |
}); | ||
source.addFeature(aoiFeatures); | ||
} | ||
|
||
/** | ||
* Gets a task from the server and uses sets up the task returned as the currently selected task | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo in description There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
* @param feature | ||
*/ | ||
function onTaskSelection(feature) { | ||
//get id from feature | ||
var taskId = feature.get('taskId'); | ||
var projectId = vm.projectData.projectId; | ||
// get full task from task service call | ||
var taskPromise = taskService.getTask(projectId, taskId); | ||
taskPromise.then(function (data) { | ||
//task returned successfully | ||
vm.selectedTask = data; | ||
vm.isSelectTaskMappable = !data.taskLocked && (data.taskStatus === 'READY' || data.taskStatus === 'INVALIDATED'); | ||
vm.currentTab = 'mapping'; | ||
vm.mappingStep = 'view'; | ||
}, function () { | ||
// task not returned successfully | ||
// TODO - may want to handle error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error is handled so we can remove the TODO There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
vm.selectedTask = null; | ||
vm.isSelectTaskMappable = false; | ||
vm.currentTab = 'mapping'; | ||
vm.mappingStep = 'task-get-error'; | ||
}); | ||
} | ||
} | ||
})(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add function comment