Skip to content

Conversation

@ahocevar
Copy link
Member

@ahocevar ahocevar commented May 8, 2015

This pull request adds a geometryFunction config option to ol.interaction.Draw, which gives the application developer control over the geometry that is created from the draw sketch.

Circle draw mode is a good use case where such a hook makes sense. To be able to create a serializable geometry instead of an ol.geom.Circle, a convenience function is added to allow for creation of a regular ol.geom.Polygon geometry representing a circle or - with fewer sides - e.g. a square.

To show how this works, the draw-features.html example can now also draw squares.

@ahocevar ahocevar force-pushed the draw-regular-polygon branch from efcfb6b to e57e74d Compare May 8, 2015 11:19
@ahocevar
Copy link
Member Author

Thanks for any review. @tschaub, I think you expressed interest in this.

ahocevar added 4 commits May 14, 2015 23:24
Since these methods are implemented by all subclasses, it makes sense to
define them in the base class as abstract method.
This allows applications to control the geometry that is created from the
drawing sketch. Will e.g. be useful to create a regular polygon instead of
a circle when in Circle mode.
@bartvde
Copy link
Member

bartvde commented May 18, 2015

in the example, during drawing, there is no outline shown on the rectangle. This is shown on the circle though.

screen shot 2015-05-18 at 11 30 01
screen shot 2015-05-18 at 11 29 52

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it needed to have the default defined here as well? The default is already in ol.geom.Polygon.fromCircle ?

@bartvde
Copy link
Member

bartvde commented May 18, 2015

@ahocevar this looks good to me except for a few minor comments.
When using the example, it doesn't feel like the most intuitive way to draw a box, but maybe I just need to get used to it. Also I'd expect the square to have the size of the radius all the time, and not only when being at a corner, but this is minor.

screen shot 2015-05-18 at 12 03 19
screen shot 2015-05-18 at 12 03 12

@ahocevar
Copy link
Member Author

@bartvde:

The missing outline is because no outline is defined in the default polygon style for the draw interaction (the outline comes from the sketch linestring).

The radius of the square is half of the diagonal, so the square corners intersect the imaginary circle at each vertex.

Any suggestions for improvements? Do you think the example should use a custom style (adds a lot of code)? Or should I introduce a RegularPolygon geometry type and add a default style like for the Circle type?

For the radius to look more natural, I could change the example so the start angle is the heading from the center to the end point of the sketch line. Other ideas?

@bartvde
Copy link
Member

bartvde commented May 18, 2015

Hard questions to answer @ahocevar
I am trying to look at prior art wrt geometry types, such as ISO SQL MM.

https://msdn.microsoft.com/en-us/library/bb964711.aspx
http://doesen0.informatik.uni-leipzig.de/proceedings/paper/68.pdf

It seems our circle geometry type is called CircularString elsewhere?

At first sight it doesn't seem common to have a different geometry type for regular polygons?

@ahocevar ahocevar force-pushed the draw-regular-polygon branch from e57e74d to af02f8f Compare May 19, 2015 17:59
@ahocevar
Copy link
Member Author

@bartvde I addressed all your concerns and added a box drawing mode to the example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like a duplicate line?

@bartvde
Copy link
Member

bartvde commented May 20, 2015

Thanks for the rework @ahocevar looks good to me (I only placed one question in the latest diff).
Also the user experience is much better now!

* Min and max number of points configurable for lines and polygons
* Polygons from custom geometryFunction now have a sketch line
* The example shows how to use a custom geometryFunction
@ahocevar ahocevar force-pushed the draw-regular-polygon branch from af02f8f to 100020f Compare May 20, 2015 08:28
ahocevar added a commit that referenced this pull request May 20, 2015
More control over ol.interaction.Draw, to allow e.g. square drawing
@ahocevar ahocevar merged commit 4be106d into openlayers:master May 20, 2015
@ahocevar ahocevar deleted the draw-regular-polygon branch May 20, 2015 10:08
@bartvde bartvde mentioned this pull request May 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants