gpt4 book ai didi

openlayers - 如何更改 OpenLayers 样式?

转载 作者:行者123 更新时间:2023-12-02 03:48:15 27 4
gpt4 key购买 nike

我对网络制图非常非常陌生。我有一个由 PostGis 数据库的形状文件制作的 OpenLayers map ,有一个矢量图层,它有默认样式(GeoServer SLD),但我想在用户单击刷新按钮时更改矢量图层的样式。我在网上搜索,没有找到简单明了的例子。任何人都请帮助我,或者有人想做同样的事情并为此找到了简单的教程?非常感谢任何帮助。

<script type="text/javascript">
var map;
function init() {
var bounds = new OpenLayers.Bounds(
68.089442, 6.752729,
97.407576, 37.072537);

var options = {
controls: [ new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoom()
],

maxExtent: bounds,
maxResolution: 0.11843675,
projection: "EPSG:4326",
units: 'degrees'
};


map = new OpenLayers.Map ("map", options );

var india = new OpenLayers.Layer.WMS(
"cite:india_state - Tiled",
"http://localhost:8080/geoserver/cite/wms",
{LAYERS: 'cite:india_state',STYLES: 'style',
//format: format,
tiled: true,
tilesOrigin: map.maxExtent.left + ',' + map.maxExtent.bottom
},
{buffer: 0, displayOutsideMaxExtent: true,
isBaseLayer: true,
yx: {'EPSG:4326' : true}
}
);

var style = new OpenLayers.Style();
//rule used for all polygons
var rule_fsa = new OpenLayers.Rule({
symbolizer: {
fillColor: "#ff9a9a",
fillOpacity: 0.5,
strokeColor: "#000000",
strokeWidth: 1,
strokeDashstyle: "dash",
label: "${name}",
labelAlign: "cc",
fontColor: "#333333",
fontOpacity: 0.9,
fontFamily: "Arial",
fontSize: 14
}
});

var rule_highlight = new OpenLayers.Rule({
filter: new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.EQUAL_TO,
property: "classification",
value: "1",
}),

symbolizer: {
fillColor: "#FF7144",
fillOpacity: 0.6,
strokeColor: "#FF0000",
strokeWidth: 2,
strokeDashstyle: "solid",
label: " ${name}",
labelAlign: "cc",
fontColor: "#000000",
fontOpacity: 1,
fontFamily: "Arial",
fontSize: 16,
fontWeight: "600"
}
});

style.addRules([rule_fsa, rule_highlight]);

var polygon = new OpenLayers.Layer.Vector("Polygon", {
Style: 'style',
rendererOptions: {zIndexing: true}
});

map.addLayers([india,polygon]);

map.zoomToMaxExtent();
}
</script>

最佳答案

矢量图层可以关联一个StyleMap,它可以确定您的特征在不同意图下的显示方式:默认状态、选择特征时、编辑时等。

查看样本:http://acanimal.github.io/Openlayers-Cookbook/请参阅第 7 章使用 StyleMap 和渲染意图代码。该代码创建一个空矢量图层,您可以在其中添加功能并重新定义默认和选择意图。

我还向您推荐 OpenLayers Cookbook http://www.packtpub.com/openlayers-create-gis-web-applications-cookbook/book

干杯。

关于openlayers - 如何更改 OpenLayers 样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15515395/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com