我创建了各种图层,如点,线和多边形,现在我想要一个图层切换器在打开的图层3中打开和关闭这些图层。但是我没有。我用来创建点,线和面的代码如下- 对于Point-
var iconFeature = new ol.Feature({
geometry: new ol.geom.Point([8637791.36, 1456487.82]),
name: 'Police Station',
population: 4000,
rainfall: 500
});
var vectorLayer = new ol.layer.Vector({
source: vectorSource,
title: 'point_layer'
});
对于行-
var coordinates = [[8623931.28, 1449016.75],[8637791.36, 1456487.82]];
var layerLines = new ol.layer.Vector({
source: new ol.source.Vector({
features: [new ol.Feature({
geometry: new ol.geom.LineString(coordinates),
name: 'Line',
})]
}),
});
map.addLayer(layerLines);
对于多边形-
var ring = [[77.4700927734375, 12.906190219892437],[77.4707794189453, 12.987162237749473],
[77.5188446044922, 12.989838549012532],[77.51060485839844, 12.961066692801282],
[77.51747131347656, 12.953705916047227],[77.52708435058594, 12.94500653581774],
[77.51815795898438, 12.936306851970144],[77.50030517578125, 12.92426063498786],
[77.486572265625, 12.912883118595701],[77.4700927734375, 12.906190219892437]];
var polygon = new ol.geom.Polygon([ring]);
polygon.transform('EPSG:4326', 'EPSG:3857');
var polygonfeature = new ol.Feature(polygon);
var property = { "name": "Boundary"};
polygonfeature.setProperties(property);
// Create vector source and the feature to it.
var vectorSource1 = new ol.source.Vector();
vectorSource1.addFeature(polygonfeature);
// Create vector layer attached to the vector source.
var vectorLayer1 = new ol.layer.Vector({
source: vectorSource1,
title: 'polygon_layer'
});
// Add the vector layer to the map.
map.addLayer(vectorLayer1);
现在,我正在尝试使用一个层切换器在它们之间进行切换。任何人都可以帮助我.....提前感谢。