-
Notifications
You must be signed in to change notification settings - Fork 72
Catalogtree #126
Catalogtree #126
Changes from 55 commits
d299aac
d2c6b8b
c43833a
7f4eac8
56e2fdf
ab34f4f
a54e00f
726fb48
d5fa6a9
f73062c
e723ab8
8352d61
1b006a8
21db4e6
63846ba
5bba3b1
060b834
3bf3627
45885ce
2429a08
651b5a2
72d54d3
0a16d3f
5b243fa
7f9976c
ce5a035
a2641fb
71ec87c
ed3c5f4
595cf8f
938cf42
d986228
eebf2f5
1a5b569
1cda445
b3d8ece
f9d1c7d
a7eb6d4
76faeb6
4409649
339ff1a
97c2b2a
5213d37
8e2b368
fc76b19
b813229
230583a
a45aac4
504c4a9
a617b73
29ff945
8b0b860
a4ff512
3a87edd
d750ab8
4ed9129
ca0ae2a
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 |
---|---|---|
@@ -1 +1,5 @@ | ||
source rc_dev | ||
|
||
export BASE_URL_PATH=/ltmom | ||
export SERVICE_URL=http://mf-chsdi30t.bgdi.admin.ch | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
(function() { | ||
goog.provide('ga_catalogitem_directive'); | ||
|
||
goog.require('ga_map_service'); | ||
goog.require('ga_popup_service'); | ||
|
||
//static functions | ||
function getMapLayer(map, id) { | ||
var layer; | ||
map.getLayers().forEach(function(l) { | ||
if (l.get('id') == id) { | ||
layer = l; | ||
} | ||
}); | ||
return layer; | ||
}; | ||
|
||
function addLayerToMap(scope, doAlert) { | ||
var layer = getMapLayer(scope.map, scope.item.idBod), | ||
olLayer; | ||
if (!angular.isDefined(layer)) { | ||
olLayer = scope.gaLayers.getOlLayerById(scope.item.idBod); | ||
if (olLayer) { | ||
scope.item.errorLoading = false; | ||
scope.map.getLayers().push(olLayer); | ||
} else { | ||
if (doAlert) { | ||
//FIXME: better error handling | ||
var msg = 'The desired Layer is not defined ' + | ||
'by the gaLayers service (' + scope.item.idBod + ').'; | ||
alert(msg); | ||
} | ||
scope.item.errorLoading = true; | ||
scope.item.selectedOpen = false; | ||
} | ||
} | ||
}; | ||
|
||
function removeLayerFromMap(map, id) { | ||
var layer = getMapLayer(map, id); | ||
if (angular.isDefined(layer)) { | ||
map.removeLayer(layer); | ||
} | ||
}; | ||
|
||
var module = angular.module('ga_catalogitem_directive', [ | ||
'ga_map_service', | ||
'ga_popup_service' | ||
]); | ||
|
||
/** | ||
* See examples on how it can be used | ||
*/ | ||
module.directive('gaCatalogitem', | ||
['$compile', 'gaLayers', 'gaPopup', | ||
function($compile, gaLayers, gaPopup) { | ||
return { | ||
restrict: 'A', | ||
templateUrl: 'components/catalogtree/partials/catalogitem.html', | ||
scope: { | ||
item: '=gaCatalogitemItem', | ||
map: '=gaCatalogitemMap' | ||
}, | ||
compile: function(tEl, tAttr) { | ||
var contents = tEl.contents().remove(); | ||
var compiledContent; | ||
return function(scope, iEl, iAttr) { | ||
if (!compiledContent) { | ||
compiledContent = $compile(contents); | ||
} | ||
scope.gaLayers = gaLayers; | ||
scope.getLegend = getLegend; | ||
scope.toggle = toggle; | ||
scope.switchLayer = switchLayer; | ||
scope.previewLayer = previewLayer; | ||
scope.removePreviewLayer = removePreviewLayer; | ||
|
||
compiledContent(scope, function(clone, scope) { | ||
iEl.append(clone); | ||
}); | ||
}; | ||
} | ||
}; | ||
function previewLayer() { | ||
if (this.map) { | ||
if (this.item.selectedOpen) { | ||
removeLayerFromMap(this.map, this.item.idBod); | ||
} else { | ||
addLayerToMap(this, false); | ||
} | ||
this.item.preview = true; | ||
} | ||
}; | ||
|
||
function removePreviewLayer() { | ||
this.switchLayer(false); | ||
this.item.preview = false; | ||
}; | ||
|
||
function switchLayer(fromClick) { | ||
if (fromClick) { | ||
this.item.selectedOpen = !this.item.selectedOpen; | ||
} | ||
if (this.map) { | ||
if (this.item.selectedOpen) { | ||
addLayerToMap(this, fromClick); | ||
} else { | ||
removeLayerFromMap(this.map, this.item.idBod); | ||
} | ||
} | ||
}; | ||
|
||
function toggle(ev) { | ||
this.item.selectedOpen = !this.item.selectedOpen; | ||
ev.preventDefault(); | ||
}; | ||
|
||
function getLegend(ev, bodid) { | ||
var scope = this; | ||
scope.gaLayers.getMetaDataOfLayer(bodid) | ||
.success(function(data) { | ||
gaPopup.create({ | ||
title: 'metadata_window_title', | ||
content: data, | ||
x: 400, | ||
y: 200 | ||
}).open(scope); | ||
}) | ||
.error(function() { | ||
//FIXME: better error handling | ||
var msg = 'Could not retrieve information for ' + bodid; | ||
alert(msg); | ||
}); | ||
ev.stopPropagation(); | ||
}; | ||
}] | ||
); | ||
})(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
(function() { | ||
goog.provide('ga_catalogtree_directive'); | ||
|
||
var module = angular.module('ga_catalogtree_directive', [ | ||
]); | ||
|
||
/** | ||
* See examples on how it can be used | ||
*/ | ||
module.directive('gaCatalogtree', | ||
['$http', '$translate', | ||
function($http, $translate) { | ||
return { | ||
restrict: 'A', | ||
replace: true, | ||
templateUrl: 'components/catalogtree/partials/catalogtree.html', | ||
scope: { | ||
options: '=gaCatalogtreeOptions', | ||
map: '=gaCatalogtreeMap' | ||
}, | ||
link: function(scope, element, attrs) { | ||
var currentTopic; | ||
scope.updateCatalogTree = function() { | ||
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. Do we really need a reference to the updateCatalogTree function in the scope? Instead, can't updateCatalogTree just be local to the link function? 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. Absolutely. I'll adapt. |
||
if (angular.isDefined(currentTopic)) { | ||
$http.jsonp(scope.options.getUrlForTopic(currentTopic), { | ||
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. I've used a URL template rather than a URL function in #261. We should be consistent. I have a preference for templates but I can probably be convinced otherwise. 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. I have no problem going the template way. But the change would be in the controller, not the directive, right? So we would still have a function call to the controller function? 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. As I saw it the directive would do
|
||
params: { | ||
'lang': $translate.uses(), | ||
'callback': 'JSON_CALLBACK' | ||
} | ||
}).success(function(data, status, header, config) { | ||
scope.root = data.results.root; | ||
}).error(function(data, status, headers, config) { | ||
scope.root = undefined; | ||
}); | ||
} | ||
}; | ||
|
||
scope.$on('translationChangeSuccess', function() { | ||
scope.updateCatalogTree(); | ||
}); | ||
|
||
scope.$on('gaTopicChange', function(event, topic) { | ||
currentTopic = topic.id; | ||
scope.updateCatalogTree(); | ||
}); | ||
|
||
|
||
} | ||
}; | ||
}] | ||
); | ||
})(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
(function() { | ||
goog.provide('ga_catalogtree'); | ||
|
||
goog.require('ga_catalogitem_directive'); | ||
goog.require('ga_catalogtree_directive'); | ||
|
||
angular.module('ga_catalogtree', [ | ||
'ga_catalogitem_directive', | ||
'ga_catalogtree_directive' | ||
]); | ||
})(); |
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.
Your module should depend on ga_translation.