圆圈没有在OpenLayers中显示
问题描述:
对OpenLayers极为新颖,并尝试在点击原点周围的地图上绘制圆圈。我有这个代码 -圆圈没有在OpenLayers中显示
circleLayer = new OpenLayers.Layer.Vector "Circle Search"
circle = new OpenLayers.Geometry.Polygon.createRegularPolygon(
new OpenLayers.Geometry.Point(lat,lon),
100,
30
)
console.log(circle)
feature = new OpenLayers.Feature.Vector(circle)
circleLayer.addFeatures(feature)
mapApp.map.openLayersMap.addLayer circleLayer
但是圈子没有出现,我不知道为什么。谁能告诉我?
答
您是否将您的纬度转换为您的地图使用的投影?
测试: 尝试使用0,0作为lon,纬度更大的圆圈,看它是否出现在非洲中东部的海岸附近。
如果是这样的问题,那么这里就是你该怎么办变换:
添加在顶部:
projLatLon = new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
projMap = new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator Projection
那么您的示例代码的第三行变为:
new OpenLayers.Geometry.Point(lat,lon).transform(projLatLon,projMap),