I am learning more and more all the time with help from this community. With help I have now been able to display the LayerList widget in an HTML div and hide individual layers if there is nothing displayed on the map for the layer.
I would now like to colour the layers to match the graphic symbol I am using on the map. See the attached screenshot so you can understand what I am trying to do.
Thank you in advance
Hi David,
I was finally able to get some time to look at this. The listItemCreated function actually gets called multiple times (map initialization and at other times) and this is likely why you are seeing the misleading layer count info. We've actually fixed this in the next version of the API where the function will only be called once. I moved the log statement to the bottom and have it simply logging out the layers collection and there is only one layer for each category.
To remove the layers without any sightings from the layer list you can simply set the listMode to hide for that layer. I modified your logic slightly to show this on line 299 of the codepen below. I hope this helps.
Here is the codepen I was playing with. https://codepen.io/sagewall/pen/abMNeZQ
Hi @Sage_Wall ,
I really like your solutions and since being new to Map SDK reaching out to you. I am working on this codepen: https://codepen.io/vntbstgk-the-decoder/pen/ZEPJBEE.
My questions are:
Can we add feature count in front of each legend?
My data is a tree data and I want to get top 5 species in legend in custom legend. Since the data gets updated overtime, I want the legends to be dynamic.
This is a static ExB that i created. https://experience.arcgis.com/experience/d5a32539f144401f946629fdfa2894a7/ I want to create a dynamic version of this using Map SDK.
Thank you
A spatial reference is required, but if one is not provided the API will infer one based on the geometry of the features. It's best practice to define a spatial reference if possible.
Hello again. I have adapted my code now for the changes you have made and it works 😊
Thank you so much for al your help. It has made so much difference to my project but also to my understanding. You are very kind
One final question. Is SpatialReference required? I notice you built it in to your working example
Thanks @DavidShearan,
I'll try and take a look later today, it's been a busy week.
Hello again, hope you had a good vacation.
speciesName = 'Papilio alexanor' and commonName = 'Southern Swallowtail'
Here are the first few elements from the sightings array - the array would normally be bigger but I was testing with a limit of 10 records extracted so I could look at the results more closely. The array dump was done using console/log
8: Object { MapID: "351", MapFullName: "xyz", MapLocation: "Mt Pantokrator - Cove meadow ", … }
Hi @DavidShearan ,
Sorry for the slow reply, I've been on vacation. Could you please send a sample of what the results from the PHP queries are for the following variables? I don't need the whole response but just a few records from each of these would be extremely helpful for debugging.
var sightings = <?php echo json_encode($coords) ?>; var speciesName = <?php echo json_encode($thisTaxon) ?>; var commonName = <?php echo json_encode($evernacular) ?>;
Happy New Year
i have posted an update on the work I am doing but I posted it as a reply to my original post rather than as a reply to you. I am guessing that means you didn’t get a notification.
I am only sending this in case I am right about the notification. There is definitely no rush 🙂
Huge thank you for all of your advice.
I have now made substantial progress. You can see the results in my attachment DistributionMap.jpg and my full Javascript in sourcecode.txt
There are a couple of things I am still wrestling with:
Many thanks again - I am so close and it's down to your detailed and expert help.
Excellent, thank you. I couldn't see that code before. Maybe I was clicking on the wrong link in your previous reply? Anyway that looks like exactly what I am looking for. I will let you know how I get on
Lines 87 to 109 in the codepen is an array of objects. It could contain hundreds or thousands of entries but I only wrote out 3. I just guessed at what the response from a MySQL query would look like based on this website. Then I loop through each result, create a graphic and add the graphic to the corresponding feature layer.
Hi. Only just returning to this after a break around Christmas. Hopefully I can get my brain back in gear and get this sorted. Just one thing - I can't see where you are using arrays in the codepen example you have given me. It looks just the same as the previous example.
Yeah exactly,
If your data is coming back from you database query as an array of objects you you loop through the results and create a graphic for each one, then push that graphic into the appropriate feature layer's source array. Modified codepen that does that 😀https://codepen.io/sagewall/pen/oNVvXOL
It may be a little more work up front than plotting individual graphics on the map, but puts you in a great place moving forward if you ever want to add additional things like searching the data, or adding popups or tables and things that graphics alone don't support.
Just to let you know I am still working on this although I haven’t been able to give it any attention over the last few days.
I did look in detail at your code and considered how I would adapt it for my situation. You have defined two adult points separately and then listed them as the source for the feature layer. I could have hundreds of separate points in an array of data selected from my database. Will I need to replicate your code but in a loop to define each point?
Hello again. I have applied that and now have text under each list item that simply says ‘No legend’ so clearly I am nearLy there. Now I guess I have to give each one a label title? I am assuming that I need a Renderer to achieve this? Will Simple Renderer do the job or is there an easier way to accomplish it.
I think the best result would be for the legend to show the green dot for Adults and then the label Adults. However if I did achieve that then the word Adults would appear twice. Could I switch off the title next to the eye?
sorry, it seems like I need to be led step by step through this. I am constantly searching the online documentation but don’t know whether I am going in the right direction or not
That is a very detailed description and explanation. Thank you for taking the time to understand my issue. That appears to give me what I want and will give it a try.
The Legend widget by itself doesn't have the ability to turn on or off the visibility of layers but when it's added into the layer list's list item with the listItemCreatedFunction the ability to toggle layers on and off in LayerList widget is preserved. So you can still control visibility with the visibility icon (eye) on the left of the layer name and open and close the panel containing the legend with the right hamburger looking button.
https://developers.arcgis.com/javascript/latest/sample-code/widgets-layerlist-legend/
Layer and legend visible
Layer and legend not visible
In your example you would end up with three layers in your layer list and each layer would have a legend that shows how that individual layer looks on the map right underneath it.
Thank you. I did a lot of searching before posting my question and I found this along the way. It looked really interesting but I still want the users to be able to switch on/off the layers and it didn’t look as though I could accomplish this using a legend.
Perhaps I am wrong?
I think what you are asking could be accomplished, but as an alternative you might consider adding a Legend to the list item panel as shown in this sample. https://developers.arcgis.com/javascript/latest/sample-code/widgets-layerlist-legend/ this would enable to you have symbols that differ in more than just the color and still provide your users a preview of what the layer looks like on the map.
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.