javascript - Google Maps API v3 - Snap to polyline edges -


does knows how make marker or polyline snap coordinates of existing polyline?

i'm looking behavior in googlemaps engine lite: https://mapsengine.google.com

if select polyline or marker there , try edit polyline coordinate (using ctrl or shift) snap marker or polyline coordinates

there is, far know, no easy way it. polylines have locations (latlng objects) pass them , it.

so, in mind, can take 2 approaches:

  1. instead of polyline, can draw polygon.
  2. change polyline include more points.

polygon

with approach, have draw thin polygon, thin enough line.

wit approach can check if marker inside polygon using containslocation() method, , if not, set new position inside polygon.

the drawback polygon needs very, thin, , need set width line. if width big, dragging inaccurate, , if small may miss it.

polyline

with approach, have add multiple points polyline, , move marker 1 of points every time went out.

this way there no need create width calculate line, need calculate dozens if not hundreds of points automatically, , add them polyline.

both solutions work, , both have pros , cons. in end, pretty goes around which poison prefer old saying.

extra

theory aside, did find good example polylines strategy (kudos @geocodezip comment , @bradbarrow response).


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -