[英]Openlayers Styling WMS with SLD from external file problem
I am facing with problem how to use style in SLD format to styling WMS from geoserver.我面临如何使用 SLD 格式的样式从地理服务器设置 WMS 样式的问题。 I would like to add SLD definition as variable ${sld} from external.js file:我想将 SLD 定义添加为 external.js 文件中的变量 ${sld} :
const sld = `<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:gml="http://www.opengis.net/gml" version="1.0.0" xmlns:ogc="http://www.opengis.net/ogc" xmlns:sld="http://www.opengis.net/sld">
<sld:UserLayer>
...
<sld:ColorMap type="ramp">
<sld:ColorMapEntry quantity="0" label ="0" color="#000000"/>
<sld:ColorMapEntry quantity="1200" label="1200" color="#d7191c"/>
</sld:ColorMap>
...
</sld:UserLayer>
</StyledLayerDescriptor>
export default sld
The code in main.js is: main.js 中的代码是:
import sld from "./SLD_styles/style1"
...
const wmsSource2 = new TileWMS({
url: "https://...",
params: {
LAYERS: "workSpace:layerName",
STYLES: undefined,
SLD_BODY: encodeURIComponent(sld),
},
serverType: "geoserver",
crossOrigin: "anonymous",
})
I've tried so many ways to achive that but without success.我已经尝试了很多方法来实现这一目标但没有成功。 Can someone halp me how exactly SLD should look like?有人能告诉我 SLD 到底应该是什么样子吗? Probably I have problem with matching names, isDefault parameter and so.可能我在匹配名称、isDefault 参数等方面有问题。
Thanks, Piotr谢谢,彼得
Import sld variable works fine.导入 sld 变量工作正常。 I have tried to import from.sld file using SLD: url, with out success as well.我尝试使用 SLD 导入 from.sld 文件:url,但也没有成功。
Checked "external styles" and "library mode" (part of the SLD spec) in the GeoServer documentation:检查 GeoServer 文档中的“外部样式”和“库模式”(SLD 规范的一部分):
https://docs.geoserver.org/maintain/en/user/styling/sld/working.html#external-styles https://docs.geoserver.org/maintain/en/user/styling/sld/working.html#external-styles
In particular, your style is likely not being used because you're in library mode:特别是,您的样式可能未被使用,因为您处于库模式:
Here is a working example using the style name in the URL:这是一个使用 URL 中样式名称的工作示例:
https://gs-main.geosolutionsgroup.com/geoserver/topp/wms?service=WMS&version=1.1.0&request=GetMap&layers=topp%3Astates&bbox=-124.73142200000001%2C24.955967%2C-66.969849%2C49.371735&width=768&height=330&srs=EPSG%3A4326&styles=popgray&format=application/openlayers&sld=https://gs-main.geosolutionsgroup.com/geoserver/styles/popgray.sld https://gs-main.geosolutionsgroup.com/geoserver/topp/wms?service=WMS&version=1.1.0&request=GetMap&layers=topp%3Astates&bbox=-124.73142200000001%2C24.955967%2C-66.969849%2C48&hersight335&shersight71 =EPSG%3A4326&styles=popgray&format=application/openlayers&sld=https://gs-main.geosolutionsgroup.com/geoserver/styles/popgray.sld
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.