Draw toolbar: Change default size of Circle or Rectangle on click

4545
5
Jump to solution
06-03-2015 05:33 AM
YohanBienvenue
Occasional Contributor II

Hi,

When you use the CIRCLE or RECTANGLE with the Draw toolbar, if instead of mouse dragging you instead just click in the map, then a Circle or Rectangle with a pre-defined size is displayed in the map.

I'd like to know if I can change this pre-defined size. Could I change it so that the default size of the circle or rectangle is very small, almost like a point. Is this a variable I could override or is this a hardcoded value in the API?

Thanks

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ChrisSmith7
Frequent Contributor

I still wasn't successful to adjust the sizing... Looking at http://js.arcgis.com/3.13/esri/toolbars/draw.js  it seems like it may be set as a default here:

                    case d.CIRCLE:
                        this._clear();
                        this._drawEnd(q.createCircle({
                            center: b,
                            r: 48,
                            numberOfPoints: 60,
                            map: a
                        }));
                        break;

I'm not sure about this, though... Chrome wont let me hot swap changes to the file in memory for some reason. If this is doing what I think it's doing, I'm really not sure if there's a way to adjust this without changing the API...

View solution in original post

5 Replies
ChrisSmith7
Frequent Contributor

If you are using SimpleFillSymbol(), for instance, as CIRCLE, like they do here:

ArcGIS API for JavaScript Sandbox

e.g.

            default:
              symbol = new SimpleFillSymbol();
              break;

Then you might be able to set the style in the constructor, like so:

SimpleFillSymbol | API Reference | ArcGIS API for JavaScript

I'm testing that now to make sure it works...

UPDATE: so it looks like you can change the fill color and style - haven't been able to figure out size yet. May have to see how the default symbol is getting set...

YohanBienvenue
Occasional Contributor II

Ok thanks Chris,

Before digging into the API code I figured I'd ask in case I missed something obvious in the doc. I'll do some more digging and add some breakpoints in the pretty print version of the API code later today, and update my post if I find anything.

If it's a variable I think I could override it, but otherwise it might not be possible. Will see.

0 Kudos
ChrisSmith7
Frequent Contributor

I still wasn't successful to adjust the sizing... Looking at http://js.arcgis.com/3.13/esri/toolbars/draw.js  it seems like it may be set as a default here:

                    case d.CIRCLE:
                        this._clear();
                        this._drawEnd(q.createCircle({
                            center: b,
                            r: 48,
                            numberOfPoints: 60,
                            map: a
                        }));
                        break;

I'm not sure about this, though... Chrome wont let me hot swap changes to the file in memory for some reason. If this is doing what I think it's doing, I'm really not sure if there's a way to adjust this without changing the API...

YohanBienvenue
Occasional Contributor II

Yeah 48 seems to be the magic number here, and it's hardcoded in the API.. bummer. I mean I guess I could override the whole _onClickHandler function itself, but it's a bit dirty and adds maintenance for when the API changes in the future.

So I think I'll try a different approach, and see if I can detect this click on the client side, and hotswap the Draw tool from a Circle/Rectangle to a Point when that happens. It might solve my problem.

Thanks again Chris

Edit: Just for completion, what I ended up doing is this. For my handler the result is that same as if the user had used the point tool.

        onDrawEnd: function(event) {

                if (!event.target._dragged){

                    event.geometry = event.geometry.getCentroid();

                }

                .....

        }

0 Kudos
ChrisSmith7
Frequent Contributor

No problem - that reminds me, Tim created an advanced draw widget Javascript API - Advanced Draw widget  - I wonder if he's thought about extending it to support something like this.

0 Kudos