Coder Social home page Coder Social logo

polysnapper's Introduction

PolySnapper

Google Maps V3 Polygon Snapping

PolySnapper GIF

Check out the jsfiddle

Vanilla JS: No Deps.

bower install polysnapper


###properties

  • map: a google.maps.Map object.
  • threshold: an integer minimum number of meters that will cause a snap to occur.
  • marker: a google.maps.Marker that will appear when the users' mouse is within threshold distance from any point in polygons
  • keyRequired: a boolean. If true, requires key to be held for snapping
  • key: either 'shift' or 'ctrl' for now. requires keyRequired to be true
  • polygons: an array of google.maps.Polygon objects that are snappable. These polygons MUST have a snapable:true property set on them. This allows you to use already existing polygon collections and only snap to the polygons you desire.
  • polystyle: an object literal describing StrokeWeight, fillColor, etc that will be used on the polygon the user begins drawing when enable() is called
  • hidePOI: when drawing polygons, often Points of Interest get in the way of click events. You can automagically hide them on enable() and show them on disable().
  • onEnabled: a callback once enabled() has been called.
  • onDisabled: a callback once disabled() has been called.
  • onChange: a callback when a point is added, removed, or moved.

###methods

  • enable(): invoke the custom drawing manager to begin drawing your polygon.
  • disable(): cancel the custom drawing manager and remove the polygon from the map.
  • enabled(): a boolean. whether we are in the enabled state, or not.
  • polygon(): returns the currently editing polygon. You should call this immediately before calling disable() to get a copy of your polygon.

a brief example might look like:

    var PS = PolySnapper({
          map: map,
          threshold: 20,
          key: 'shift',
          keyRequired: true,
          polygons: polygons,
          polystyle: polystyle,
          hidePOI: true,
          onEnabled: function(){
    		console.log("enabled");
          },
          onDisabled: function(){
    		console.log("disabled");
          },
          onChange: function(){
            console.log("a point was added, removed, or moved.");
          }
    });
    
    //first enable the manager (enter drawing mode)
    PS.enable();
    
    //user draws the polygon, point by point, snapping when necessary.
    //now, retrieve the polygon from the manager.
    the_poly = PS.polygon();
    
    //and disable the manager (exit drawing mode and clean up poly).
    //you should now use the_poly as a polygon reference
    PS.disable();

polysnapper's People

Contributors

jars avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

polysnapper's Issues

Edit existing polygon

Thanks for your work. I have been able to use this to draw new polygons, but could not figure how to edit an existing one with Snapping enabled.

Setting

snapable: true, editable: true

Enables the editing, but it does not snap.

PS.polygon()

Hey,
great plugin, still works ๐Ÿ‘ :)

But how do I get the coordinates that I'd have to save with the help of PS.polygon() ?

Thanks!

Close Polygon when dblClick

Is there any way to implement a function that closes the polygon when we double-click the mouse?

Best regards!
Alexandre

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.