AnsweredAssumed Answered

How to show data from local database in popup template?

Question asked by kendees on Feb 7, 2017

Hey. I'm working on a web application for displaying invasive plants on map and I'm trying to work with ArcGIS API for JavaScript 4 and I need a help about displaying data stored in my local database into popup using popupTemplate. Example is HERE. Basically I want to reproduce something very similiar to this. But the data that are being displayed on that example are stored in a table on ArcGIS server and are connected to the layer and objects in it, if I understand right. So the "print" into the popup is quite easy using brackets { } and attribute name. But what if want to display additional data, which I don't have or I don't want to have on ArcGIS server with the layout, but I have them stored in my local MySQL database?

 

I was trying to do something on event 'click'. But how can I get the {ObjectID} or something that I can take and find a match in my database? I was thinking about a solution, that I would get the ObjectID which relates to the position where I clicked, send it through ajax to a controller, which would find the matched row and send result back so it could be displayed. But that means that on every click there would be an ajax call. But I can't figure out how to get it work. There're some ajax calls only when the map and the layer are rendered. All the data from table are loaded when the map is initializing. That means that when I click on some object in the layer, no ajax calls is being processed, just the popup shows but the data are already here for every object. So I don't know how to get the {ObjectID} that I have clicked on. As you know, in the template it's pretty easy to print some attribute just using this syntax - {ObjectID}. But how to get it outside the template, I mean, how to get the ObjectID on click so I can store it in a var and send it to controller to handle it. Then I think it's possible to print out additional data about the plants - like description, dimensions, url to its profile, etc. from my own database in the popup, which will be related to the object I clicked. I hope you understand, if not I will try to clarify it again. And of course, if you have any other idea how to do something like this or have your own solution or suggestion how this could be done, feel free to comment. I would be glad. Thank you very much.

Outcomes