<!DOCTYPE html>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>地图 - 导出为图片</title>
  <style type="text/css">
    .pane a{display:block;color:#fff;text-align:left;padding:0 10px;min-width:28px;min-height:28px;float:left}
  <link rel="stylesheet" href="">
  <script type="text/javascript" src=""></script>

    <div id="map" class="container"></div>
    <div class="pane"><a href="javascript:save();">Export image</a></div>

      var map = new maptalks.Map('map', {
        center: [-0.113049,51.498568],
        zoom: 14,
        baseLayer: new maptalks.TileLayer('base', {
          // crossOrigin : 'anonymous', // required if renderer is canvas
          // renderer : 'canvas',
          urlTemplate: 'https://{s}{z}/{x}/{y}.png',
          subdomains: ['a','b','c','d'],
          attribution: '&copy; <a href="">OpenStreetMap</a> contributors, &copy; <a href="">CARTO</a>'

      new maptalks.VectorLayer('v', new maptalks.Marker(map.getCenter()))

      // Export map to an image
      // External image(tiles, marker images) hosts need to support CORS
      function save() {
        var data = map.toDataURL({
          'mimeType' : 'image/jpeg', // or 'image/png'
          'save' : true,             // to pop a save dialog
          'fileName' : 'map'         // file name