Since there's no str_replace() in eZ Publish (aside from a custom template operator for which there are extensions), you could run it through explode and then implode to remove those line breaks:
{set $a = $a|explode("\n")|implode()}
For your case you might need some of those extra operators too:
call to javascript: map.addOverlay(createMarker(...., '{$a | str_replace("\r","") | str_replace("\n","")}' ));
And now it works. However, I prefer your version as then I would not have to install the extension swark and rebuild the ezgenerateautoload which is giving me other headaches, e.g. how to run php command on remote web-hosting server when only having ftp access?