Questions about the MapLayout table 'Action' button #1034
Replies: 11 comments
-
Hi @PaulDudaRESPEC . You are right the PlotTable feature gives me the 'Plot' button and an optional 'Action' button. There is a function that can be overwritten in the MapLayout JavaScript API, you can use the following snipped:
This should give you the ability to add a custom text in the button, and also it should give you the ability to add any extra functionality to the action button. You should enable the Lamentably, it is not in the documentation as you can see : https://docs.tethysplatform.org/en/latest/tethys_sdk/layouts/map_layout.html But it can be seen here in the tethys source code at: |
Beta Was this translation helpful? Give feedback.
-
Thank you! I'll give it a try! |
Beta Was this translation helpful? Give feedback.
-
Where do I put that code snippet within my tethys app? What file and folder? |
Beta Was this translation helpful? Give feedback.
-
You should put the snippet inside the JavaScript file that you are importing. This is generally the main.js file that gets created when the tethys application gets scaffolded, but if you are using a custom template it would be the imported JavaScript file in the block scripts portion for example:
More can be found at : https://docs.tethysplatform.org/en/stable/tethys_sdk/layouts.html#layout-custom-template in the section Custom Template and JavaScript |
Beta Was this translation helpful? Give feedback.
-
Thank you for your response. As far as I can tell I've done exactly what those instructions indicate. I must be missing something else. |
Beta Was this translation helpful? Give feedback.
-
@PaulDudaRESPEC, can you provide the repo of your code? or can you provide a reproducible example? Also if needed we can arrange a video call meeting and we can go through it together. |
Beta Was this translation helpful? Give feedback.
-
Since I'm just trying to learn a bit about tethys and evaluate it as a platform we might want to build off, at this point I'm just using your map_layout_tutorial and trying to customize it a bit. The zip file below contains my slightly customized version of that tutorial: tethysapp-map_layout_tutorial-extended.zip Thank you for your continued support! |
Beta Was this translation helpful? Give feedback.
-
@PaulDudaRESPEC, I was able to make the button work. I am attaching a zipped file with the updated source code:
and edit the custom_map_layout.html:
This would only work for the catchment layer, and if it wants to be reproduced to other layers, the |
Beta Was this translation helpful? Give feedback.
-
Thank you, it worked using the code in your zip file! I think I had something wrong for the action button in my js file from the beginning that was making it not work all along. If I could trouble you with one more detail, could you extend your example to do something on the 'onClick' event for the custom action button? I'd like to do some custom python when the user clicks that button. |
Beta Was this translation helpful? Give feedback.
-
Hi @PaulDudaRESPEC, sorry for the late reply I hope this is still helpful to you. I think in order to have some custom python code to work with your button. You might need something like this below: MAP_LAYOUT.action_button_generator(function(feature) {
let layer_name = MAP_LAYOUT.get_layer_name_from_feature(feature);
// Assuming fetch API is available for making HTTP requests
// Note: Adjust the URL as needed for your actual endpoint.
let callEndpoint = async (layerName) => {
try {
const response = await fetch('test-controller/', {
method: 'POST', // or 'GET' depending on your endpoint
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ layerName: layerName }), // Send layer_name as part of the request body, adjust as needed.
});
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
console.log(data); // Handle the response data as needed
} catch (error) {
console.error('Error:', error);
}
};
let action_button = `
<div class="action-btn-wrapper">
<a href="javascript:void(0);" role="button" class="btn btn-primary" onClick="(function() { (${callEndpoint.toString()})('${layer_name.replace(/'/g, "\\'")}'); })()">
${layer_name ? layer_name : 'Action'}
</a>
</div>
`;
return action_button;
}); and where you have your map layout controller you can add the following below: @controller
def test_controller(request):
print("I am here")
pass Notice that we are calling the controller url using the fetch library. There is also another way to add custom functions inside your maplayout controller. The following might be helpful: |
Beta Was this translation helpful? Give feedback.
-
Awesome, I'll give that a try. Thank you again! |
Beta Was this translation helpful? Give feedback.
-
I'm exploring Tethys as a toolkit to build an app for a client. I'm looking specifically at how I can customize the PlotTable feature within the MapLayout. I see that the PlotTable feature gives me the 'Plot' button and an optional 'Action' button. I don't see a way to do 2 things I would need -- first, a way to customize the text of the 'Action' button; and second, a simple way to override the click event on the 'Action' button with my own code.
Do these features exist? Since I'm very new to Tethys I know I may be misunderstanding something; on the other hand this might be a feature request. Either way I would appreciate if someone could patiently point me in the right direction. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions