【发布时间】:2015-08-27 21:49:35
【问题描述】:
我正在尝试绘制一个与国际日期变更线重叠的简单矩形多边形。目前在创建多边形时,它会以相反的方向缠绕。
完整示例:http://jsfiddle.net/mcroteau/dkk2yu3L/
期望的输出:
实际输出:
Javascript:
var wgs84Proj = new ol.proj.Projection({ code : "EPSG:4326" });
var origProj = new ol.proj.Projection({ code : "EPSG:900913" });
var mapTile = new ol.layer.Tile({
source: new ol.source.OSM()
});
var convertedCoordinates = [];
var unformattedCoordinates = [[175, 70], [175, 60], [-160, 60], [-160, 70]];
$(unformattedCoordinates).each(function(index, coordinate){
var lat = coordinate[0];
var lon = coordinate[1];
var circle = new ol.geom.Circle([lat, lon])
circle.transform(wgs84Proj, origProj);
convertedCoordinates.push(circle.getCenter());
});
var polygonGeometry = new ol.geom.Polygon([convertedCoordinates])
var polygonFeature = new ol.Feature({ geometry : polygonGeometry });
var vectorSource = new ol.source.Vector();
vectorSource.addFeature(polygonFeature);
var vectorLayer = new ol.layer.Vector({
source: vectorSource
});
var mapView = new ol.View({
center: [-19000000, 9500000],
zoom: 3
})
var map = new ol.Map({
layers : [mapTile],
target : 'map',
view : mapView
});
map.addLayer(vectorLayer);
我不确定是否存在我在 OpenLayers 3 API 中遗漏的配置设置或必须对数据点进行的转换。任何指导将不胜感激。
更新的工作示例
【问题讨论】:
-
我不确定您尝试做什么,但请看一下带有坐标的地图 - 您绘制的矩形正是属于您的坐标的那个。你有参考图片来展示你想要达到的目标吗?
-
无需创建 Circle 对象,只需使用“var xy = ol.proj.transform(coordinate, 'EPSG:4326', 'EPSG:3857')” 然后 push(xy)。此外,您还颠倒了经纬度名称,但这没关系,只是名称错误。