# How to create multipoygon in Openlayers 4? [closed]

I want to create a separate layer in Openlayers 4 with multipolygon geometry. I thought, it's enough to know a few coordinates, put it in an array and create the geometry. After reading documentations, I've no idea to create a multipolygon in Version 4.

Any ideas? Examples? Please let me know.

I solved the Problem myself. Here are some Details: I wanted to Show a polygon with hole. So i need a multipolygon. First, I draw a rectangle as polygon with coordinates and show them in the map. Second, I edit the polygon to multipolygon and added a second polygon as hole. I didn't find a simple examples, how to do this. Here it is...

``````//area from database in ESPG:4258
var gebiet = '10.59 53.36, 10.73 53.42, 11.07 53.14, 12.11 52.87, 11.90 53.24, 12.04 53.37, 12.33 53.31, 12.51 53.95, 11.92 53.98, 11.47 53.75, 10.77 53.78, 10.95 53.64, 10.59 53.36';
var style=
new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'gray',
width: 1
}),
fill: new ol.style.Fill({
color: 'rgba(80, 80, 80, 0.2)'
})
});

//import data and parse to array
function parseData(inputData, rowSeparator, colSeparator){
var outputData = inputData.split(rowSeparator);
parsedData =  new Array(outputData.length);
for (var i = 0; i < parsedData.length; ++i) {
parsedData[i] = outputData[i].split(colSeparator);
}

return parsedData;
}

//create layer
function createLayer(features, id, style){
//console.log('in func createLinestringLayer');
return new ol.layer.Vector({
source: new ol.source.Vector({
features: [new ol.Feature({
geometry: features,
id: id,
name: 'Line'
})]
}),
style: style
})
}

//set features
function setFeatures(inputData, simplify){
var parsedData = parseData(inputData, ', ', ' ');
var lineString = new ol.geom.LineString();

for (var i = 0; i < parsedData.length; ++i) {
var coordinates = ol.proj.fromLonLat([parseFloat(parsedData[i][0]), parseFloat(parsedData[i][1])]);
lineString.appendCoordinate(coordinates);
}

if(simplify > 0){
lineString = lineString.simplify(simplify);
}

return lineString;
}

var  geomPoly = new ol.geom.MultiPolygon([
[
setFeatures(gebiet, 500).getCoordinates(),
[[0.5e6, 7.52e6], [2e6, 7.52e6], [2e6, 6.5e6], [0.5e6, 6.5e6], [0.5e6, 7.52e6]]
]
]);