Title: Change KML file dynamically via javascript
Last modified: August 28, 2018

---

# Change KML file dynamically via javascript

 *  Resolved [benbois](https://wordpress.org/support/users/benbois/)
 * (@benbois)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/change-kml-file-dynamically-via-javascript/)
 * Hi,
 * I’m looking for a solution to change / load a KML file dynamically via javascript.
   
   I used to do it with Google Map and this simple code:
 *     ```
       function mapRedraw(idmap,url) {
           if(jQuery("body").data(idmap) != url) {
               var kml="/maps/" + url + "?v="+(new Date()).getTime(),
               f = new FlexibleMap();
               f.dblclickZoom=false;
               f.scrollwheel=true;
               f.mapTypeControl=false;
               f.zoomControl = false;
               f.showKML(idmap, kml);
                       jQuery("body").data(idmap,url);
           }
       }
   
       jQuery(window).ready(function() {
           jQuery(".map-link").click( function(e){
               e.preventDefault();
               var kml_link = jQuery(this).data("url"),
               kml_map = jQuery(this).data("map"),
               kml_type = jQuery(this).data("type"),
               kml_lang = "_" + jQuery(this).data("lang");
               if(kml_type == undefined) kml_type="kml";
               if(kml_lang == '_undefined') kml_lang="_en";
   
               var link = kml_link + kml_lang + "." + kml_type;
               mapRedraw(kml_map,link);
                       });
           });
       ```
   
 * But I’m stuck with OSM :/
    Any help appreciated.

Viewing 1 replies (of 1 total)

 *  Thread Starter [benbois](https://wordpress.org/support/users/benbois/)
 * (@benbois)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/change-kml-file-dynamically-via-javascript/#post-10635434)
 * Finally, I managed to do it by using the file_list, file_title and file_color_list
   parameters.

Viewing 1 replies (of 1 total)

The topic ‘Change KML file dynamically via javascript’ is closed to new replies.

 * ![](https://ps.w.org/osm/assets/icon-256x256.png?rev=2087144)
 * [OSM - OpenStreetMap](https://wordpress.org/plugins/osm/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/osm/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/osm/)
 * [Active Topics](https://wordpress.org/support/plugin/osm/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/osm/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/osm/reviews/)

 * 1 reply
 * 1 participant
 * Last reply from: [benbois](https://wordpress.org/support/users/benbois/)
 * Last activity: [7 years, 9 months ago](https://wordpress.org/support/topic/change-kml-file-dynamically-via-javascript/#post-10635434)
 * Status: resolved