I have a position (lon, lat) and a radius. The radius is a float value and is in the km (kilometer) unit.
For example: Lat=46.92, Lon=7.95 and radius 5km.
Now my goal is to draw a circle or point at this position with this radius.
I'm using the follow transformation:
function GetLonLatObj(lat, lon) {
var lonLat = new OpenLayers.LonLat( lon ,lat )
.transform(
new OpenLayers.Projection("EPSG:4326"), // Transformation aus dem Koordinatensystem WGS 1984
map.getProjectionObject() // in das Koordinatensystem 'Spherical Mercator Projection'
);
return lonLat
}
To draw the circle on the right position is no problem. Unfortunately the circle is to small and has no radius of 5 km on the map.
Here is my code:
var map = new OpenLayers.Map("mapdiv");
map.addLayer(new OpenLayers.Layer.OSM('OpenStreetMap',
"https://a.tile.openstreetmap.org/${z}/${x}/${y}.png",
"https://b.tile.openstreetmap.org/${z}/${x}/${y}.png",
"https://c.tile.openstreetmap.org/${z}/${x}/${y}.png"
));
map.addLayer(vectorNotamLayer);
zoom = 12;
var vectorNotamLayer = new OpenLayers.Layer.Vector("Simple Geometry", {
styleMap: new OpenLayers.StyleMap({
'default': {
pointRadius: "${Radius}",
label : "${Title}",
fontSize: "20px",
fontWeight: "bold",
labelAlign: "cm",
labelYOffset: -10,
fillOpacity: 0.4,
labelOutlineWidth: 3
}
}),
});
var lon = 7.95;
var lat = 46.92;
var radius = 5;
var upper = item.upper;
var lower = item.lower;
var number = item.number;
var title = series + number + " " + lower + "-" + upper;
var latLonObj = GetLonLatObj(lat, lon);
var point = new OpenLayers.Geometry.Point(latLonObj.lon, latLonObj.lat);
var pointFeature = new OpenLayers.Feature.Vector(point);
pointFeature.attributes = {
Title: title,
Radius: radius,
};
vectorNotamLayer.addFeatures([pointFeature]);
Can sombody help me here please?
Edit:
I changed the code from:
var pointFeature = new OpenLayers.Feature.Vector(point);
pointFeature.attributes = {
Title: title,
Radius: radius,
};
To
var poly = OpenLayers.Geometry.Polygon.createRegularPolygon
(
point,
radius,
36,
0
);