PageSourceSearch

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

js bgcgh.ca collected 2026-10-06 18:40:54 UTC 10,287 bytes, 405 lines download raw bytes

1/**
2 * @namespace WPGMZA
3 * @module OLMarker
4 * @requires WPGMZA.Marker
5 * @pro-requires WPGMZA.ProMarker
6 */
7jQuery(function($) {
8	
9	var Parent;
10	
11	WPGMZA.OLMarker = function(options)
12	{
13		var self = this;
14		
15		Parent.call(this, options);
16		
17		var settings = {};
18		if(options)
19		{
20			for(var name in options)
21			{
22				if(options[name] instanceof WPGMZA.LatLng)
23				{
24					settings[name] = options[name].toLatLngLiteral();
25				}
26				else if(options[name] instanceof WPGMZA.Map)
27				{
28					// Do nothing (ignore)
29				}
30				else
31					settings[name] = options[name];
32			}
33		}
34
35		var origin = ol.proj.fromLonLat([
36			parseFloat(this.lng),
37			parseFloat(this.lat)
38		]);
39		
40		if(WPGMZA.OLMarker.renderMode == WPGMZA.OLMarker.RENDER_MODE_HTML_ELEMENT)
41		{
42			var img = $("<img alt=''/>")[0];
43			img.onload = function(event) {
44				self.updateElementHeight();
45				if(self.map)
46					self.map.olMap.updateSize();
47			}
48			img.src = WPGMZA.defaultMarkerIcon;
49			
50			this.element = $("<div class='ol-marker'></div>")[0];
51			this.element.appendChild(img);
52			
53			this.element.wpgmzaMarker = this;
54			
55			$(this.element).on("mouseover", function(event) {
56				self.dispatchEvent("mouseover");
57			});
58
59			$(this.element).on("mouseout", function(event) {
60				self.dispatchEvent("mouseout");
61			});
62			
63			this.overlay = new ol.Overlay({
64				element: this.element,
65				position: origin,
66				positioning: "bottom-center",
67				stopEvent: false
68			});
69			this.overlay.setPosition(origin);
70			
71			if(this.animation)
72				this.setAnimation(this.animation);
73			else if(this.anim)	// NB: Code to support old name
74				this.setAnimation(this.anim);
75			
76			if(options)
77			{
78				if(options.draggable)
79					this.setDraggable(true);
80			}
81			
82			this.rebindClickListener();
83		}
84		else if(WPGMZA.OLMarker.renderMode == WPGMZA.OLMarker.RENDER_MODE_VECTOR_LAYER)
85		{
86			this.feature = new ol.Feature({
87				geometry: new ol.geom.Point(origin)
88			});
89			
90			this.feature.setStyle(this.getVectorLayerStyle());
91			this.feature.wpgmzaMarker = this;
92			this.feature.wpgmzaFeature = this;
93		}
94		else
95			throw new Error("Invalid marker render mode");
96		
97		this.setOptions(settings);
98		this.trigger("init");
99	}
100	
101	// NB: Does not presently inherit OLFeature, which it probably should
102	
103	if(WPGMZA.isProVersion())
104		Parent = WPGMZA.ProMarker;
105	else
106		Parent = WPGMZA.Marker;
107	
108	WPGMZA.OLMarker.prototype = Object.create(Parent.prototype);
109	WPGMZA.OLMarker.prototype.constructor = WPGMZA.OLMarker;
110	
111	WPGMZA.OLMarker.RENDER_MODE_HTML_ELEMENT		= "element";
112	WPGMZA.OLMarker.RENDER_MODE_VECTOR_LAYER		= "vector";	// NB: This feature is experimental
113	
114	WPGMZA.OLMarker.renderMode = WPGMZA.settings && WPGMZA.settings.olMarkerMode && WPGMZA.settings.olMarkerMode === WPGMZA.OLMarker.RENDER_MODE_VECTOR_LAYER ? WPGMZA.OLMarker.RENDER_MODE_VECTOR_LAYER : WPGMZA.OLMarker.RENDER_MODE_HTML_ELEMENT;
115	
116	if((WPGMZA.settings.engine == "open-layers" || WPGMZA.settings.engine == "open-layers-latest") && WPGMZA.OLMarker.renderMode == WPGMZA.OLMarker.RENDER_MODE_VECTOR_LAYER)
117	{
118		WPGMZA.OLMarker.defaultVectorLayerStyle = new ol.style.Style({
119			image: new ol.style.Icon({
120				anchor: [0.5, 1],
121				src: WPGMZA.defaultMarkerIcon
122			})
123		});
124		
125		WPGMZA.OLMarker.hiddenVectorLayerStyle = new ol.style.Style({});
126	}
127	
128	WPGMZA.OLMarker.prototype.getVectorLayerStyle = function()
129	{
130		if(this.vectorLayerStyle)
131			return this.vectorLayerStyle;
132		
133		return WPGMZA.OLMarker.defaultVectorLayerStyle;
134	}
135	
136	WPGMZA.OLMarker.prototype.updateElementHeight = function(height, calledOnFocus)
137	{
138		var self = this;
139		
140		if(!height)
141			height = $(this.element).find("img").height();
142		
143		if(height == 0 && !calledOnFocus)
144		{
145			$(window).one("focus", function(event) {
146				self.updateElementHeight(false, true);
147			});
148		}
149		
150		$(this.element).css({height: height + "px"});
151	}
152	
153	WPGMZA.OLMarker.prototype.addLabel = function()
154	{
155		this.setLabel(this.getLabelText());
156	}
157	
158	WPGMZA.OLMarker.prototype.setLabel = function(label)
159	{
160		if(WPGMZA.OLMarker.renderMode == WPGMZA.OLMarker.RENDER_MODE_VECTOR_LAYER)
161		{
162			console.warn("Marker labels are not currently supported in Vector Layer rendering mode");
163			return;
164		}
165		
166		if(!label)
167		{
168			if(this.label){
169				$(this.element).find(".ol-marker-label").remove();
170				this.label = false;
171			}
172			
173			return;
174		}
175		
176		if(!this.label)
177		{
178			this.label = $("<div class='ol-marker-label'/>");
179			$(this.element).append(this.label);
180		}
181		
182		label = label.replaceAll("&amp;", "&");
183		this.label.html(label);
184	}
185	
186	WPGMZA.OLMarker.prototype.getVisible = function(visible)
187	{
188		if(WPGMZA.OLMarker.renderMode == WPGMZA.OLMarker.RENDER_MODE_VECTOR_LAYER)
189		{
190			
191		}
192		else
193			return this.overlay.getElement().style.display != "none";
194	}
195	
196	WPGMZA.OLMarker.prototype.setVisible = function(visible)
197	{
198		Parent.prototype.setVisible.call(this, visible);
199		
200		if(WPGMZA.OLMarker.renderMode == WPGMZA.OLMarker.RENDER_MODE_VECTOR_LAYER)
201		{
202			if(visible)
203			{
204				var style = this.getVectorLayerStyle();
205				this.feature.setStyle(style);
206			}
207			else
208				this.feature.setStyle(WPGMZA.OLMarker.hiddenVectorLayerStyle);
209			
210			/*var source = this.map.markerLayer.getSource();
211			
212			/*if(this.featureInSource == visible)
213				return;
214			
215			if(visible)
216				source.addFeature(this.feature);
217			else
218				source.removeFeature(this.feature);
219			
220			this.featureInSource = visible;*/
221		}
222		else
223			this.overlay.getElement().style.display = (visible ? "block" : "none");
224	}
225	
226	WPGMZA.OLMarker.prototype.setPosition = function(latLng)
227	{
228		Parent.prototype.setPosition.call(this, latLng);
229		
230		var origin = ol.proj.fromLonLat([
231			parseFloat(this.lng),
232			parseFloat(this.lat)
233		]);
234	
235		if(WPGMZA.OLMarker.renderMode == WPGMZA.OLMarker.RENDER_MODE_VECTOR_LAYER)
236			this.feature.setGeometry(new ol.geom.Point(origin));
237		else
238			this.overlay.setPosition(origin);
239	}
240	
241	WPGMZA.OLMarker.prototype.updateOffset = function(x, y)
242	{
243		if(WPGMZA.OLMarker.renderMode == WPGMZA.OLMarker.RENDER_MODE_VECTOR_LAYER)
244		{
245			console.warn("Marker offset is not currently supported in Vector Layer rendering mode");
246			return;
247		}
248		
249		var x = this._offset.x;
250		var y = this._offset.y;
251		
252		this.element.style.position = "relative";
253		this.element.style.left = x + "px";
254		this.element.style.top = y + "px";
255	}
256	
257	WPGMZA.OLMarker.prototype.setAnimation = function(anim)
258	{
259		if(WPGMZA.OLMarker.renderMode == WPGMZA.OLMarker.RENDER_MODE_VECTOR_LAYER)
260		{
261			console.warn("Marker animation is not currently supported in Vector Layer rendering mode");
262			return;
263		}
264		
265		Parent.prototype.setAnimation.call(this, anim);
266		
267		switch(anim)
268		{
269			case WPGMZA.Marker.ANIMATION_NONE:
270				$(this.element).removeAttr("data-anim");
271				break;
272			
273			case WPGMZA.Marker.ANIMATION_BOUNCE:
274				$(this.element).attr("data-anim", "bounce");
275				break;
276			
277			case WPGMZA.Marker.ANIMATION_DROP:
278				$(this.element).attr("data-anim", "drop");
279				break;
280		}
281	}
282	
283	WPGMZA.OLMarker.prototype.setDraggable = function(draggable)
284	{
285		var self = this;
286		
287		if(WPGMZA.OLMarker.renderMode == WPGMZA.OLMarker.RENDER_MODE_VECTOR_LAYER)
288		{
289			console.warn("Marker dragging is not currently supported in Vector Layer rendering mode");
290			return;
291		}
292		
293		if(draggable)
294		{
295			var options = {
296				disabled: false
297			};
298			
299			if(!this.jQueryDraggableInitialized)
300			{
301				options.start = function(event) {
302					self.onDragStart(event);
303				}
304				
305				options.stop = function(event) {
306					self.onDragEnd(event);
307				};
308			}
309			
310			try{
311				$(this.element).draggable(options);
312				this.jQueryDraggableInitialized = true;
313				
314				this.rebindClickListener();
315			} catch (ex){
316				/* Draggable not available */
317			}
318		}
319		else
320			$(this.element).draggable({disabled: true});
321	}
322	
323	WPGMZA.OLMarker.prototype.setOpacity = function(opacity)
324	{
325		if(WPGMZA.OLMarker.renderMode == WPGMZA.OLMarker.RENDER_MODE_VECTOR_LAYER)
326		{
327			console.warn("Marker opacity is not currently supported in Vector Layer rendering mode");
328			return;
329		}
330		
331		$(this.element).css({opacity: opacity});
332	}
333	
334	WPGMZA.OLMarker.prototype.onDragStart = function(event)
335	{
336		this.isBeingDragged = true;
337		
338		this.map.olMap.getInteractions().forEach(function(interaction) {
339			
340			if(interaction instanceof ol.interaction.DragPan)
341				interaction.setActive(false);
342			
343		});
344	}
345	
346	WPGMZA.OLMarker.prototype.onDragEnd = function(event)
347	{
348		var self = this;
349		var offset = {
350			top:	parseFloat( $(this.element).css("top").match(/-?\d+/)[0] ),
351			left:	parseFloat( $(this.element).css("left").match(/-?\d+/)[0] )
352		};
353		
354		$(this.element).css({
355			top: 	"0px",
356			left: 	"0px"
357		});
358		
359		var currentLatLng 		= this.getPosition();
360		var pixelsBeforeDrag 	= this.map.latLngToPixels(currentLatLng);
361		var pixelsAfterDrag		= {
362			x: pixelsBeforeDrag.x + offset.left,
363			y: pixelsBeforeDrag.y + offset.top
364		};
365		var latLngAfterDrag		= this.map.pixelsToLatLng(pixelsAfterDrag);
366		
367		this.setPosition(latLngAfterDrag);
368		
369		this.isBeingDragged = false;
370		this.trigger({type: "dragend", latLng: latLngAfterDrag});
371
372		this.trigger("change");
373		
374		// NB: "yes" represents disabled
375		if(this.map.settings.wpgmza_settings_map_draggable != "yes")
376			this.map.olMap.getInteractions().forEach(function(interaction) {
377				
378				if(interaction instanceof ol.interaction.DragPan)
379					interaction.setActive(true);
380				
381			});
382	}
383	
384	WPGMZA.OLMarker.prototype.onElementClick = function(event)
385	{
386		var self = event.currentTarget.wpgmzaMarker;
387		
388		if(self.isBeingDragged)
389			return; // Don't dispatch click event after a drag
390		
391		self.dispatchEvent("click");
392		self.dispatchEvent("select");
393	}
394	
395	/**
396	 * Binds / rebinds the click listener. This must be bound after draggable is initialized,
397	 * this solves the click listener firing before dragend
398	 */
399	WPGMZA.OLMarker.prototype.rebindClickListener = function()
400	{
401		$(this.element).off("click", this.onElementClick);
402		$(this.element).on("click", this.onElementClick);
403	}
404	
405});

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.