【问题标题】:Return canvas (image) in openlayers 4在openlayers 4中返回画布(图像)
【发布时间】:2017-07-31 13:20:30
【问题描述】:

该示例显示了如何将按钮单击事件绑定到画布,然后它返回图像Example。我该如何更改它,当我使用带有永久链接的调用 openlayers 时,它会自动返回该图像?我想使用来自 c++ 程序的简单获取请求来获取图像。我有 例如“#map=12/1085115.28/6035092.46/0”作为解析参数。有任何想法吗? 谢谢和问候 梅丽娜

到目前为止,我已经完成了参数解析

<!DOCTYPE html>
<html>
  <head>
    <title>OpenStreetMap</title>
    <link rel="stylesheet" href="https://openlayers.org/en/v4.2.0/css/ol.css" type="text/css">
    <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
    <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
    <script src="https://openlayers.org/en/v4.2.0/build/ol.js"></script>
  </head>
  <body>
    <div id="map" class="map"></div>
    <script>
        var center = [0,0];
        var zoom = 0;
        var rotation = 0;
        if (window.location.has !== '')
        {
         var hash = window.location.hash.replace('#map=', '');
         var parts = hash.split('/');
         console.log (parts);
         if (parts.length === 4)
         {
            zoom = parseInt(parts[0],10);
            center = [
             parseFloat(parts[1]),
             parseFloat(parts[2])
             ];
            rotation = parseFloat(parts[3]);
         var rotation = 0;
        }
    }
      var openStreetMapLayer = new ol.layer.Tile({
        source: new ol.source.OSM({
          attributions: [
            'All maps © <a href="http://www.openstreetmap.org">openStreetMapLayer</a>',
            ol.source.OSM.ATTRIBUTION
          ],
          opaque: false,
        //  url: '<myosmserver>/hot/{z}/{x}/{y}.png'
        })
      });


      var map = new ol.Map({
        layers: [
          openStreetMapLayer
        ],
        target: 'map',
        controls: ol.control.defaults({
          attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
            collapsible: false
          })
        }),
        view: new ol.View({
          maxZoom: 20,
          center: center,
          zoom: zoom
        })
      });

    </script>
  </body>
</html>

【问题讨论】:

    标签: javascript canvas openlayers openlayers-3 html2canvas


    【解决方案1】:

    您不能添加以某种方式将地图下载为图像的链接。你需要在某个地方渲染它。

    这就是它的工作原理。当 Openlayers 呈现地图时,它会在 HTML 画布元素中呈现它。下载功能不是 Openlayers 功能,而是 HTML 画布功能。画布有 API 来拍摄当前画布的快照。您可以将其下载为图像。

    您可以在浏览器中渲染地图,也可以在服务器端渲染它。我没有尝试在服务器上渲染 Openlayers 地图,但应该可以。

    【讨论】:

      猜你喜欢
      • 2018-03-05
      • 2015-01-03
      • 2022-11-03
      • 2016-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多