Git Product home page Git Product logo

google.maps.polyline.edit's Introduction

Polyline editing for the Google Maps V3 API

This library adds an edit method to the google.maps.Polyline class. When the polyline is in edit mode it shows up draggable markers for every point. Right clicking an existing marker will remove it. By default you will see transparent "ghost" markers. Click and drag them to add new points to the polyline.

Screenshot

Examples

Basic Usage

var polyline = new google.maps.Polyline({
  map: map,
  path: [
    new google.maps.LatLng(40.77153,-73.97722),
    new google.maps.LatLng(40.77803,-73.96657)
  ]
});

polyline.edit(); // start edit

Stopping an edit

To stop editing simply pass false to the method.

polyline.edit(false);

Options for editing

You can disable ghost markers by passing an options object and set the ghost property to false.

var options = {
  ghosts: false
}

polyline.edit(true, options);

Events

While in edit mode events are fired while interacting with the polyline.

  • edit_start - Editing was enabled.
  • edit_end - Editing was disabled. Passes the new path.
  • update_at - A point was edited. Passes index and position
  • insert_at - A point was added. Passes index and position
  • remove_at - A point was deleted. Passes index and position

Example:

// when editing started
google.maps.event.addListener(polyline, 'edit_start', function(){
  log("[edit_start]");
});

// when editing in finished
google.maps.event.addListener(polyline, 'edit_end', function(path){
  var coords = [];
  
  path.forEach(function(position){ 
    coords.push(position.toUrlValue(5));
  });
  
  log("[edit_end]   path: " + coords.join(" | "));
});

// when a single point has been moved
google.maps.event.addListener(polyline, 'update_at', function(index, position){
  log("[update_at]  index: " +  index +  " position: " + position);
});

// when a new point has been added
google.maps.event.addListener(polyline, 'insert_at', function(index, position){
  log("[insert_at]  index: " +  index +  " position: " + position);
});

// when a point was deleted
google.maps.event.addListener(polyline, 'remove_at', function(index, position){
  log("[remove_at]  index: " +  index +  " position: " + position);
});

Marker images

Note: This class uses several marker images in edit mode.

  • GhostVertex - ghostVertex.png
  • GhostVertexOver - ghostVertexOver.png
  • Vertex - vertex.png
  • VertexOver - vertexOver.png

By default it looks for those images in "../src/images/".

You can override this settings globally:

google.maps.Polyline.prototype.edit.settings.imagePath = "/myImages/polyline/" 

or you can pass the imagePath option to the edit call:

polyline.edit(true, {
  imagePath: "/myImages/polyline/"
}); 

Thanks

Origial work is done by Dmitry Ryshkin. Special thanks Jan Pieter Waagmeester for the idea of using the library google.maps.geometry, which performs spherical linear interpolation between the two locations.

License

Licensed under the MIT license.

google.maps.polyline.edit's People

Contributors

aemkei avatar afanasy avatar

Watchers

 avatar  avatar

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.