0

All I want to do is create a 500m circle around One Tree Hill in Auckland New Zealand, but nothing works for me. The codes I've tried seem to run, I've specified huge radii to check to see if the circles are being drawn elsewhere. I'm out of ideas. Other simple vector features, using the same coordinate system are drawn and visible.

Where am I going wrong?

Here is the simplest code I've used, so far.

var circle = new ol.geom.Circle(ol.proj.fromLonLat([174.7896, -36.9049]), 500);
var circleFeature = new ol.Feature(circle);

var CircleLayer = new ol.layer.Vector({
    source: new ol.source.Vector({
        circleFeature
    }),
    visible: true,
    title: 'Auckland Circle',
    style: new ol.style.Style({
        fill: fillStyle,
        stroke: strokeStyle
    })
    
});
map.addLayer(CircleLayer);

1 Answer 1

3

To add the feature to the vector source you need:

source: new ol.source.Vector({
    features: [circleFeature]
}),

Note that the circle has a radius of 500 projection units. In the EPSG:3857 projection that is 500m on the ground only at the equator. For 500m on the ground elsewhere you would need

ol.geom.Polygon.circular([174.7896, -36.9049], 500).transform('EPSG:4326', 'EPSG:3857')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.