A plugin for Google Maps for drawing shapes with the mouse or touch device. Once a shape is defined, its coordinates can be retrieved for use in your application. Works on all browsers and most mobile devices.
Follow Google's hello world example to create a Google Maps instance. Insure that the Google Maps object is available in the same scope as where the plugin will be started.
Map Lasso is compatible with jQuery versions greater than 1.4.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
<script src="jquery.mapLasso.1.0.js" type="text/javascript"></script>
Attach the plugin to the DOM element that contains the map. Pass the Google Maps object to the plugin as the map parameter. This is the only required parameter.
$('#map').mapLasso({
map: map
});
The following configuration options are available in the Map Lasso plugin and are defined in the configuration object.
$('#map').mapLasso({
startElem: $('a.start-lasso'),
map: map,
strokeWeight: 3,
strokeColor: '#FF0000'
};
The class or id to attach the start lasso event handler to, example: 'a.start-lasso, #start-lasso etc'.
Width in pixels of the lasso stroke.
Color of the lasso stroke in hex.
Opacity of the lasso stroke
Fill color of the lasso in hex.
Opacity of the lasso fill.
Max points to represent the lasso. If the lasso contains more points than this parameter, a factoring algorithm is used to reduce them to below this number.
Minimum number of points before considering the shape a valid lasso.
The Google Maps object. See Google Maps API for more information.
The following public methods are available and are accessed via the jQuery data object of the element the plugin was assigned to.
$('.get-coords').click(function(event) {
console.log($('#map').data('mapLasso').getCoords());
});
Returns the coordinates of the lasso tool as an array of Google Maps LatLng objects (see Google's docs). Optionally pass an options object to customize the response. Currently the only option is "type: array" to return the response as an array of latitude and longitude coordinates.
Clears the lasso from the map.
Events are defined as functions when the plugin is started. Example:
$('#map').mapLasso({
onStart: function(event){
alert('Started here: ' + event.latLng.toString());
}
};
Fires when the user starts creating the lasso. The Google Maps click event object is available for use in this event.
Fires when the user ends the lasso. The Google Maps click event object is available for use in this event.
This plugin is dual licensed under the MIT and GPL licenses.