-(AGSPolygon*) circleWithCenter:(AGSPoint*)point radius:(double)radiusInMiles { AGSGeometryEngine *ge = [AGSGeometryEngine defaultGeometryEngine]; // Get a point in a spatial reference whose unit is Meters. AGSPoint *pointToBufferAround = (AGSPoint *)[ge projectGeometry:point toSpatialReference:[AGSSpatialReference webMercatorSpatialReference]]; // Get a "circle" around it, using the unit Meters (1 mile ~= 1609.344 meters). AGSPolygon *circle = [ge bufferGeometry:pointToBufferAround byDistance:radiusInMiles*1609.344]; // Project the output back to the projection of the input point (which is presumably what you're after). circle = (AGSPolygon *)[ge projectGeometry:circle toSpatialReference:point.spatialReference]; return circle; }
-(AGSPolygon*) circleWithCenter:(AGSPoint*)point radius:(double)radiusInMiles { AGSGeometryEngine *ge = [AGSGeometryEngine defaultGeometryEngine]; // Get a "circle" around the point, using the 1 decimal degree ~= 69 miles. AGSPolygon *circle = [ge bufferGeometry:point byDistance:radiusInMiles/69]; return circle; }
You can add this to a graphics layer by converting it into a AGSGraphic object.
Something like below code will help for that:
[self.graphicsLayer addGraphic:[AGSGraphic graphicWithGeometry: [self circleWithCenter:point radius:10.0f] symbol:[AGSSimpleLineSymbol simpleLineSymbol] attributes:nil]];
Can i get the solution for arcgis javascript api for same?
You can do the same thing.
Use the JavaScript GeometryEngine. See geometryEngine GeodesicBuffer which will give you a circular polygon back around the center point, and you can then use Graphic and GraphicsLayer to add these to your MapView.
Sorry i didnt get you.The code below is used for drawing circle and polygon.From this how can we get the radius of the circle which we draw.
require([
"esri/map", "esri/toolbars/draw",
"esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleLineSymbol",
"esri/symbols/SimpleFillSymbol", "esri/geometry/webMercatorUtils", "esri/symbols/CartographicLineSymbol",
"esri/graphic",
"esri/Color", "dojo/dom", "dojo/on", "dojo/domReady!"
], function(
Map, Draw,
SimpleMarkerSymbol, SimpleLineSymbol,
SimpleFillSymbol, WebMercatorUtils, CartographicLineSymbol,
Graphic,
Color, dom, on
) {
var circleArray = [];
map = new Map("mapDiv", {
basemap: "streets",
center: [-148.6234374999831, 62.10143229517362],
zoom: 3
});
map.on("load", initToolbar);
// fill symbol used for extent, polygon and freehand polygon, use a picture fill symbol
// the images folder contains additional fill images, other options: sand.png, swamp.png or stiple.png
var fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASH,
new Color([255, 0, 0]), 2), new Color([255, 255, 0, 0.25])
);
function initToolbar() {
tb = new Draw(map);
tb.on("draw-end", addGraphic);
// event delegation so a click handler is not
// needed for each individual button
on(dom.byId("info"), "click", function(evt) {
if (evt.target.id === "info") {
return;
}
var tool = evt.target.id.toLowerCase();
map.disableMapNavigation();
tb.activate(tool);
});
}
function postGraphic(geometry) {
$("#vertices").text("");
if (geometry.type === 'polygon') {
//Our polygons should have only one ring
var polygon = geometry.rings[0];
var vertices = "";
var latLong = [];
for (var i = 0; i < polygon.length; i++) {
if (geometry.spatialReference.isWebMercator()) {
//Convert to traditional decimal degrees
longLat = WebMercatorUtils.xyToLngLat(polygon[0], polygon[1]);
} else
longLat = [polygon[0], polygon[1]];
x = longLat[0];
y = longLat[1];
var objLatLong = {};
objLatLong.long = longLat[0];
objLatLong.lat = longLat[1];
latLong.push(objLatLong)
//Convert the vertices to the format x,y;x,y;
vertices = vertices + x + ',' + y + ';';
}
$("#vertices").text(vertices);
}
}
var circleFlag = false;
var polygonFlag = false;
$('#Circle').on("click", function() {
circleFlag = true;
polygonFlag = false;
})
;
$('#Polygon').on("click", function() {
circleFlag = false;
polygonFlag = true;
})
;
function addGraphic(evt) {
//deactivate the toolbar and clear existing graphics
tb.deactivate();
map.enableMapNavigation();
// figure out which symbol to use
var symbol;
symbol = fillSymbol;
var graphic = new Graphic(evt.geometry, symbol);
map.graphics.add(graphic);
postGraphic(evt.geometry);
}
});