Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var GMapCircleArea = function (map) {
- this.active = false;
- this.marker = null;
- this.circle = null;
- this.map = map;
- }
- GMapCircleArea.prototype = {
- drawArea: function (opt_options)
- {
- var options = opt_options || {};
- this.drawMarker({
- 'position': options['position'] || this.map.getCenter()
- });
- this.drawCircle({
- 'position': options['position'] || this.map.getCenter(),
- 'radius': options['radius'] || 0
- });
- return this;
- },
- /**
- * Add a Google Map marker to the current map
- */
- drawMarker: function(opt_options)
- {
- var options = opt_options || {};
- spCircleArea.gMarker = new google.maps.Marker({
- map: this.map,
- draggable: true,
- position: options['position'] || this.map.getCenter(),
- animation: google.maps.Animation.DROP,
- title: 'Move me!'
- });
- var self = this;
- google.maps.event.addListener(this.marker, 'dragstart', function() {
- self.updateCircleCenter();
- });
- google.maps.event.addListener(spCircleArea.gMarker, 'drag', function() {
- self.updateCircleCenter();
- });
- google.maps.event.addListener(spCircleArea .gMarker, 'dragend', function() {
- self.updateCircleCenter();
- });
- return this;
- },
- /**
- * Add a Google Map Circle to the current map
- */
- drawCircle: function (opt_options)
- {
- var options = opt_options || {};
- var radius = parseInt(options['radius'] || 0)
- this.circle = new google.maps.Circle({
- map: this.map,
- center: this.marker.getPosition(),
- strokeWeight: 2,
- radius: radius
- });
- return this;
- },
- updateCircleCenter: function ()
- {
- this.circle.setCenter(spCircleArea.gMarker.getPosition());
- return this;
- }
- };
- var map = new google.maps.Map(document.getElementById('map'), {
- center: new google.maps.LatLng(48.856614, 2.3522219000000177),
- zoom: 8,
- mapTypeId: google.maps.MapTypeId.ROADMAP
- }),
- spCircleArea = new GMapCircleArea(map),
- area = spCircleArea.drawArea({'position:LatLng, 'radius':radius});
Add Comment
Please, Sign In to add comment