I added a point like this and it works fine, but for polygon it's not working.
var iconFeature = new ol.Feature({
geometry: new ol.geom.Point([8637791.36, 1456487.82]),
name: 'Null Island',
population: 4000,
rainfall: 500
});
var vectorSource = new ol.source.Vector({
features: [iconFeature]
});
var vectorLayer = new ol.layer.Vector({
source: vectorSource
});
My code for polygon is as follows -
var poly = new ol.Feature({
geometry: new ol.geom.Polygon([8623931.28, 1449016.75],[8624007.72, 1458265.63],
[8629358.31, 1458571.37],[8628441.06, 1455284.58],[8625765.77, 1449781.12],[8630275.55, 1453450.09],
[8629281.88, 1452456.42],[8627294.51, 1451080.54],[8625765.76,1449781.11],[8623931.28, 1449016.75]),
name: 'hello',
population: 200,
rainfall: 40
});
var vectorSource1 = new ol.source.Vector({
features: [poly]
});
var vectorLayer1 = new ol.layer.Vector({
source: vectorSource1
});
map.addLayer(vectorLayer,vectorLayer1);
It's not adding polygon to map. Also on click I want a popup showing name, population and rainfall