我正在尝试在openlayers 3中执行基于规则的样式,这是我的代码:
<!DOCTYPE html>
<html>
<head>
<title>CONFIG</title>
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://openlayers.org/en/v3.8.2/css/ol.css" type="text/css">
<script src="http://openlayers.org/en/v3.8.2/build/ol.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<div id="map" class="map"></div>
</div>
</div>
<script>
var layerStyle = {
default: {
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(0, 0, 0, 1.0)',
width: 0.5
}),
fill: new ol.style.Fill({
color: 'rgba(0, 255, 0, 0.5)'
})
})
},
filter: [{
type: "AND",
rules: [{
type: "==",
property: "CODE",
value: "16"
}, {
type: "==",
property: "NAME",
value: "CHIKMAGALUR"
}],
symbolizers: {
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(0, 255, 0, 0.5)',
width: 0.5
}),
fill: new ol.style.Fill({
color: 'red'
})
})
}
} ]
};
var geojson_layer = new ol.layer.Vector({
source: new ol.source.Vector({
url: 'file.geojson',
format: new ol.format.GeoJSON()
}),
});
var vectorLayer = new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(geojsonObject)
});
if ('CODE'=='16' && 'NAME'=='CHIKMAGALUR') {
style: symbolizers;
}
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
}),
vectorLayer,
],
target: 'map',
controls: ol.control.defaults({
attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
collapsible: false
})
}),
view: new ol.View({
center: [0, 0],
zoom: 5
})
});
</script>
</body>
</html>
我正在尝试从符号设备中获取样式,但我收到错误。和openlayer2一样,我使用过滤器进行AND操作,但我坚持了下来。有人可以帮我吗?
答案 0 :(得分:2)
在OL3中,矢量图层具有样式属性,可以是Style对象,Style对象数组或返回Style对象或Style对象数组的函数。您可能希望将样式函数用于您要执行的操作。
请参阅以下示例,了解如何执行此操作:
http://openlayers.org/en/v3.20.1/examples/earthquake-clusters.html