PageSourceSearch

https://www.bgcgh.ca/wp-content/plugins/wp-google-maps/js/v8/map-e…/marker-panel.js?ver=10.0.09+pro-10.0.07

js bgcgh.ca collected 2026-10-06 18:39:19 UTC 7,199 bytes, 238 lines download raw bytes

1/**
2 * @namespace WPGMZA
3 * @module MarkerPanel
4 * @requires WPGMZA.FeaturePanel
5 */
6jQuery(function($) {
7	
8	WPGMZA.MarkerPanel = function(element, mapEditPage)
9	{
10		WPGMZA.FeaturePanel.apply(this, arguments);
11	}
12	
13	WPGMZA.extend(WPGMZA.MarkerPanel, WPGMZA.FeaturePanel);
14	
15	WPGMZA.MarkerPanel.createInstance = function(element, mapEditPage)
16	{
17		if(WPGMZA.isProVersion())
18			return new WPGMZA.ProMarkerPanel(element, mapEditPage);
19		
20		return new WPGMZA.MarkerPanel(element, mapEditPage);
21	}
22
23	WPGMZA.MarkerPanel.prototype.initDefaults = function(){
24		var self = this;
25		
26		WPGMZA.FeaturePanel.prototype.initDefaults.apply(this, arguments);
27		
28		this.adjustSubMode = false;
29
30		if(WPGMZA.InternalEngine.isLegacy()){
31			/* Only applies in legacy */
32			this.onTabActivated(null);
33		}
34
35		$(document.body).on("click", "[data-adjust-" + this.featureType + "-id]", function(event) {
36			self.onAdjustFeature(event);
37		});
38
39		$(document.body).on("click", ".wpgmza_approve_btn", function(event) {
40			self.onApproveMarker(event);
41		});
42		
43	}
44
45	WPGMZA.MarkerPanel.prototype.onAdjustFeature = function(event){
46		var self		= this;
47		var name		= "data-adjust-" + this.featureType + "-id";
48		var id			= $(event.currentTarget).attr(name);
49
50		this.discardChanges();
51
52		this.adjustSubMode = true;
53
54		this.select(id);
55	}
56
57	WPGMZA.MarkerPanel.prototype.onApproveMarker = function(event){
58		var self		= this;
59		
60		var route		= "/" + this.featureType + "s/" + $(event.currentTarget).attr('id');
61		WPGMZA.restAPI.call(route, {
62			method:		"POST",
63			data:		{
64				approved : "1"
65			},
66			success:	function(data, status, xhr) {
67				self.featureDataTable.reload();
68			}
69		});
70	}
71
72	WPGMZA.MarkerPanel.prototype.onFeatureChanged = function(event){
73		if(this.adjustSubMode){
74			var aPos = this.feature.getPosition();
75
76			if(aPos){
77				$(this.element).find("[data-ajax-name='lat']").val(aPos.lat);
78				$(this.element).find("[data-ajax-name='lng']").val(aPos.lng);
79			}
80			// Exit early, we don't want to adjust the address
81			return;
82		}
83
84		var addressField = $(this.element).find("input[data-ajax-name$='address']");
85		
86		if(!addressField.length)
87			return;
88		
89		var pos = this.feature.getPosition();
90		addressField.val(pos.lat + ', ' + pos.lng);
91		addressField.trigger('change');
92	}
93
94	WPGMZA.MarkerPanel.prototype.setTargetFeature = function(feature){
95		if(WPGMZA.FeaturePanel.prevEditableFeature){
96			var prev = WPGMZA.FeaturePanel.prevEditableFeature;
97			
98			if(prev.setOpacity){
99				prev.setOpacity(1);
100			}
101		}
102
103
104		/**
105		 * We could probably make this adjust mode code more elegant in the future
106		 *
107		 * Temporary solution as it is causing trouble for clients 
108		 *
109		 * Date: 2021-01-15
110		*/
111		$(this.element).find('[data-ajax-name]').removeAttr('disabled');
112		$(this.element).find('fieldset').show();
113		$(this.element).find('.wpgmza-adjust-mode-notice').addClass('wpgmza-hidden');
114
115		$(this.element).find('[data-ajax-name="lat"]').attr('type', 'hidden');
116		$(this.element).find('[data-ajax-name="lng"]').attr('type', 'hidden');
117
118		$(this.element).find('.wpgmza-hide-in-adjust-mode').removeClass('wpgmza-hidden');				
119		$(this.element).find('.wpgmza-show-in-adjust-mode').addClass('wpgmza-hidden');
120
121		/* Re-add disabled attribute to pro feature fields */
122		$(this.element).find('.wpgmza-pro-feature [data-ajax-name]').attr('disabled', 'disabled');
123
124		if(feature){
125			if(feature.setOpacity){
126				feature.setOpacity(0.7);
127			}
128
129			feature.getMap().panTo(feature.getPosition());
130
131			if(this.adjustSubMode){
132				$(this.element).find('[data-ajax-name]').attr('disabled', 'disabled');
133				$(this.element).find('fieldset:not(.wpgmza-always-on)').hide();
134				$(this.element).find('.wpgmza-adjust-mode-notice').removeClass('wpgmza-hidden');
135
136				$(this.element).find('[data-ajax-name="lat"]').attr('type', 'text').removeAttr('disabled');
137				$(this.element).find('[data-ajax-name="lng"]').attr('type', 'text').removeAttr('disabled');
138
139				$(this.element).find('.wpgmza-hide-in-adjust-mode').addClass('wpgmza-hidden');				
140				$(this.element).find('.wpgmza-show-in-adjust-mode').removeClass('wpgmza-hidden');				
141			}
142		} else {
143			this.adjustSubMode = false;
144		}
145
146		WPGMZA.FeaturePanel.prototype.setTargetFeature.apply(this, arguments);
147	}
148	
149	WPGMZA.MarkerPanel.prototype.onSave = function(event)
150	{
151		var self		= this;
152		var geocoder	= WPGMZA.Geocoder.createInstance();
153		var address		= $(this.element).find("[data-ajax-name='address']").val();
154
155		var geocodingData = {
156			address: address
157		}
158
159		
160		WPGMZA.mapEditPage.drawingManager.setDrawingMode(WPGMZA.DrawingManager.MODE_NONE);
161		this.showPreloader(true);
162		
163		// New cloud functions
164		var cloud_lat = false;
165		var cloud_lng = false;
166
167		// is the lat and lng set from the WPGM Cloud Search?
168		if (document.getElementsByName("lat").length > 0) { cloud_lat = document.getElementsByName("lat")[0].value; }
169		if (document.getElementsByName("lng").length > 0) { cloud_lng = document.getElementsByName("lng")[0].value; }
170
171		if (cloud_lat && cloud_lng) {
172			if(!WPGMZA_localized_data.settings.googleMapsApiKey || WPGMZA_localized_data.settings.googleMapsApiKey === ''){
173				//Let's only do this if it's not their own key, this causes issues with repositioning a marker 
174				geocodingData.lat = parseFloat(cloud_lat);
175				geocodingData.lng = parseFloat(cloud_lng);
176			}
177		}
178		
179		var addressUnchanged = !this.hasDirtyField('address');
180
181		if(this.adjustSubMode || addressUnchanged){
182			// Trust the force!
183			WPGMZA.FeaturePanel.prototype.onSave.apply(self, arguments);
184		} else {
185			if(WPGMZA.settings && WPGMZA.settings.reduce_editor_geocoding){
186				/* User has reduced geocoding enabled */
187				let existingCoordinates = {
188					lat : $(this.element).find("[data-ajax-name='lat']").val().trim(),
189					lng : $(this.element).find("[data-ajax-name='lng']").val().trim(),
190				};
191
192				if(existingCoordinates.lat.length > 0 && existingCoordinates.lng.length > 0){
193					/* Lat and lng already exist, no need to re-geocode in this case */
194					WPGMZA.FeaturePanel.prototype.onSave.apply(this, arguments);
195					return;
196				}
197			}
198
199			geocoder.geocode(geocodingData, function(results, status) {
200				switch(status)
201				{
202					case WPGMZA.Geocoder.ZERO_RESULTS:
203						alert(WPGMZA.localized_strings.zero_results);
204						self.showPreloader(false);
205						return;
206						break;
207					
208					case WPGMZA.Geocoder.SUCCESS:	
209						break;
210
211					case WPGMZA.Geocoder.NO_ADDRESS:
212						alert(WPGMZA.localized_strings.no_address);
213						self.showPreloader(false);
214						return;
215						break;
216
217					
218					case WPGMZA.Geocoder.FAIL:
219					default:
220						alert(WPGMZA.localized_strings.geocode_fail);
221						self.showPreloader(false);
222						return;
223						break;
224				}
225				
226				var result = results[0];
227				
228				$(self.element).find("[data-ajax-name='lat']").val(result.lat);
229				$(self.element).find("[data-ajax-name='lng']").val(result.lng);
230				WPGMZA.FeaturePanel.prototype.onSave.apply(self, arguments);
231				
232			});
233		}
234
235		// WPGMZA.mapEditPage.map.resetBounds();
236	}
237
238});

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.