1/** 2 * @namespace WPGMZA 3 * @module LeafletDrawingManager 4 * @requires WPGMZA.DrawingManager 5 */ 6jQuery(function($) { 7 WPGMZA.LeafletDrawingManager = function(map) { 8 var self = this; 9 10 WPGMZA.DrawingManager.call(this, map); 11 12 this.interactions = { 13 draw : false, 14 edit : false 15 }; 16 17 this.bindEvents(); 18 } 19 20 WPGMZA.LeafletDrawingManager.prototype = Object.create(WPGMZA.DrawingManager.prototype); 21 WPGMZA.LeafletDrawingManager.prototype.constructor = WPGMZA.LeafletDrawingManager; 22 23 WPGMZA.LeafletDrawingManager.prototype.enableEditorInteraction = function(feature){ 24 const mode = this.getModeFromFeature(feature); 25 const modeConfig = this.getModeConfiguration(mode); 26 27 if(!modeConfig){ 28 return; 29 } 30 31 if(this.interactions.edit && this.interactions.edit.feature){ 32 if(feature !== this.interactions.edit.feature){ 33 /* Feature has changed */ 34 this.disableEditorInteraction(); 35 } else { 36 /* Feature has not changed, no need to change this */ 37 return; 38 } 39 } 40 41 this.interactions.edit = { 42 map : this.map && this.map.leafletMap ? this.map.leafletMap : false, 43 feature : feature 44 }; 45 46 if(!this.interactions.edit.map){ 47 return; 48 } 49 50 if(!this.interactions.edit.tooling){ 51 this.interactions.edit.tooling = new L.Edit[modeConfig.editType](feature.leafletFeature, this.interactions.edit.map); 52 } 53 54 this.interactions.edit.tooling.enable(); 55 56 feature.leafletFeature.on('edit', () => { 57 feature.trigger("change"); 58 }); 59 60 feature.leafletFeature.on('remove', () => { 61 this.disableEditorInteraction(); 62 }); 63 } 64 65 WPGMZA.LeafletDrawingManager.prototype.disableEditorInteraction = function() { 66 if(this.interactions.edit && this.interactions.edit.feature){ 67 if(this.interactions.edit.tooling){ 68 this.interactions.edit.tooling.disable(); 69 this.interactions.edit.feature.leafletFeature.remove(); 70 this.interactions.edit = false; 71 } 72 } 73 } 74 75 76 WPGMZA.LeafletDrawingManager.prototype.setDrawingMode = function(mode) { 77 WPGMZA.DrawingManager.prototype.setDrawingMode.call(this, mode); 78 79 if(this.interactions.draw && this.interactions.draw.tooling){ 80 this.interactions.draw.tooling.disable(); 81 this.interactions.draw.tooling = false; 82 } 83 84 const modeConfig = this.getModeConfiguration(mode); 85 if(!modeConfig){ 86 return; 87 } 88 89 this.interactions.draw = { 90 map : this.map && this.map.leafletMap ? this.map.leafletMap : false, 91 config : modeConfig 92 }; 93 94 if(!this.interactions.draw.map) { 95 return; 96 } 97 98 this.interactions.draw.tooling = new L.Draw[modeConfig.type](this.interactions.draw.map, modeConfig.drawOptions); 99 100 this.interactions.draw.tooling.enable(); 101 } 102 103 WPGMZA.LeafletDrawingManager.prototype.bindEvents = function(){ 104 const map = this.map && this.map.leafletMap ? this.map.leafletMap : false; 105 if(!map){ 106 return; 107 } 108 109 map.on(L.Draw.Event.CREATED, (e) => { 110 if(this.interactions.draw.tooling){ 111 this.interactions.draw.tooling.disable(); 112 } 113 114 if(!this.interactions.draw.config || !this.interactions.draw.config.events.complete){ 115 return; 116 } 117 118 var WPGMZAEvent = new WPGMZA.Event(this.interactions.draw.config.events.complete); 119 switch(this.interactions.draw.config.mode) { 120 case WPGMZA.DrawingManager.MODE_POLYGON: 121 WPGMZAEvent.enginePolygon = e.layer; 122 break; 123 124 case WPGMZA.DrawingManager.MODE_POLYLINE: 125 WPGMZAEvent.enginePolyline = e.layer; 126 break; 127 128 case WPGMZA.DrawingManager.MODE_CIRCLE: 129 WPGMZAEvent.engineCircle = e.layer; 130 break; 131 132 case WPGMZA.DrawingManager.MODE_RECTANGLE: 133 WPGMZAEvent.engineRectangle = e.layer; 134 break; 135 case WPGMZA.DrawingManager.MODE_IMAGEOVERLAY: 136 WPGMZAEvent.engineImageoverlay = { 137 engineRectangle : e.layer 138 }; 139 break; 140 141 default: 142 throw new Error("Drawing mode not implemented"); 143 break; 144 } 145 146 this.dispatchEvent(WPGMZAEvent); 147 }); 148 149 this.on('refresh', () => { 150 /* Refresh handles if editing */ 151 if(this.interactions.edit.tooling.enabled()){ 152 this.interactions.edit.tooling.disable() 153 this.interactions.edit.tooling.enable() 154 } 155 }) 156 } 157 158 WPGMZA.LeafletDrawingManager.prototype.getModeFromFeature = function(feature){ 159 if(feature instanceof WPGMZA.Marker){ 160 return WPGMZA.DrawingManager.MODE_MARKER; 161 } else if(feature instanceof WPGMZA.Polygon){ 162 return WPGMZA.DrawingManager.MODE_POLYGON; 163 } else if(feature instanceof WPGMZA.Polyline){ 164 return WPGMZA.DrawingManager.MODE_POLYLINE; 165 } else if(feature instanceof WPGMZA.Circle){ 166 return WPGMZA.DrawingManager.MODE_CIRCLE; 167 } else if(feature instanceof WPGMZA.Rectangle){ 168 return WPGMZA.DrawingManager.MODE_RECTANGLE; 169 } else if(feature instanceof WPGMZA.Heatmap){ 170 return WPGMZA.DrawingManager.MODE_HEATMAP; 171 } else if(feature instanceof WPGMZA.Pointlabel){ 172 return WPGMZA.DrawingManager.MODE_POINTLABEL; 173 } else if(feature instanceof WPGMZA.Imageoverlay){ 174 return WPGMZA.DrawingManager.MODE_IMAGEOVERLAY; 175 } 176 return WPGMZA.DrawingManager.MODE_NONE; 177 } 178 179 WPGMZA.LeafletDrawingManager.prototype.getModeConfiguration = function(mode){ 180 const config = { 181 mode : mode, 182 type : false, 183 editType : false, 184 events : { 185 complete : false, 186 change : 'change' 187 }, 188 drawOptions : { 189 shapeOptions : { 190 color : "#0494f4", 191 fillColor : "#FFFFFF", 192 fillOpacity: 0.3, 193 weight: 2, 194 opacity: 0.8 195 } 196 } 197 }; 198 199 switch(mode) { 200 case WPGMZA.DrawingManager.MODE_NONE: 201 case WPGMZA.DrawingManager.MODE_MARKER: 202 case WPGMZA.DrawingManager.MODE_POINTLABEL: 203 case WPGMZA.DrawingManager.MODE_HEATMAP: 204 break; 205 case WPGMZA.DrawingManager.MODE_POLYGON: 206 config.type = "Polygon"; 207 config.editType = "Poly"; 208 config.events.complete = "polygonclosed"; 209 config.drawOptions.metric = this.map.settings.store_locator_distance === WPGMZA.Distance.KILOMETERS ? true : false;
210 break; 211 case WPGMZA.DrawingManager.MODE_POLYLINE: 212 config.type = "Polyline"; 213 config.editType = "Poly"; 214 config.events.complete = "polylinecomplete"; 215 config.drawOptions.metric = this.map.settings.store_locator_distance === WPGMZA.Distance.KILOMETERS ? true : false; 216 break; 217 case WPGMZA.DrawingManager.MODE_CIRCLE: 218 config.type = "Circle"; 219 config.events.complete = "circlecomplete"; 220 config.drawOptions.metric = this.map.settings.store_locator_distance === WPGMZA.Distance.KILOMETERS ? true : false; 221 config.drawOptions.minRadius = 1; 222 break; 223 case WPGMZA.DrawingManager.MODE_RECTANGLE: 224 config.type = "Rectangle"; 225 config.events.complete = "rectanglecomplete"; 226 config.drawOptions.metric = this.map.settings.store_locator_distance === WPGMZA.Distance.KILOMETERS ? true : false; 227 break; 228 case WPGMZA.DrawingManager.MODE_IMAGEOVERLAY: 229 config.type = "Rectangle"; 230 config.events.complete = "imageoverlaycomplete"; 231 break; 232 default: 233 throw new Error("Invalid drawing mode"); 234 break; 235 } 236 237 config.editType = config.editType ? config.editType : config.type; 238 239 return config.type ? config : false; 240 } 241 242});
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.