Gaps between adjacent OpenLayers 3 polygons
by Jose GĂłmez
HTML
<link rel="stylesheet" href="http://openlayers.org/en/v3.15.1/css/ol.css">
<script src="http://openlayers.org/en/v3.15.1/build/ol.js"></script>
<div id="map2d" style="width:400px;height:400px;float:left;"></div>
JavaScript
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.MapQuest({layer: 'sat'})
})
],
target: 'map2d'
});
map.getView().setCenter(ol.proj.transform([-20, 75], 'EPSG:4326', 'EPSG:3857'));
map.getView().setZoom(3.5);
var geometry = new ol.geom.MultiPolygon([
[ [ [-50, 70], [ 20, 70], [ 20, 69], [-50, 69], [-50, 70] ] ],
[ [ [-50, 71], [ 20, 71], [ 20, 70], [-50, 70], [-50, 71] ] ],
[ [ [-50, 72], [ 20, 72], [ 20, 71], [-50, 71], [-50, 72] ] ],
[ [ [-50, 73], [ 20, 73], [ 20, 72], [-50, 72], [-50, 73] ] ],
[ [ [-50, 74], [ 20, 74], [ 20, 73], [-50, 73], [-50, 74] ] ],
[ [ [-50, 75], [ 20, 75], [ 20, 74], [-50, 74], [-50, 75] ] ],
[ [ [-50, 76], [ 20, 76], [ 20, 75], [-50, 75], [-50, 76] ] ],
[ [ [-50, 77], [ 20, 77], [ 20, 76], [-50, 76], [-50, 77] ] ],
[ [ [-50, 78], [ 20, 78], [ 20, 77], [-50, 77], [-50, 78] ] ],
[ [ [-50, 79], [ 20, 79], [ 20, 78], [-50, 78], [-50, 79] ] ],
]);
geometry.transform('EPSG:4326', 'EPSG:3857');
var vectorLayer = new ol.layer.Vector({
map: this.map,
source: new ol.source.Vector({
features: [new ol.Feature({
geometry: geometry
})]
}),
style: new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(0, 128, 255, 0.5)'
})
})
});
map.addLayer(vectorLayer);