2016-12-30 44 views
0

私はOpenLayersをしてJavaScriptに非常に新しいです、と私は次のような問題があります。openlayersでポリゴンの座標を設定する方法は?

私はOpenLayersをを使用してマップ上に視覚化したい点の座標を表す.csvテーブルを持っています。私はOpenLayersをページ上の次の例を発見した

https://openlayers.org/en/latest/examples/polygon-styles.html

しかし、私はそこの座標の表現を理解できませんでした。具体的には、私は、例えば[-5e6, 6e6]座標にeはどういう意味かわかりませんでした。

しかし、私は自分の座標を使用して、私のマップ上の単純な四角形をプロットしてみましたが、それは単に以下のように、地図の中心で、私にポイントを与える:だから

https://jsfiddle.net/api/post/library/pure/#&togetherjs=bD5bfPm7vz

Iドン正確に何が間違っているのか分からず、私は何を変えるべきですか?私は座標が書かれているすべての方法だと思うが、確かではない。

そして、これは私のコードです:

var styles = [ 
    new ol.style.Style({ 
    stroke: new ol.style.Stroke({ 
     color: 'blue', 
     width: 3 
    }), 
    fill: new ol.style.Fill({ 
     color: 'rgba(0, 0, 255, 0.1)' 
    }) 
    }), 
    new ol.style.Style({ 
    image: new ol.style.Circle({ 
     radius: 5, 
     fill: new ol.style.Fill({ 
     color: 'orange' 
     }) 
    }), 
    geometry: function(feature) { 
     // return the coordinates of the first ring of the polygon 
     var coordinates = feature.getGeometry().getCoordinates()[0]; 
     return new ol.geom.MultiPoint(coordinates); 
    } 
    }) 
]; 

var geojsonObject = { 
    'type': 'FeatureCollection', 
    'crs': { 
    'type': 'name', 
    'properties': { 
     'name': 'EPSG:3857' 
    } 
    }, 
    'features': [{ 
    'type': 'Feature', 
    'geometry': { 
     'type': 'Polygon', 
     'coordinates': [[[-5e6, 6e6], [-5e6, 8e6], [-3e6, 8e6], 
      [-3e6, 6e6], [-5e6, 6e6]]] 
    } 
    }] 
}; 

var source = new ol.source.Vector({ 
    features: (new ol.format.GeoJSON()).readFeatures(geojsonObject) 
}); 

var layer = new ol.layer.Vector({ 
    source: source, 
    style: styles 
}); 

    var basic = new ol.layer.Tile({ 
     source: new ol.source.OSM() 
    }); 

var map = new ol.Map({ 
    layers: [basic, layer], 
    target: 'map', 
    view: new ol.View({ 
    center: [0, 3000000], 
    zoom: 2 
    }) 
}); 

答えて

0

OK、私は答えを見つけました。 次座標[-5e6, 6e6]はX、Yの形式であり、EPSG:3857投影に基づいています。 XeYX * 10^Yに等しい。通常、openlayersはEPSG:3857投影を使用しますが、経度/緯度座標フォーマットを使用するには、投影:EPSG:4326投影を使用する必要があります。projection: 'EPSG:4326

関連する問題