Search code examples
javascriptd3.jsgisesriarcgis-js-api

Draw a circle on gisMap


I dont know how can i draw a circle on gismap.

After click on button function get a radius for circle (val). If radius is == 1 then i want to draw circle on radius 1 on the map using this cord as a center of circle (21.1, 52.14).

How do this using d3.js?

Code:

function map()
{
      var map;

      require(["esri/map", "dojo/domReady!"], function(Map) {
        map = new Map("map", {
          basemap: "topo",  //For full list of pre-defined basemaps, navigate to http://arcg.is/1JVo6Wd
          center: [14.70, 52.53], // longitude, latitude
          zoom: 6
        });
      });

}

    function DrawCircle()
    {
        var val = document.getElementById("InputMin1").value;

   if(val == 1)
    {
        var svg = d3.select('svg');
        var originX = 21.1; 
        var originY = 52.14;
        var outerCircleRadius = 100;

        var outerCircle = svg.append("circle").attr({
            cx: originX,
            cy: originY,
            r: outerCircleRadius,
            fill: "none",
            stroke: "black"
        });
    }

}


Solution

  • Well, As I am understanding you just want to add a circle of certain distance on the esri map.

    Below running sample draw a circle on a center (21.1, 52.14).

    var map;
    
          require(["esri/map", "esri/geometry/Circle", "esri/layers/GraphicsLayer","esri/graphic", "esri/units", "esri/geometry/Point", "esri/symbols/SimpleFillSymbol", "esri/symbols/SimpleLineSymbol", "esri/Color"], function(Map, Circle,GraphicsLayer, Graphic, Units, Point,SimpleFillSymbol, SimpleLineSymbol, Color) {
            map = new Map("map", {
              basemap: "topo",  
              center: [14.70, 52.53], // longitude, latitude
              zoom: 5
            });
            
           var centerPoint = new Point([21.1, 52.14]);
      var circleGeometry = new Circle({
        center: centerPoint,
        radius: 100,             // add distance
        radiusUnit: Units.MILES, // add distance unit
        geodesic: true
      });
            var gl = new GraphicsLayer({ id: "circles" });
            map.addLayer(gl);
             var sfs = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
        new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT,
        new Color([255,0,0]), 2),new Color([255,255,0,0.25])
      );
            var graphic = new Graphic(circleGeometry,sfs);
            gl.add(graphic);
          });
    html, body, #map {
            height: 100%;
            margin: 0;
            padding: 0;
          }
    <link rel="stylesheet" href="https://js.arcgis.com/3.16/esri/css/esri.css">
     <script src="https://js.arcgis.com/3.16/"></script>
    
         
    
       <body>
        <div id="map"></div>
      </body>

    Hoping this will help you :)