Guest User

Untitled

a guest
Nov 23rd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var GMapCircleArea = function (map) {
  2.   this.active = false;
  3.   this.marker = null;
  4.   this.circle = null;
  5.   this.map = map;
  6. }
  7.  
  8. GMapCircleArea.prototype = {
  9.  
  10.   drawArea: function (opt_options)
  11.   {
  12.     var options = opt_options || {};
  13.  
  14.     this.drawMarker({
  15.       'position': options['position'] || this.map.getCenter()
  16.     });
  17.  
  18.     this.drawCircle({
  19.       'position': options['position'] || this.map.getCenter(),
  20.       'radius': options['radius'] || 0
  21.     });
  22.  
  23.     return this;
  24.   },
  25.  
  26.   /**
  27.    * Add a Google Map marker to the current map
  28.    */
  29.   drawMarker: function(opt_options)
  30.   {
  31.     var options = opt_options || {};
  32.  
  33.     spCircleArea.gMarker = new google.maps.Marker({
  34.       map: this.map,
  35.       draggable: true,
  36.       position: options['position'] || this.map.getCenter(),
  37.       animation: google.maps.Animation.DROP,
  38.       title: 'Move me!'
  39.     });
  40.  
  41.     var self = this;
  42.     google.maps.event.addListener(this.marker, 'dragstart', function() {
  43.       self.updateCircleCenter();
  44.     });
  45.     google.maps.event.addListener(spCircleArea.gMarker, 'drag', function() {
  46.       self.updateCircleCenter();
  47.     });
  48.     google.maps.event.addListener(spCircleArea  .gMarker, 'dragend', function() {
  49.       self.updateCircleCenter();
  50.     });
  51.  
  52.     return this;
  53.   },
  54.  
  55.   /**
  56.    * Add a Google Map Circle to the current map
  57.    */
  58.   drawCircle: function (opt_options)
  59.   {
  60.     var options = opt_options || {};
  61.     var radius = parseInt(options['radius'] || 0)
  62.  
  63.     this.circle = new google.maps.Circle({
  64.       map: this.map,
  65.       center: this.marker.getPosition(),
  66.       strokeWeight: 2,
  67.       radius: radius
  68.     });
  69.  
  70.     return this;
  71.   },
  72.  
  73.   updateCircleCenter: function ()
  74.   {
  75.     this.circle.setCenter(spCircleArea.gMarker.getPosition());
  76.  
  77.     return this;
  78.   }
  79.  
  80. };
  81.  
  82.  
  83.  
  84.  
  85.  
  86. var map = new google.maps.Map(document.getElementById('map'), {
  87.             center: new google.maps.LatLng(48.856614, 2.3522219000000177),
  88.             zoom: 8,
  89.             mapTypeId: google.maps.MapTypeId.ROADMAP
  90.           }),
  91.     spCircleArea = new GMapCircleArea(map),
  92.     area = spCircleArea.drawArea({'position:LatLng, 'radius':radius});
Add Comment
Please, Sign In to add comment