2014-11-30 14 views

cevap

12

ol.geom.Polygon yapıcısını kullanmanız gerekir. Bu kurucu bir dizi halka bekler, her bir halka bir dizi koordinattır. Şimdi bir bakış açısıyla bir harita bu çokgen görüntülemek istiyorsanız

// A ring must be closed, that is its last coordinate 
// should be the same as its first coordinate. 
var ring = [ 
    [a[0].lng, a[0].lat], [a[1].lng, a[1].lat], 
    [a[2].lng, a[2].lat], [a[0].lng, a[0].lat] 
]; 

// A polygon is an array of rings, the first ring is 
// the exterior ring, the others are the interior rings. 
// In your case there is one ring only. 
var polygon = new ol.geom.Polygon([ring]); 

: Senin durumunda

bu çokgen oluşturmak nasıl olduğunu (bu a adlı lnglat çiftlerinin dizinizi varsayar) kimin projeksiyonu Web Merkatör (EPSG:3857) Eğer EPSG:3857 için EPSG:4326 den poligonu dönüşümü gerekir:

polygon.transform('EPSG:4326', 'EPSG:3857'); 

Ve aslında w gereken poligonu gösterilecek

// Create feature with polygon. 
var feature = new ol.Feature(polygon); 

// Create vector source and the feature to it. 
var vectorSource = new ol.source.Vector(); 
vectorSource.addFeature(feature); 

// Create vector layer attached to the vector source. 
var vectorLayer = new ol.layer.Vector({ 
    source: vectorSource 
}); 

// Add the vector layer to the map. 
map.addLayer(vectorLayer); 
+0

Hızlı not:: OL3.5 ile kullanın lütfen başka katman olarak haritaya eklemek, hangi (aşağıya bakınız, gerçekten bir vektör kaynağı) bir özellik nesnesi içinde rap ve bir vektör katmanına eklemek ol.geom.Polygon üzerinde .applyTransform (ol.proj.getTransform ('EPSG: 4326', 'EPSG: 3857')). –

İlgili konular