PageSourceSearch

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

js bgcgh.ca collected 2026-10-06 18:39:20 UTC 11,677 bytes, 483 lines download raw bytes

1/**
2 * @namespace WPGMZA
3 * @module Marker
4 * @requires WPGMZA
5 */
6jQuery(function($) {
7	
8	/**
9	 * Base class for markers. <strong>Please <em>do not</em> call this constructor directly. Always use createInstance rather than instantiating this class directly.</strong> Using createInstance allows this class to be externally extensible.
10	 * @class WPGMZA.Marker
11	 * @constructor WPGMZA.Marker
12	 * @memberof WPGMZA
13	 * @param {object} [row] Data to map to this object (eg from the database)
14	 * @augments WPGMZA.Feature
15	 */
16	WPGMZA.Marker = function(row)
17	{
18		var self = this;
19		
20		this._offset = {x: 0, y: 0};
21		
22		WPGMZA.assertInstanceOf(this, "Marker");
23		
24		this.lat = "36.778261";
25		this.lng = "-119.4179323999";
26		this.address = "California";
27		this.title = null;
28		this.description = "";
29		this.link = "";
30		this.icon = "";
31		this.approved = 1;
32		this.pic = null;
33		
34		this.isFilterable = true;
35		this.disableInfoWindow = false;
36		
37		WPGMZA.Feature.apply(this, arguments);
38		
39		if(row && row.heatmap)
40			return; // Don't listen for these events on heatmap markers.
41		
42		if(row)
43			this.on("init", function(event) {
44				if(row.position)
45					this.setPosition(row.position);
46				
47				if(row.map)
48					row.map.addMarker(this);
49			});
50		
51		this.addEventListener("added", function(event) {
52			self.onAdded(event);
53		});
54		
55		this.handleLegacyGlobals(row);
56	}
57	
58	WPGMZA.Marker.prototype = Object.create(WPGMZA.Feature.prototype);
59	WPGMZA.Marker.prototype.constructor = WPGMZA.Marker;
60	
61	/**
62	 * Returns the contructor to be used by createInstance, depending on the selected maps engine.
63	 * @method
64	 * @memberof WPGMZA.Marker
65	 * @return {function} The appropriate contructor
66	 */
67	WPGMZA.Marker.getConstructor = function()
68	{
69		switch(WPGMZA.settings.engine)
70		{
71			case "open-layers":
72			case "open-layers-latest":
73				if(WPGMZA.isProVersion())
74					return WPGMZA.OLProMarker;
75				return WPGMZA.OLMarker;
76				break;
77			case "leaflet":
78			case "leaflet-azure":
79			case "leaflet-stadia":
80			case "leaflet-maptiler":
81			case "leaflet-locationiq":
82			case "leaflet-zerocost":
83				if(WPGMZA.isProVersion())
84					return WPGMZA.LeafletProMarker;
85				return WPGMZA.LeafletMarker;
86				break;
87			default:
88				if(WPGMZA.isProVersion())
89					return WPGMZA.GoogleProMarker;
90				return WPGMZA.GoogleMarker;
91				break;
92		}
93	}
94	
95	/**
96	 * Creates an instance of a marker, <strong>please <em>always</em> use this function rather than calling the constructor directly</strong>.
97	 * @method
98	 * @memberof WPGMZA.Marker
99	 * @param {object} [row] Data to map to this object (eg from the database)
100	 */
101	WPGMZA.Marker.createInstance = function(row)
102	{
103		var constructor = WPGMZA.Marker.getConstructor();
104		return new constructor(row);
105	}
106	
107	WPGMZA.Marker.ANIMATION_NONE			= "0";
108	WPGMZA.Marker.ANIMATION_BOUNCE			= "1";
109	WPGMZA.Marker.ANIMATION_DROP			= "2";
110	
111	Object.defineProperty(WPGMZA.Marker.prototype, "offsetX", {
112		
113		get: function()
114		{
115			return this._offset.x;
116		},
117		
118		set: function(value)
119		{
120			this._offset.x = value;
121			this.updateOffset();
122		}
123		
124	});
125	
126	Object.defineProperty(WPGMZA.Marker.prototype, "offsetY", {
127		
128		get: function()
129		{
130			return this._offset.y;
131		},
132		
133		set: function(value)
134		{
135			this._offset.y = value;
136			this.updateOffset();
137		}
138		
139	});
140	
141	/**
142	 * Called when the marker has been added to a map
143	 * @method
144	 * @memberof WPGMZA.Marker
145	 * @listens module:WPGMZA.Marker~added
146	 * @fires module:WPGMZA.Marker~select When this marker is targeted by the marker shortcode attribute
147	 */
148	WPGMZA.Marker.prototype.onAdded = function(event)
149	{
150		var self = this;
151		
152		this.addEventListener("click", function(event) {
153			self.onClick(event);
154		});
155		
156		this.addEventListener("mouseover", function(event) {
157			self.onMouseOver(event);
158		});
159		
160		this.addEventListener("select", function(event) {
161			self.onSelect(event);
162		});
163		
164		if(this.map.settings.marker == this.id){
165			self.trigger("select");
166		}
167		
168		if(this.infoopen == "1"){
169			// Flag a one-shot (one use) call to disable auto-pan controllers in the native engines
170			this._osDisableAutoPan = true;
171
172			this.openInfoWindow(true);
173		}
174	}
175	
176	WPGMZA.Marker.prototype.handleLegacyGlobals = function(row)
177	{
178		if(!(WPGMZA.settings.useLegacyGlobals && this.map_id && this.id))
179			return;
180		
181		var m;
182		if(WPGMZA.pro_version && (m = WPGMZA.pro_version.match(/\d+/)))
183		{
184			if(m[0] <= 7)
185				return; // Don't touch the legacy globals
186		}
187		
188		if(!WPGMZA.legacyGlobals.marker_array[this.map_id])
189			WPGMZA.legacyGlobals.marker_array[this.map_id] = [];
190		
191		WPGMZA.legacyGlobals.marker_array[this.map_id][this.id] = this;
192		
193		if(!WPGMZA.legacyGlobals.wpgmaps_localize_marker_data[this.map_id])
194			WPGMZA.legacyGlobals.wpgmaps_localize_marker_data[this.map_id] = [];
195		
196		var cloned = $.extend({marker_id: this.id}, row);
197		WPGMZA.legacyGlobals.wpgmaps_localize_marker_data[this.map_id][this.id] = cloned;
198	}
199	
200	WPGMZA.Marker.prototype.initInfoWindow = function()
201	{
202		if(this.infoWindow)
203			return;
204		
205		this.infoWindow = WPGMZA.InfoWindow.createInstance();
206	}
207	
208	/**
209	 * Placeholder for future use
210	 * @method
211	 * @memberof WPGMZA.Marker
212	 */
213	WPGMZA.Marker.prototype.openInfoWindow = function(autoOpen) {
214
215		if(!this.map) {
216			console.warn("Cannot open infowindow for marker with no map");
217			return;
218		}
219		
220		// NB: This is a workaround for "undefined" in InfoWindows (basic only) on map edit page
221		// removed by Nick 30 Dec 2020
222		// 
223		//if(WPGMZA.currentPage == "map-edit" && !WPGMZA.pro_version)
224		//	return;
225		
226		if(!autoOpen){
227			if(this.map.lastInteractedMarker)
228				this.map.lastInteractedMarker.infoWindow.close();
229			this.map.lastInteractedMarker = this;
230		}
231		
232		this.initInfoWindow();
233		this.infoWindow.open(this.map, this);
234	}
235	
236	/**
237	 * Called when the marker has been clicked
238	 * @method
239	 * @memberof WPGMZA.Marker
240	 * @listens module:WPGMZA.Marker~click
241	 */
242	WPGMZA.Marker.prototype.onClick = function(event)
243	{
244		
245	}
246	
247	/**
248	 * Called when the marker has been selected, either by the icon being clicked, or from a marker listing
249	 * @method
250	 * @memberof WPGMZA.Marker
251	 * @listens module:WPGMZA.Marker~select
252	 */
253	WPGMZA.Marker.prototype.onSelect = function(event)
254	{
255		this.openInfoWindow();
256	}
257	
258	/**
259	 * Called when the user hovers the mouse over this marker
260	 * @method
261	 * @memberof WPGMZA.Marker
262	 * @listens module:WPGMZA.Marker~mouseover
263	 */
264	WPGMZA.Marker.prototype.onMouseOver = function(event)
265	{
266		if(WPGMZA.settings.wpgmza_settings_map_open_marker_by == WPGMZA.InfoWindow.OPEN_BY_HOVER)
267			this.openInfoWindow();
268	}
269	
270	/**
271	 * Gets the marker icon image URL, without the protocol prefix
272	 * @method
273	 * @memberof WPGMZA.Marker
274	 * @return {string} The URL to the markers icon image
275	 */
276	WPGMZA.Marker.prototype.getIcon = function()
277	{
278		function stripProtocol(url)
279		{
280			if(typeof url != "string")
281				return url;
282			
283			return url.replace(/^http(s?):/, "");
284		}
285		
286		if(WPGMZA.defaultMarkerIcon)
287			return stripProtocol(WPGMZA.defaultMarkerIcon);
288		
289		return stripProtocol(WPGMZA.settings.default_marker_icon);
290	}
291	
292	/**
293	 * Gets the position of the marker
294	 * @method
295	 * @memberof WPGMZA.Marker
296	 * @return {object} LatLng literal of this markers position
297	 */
298	WPGMZA.Marker.prototype.getPosition = function()
299	{
300		return new WPGMZA.LatLng({
301			lat: parseFloat(this.lat),
302			lng: parseFloat(this.lng)
303		});
304	}
305	
306	/**
307	 * Sets the position of the marker.
308	 * @method
309	 * @memberof WPGMZA.Marker
310	 * @param {object|WPGMZA.LatLng} latLng The position either as a LatLng literal or instance of WPGMZA.LatLng.
311	 */
312	WPGMZA.Marker.prototype.setPosition = function(latLng)
313	{
314		if(latLng instanceof WPGMZA.LatLng){
315			this.lat = latLng.lat;
316			this.lng = latLng.lng;
317		} else {
318			this.lat = parseFloat(latLng.lat);
319			this.lng = parseFloat(latLng.lng);
320		}
321	}
322	
323	WPGMZA.Marker.prototype.setOffset = function(x, y)
324	{
325		this._offset.x = x;
326		this._offset.y = y;
327		
328		this.updateOffset();
329	}
330	
331	WPGMZA.Marker.prototype.updateOffset = function()
332	{
333		
334	}
335	
336	/**
337	 * Returns the animation set on this marker (see WPGMZA.Marker ANIMATION_* constants).
338	 * @method
339	 * @memberof WPGMZA.Marker
340	 */
341	WPGMZA.Marker.prototype.getAnimation = function()
342	{
343		return this.anim;
344	}
345	
346	/**
347	 * Sets the animation for this marker (see WPGMZA.Marker ANIMATION_* constants).
348	 * @method
349	 * @memberof WPGMZA.Marker
350	 * @param {int} animation The animation to set.
351	 */
352	WPGMZA.Marker.prototype.setAnimation = function(animation)
353	{
354		
355	}
356	
357	/**
358	 * Get the marker visibility
359	 * @method
360	 * @todo Implement
361	 * @memberof WPGMZA.Marker
362	 */
363	WPGMZA.Marker.prototype.getVisible = function()
364	{
365		
366	}
367	
368	/**
369	 * Set the marker visibility. This is used by the store locator etc. and is not a setting. Closes the InfoWindow if the marker is being hidden and the InfoWindow for this marker is open.
370	 * @method
371	 * @memberof WPGMZA.Marker
372	 * @param {bool} visible Whether the marker should be visible or not
373	 */
374	WPGMZA.Marker.prototype.setVisible = function(visible)
375	{
376		if(!visible && this.infoWindow)
377			this.infoWindow.close();
378	}
379	
380	WPGMZA.Marker.prototype.getMap = function()
381	{
382		return this.map;
383	}
384	
385	/**
386	 * Sets the map this marker should be displayed on. If it is already on a map, it will be removed from that map first, before being added to the supplied map.
387	 * @method
388	 * @memberof WPGMZA.Marker
389	 * @param {WPGMZA.Map} map The map to add this markmer to
390	 */
391	WPGMZA.Marker.prototype.setMap = function(map)
392	{
393		if(!map)
394		{
395			if(this.map)
396				this.map.removeMarker(this);
397		}
398		else
399			map.addMarker(this);
400		
401		this.map = map;
402	}
403	
404	/**
405	 * Gets whether this marker is draggable or not
406	 * @method
407	 * @memberof WPGMZA.Marker
408	 * @return {bool} True if the marker is draggable
409	 */
410	WPGMZA.Marker.prototype.getDraggable = function()
411	{
412		
413	}
414	
415	/**
416	 * Sets whether the marker is draggable
417	 * @method
418	 * @memberof WPGMZA.Marker
419	 * @param {bool} draggable Set to true to make this marker draggable
420	 */
421	WPGMZA.Marker.prototype.setDraggable = function(draggable)
422	{
423		
424	}
425	
426	/**
427	 * Sets options on this marker
428	 * @method
429	 * @memberof WPGMZA.Marker
430	 * @param {object}
430 options An object containing the options to be set
431	 */
432	WPGMZA.Marker.prototype.setOptions = function(options)
433	{
434		
435	}
436	
437	WPGMZA.Marker.prototype.setOpacity = function(opacity)
438	{
439		
440	}
441	
442	/**
443	 * Centers the map this marker belongs to on this marker
444	 * @method
445	 * @memberof WPGMZA.Marker
446	 * @throws Marker hasn't been added to a map
447	 */
448	WPGMZA.Marker.prototype.panIntoView = function()
449	{
450		if(!this.map)
451			throw new Error("Marker hasn't been added to a map");
452		
453		this.map.setCenter(this.getPosition());
454	}
455	
456	/**
457	 * Overrides Feature.toJSON, serializes the marker to a JSON object
458	 * @method
459	 * @memberof WPGMZA.Marker
460	 * @return {object} A JSON representation of this marker
461	 */
462	WPGMZA.Marker.prototype.toJSON = function()
463	{
464		var result = WPGMZA.Feature.prototype.toJSON.call(this);
465		var position = this.getPosition();
466		
467		$.extend(result, {
468			lat: position.lat,
469			lng: position.lng,
470			address: this.address,
471			title: this.title,
472			description: this.description,
473			link: this.link,
474			icon: this.icon,
475			pic: this.pic,
476			approved: this.approved
477		});
478		
479		return result;
480	}
481	
482	
483});

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.