I am trying to embed some kml files for local county bodries but am not sure how to asign multiple ones as I am coding in dreamweaver. Also I have made a drop down menu for eack kml file but am not sure how to link and get it all to work, mainly want the boundries to be shown on the map at all times and when selected in the dropdown menu, that particular county is shown on the map. Please see my coding I have done, and if there is any advice i would appreciate it. I am completely new to this and trying to teach myself. var kmlUrl = 'maps/central bedfordshire' ; var kmlOptions = { suppressInfoWindows: true, preserveViewport: false, map: map }; var kmlLayer = new google.maps.KmlLayer(kmlUrl, kmlOptions); function countiesDropdown(container){ var counties = { "bedfordshire", "hertfordshire", "cambridgeshire", "northamptonshire", "buckinghamshire" } var out = "<select><option value=""></option>";</select> <select> for (var key in counties) {</select> <select> out += "<option value="" + key + "">" + counties[key] + "</option>";</select> <select> }</select> <select> out += "</select>"; console.log(out); document.getElementById(container).innerHTML = out; } I have already inbeded the general map and markers etc and they work fine hence why have only given the coding that isn't working. Here is the HTML part. HTML Code: <div id="menu" style=" position: absolute; margin: 45px 80px;" > <select id="Counties"> <option value="">Select County</option> <option value="bedfordshire">Bedfordshire</option> <option value="buckinghamshire">Buckinghamshire</option> <option value="cambridgeshire">Cambridgeshire</option> <option value="hertfordshire">Hertfordshire</option> <option value="northamptonshire">Northamptonshire</option> </select> </div> Hope this enough of an understanding of what i have and am trying to do.
I don't know Google Earth but this function is not good: function countiesDropdown(container){ var counties = { "bedfordshire", "hertfordshire", "cambridgeshire", "northamptonshire", "buckinghamshire" } var out = "<select><option value=""></option>";</select> <select> for (var key in counties) {</select> <select> out += "<option value="" + key + "">" + counties[key] + "</option>";</select> <select> }</select> <select> out += "</select>"; console.log(out); document.getElementById(container).innerHTML = out; } Code (markup): It would be better: function countiesDropdown() { var counties = { "bedfordshire" : "Bedfordshire", "hertfordshire" : "Hertfordshire", "cambridgeshire" : "Cambridgeshire", "northamptonshire" : "Northamptonshire", "buckinghamshire" : "Buckinghamshire" }, out = '<select id="Counties" name="someName"><option value=""></option>', key; for (key in counties) { if (counties.hasOwnProperty(key)) { out += '<option value="' + key + '">' + counties[key] + '</option>'; } } out += '</select>'; console.log(out); document.getElementById('container').innerHTML = out; } countiesDropdown(); Code (markup):
I think I have miss construded the coding as been trying to do this without any knowledge of javascript. Thank you for your help. So will this this work with my current HTML setup, or do I need to change the HTML coding of the <value>?
This function will create the html for the select element. Try it in https://jsfiddle.net/. You just have to make <div id="container"></div> in the HTML section
Thank you, I'll have a mess around with this. My general idea is to be able to insert a kml file to show all the boundry lines of each countie in the UK and then use the selction menu to focus in on that particular county. Do you know how to help me with this?
Wouldn't a better approach just be having a select with all the counties, and load the appropriate kml file on selection? That way you offset any loading until the user actually choose to load something.
I only really want a faint county border lining on the map of UK itself, so I am guessing you can do this by apply the KML file as a layer. I have already created the KML file just not sure how to write it in. I then just want at this moment in time, but if it is done easier then happy with all, but just want the select menu to be able to be selected of a certain county and that is then shown on the map. If that make sense.