Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var configurePolygonOptions=function configurePolygonOptions(strokeColor,strokeWeight,strokeOpacity,fillColor,fillOpacity)
- {
- this.strokeColor=strokeColor;
- this.strokeWeight=strokeWeight;
- this.strokeOpacity=strokeOpacity;
- this.fillColor=fillColor;
- this.fillOpacity=fillOpacity;
- };
- configurePolygonOptions.prototype.setPaths=function setPathsForPolygon(paths)
- {
- this.paths=paths;
- };
- configurePolygonOptions.prototype.setStrokeColor=function setStrokeColor(color)
- {
- this.strokeColor=color;
- };
- configurePolygonOptions.prototype.setStrokeWeight=function setStrokeWeight(weight)
- {
- this.strokeWeight=weight;
- };
- configurePolygonOptions.prototype.setStrokeOpacity=function setStrokeOpacity(weight)
- {
- this.strokeWeight=strokeWeight;
- };
- configurePolygonOptions.prototype.setFillColor=function setFillColor(color)
- {
- this.fillColor=color;
- };
- configurePolygonOptions.prototype.setFillOpacity=function setFillOpacity(opacity)
- {
- this.fillOpacity=opacity;
- };
- configurePolygonOptions.prototype.setProperty=function setProperty(prop,value)
- {
- this[prop]=value;
- };
- configurePolygonOptions.prototype.setMap=function(map)
- {
- this.map=map;
- };
- configurePolygonOptions.prototype.setEditable=function(edit)
- {
- this.editable=edit;
- };
- configurePolygonOptions.prototype.setDraggable=function(drag)
- {
- this.draggable=drag;
- };
- var createPolygon=function createPolygon(options)
- {
- return new google.maps.Polygon(options);
- };
- var addPolygonToMap=function addPolygonToMap(poly)
- {
- poly.setMap(map);
- };
- //How I used it:
- polygonOptions.setPaths(vertices);
- polygon=createPolygon(polygonOptions);
- polygon.setMap(map);
- //How the listener for the custom control ending up looking:
- google.maps.event.addDomListener(controlUI,'click',function(){
- console.log('polygon custom control clicked');
- mapPolygonListener=google.maps.event.addListener(map,'click',function(event){
- console.log('Vertices being added to the map');
- console.log('For each vertex a marker has been created');
- addMarkerToCurrentMap(createMapMarker(event.latLng,'Vertex'));
- vertices.push(event.latLng);
- });
- google.maps.event.addListenerOnce(map,'rightclick',function(event){
- //here is the polygon rendering code
- var polygonOptions=new configurePolygonOptions('#FF0000',2,0.8,'#FF0000',0.35);
- var polygon;
- if(typeof mapPolygonListener!='undefined')
- {
- vertices.push(event.latLng);
- addMarkerToCurrentMap(createMapMarker(event.latLng,'End-Vertex'));
- console.log('The polygon end event is here')
- if(vertices.length>2)
- {
- console.log('rendering polygon');
- polygonOptions.setPaths(vertices);
- polygon=createPolygon(polygonOptions);
- polygon.setMap(map);
- google.maps.event.removeListener(mapPolygonListener);
- mapPolygonListener=void 0;
- }
- }
- });
- },false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement