[英]Loading WMS in Vuejs with OpenLayers
我正在尝试从 Vue.js 中的本地主机 Geoserver 读取 WMS 层。 我在与 vue.js 不同的端口上运行 Geoserver。
我应该如何在 Vue JS 中加载我的 WMS 层,就像在这个例子中一样: https : //vuelayers.github.io/#/docs/component/tile-layer
<template>
<vl-map :load-tiles-while-animating="true" :load-tiles-while-interacting="true" data-projection="EPSG:4326" style="height: 400px">
<vl-view :zoom.sync="zoom" :center.sync="center" :rotation.sync="rotation"></vl-view>
<vl-layer-tile>
<vl-source-sputnik></vl-source-sputnik>
</vl-layer-tile>
<vl-layer-tile id="wmts">
<vl-source-wmts :attributions="attribution" :url="url" :layer-name="layerName" :matrix-set="matrixSet" :format="format"
:style-name="styleName"></vl-source-wmts>
</vl-layer-tile>
</vl-map>
</template>
//////////////////////////////// For WMS SOURCES
<script>
export default {
data () {
return {
zoom: 4,
center: [50, 40],
rotation: 0,
cmp: 'vl-source-wms',
url: 'http://localhost:8081/geoserver/cite/wms',
layers: 'cite:vnm_polbnda_adm3_2014_pdc',
extParams: { TILED: true },
serverType: 'geoserver',
}
},
}
</script>
在我的浏览器中:访问 XMLHttpRequest at ' http://192.168.1.23:3000/sockjs-node/info?t=1578388235952 ' from origin ' http://localhost:3000 ' has been Blocked by CORS policy: The value of当请求的凭据模式为“包含”时,响应中的“Access-Control-Allow-Origin”标头不能是通配符“*”。 XMLHttpRequest 发起的请求的凭证模式由 withCredentials 属性控制。
您有 CORS 问题(CORS 代表跨域资源共享)。 您需要在您的服务器上启用 CORS。
devServer: {
...
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
"Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
}
}
可以在此处找到一些用于启用 CORS 的好资源:
https://scotch.io/courses/build-an-online-shop-with-vue/enabling-cors
如果你有一个 PHP 后端,你可以只包含以下标题:
header(“Access-Control-Allow-Origin: *”);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.