OpenLayers Blog

All the maps that are fit to blog

Snap & Split

March 11th, 2009 by Tim Schaub · 5 Comments

We’ve been advancing the editing capabilities of OpenLayers with each release since the initial inclusion of the vector feature rendering in 2.4.  The upcoming 2.8 release will bring two new enhancements that I’m particularly excited about: snapping and splitting.

The snapping example demonstrates some of the configuration options of the snapping agent.  This control can be set up to work with any number of target layers.  Modified features in a source layer are snapped to eligible features in target layers based on tolerance settings.  Snapping options for nodes, vertices, and edges can be independently configured.

The split feature example uses the new split control to generate temporary sketches for splitting existing features.  The control can also be configured to listen for edits on an existing layer and split features on any target layer.

The snapping and split controls can be used together to provide an editing environment that maintains some basic topology rules.  Both controls trigger events that let the application designer customize exactly what happens before, during, and after snapping and splitting.  You can find documentation and additional examples for both of the controls in the growing prose documentation.

Thanks to Sweco for supporting this work.  We’re excited to have it in the trunk.

Tags: Features · Release · Vector

5 responses so far ↓

  • 1 Mikhael Torstfeldt // Mar 11, 2009 at 3:12 pm

    Does the snapping provide support for Z?

  • 2 tschaub // Mar 11, 2009 at 3:26 pm

    The snapping control relies on the new geometry.distanceTo method. This calculates distance based on x, y coords only (see

    It would be a reasonably small enhancement to add support for 3d distance calculations there.

  • 3 Guillaume Sueur // Mar 11, 2009 at 7:54 pm

    Great, great work ! A must have ! The quality of the tools and their options is just professionnal !
    I would suggest two enhancements, a trivial one and another not :
    - have the blue square cursor activated as soon as you activate the editing tool. That may help control the snapping of the first point of the new geometry
    - have a circle of radius = tolerance around that cursor. But not easy to deal with the various tolerance settings. Maybe only if they are all set to the same value then, as it must be the most common way of use ?
    Best regards and many thanks !


  • 4 Reklov Kozhuharov // Apr 15, 2009 at 1:55 pm

    Yes, great work! I’m quite new to OpenLayers and just started to explore the vast possibilities …
    But I’m wondering though: The snapping and splitting controls are already documented in the library and there are examples available, so I spent two hours trying to build in the – yet – non-existent snapping control.
    Is there no way to mark the functions of prospective releases in the library, so that users can distinguish them from the functions currently available?
    Nevertheless, I appreciate open layers and can’t wait for 2.8… Thanks!

  • 5 tschaub // Apr 15, 2009 at 2:05 pm

    Reklov, thanks for your comments. I can imagine that it is frustrating to try to use newly added features in an old release. I do notice that I said “the upcoming 2.8 release will bring …” in the post.

    If you want to try out the latest features, you can always use the hosted nightly build:

    This should get you the functionality you find in the examples.