Im am trying to assign the function of my dropdown menu so when you
click on the selected county it will focue on that countie. I have
written out what I can below, through research as I am new to all this,
but am not sure how to link it all together.
I know I haven’t got the googlemaps attached but I do in my full page,
it is just this section i am having trouble in trying to link together.
Never repeat yourself like this, it’s a sign that you’re not doing things correctly.
I’m not sure why you changed back to click events on the dropdown, my answer in your previous thread was closer to what you want. This example shows how you can save lat lng for each county in an object and pull them out when you change the select.
var changeCounty = function(event) {
var county = event.target.value;
extendBounds(county);
e.preventDefault();
}
var countySelect = document.getElementById('Counties')
countySelect.addEventListener('change', changeCounty, false);
var countyBounds = {
bedfordshire: {
lat: 52.33,
lng: -0.05
}
}
var extendBounds = function(key) {
var county = countyBounds[key];
var bounds = new google.maps.LatLngBounds();
bounds.extend(new google.maps.LatLng(county.lat, county.lng));
map.fitBounds(bounds);
}
I’m not sure why you had 2 lat lng’s for each but if that is required then you can save 4 points for each county,
thank you for your help. I researched after your last post and came up with what I posted here. I’m learning as I go along lol
The two sets of latlng is to point out the whole county for the map. Thanks again
And you’ll need to change your function to use the new properties.
var extendBounds = function(key) {
var county = countyBounds[key];
var bounds = new google.maps.LatLngBounds();
bounds.extend(new google.maps.LatLng(county.lat1, county.lng1));
bounds.extend(new google.maps.LatLng(county.lat2, county.lng2));
map.fitBounds(bounds);
}