AnsweredAssumed Answered

Draw graphics + Query

Question asked by jay.kapalczynski on Dec 8, 2014
Latest reply on Dec 12, 2014 by jay.kapalczynski

I am using the below code to draw graphics in the map.  Everything works great....

But I want to use those geometries to do spatial queries.  I need to call a specific Feature to get the geometry for the query making the Graphic far to general.   I am trying to select all the features from X Feature that are within the Geometry Drawn.  Noting that there might be other graphics in the map so thats why I am thinking I need to separate them and get them into a Feature that I can reference by itself.

 

I think I need to push the graphics drawn to a Feature?  Not sure how to do this.  Once I have the feature I can use its geometry for the query. 

 

Not sure if I am on the right path here...AND unsure how to convert the graphic to a feature so that its geometry can be used in a query....hope someone can help.

 

 

    // markerSymbol is used for point and multipoint, see http://raphaeljs.com/icons/#talkq for more examples

    var DrawmarkerSymbol = new SimpleMarkerSymbol();

        DrawmarkerSymbol.setPath("M16,4.938c-7.732,0-14,4.701-14,10.5c0,1.981,0.741,3.833,2.016,5.414L2,25.272l5.613-1.44c2.339,1.316,5.237,2.106,8.387,2.106c7.732,0,14-4.701,14-10.5S23.732,4.938,16,4.938zM16.868,21.375h-1.969v-1.889h1.969V21.375zM16.772,18.094h-1.777l-0.176-8.083h2.113L16.772,18.094z");

        DrawmarkerSymbol.setColor(new Color("#00FFFF"));

 

  // http://blogs.esri.com/esri/arcgis/2012/02/03/esri-picture-marker-symbol-generator-for-javascript-developers/

  var DrawPicturemarkerSymbol = new esri.symbol.PictureMarkerSymbol({

  "angle": 0,

  "xoffset": 0,

  "yoffset": 12,

  "type": "esriPMS",

  "url": "http://static.arcgis.com/images/Symbols/Basic/RedStickpin.png",

  "contentType": "image/png",

  "width": 24,

  "height": 24

  });

 

        // lineSymbol used for freehand polyline, polyline and line.

        var DrawlineSymbol = new CartographicLineSymbol(

          CartographicLineSymbol.STYLE_SOLID,

          new Color([255,0,0]), 2,

          CartographicLineSymbol.CAP_ROUND,

          CartographicLineSymbol.JOIN_MITER, 5

        );

        var DrawfillSymbol = new SimpleFillSymbol(

           "solid",

           new SimpleLineSymbol("solid", new Color([255,0,0]), 2),

           new Color([0,128,255,0.25])

         );

 

        function initToolbar() {

          tb = new Draw(app.map);

          tb.on("draw-end", addGraphic);

              // event delegation so a click handler is not

              // needed for each individual button

          on(dom.byId("infoShapefileCreate"), "click", function(evt) {

            if ( evt.target.id === "info" ) {

              return;

            }

            var tool = evt.target.id.toLowerCase();

            app.map.disableMapNavigation();

            tb.activate(tool);

          });

        }

 

  function addGraphic(evt) {

          //deactivate the toolbar and clear existing graphics

          tb.deactivate();

          app.map.enableMapNavigation();

 

          // figure out which symbol to use

          var symbol;

          if ( evt.geometry.type === "point" || evt.geometry.type === "multipoint") {

            symbol = DrawPicturemarkerSymbol;

          } else if ( evt.geometry.type === "line" || evt.geometry.type === "polyline") {

            symbol = DrawlineSymbol;

          }

          else {

            symbol = DrawfillSymbol;

          }

          app.map.graphics.add(new Graphic(evt.geometry, symbol));

    }

Outcomes