Also, when I don't call "size_map()" it doesn't have the recursion error. but it does't size my map.
On Apr 1, 3:48 pm, The Net Duck <[email protected]> wrote: > Hi > I have a array of latlng objects that I run through and extend bounds > so that these paths always show up on the map ie the map resizes to > fit the lines. When I do this I get a "too much recursion" error in > firebug. I was wondering how I could fix this? > > Here is the code. > document.observe('dom:loaded', function() { > // this stuff gets executed on the body's on on load time}); > > // lat, lng is the center point of the map when starting > function initialize_map(lat, lng) > { > // in the form ... (lat, lng) > var latlng = new google.maps.LatLng(lat, lng); > var myOptions = { > zoom: 8, > center: latlng, > mapTypeControl: true, > mapTypeControlOptions: {style: > google.maps.MapTypeControlStyle.DROPDOWN_MENU}, > navigationControl: true, > navigationControlOptions: {style: > google.maps.NavigationControlStyle.ANDROID}, > mapTypeId: google.maps.MapTypeId.ROADMAP > }; > > // Global Variables > window.map = new > google.maps.Map(document.getElementById("map_canvas"), myOptions); > window.bounds = new google.maps.LatLngBounds();} > > // this creates a new marker given the info. > // icon_type is either; > // amer > // other > // user > // Be aware that if you change the icon_file_name you need ot make > sure to account for that in this code. > function place_marker(icon_type, description, lat, lng) > { > // create the marker > var image = "../images/" + icon_type + "_icon.png"; > var latlng = new google.maps.LatLng(lat, lng); > var marker = new google.maps.Marker({ > position: latlng, > map: map, > title:description, > clickable: true, > icon:image > }); > > // create the info window when clicked on. > var info_window = new google.maps.InfoWindow({ > content: description > }); > > google.maps.event.addListener(marker, 'click', function() { > info_window.open(map,marker); > }); > > } > > function draw_route(route, color) > { > if (route.type == "LineString"){ > create_polyline(route.coordinates, color).setMap(map); > } > else if (route.type == "MultiLineString"){ > route.coordinates.each(function(line){ > create_polyline(line, color).setMap(map); > }); > } > > set_map_bounds(route.coordinates); > > } > > function create_polyline(coordinates, color) > { > // Building the path for the polyline > var line_path = build_line_path(coordinates); > // Building the polyline > var byways_route = new google.maps.Polyline({ > path: line_path, > strokeColor: color, > strokeOpacity: 1.0, > strokeWeight: 2 > }); > > return byways_route; > > } > > function set_map_bounds(coordinates) > { > var line_path = build_line_path(coordinates); > > // extends the bounds checking each coord in line path > for (var i = 0; i < line_path.length; i+=1){ > bounds.extend(line_path[i]); > } > > } > > function build_line_path(coordinates) > { > var line_path = coordinates.map(function(coord){ > return new google.maps.LatLng(coord[1], coord[0]); > }); > > return line_path; > > } > > function size_map() > { > map.fitBounds(bounds); > > } > > Please be aware that "draw_route" gets called many times by my Rails > view page and the incoming "route" contains a Json array of lat / lng > coords that are accessed with the "coordinates" call > > Thank you ! > > - The Net Duck -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.
