Select to view content in your preferred language

KML switcher and base map?

1434
8
09-24-2018 03:06 PM
EricParrish
Emerging Contributor
I don't a huge amount of experience with JavaScript. I have done some things in Google Maps/Earth API's but my knowledge is still basic. I need to build an web interface with two base kml's. I also need to add a bunch more optional kml's with checkboxes or other form-based controls. These controls would be toggled on and off by the user. I found this resource KML | ArcGIS API for JavaScript 3.25.  But what do I need to do to add the functionality I have described. Been searching around but still don't have something that works.
 
Any help or examples would be greatly appreciated! Thanks

argis‌ toggle layers on and off‌ kml‌

0 Kudos
8 Replies
RobertScheitlin__GISP
MVP Emeritus

Eric you would have to combine that sample and this one:

Toggle layer visibility | ArcGIS API for JavaScript 3.25 

0 Kudos
KellyHutchins
Esri Frequent Contributor

You can also accomplish this task with the newer 4.x version of the ArcGIS API for JavaScript.  You'll use the same approach of combining the KML sample with the LayerList sample: 

KML sample: 

KMLLayer | ArcGIS API for JavaScript 4.8 

LayerList sample: 

LayerList widget | ArcGIS API for JavaScript 4.8 

Combined Sample: 

JS Bin - Collaborative JavaScript Debugging 

0 Kudos
EricParrish
Emerging Contributor

Hi Kelly, I tried your hybrid. Only I get only the one layer to work not only in your example but mine as well?

yours https://bcczo.colorado.edu/GISapi/layers-kmltoggle-source.html

mine https://bcczo.colorado.edu/GISapi/layers-kmltoggleczo.html

Thanks so much!!

0 Kudos
KellyHutchins
Esri Frequent Contributor

Eric in my example they both work - one layer is in California and the other in Pennsylvania.   And in your example if I look in the dev console it seems like there is an issue with adding the boundaries kml. 

There are some limitations when using KML that are outlined here: 

KML—ArcGIS Online Help | ArcGIS 

0 Kudos
EricParrish
Emerging Contributor

Yes now I see Pennsylvania, sorry it is way off the loading extent. Only now where is my second kml? Doesn't show up in the UR menu either. I double checked them they are valid kml's. I have only changed the base map to "satellite" and the kml URL.

Thank you

0 Kudos
EricParrish
Emerging Contributor

Neither excel the 10mb limit or exceed the extent seen. It was built own the same manner as the one that does show.

0 Kudos
KellyHutchins
Esri Frequent Contributor

I'm not a kml expert so not sure what is wrong but if I run both of your kml files through this kml validator the one that displays comes back as valid and the one that does not display comes back as invalid. 

Galdos KML Validator 

EricParrish
Emerging Contributor

Hi Kelly,

Thanks for everything so far.

Part 2: Now I need better control for the user over those kml layers. This will allow the user choose which ones they want to see and all but one or two would be turned "off" when the page loads until the user clicks on it. I was originally looking to do this with check boxes but am open to what will work best.

I've looked around but have not seen a good ways to do this. Found a few that don't work. 

Do you have any helpful suggestions here?

Again THANKS

0 Kudos