1/** 2 * @namespace WPGMZA 3 * @module GooglePolygon 4 * @requires WPGMZA.Polygon 5 * @pro-requires WPGMZA.ProPolygon 6 */ 7jQuery(function($) { 8 9 var Parent; 10 11 WPGMZA.GooglePolygon = function(options, googlePolygon) 12 { 13 var self = this; 14 15 if(!options) 16 options = {}; 17 18 Parent.call(this, options, googlePolygon); 19 20 if(googlePolygon) 21 { 22 this.googlePolygon = googlePolygon; 23 } 24 else 25 { 26 this.googlePolygon = new google.maps.Polygon(); 27 } 28 29 this.googleFeature = this.googlePolygon; 30 31 if(options && options.polydata) 32 this.googlePolygon.setOptions({ 33 paths: this.parseGeometry(options.polydata) 34 }); 35 36 this.googlePolygon.wpgmzaPolygon = this; 37 38 if(options) 39 this.setOptions(options); 40 41 google.maps.event.addListener(this.googlePolygon, "click", function() { 42 self.dispatchEvent({type: "click"}); 43 }); 44 45 google.maps.event.addListener(this.googlePolygon, "rightclick", function(event) { 46 if(typeof self.map !== 'undefined' && self.map instanceof WPGMZA.Map){ 47 var wpgmzaEvent = new WPGMZA.Event("rightclick"); 48 wpgmzaEvent.latLng = { 49 lat: event.latLng.lat(), 50 lng: event.latLng.lng() 51 }; 52 53 self.map.dispatchEvent(wpgmzaEvent); 54 } 55 }); 56 } 57 58 if(WPGMZA.isProVersion()) 59 Parent = WPGMZA.ProPolygon; 60 else 61 Parent = WPGMZA.Polygon; 62 63 WPGMZA.GooglePolygon.prototype = Object.create(Parent.prototype); 64 WPGMZA.GooglePolygon.prototype.constructor = WPGMZA.GooglePolygon; 65 66 WPGMZA.GooglePolygon.prototype.updateNativeFeature = function() 67 { 68 this.googlePolygon.setOptions(WPGMZA.GoogleFeature.getGoogleStyle(this.getScalarProperties())); 69 } 70 71 /** 72 * Returns true if the polygon is editable 73 * @return void 74 */ 75 WPGMZA.GooglePolygon.prototype.getEditable = function() 76 { 77 return this.googlePolygon.getOptions().editable; 78 } 79 80 /** 81 * Sets the editable state of the polygon 82 * @return void 83 */ 84 WPGMZA.GooglePolygon.prototype.setEditable = function(value) 85 { 86 var self = this; 87 88 this.googlePolygon.setOptions({editable: value}); 89 90 if(value) 91 { 92 // TODO: Unbind these when value is false 93 this.googlePolygon.getPaths().forEach(function(path, index) { 94 95 var events = [ 96 "insert_at", 97 "remove_at", 98 "set_at" 99 ]; 100 101 events.forEach(function(name) { 102 google.maps.event.addListener(path, name, function() { 103 self.trigger("change"); 104 }) 105 }); 106 107 }); 108 109 // TODO: Add dragging and listen for dragend 110 google.maps.event.addListener(this.googlePolygon, "dragend", function(event) { 111 self.trigger("change"); 112 }); 113 114 google.maps.event.addListener(this.googlePolygon, "click", function(event) { 115 116 if(!WPGMZA.altKeyDown) 117 return; 118 119 var path = this.getPath(); 120 path.removeAt(event.vertex); 121 self.trigger("change"); 122 123 }); 124 } 125 } 126 127 WPGMZA.GooglePolygon.prototype.setVisible = function(visible) { 128 this.googlePolygon.setVisible(visible ? true : false); 129 } 130 131 WPGMZA.GooglePolygon.prototype.setDraggable = function(value) 132 { 133 this.googlePolygon.setDraggable(value); 134 } 135 136 /** 137 * Returns the polygon represented by a JSON object 138 * @return object 139 */ 140 WPGMZA.GooglePolygon.prototype.getGeometry = function() 141 { 142 var result = []; 143 144 // TODO: Support holes using multiple paths 145 var path = this.googlePolygon.getPath(); 146 for(var i = 0; i < path.getLength(); i++) 147 { 148 var latLng = path.getAt(i); 149 result.push({ 150 lat: latLng.lat(), 151 lng: latLng.lng() 152 }); 153 } 154 155 return result; 156 } 157 158});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.