Really sorry that was issue in network.
radius:1927212.6012732424
The above radius i got when executed that code.
But is this valid value,i doubt that?
Probably best to post a question like that over on the ArcGIS API for JavaScript space. But if your previous require statement worked, this will work too. Since you're getting started with the APIs, perhaps take a look at the Develop sections of the DevLabs and Hackerlabs (including the 3.x labs).
When i try to add
esri/geometry/geometryEngine
under require in the which i posted before ,it is giving me error saying
Uncaught ReferenceError: require is not defined
Can i get your help on this?
No problem . The following should get you the radius in meters:
<SPAN class="keyword token">var</SPAN> radius <SPAN class="operator token">=</SPAN> geometryEngine<SPAN class="punctuation token">.</SPAN><SPAN class="token function">distance</SPAN><SPAN class="punctuation token">(</SPAN>geometry<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getCentroid</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN>geometry<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getPoint</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"meters"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
Thank you this was really useful.
one more clarification.
I saw the below format in tutorial:
geometry.getPoint(0,0)Object {type: "point", x: -15849192.693999259, y: 10478016.378614787, spatialReference: Object}geometry.getCentroid()Object {type: "point", x: -18090547.842482734, y: 10478016.37861477, spatialReference: Object}
How can i proceed with distance function.Sorry i am new to esri map? Can you please clarify this too?
Ah. That's a very different question.
You should use Polygon.getCentroid() to get the centerpoint of the circle.
Then use Polygon.getPoint(0,0) to get a Point from the circle and use geometryEngine.distance() between the two points to determine the radius.
That assumes you used the Draw.CIRCLE type when you call draw.activate().
Please note that you appear to be using the draw-end event and it seems that is deprecated in favor of the draw-complete event.
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); }});
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.
Can i get the solution for arcgis javascript api for same?
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]];
-(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; }
-(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; }
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.