So i would really like to modify this example:
http://openlayers.org/en/v3.0.0/examples/tissot.html?q=circle
Problem is that when I try to apply it to my map it doesn't work, probably because I use OSM style which is not spherical:
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
}),
new ol.layer.Vector({
source: vectorSource
})
],
renderer: 'canvas',
target: 'map',
view: new ol.View({
center: ol.proj.transform([2.1833, 41.3833], 'EPSG:4326', 'EPSG:3857'),
zoom: 2
})
});
And for the question: how to create circular polygon?
As I can see, there are two choices:
-
Somehow convert geom.Circle in geom.Polygon, which I can't do, based on my noob level
-
Create my own function to do that, something like openlayers 2:
OpenLayers.Geometry.Polygon.createRegularPolygon = function(origin, radius, sides, rotation) {
var angle = Math.PI * ((1/sides) – (1/2));
if(rotation) {
angle += (rotation / 180) * Math.PI;
}
var rotatedAngle, x, y;
var points = [];
for(var i=0; i
Has anyone got to the same point in their GIS master life? Which one is better? or is there a hidden path, that only Wise and Strong ones can see? Help me please!
Best Answer
As others have correctly pointed out, the GeoJSON and WKT formats do not support circular geometries in any way. Circles are not in the KML specification either. This makes it a pain when trying to write out a map frame to KML, GeoJSON or WKT.
OpenLayers v3 does have a way to approximate a circle with a polygon, but it isn't pretty as it involves converting to great circle distance. See the API reference for the
ol.geom.Polygon.circular
method here: http://openlayers.org/en/v3.5.0/apidoc/ol.geom.Polygon.html#circularAn example of the
ol.geom.Polygon.circular
method is shown below, but can also be seen in this OpenLayers tissot indicatrix example.Alternatively, you can use
fromCircle
which, at the time of this post, is experimental.For something that you can play with, see my jsFiddle here: https://jsfiddle.net/a1syw4od/9/