저는 OpenLayers와 JavaScript에 매우 익숙합니다. 다음과 같은 문제가 있습니다.openlayers에서 다각형 좌표를 설정하는 방법은 무엇입니까?
OpenLayers를 사용하여지도에서 시각화하려는 점의 좌표를 나타내는 .csv
테이블이 있습니다. 나는 OpenLayers 페이지에서 다음의 예를 발견
,
https://openlayers.org/en/latest/examples/polygon-styles.html
그러나, 나는 거기 좌표의 표현을 이해할 수 없었다. 좀 더 구체적으로 말하자면, e
은 좌표가 [-5e6, 6e6]
인 것을 의미합니다.
그러나, 나는 내 좌표를 사용하여 내지도에 간단한 사각형을 그릴려고했는데, 그냥 다음과 같은지도의 중앙에, 나에게 포인트를주는 : 그래서
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
})
});