'Render the Map
- this is primarily done by inserting a lot of JavaScript
- CSS loaded as-standard to avoid delays in page loading
- HTML added in init() as a component'

def xml(self):

    if (not self.setup):
        self._setup()
    s3_include_ext()
    dumps = json.dumps
    s3 = current.response.s3
    js_global = s3.js_global
    js_global_append = js_global.append
    i18n_dict = self.i18n
    i18n = []
    i18n_append = i18n.append
    for (key, val) in i18n_dict.items():
        line = ('i18n.%s="%s"' % (key, val))
        if (line not in i18n):
            i18n_append(line)
    i18n = '\n'.join(i18n)
    if (i18n not in js_global):
        js_global_append(i18n)
    globals_dict = self.globals
    js_globals = []
    for (key, val) in globals_dict.items():
        line = ('S3.gis.%s=%s' % (key, dumps(val, separators=SEPARATORS)))
        if (line not in js_globals):
            js_globals.append(line)
    js_globals = '\n'.join(js_globals)
    if (js_globals not in js_global):
        js_global_append(js_globals)
    debug = s3.debug
    scripts = s3.scripts
    if s3.cdn:
        if debug:
            script = '//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore.js'
        else:
            script = '//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js'
    elif debug:
        script = URL(c='static', f='scripts/underscore.js')
    else:
        script = URL(c='static', f='scripts/underscore-min.js')
    if (script not in scripts):
        scripts.append(script)
    if self.opts.get('color_picker', False):
        if debug:
            script = URL(c='static', f='scripts/spectrum.js')
        else:
            script = URL(c='static', f='scripts/spectrum.min.js')
        if (script not in scripts):
            scripts.append(script)
    if debug:
        script = URL(c='static', f='scripts/S3/s3.gis.loader.js')
    else:
        script = URL(c='static', f='scripts/S3/s3.gis.loader.min.js')
    if (script not in scripts):
        scripts.append(script)
    callback = self.callback
    map_id = self.id
    options = self.options
    projection = options['projection']
    try:
        options = dumps(options, separators=SEPARATORS)
    except Exception as exception:
        current.log.error(('Map    %s    failed    to    initialise' % map_id), exception)
    plugin_callbacks = '\n'.join(self.plugin_callbacks)
    if callback:
        if (callback == 'DEFAULT'):
            if (map_id == 'default_map'):
                callback = ('S3.gis.show_map(null,%s)' % options)
            else:
                callback = ('S3.gis.show_map(%s,%s)' % (map_id, options))
        else:
            js_global_append(('S3.gis.options["%s"]=%s' % (map_id, options)))
        script = URL(c='static', f='scripts/yepnope.1.5.4-min.js')
        if (script not in scripts):
            scripts.append(script)
        if plugin_callbacks:
            callback = ('%s\n%s' % (callback, plugin_callbacks))
        callback = ('function(){%s}' % callback)
    else:
        js_global_append(('S3.gis.options["%s"]=%s' % (map_id, options)))
        if plugin_callbacks:
            callback = ('function(){%s}' % plugin_callbacks)
        else:
            callback = 'null'
    loader = ('s3_gis_loadjs(%(debug)s,%(projection)s,%(callback)s,%(scripts)s)' % dict(debug=('true' if s3.debug else 'false'), projection=projection, callback=callback, scripts=self.scripts))
    jquery_ready = s3.jquery_ready
    if (loader not in jquery_ready):
        jquery_ready.append(loader)
    return super(MAP, self).xml()
