From: Loïc C. <loi...@ve...> - 2014-07-07 14:26:40
|
Hi Colin, Thank you for the quick answer. To be more precise, the idea is the following: color my feature depending on the presence/absence from another application. Then, if the feature is present, append a link to the menu template. The following code (as the former code) is only a test code. I have not yet implemented the full idea. function (featureObject, variableName, glyphObject, trackObject) { function markerIsInGnpIS(markerName) { console.log('here'); var xhr = new XMLHttpRequest(); xhr.open('GET', 'http://localhost/GnpMap/webresources/marker/name/' + markerName, false); xhr.send(null); if (xhr.status == 200) { return true } return false } function addLink(markerName) { var linkLabel = 'link'; var menuTemplate = trackObject.config.menuTemplate; var already_added = false; for (var i = 0; i < menuTemplate.length; i++) { if (menuTemplate[i].label == linkLabel) { already_added = true; break; } } if (!already_added) { // negation, only for test... menuTemplate.push(new function () { this.action = 'iframeDialog', this.label = linkLabel, this.url = 'http://localhost/fakeURL', this.title = '{type} {name}' }) } } var name = featureObject.get('name'); if (!markerIsInGnpIS(name)) { //negation only for test addLink(name); return 'red' } return 'green' } This code works too, but I'm little annoyed with writing a one-liner code because it's hard to maintain. Anyway, i don't have any clue to write the same code into tracks.conf. I'm wondering if writing a plugin might be a good idea? Another point is that I perform synchronous callback to my webservice. I would prefer to use asynchronous callback. To do that, I defined my callback and try to use glyphObject.config.style.color = '<color>' instead of return '<color>' but it doesn't seems to works.... Do I modify the right value? Best regards, Loïc |