• <i id='8tzZT'><tr id='8tzZT'><dt id='8tzZT'><q id='8tzZT'><span id='8tzZT'><b id='8tzZT'><form id='8tzZT'><ins id='8tzZT'></ins><ul id='8tzZT'></ul><sub id='8tzZT'></sub></form><legend id='8tzZT'></legend><bdo id='8tzZT'><pre id='8tzZT'><center id='8tzZT'></center></pre></bdo></b><th id='8tzZT'></th></span></q></dt></tr></i><div id='8tzZT'><tfoot id='8tzZT'></tfoot><dl id='8tzZT'><fieldset id='8tzZT'></fieldset></dl></div>

    <legend id='8tzZT'><style id='8tzZT'><dir id='8tzZT'><q id='8tzZT'></q></dir></style></legend>
      <tfoot id='8tzZT'></tfoot>

      <small id='8tzZT'></small><noframes id='8tzZT'>

        • <bdo id='8tzZT'></bdo><ul id='8tzZT'></ul>

      1. 来自“file://"的图像已被跨源资源共享策略阻

        时间:2023-08-09

          <i id='WMVee'><tr id='WMVee'><dt id='WMVee'><q id='WMVee'><span id='WMVee'><b id='WMVee'><form id='WMVee'><ins id='WMVee'></ins><ul id='WMVee'></ul><sub id='WMVee'></sub></form><legend id='WMVee'></legend><bdo id='WMVee'><pre id='WMVee'><center id='WMVee'></center></pre></bdo></b><th id='WMVee'></th></span></q></dt></tr></i><div id='WMVee'><tfoot id='WMVee'></tfoot><dl id='WMVee'><fieldset id='WMVee'></fieldset></dl></div>
            <bdo id='WMVee'></bdo><ul id='WMVee'></ul>
              <tbody id='WMVee'></tbody>
            <tfoot id='WMVee'></tfoot>
          • <legend id='WMVee'><style id='WMVee'><dir id='WMVee'><q id='WMVee'></q></dir></style></legend>

            <small id='WMVee'></small><noframes id='WMVee'>

                • 本文介绍了来自“file://"的图像已被跨源资源共享策略阻止加载:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在使用 leaflet-image.js 从传单地图创建图像.用于创建图像的代码是

                  你能帮我解决这个问题吗?(而且我所有的服务器都是本地托管的.Webserver、mapserver ...)

                  解决方案

                  一般情况下,一个网站中运行的javascript代码不能访问其他网站的资源.但是来自网站的 javascript 应该能够访问来自同一网站的资源.这称为 same-origin policy,并已实施所有主流浏览器(不仅仅是 Chrome).

                  也请阅读 https://developer.mozilla.org/en-US/docs/Same-origin_policy_for_file:_URIs 和 禁用同源策略铬 .

                  最快的解决方案是通过您的 localhost:8080 网站访问图像 - 然后,该网站中的 javascript 将能够访问同一网站中的图像资源.

                  I'm using leaflet-image.js to create an image from a leaflet map. The code used to create the image is the one in the example at https://github.com/mapbox/leaflet-image ie

                  var map = L.mapbox.map('map', 'YOUR.MAPID').setView([38.9, -77.03], 14);
                  leafletImage(map, function(err, canvas) {
                      // now you have canvas
                      // example thing to do with that canvas:
                      var img = document.createElement('img');
                      var dimensions = map.getSize();
                      img.width = dimensions.x;
                      img.height = dimensions.y;
                      img.src = canvas.toDataURL();
                      document.getElementById('images').innerHTML = '';
                      document.getElementById('images').appendChild(img);
                  });
                  

                  The problem is that the image seems to be blocked by some CORS security feature. Below is an image of the Google Chrome console (not that enevn in firefox it does not work)

                  Could you help me with that ? (Also all my server are locally hosted. Webserver, mapserver ...)

                  解决方案

                  In general, javascript code running in a website cannot access resources from other websites. But a javascript from a website should be able to access resources from that same website. This is called same-origin policy, and is implemented by all major browsers (not just Chrome).

                  Do read also https://developer.mozilla.org/en-US/docs/Same-origin_policy_for_file:_URIs and Disable same origin policy in Chrome .

                  The quickest solution is to have the image reachable via your localhost:8080 website - then, the javascript in that website will be able to access a image resource in the same website.

                  这篇关于来自“file://"的图像已被跨源资源共享策略阻止加载:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:单击(右键单击)使用传单地图库获取图像叠加层的 下一篇:如何计算像geojson.io这样的Leaflet中折线的距离?

                  相关文章

                  最新文章

                    <small id='rpUIL'></small><noframes id='rpUIL'>

                  1. <legend id='rpUIL'><style id='rpUIL'><dir id='rpUIL'><q id='rpUIL'></q></dir></style></legend>
                      <i id='rpUIL'><tr id='rpUIL'><dt id='rpUIL'><q id='rpUIL'><span id='rpUIL'><b id='rpUIL'><form id='rpUIL'><ins id='rpUIL'></ins><ul id='rpUIL'></ul><sub id='rpUIL'></sub></form><legend id='rpUIL'></legend><bdo id='rpUIL'><pre id='rpUIL'><center id='rpUIL'></center></pre></bdo></b><th id='rpUIL'></th></span></q></dt></tr></i><div id='rpUIL'><tfoot id='rpUIL'></tfoot><dl id='rpUIL'><fieldset id='rpUIL'></fieldset></dl></div>
                      • <bdo id='rpUIL'></bdo><ul id='rpUIL'></ul>
                      <tfoot id='rpUIL'></tfoot>