PageSourceSearch

https://goodfoodandwineshow.co.za/wp-content/themes/gfws/pagebuild…/google_map/assets/gmaps.js?ver=4.10.3

js goodfoodandwineshow.co.za collected 2026-10-02 13:28:57 UTC 6,970 bytes, 172 lines download raw bytes

1/*!
2 * Google Maps customization v1.0
3 * Created by Ciprian Lazar.
4 * Working on Cleanlab theme
5 * Pure JavaScript! NO jQuery required!
6 */
7
8//** JavaScript for Google Maps **//
9
10var Zn_google_map = function (mapCanvasId, ourLocation, routingColor, locations, mapTypeId, zoom, scrollwheel, customStyle, customStyleActive, show_overview, show_streetview, show_maptype) {
11
12	//** Set this properties before initializing the map
13	this.mapCanvasId = mapCanvasId || '';
14	this.ourLocation = ourLocation ? new google.maps.LatLng(ourLocation[0], ourLocation[1]) : new google.maps.LatLng(41.447390, -72.843868); //** [lat,long]
15	this.routingColor = routingColor || '#FF0000';
16	this.locations = locations || [[41.447390, -72.843868, '<p>CleanLab</p>']]; //** [lat, long, tooltip, icon, size, animation, anchor]
17	this.zoom = zoom || 17;
18	this.mapTypeId = mapTypeId ? (mapTypeId.toUpperCase() === 'SATELLITE' ? google.maps.MapTypeId.SATELLITE : (mapTypeId.toUpperCase() === 'HYBRID' ? google.maps.MapTypeId.HYBRID : (mapTypeId.toUpperCase() === 'TERRAIN' ? google.maps.MapTypeId.TERRAIN : google.maps.MapTypeId.ROADMAP))) : google.maps.MapTypeId.ROADMAP;
19	this.scrollwheel = scrollwheel || false;
20	this.show_overview = show_overview || false;
21	this.show_streetview = show_streetview || false;
22	this.show_maptype = show_maptype || false;
23
24
25	//** This properties are standard for all maps
26	//this.mapStyleLight = [{ stylers: [{ lightness: 30 }] }, { elementType: 'labels', stylers: [{ lightness: 30 }] }];
27	//this.mapStyleNormal = [{ stylers: [{ lightness: 0 }] }, { elementType: 'labels', stylers: [{ lightness: 0 }] }];
28
29	// Map Color Scheme - more styles here http://snazzymaps.com/
30	this.normalMapStyle = customStyle || false;
31	this.activeMapStyle = customStyleActive || false;
32
33	this.directionsDisplay;
34	this.directionsService = new google.maps.DirectionsService();
35	this.map;
36	this.isMobile = ('ontouchstart' in window);
37
38	this.google = null;
39};
40
41Zn_google_map.prototype.init_map = function () {
42	var that = this;
43	//** Set the options for the map
44	var myOptions = {
45		zoom: this.zoom,
46		center: this.ourLocation,
47		mapTypeId: this.mapTypeId,
48		scrollwheel: this.scrollwheel,
49		noClear: true,
50		mapTypeControl: this.show_maptype,
51		streetViewControl: this.show_streetview,
52		panControl: this.isMobile,
53		panControlOptions: { position: google.maps.ControlPosition.RIGHT_CENTER },
54		draggable: !this.isMobile,
55		scaleControl: false,
56		overviewMapControl: this.show_overview,
57		zoomControl: true,
58		zoomControlOptions: {
59			style: google.maps.ZoomControlStyle.LARGE,
60			position: google.maps.ControlPosition.LEFT_CENTER
61		},
62		//** Make the map lighter
63		styles: this.normalMapStyle
64	};
65	//** Define the map
66	this.map = new google.maps.Map(document.getElementById(this.mapCanvasId), myOptions);
67	this.directionsDisplay = new google.maps.DirectionsRenderer({ polylineOptions: { strokeColor: this.routingColor } });//({ suppressMarkers: true });
68
69	//** Add the markers to the map [[lat, long, tooltip, icon, size, animation, anchor],...]
70	var infowindow = new google.maps.InfoWindow();
71	google.maps.event.addListener(infowindow, 'closeclick', function () { that.map.setOptions({ styles: that.normalMapStyle }); });
72	var marker, i;
73	for (i = 0; i < this.locations.length; i++) {
74		marker = new google.maps.Marker({
75			map: this.map,
76			position: new google.maps.LatLng(this.locations[i][0], this.locations[i][1]),
77			icon: this.locations[i][3] || null,
78			size: this.locations[i][4] || null,
79			anchor: this.locations[i][6] || null,
80			animation: this.locations[i][5] ? (this.locations[i][5].toUpperCase() === 'BOUNCE' ? google.maps.Animation.BOUNCE : (this.locations[i][5].toUpperCase() === 'DROP' ? google.maps.Animation.DROP : null)) : null
81		});
82
83		google.maps.event.addListener(marker, 'click', (function (marker, i) {
84			return function () {
85				if( typeof that.locations[i][2] != 'undefined' && that.locations[i][2].length > 0 ){
86					infowindow.setContent(that.locations[i][2]);
87					infowindow.open(that.map, marker);
88					that.map.setOptions({ styles: that.activeMapStyle });
89				}
90
91			}
92		})(marker, i));
93
94
95	}
96
97	var currCenter = this.map.getCenter();
98	window.onresize = function(event) {
99		google.maps.event.trigger(that.map, 'resize');
100		that.map.setCenter(currCenter);
101	};
102
103
104	//** If having the startLocation container, add event to <ENTER>
105	if (this.findChildByClass('zn_startLocation')) {
106		var that = this;
107		this.findChildByClass('zn_startLocation').onkeydown = function (event) { if (event.keyCode == 13) that.calcRoute(); };
108	}
109
110	//** If having removeRoute element, add event on click
111	if (this.findChildByClass('zn_removeRoute')) {
112		var that = this;
113		this.findChildByClass('zn_removeRoute').onclick = function () { that.removeRoute(); };
114	}
115
116};
117//** Load the map
118//google.maps.event.addDomListener(window, 'load', init_map);
119
120//** Calculate route based on the address
121Zn_google_map.prototype.calcRoute = function () {
122	var that = this;
123	var start = this.findChildByClass('zn_startLocation').value;
124	var end = this.ourLocation;
125	var request = {
126		origin: start,
127		destination: end,
128		travelMode: google.maps.TravelMode.DRIVING
129	};
130	this.directionsService.route(request, function (response, status) {
131		if (status === google.maps.DirectionsStatus.OK) {
132			//** Apply some styling classes
133			that.findChildByClass('zn_startLocation').classList.remove('startLocationInvalid');
134			that.findChildByClass('zn_visitUsContainer').classList.add('startLocationNotEmpty');
135			//** Show directions on the map and zoom to their bounding box
136			that.directionsDisplay.polylineOptions.strokeColor = that.routingColor;
137			that.directionsDisplay.setMap(that.map);
138			that.directionsDisplay.setDirections(response);
139			//** Supress the destination marker
140			//directionsDisplay.b.markers[1].setMap(null);
141		}
142		else {
143			//** Style the input box
144			that.findChildByClass('zn_visitUsContainer').classList.add('startLocationNotEmpty');
145			that.findChildByClass('zn_startLocation').classList.add('startLocationInvalid');
146		}
147	});
148};
149
150Zn_google_map.prototype.removeRoute = function () {
151	//** Remove the directions from the map and zoom back to our office
152	this.directionsDisplay.setMap(null);
153	this.map.setCenter(this.ourLocation);
154	this.map.setZoom(this.zoom);
155	this.findChildByClass('zn_startLocation').value = '';
156	this.findChildByClass('zn_startLocation').classList.remove('startLocationInvalid');
157	this.findChildByClass('zn_visitUsContainer').classList.remove('startLocationNotEmpty');
158};
159
160Zn_google_map.prototype.findChildByClass = function (myClassName, parent) {
161	//** Search for visit us from element and icon_close element
162	var children = document.getElementById(parent || this.mapCanvasId).getElementsByTagName('*');
163	for (child in children)
164		if ((' ' + children[child].className + ' ').indexOf(' ' + myClassName + ' ') > -1) { return children[child]; }
165
166	return null;
167};
168
169
170Zn_google_map.prototype.refreshUI = function(event){
171	window.dispatchEvent(new Event('resize'));
172};

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.