1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Trouble in assigning multiple kml files and getting them to work in dropdown menu

Discussion in 'JavaScript' started by kwood30, Mar 10, 2016.

  1. #1
    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="&quot; + key + &quot;">" + 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.
     
    kwood30, Mar 10, 2016 IP
  2. Blizzardofozz

    Blizzardofozz Well-Known Member

    Messages:
    132
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    118
    #2
    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="&quot; + key + &quot;">" + 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):
     
    Last edited: Mar 11, 2016
    Blizzardofozz, Mar 11, 2016 IP
  3. kwood30

    kwood30 Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    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>?
     
    kwood30, Mar 11, 2016 IP
  4. Blizzardofozz

    Blizzardofozz Well-Known Member

    Messages:
    132
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    118
    #4
    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
     
    Blizzardofozz, Mar 11, 2016 IP
  5. kwood30

    kwood30 Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #5
    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?
     
    kwood30, Mar 12, 2016 IP
  6. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #6
    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.
     
    PoPSiCLe, Mar 12, 2016 IP
  7. kwood30

    kwood30 Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #7
    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.
     
    kwood30, Mar 13, 2016 IP