Advertisement
vamsiampolu

Javascript problem explained

Feb 12th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var configurePolygonOptions=function configurePolygonOptions(strokeColor,strokeWeight,strokeOpacity,fillColor,fillOpacity)
  2.     {
  3.         this.strokeColor=strokeColor;
  4.         this.strokeWeight=strokeWeight;
  5.         this.strokeOpacity=strokeOpacity;
  6.         this.fillColor=fillColor;
  7.         this.fillOpacity=fillOpacity;
  8.     };
  9.  
  10.     configurePolygonOptions.prototype.setPaths=function setPathsForPolygon(paths)
  11.     {
  12.         this.paths=paths;
  13.     };
  14.  
  15.     configurePolygonOptions.prototype.setStrokeColor=function setStrokeColor(color)
  16.     {
  17.         this.strokeColor=color;
  18.     };
  19.  
  20.     configurePolygonOptions.prototype.setStrokeWeight=function setStrokeWeight(weight)
  21.     {
  22.         this.strokeWeight=weight;
  23.     };
  24.  
  25.     configurePolygonOptions.prototype.setStrokeOpacity=function setStrokeOpacity(weight)
  26.     {
  27.         this.strokeWeight=strokeWeight;
  28.     };
  29.  
  30.  
  31.     configurePolygonOptions.prototype.setFillColor=function setFillColor(color)
  32.     {
  33.         this.fillColor=color;
  34.     };
  35.  
  36.  
  37.     configurePolygonOptions.prototype.setFillOpacity=function setFillOpacity(opacity)
  38.     {
  39.         this.fillOpacity=opacity;
  40.     };
  41.  
  42.     configurePolygonOptions.prototype.setProperty=function setProperty(prop,value)
  43.     {
  44.         this[prop]=value;
  45.     };
  46.  
  47.     configurePolygonOptions.prototype.setMap=function(map)
  48.     {
  49.         this.map=map;
  50.     };
  51.  
  52.     configurePolygonOptions.prototype.setEditable=function(edit)
  53.     {
  54.         this.editable=edit;
  55.     };
  56.  
  57.     configurePolygonOptions.prototype.setDraggable=function(drag)
  58.     {
  59.         this.draggable=drag;
  60.     };
  61.  
  62.         var createPolygon=function createPolygon(options)
  63.     {
  64.         return new google.maps.Polygon(options);
  65.     };
  66.  
  67.     var addPolygonToMap=function addPolygonToMap(poly)
  68.     {
  69.         poly.setMap(map);
  70.     };
  71.  
  72. //How I used it:
  73.  
  74.     polygonOptions.setPaths(vertices); 
  75.     polygon=createPolygon(polygonOptions);
  76.     polygon.setMap(map);
  77.  
  78. //How the listener for the custom control ending up looking:
  79.  
  80. google.maps.event.addDomListener(controlUI,'click',function(){
  81.             console.log('polygon custom control clicked');
  82.             mapPolygonListener=google.maps.event.addListener(map,'click',function(event){
  83.                 console.log('Vertices being added to the map');
  84.                 console.log('For each vertex a marker has been created');
  85.                 addMarkerToCurrentMap(createMapMarker(event.latLng,'Vertex'));
  86.                 vertices.push(event.latLng);
  87.             });
  88.  
  89.         google.maps.event.addListenerOnce(map,'rightclick',function(event){
  90.             //here is the polygon rendering code
  91.                         var polygonOptions=new configurePolygonOptions('#FF0000',2,0.8,'#FF0000',0.35);
  92.             var polygon;       
  93.             if(typeof mapPolygonListener!='undefined')
  94.             {
  95.                 vertices.push(event.latLng);
  96.                 addMarkerToCurrentMap(createMapMarker(event.latLng,'End-Vertex'));
  97.                 console.log('The polygon end event is here')
  98.                 if(vertices.length>2)
  99.                 {
  100.                     console.log('rendering polygon');
  101.                     polygonOptions.setPaths(vertices); 
  102.                     polygon=createPolygon(polygonOptions);
  103.                     polygon.setMap(map);
  104.                     google.maps.event.removeListener(mapPolygonListener);
  105.                     mapPolygonListener=void 0;
  106.                 }  
  107.             }  
  108.         });
  109.            
  110.         },false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement