protected function generateJavaScript($mapId, array $mapPoints, $initializeFunctionName)
    {
        // Note: If there are several map points with coordinates and the map
        // is fit to the map points, the Google Maps API still requires a center
        // point. In that case, any point will do (e.g., the first point).
        $centerCoordinates = $mapPoints[0]->getGeoCoordinates();

        return 'var mapMarkersByUid = mapMarkersByUid || {};' . LF .
            'function ' . $initializeFunctionName . '() {' . LF .
            'var center = new google.maps.LatLng(' . \number_format($centerCoordinates['latitude'], 6, '.', '') . ', ' .
            \number_format($centerCoordinates['longitude'], 6, '.', '') . ');' . LF .
            'var mapOptions = {' . LF .
            '  mapTypeId: google.maps.MapTypeId.ROADMAP,' . LF .
            '  scrollwheel: false, ' . LF .
            '  zoom: ' . self::DEFAULT_ZOOM_LEVEL . ', ' . LF .
            '  center: center' . LF .
            '};' . LF .
            'mapMarkersByUid.' . $mapId . ' = {};' . LF .
            'var map = new google.maps.Map(document.getElementById("' . $mapId . '"), mapOptions);' . LF .
            'var bounds = new google.maps.LatLngBounds();' . LF .
            $this->createMapMarkers($mapPoints, $mapId) .
            '}';
    }