Polyline on map not zoomed in properly

20 views
Skip to first unread message

ROBIN GUPTA

unread,
Jul 25, 2018, 7:55:28 AM7/25/18
to Google Visualization API

i am using fitbound function to autozooom on polyline of map. but on first time it not works properly if i change the chartData and call same function again it works fine. the function code is below.

var mapOptions = {
                    zoom: 1,
                    center: { lat: 0, lng: 0 },
                    zoomControl: true,
                    zoomControlOptions: {
                        style: google.maps.ZoomControlStyle.SMALL
                    },
                    mapTypeId: 'satellite'
                };
                this.chart = new google.maps.Map(document.getElementById(chart_element.id), mapOptions);
                let polylinePath = new google.maps.Polyline({
                    path: chart_data,
                    geodesic: true,
                    strokeColor: '#FF0000',
                    strokeOpacity: 1.0,
                    strokeWeight: 2
                });

                /* set auto zoom level to polyline */

                var latlngbounds = new google.maps.LatLngBounds();
                for (var i = 0; i < this.chartData.length; i++) {
                    latlngbounds.extend(this.chartData[i]);
                }

                this.chart.fitBounds(latlngbounds);

                /* Set polyline chart to map */
                polylinePath.setMap(this.chart);
Reply all
Reply to author
Forward
0 new messages