JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="http://openlayers.org/en/v3.4.0/css/ol.css">
<script src="http://openlayers.org/en/v3.4.0/build/ol.js"></script>
<h2>My Map!</h2>
<div id="map" class="map"></div>
CSS
.map {
height: 400px;
width: 100%;
}
JavaScript
var polyCoords = [], coords = "95.61,38.60 95.22,37.98 95.60,37.66 94.97,37.65".split(' ');
for (var i in coords) {
var c = coords[i].split(',');
polyCoords.push(ol.proj.transform([parseFloat(c[0]), parseFloat(c[1])], 'EPSG:4326', 'EPSG:3857'));
}
var feature = new ol.Feature({
geometry: new ol.geom.Polygon(polyCoords)
})
console.debug(feature.getGeometry().getCoordinates());
var layer = new ol.layer.Vector({
source: new ol.source.Vector({
features: [feature]
})
});
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM({layer: 'osm'})
}), layer
],
view: new ol.View({
center: ol.proj.transform([95.22, 37.98], 'EPSG:4326', 'EPSG:3857'),
zoom: 4
})
});