ACC SHELL

Path : /srv/www/vhosts/eqnxde/js/
File Upload :
Current File : /srv/www/vhosts/eqnxde/js/map.js

"use strict";

window.Map = window.Map || {};

Map.init = function(element, zoom) {
	var latitude = element.attr('data-latitude'),
		longitude = element.attr('data-longitude'),
		styles = $.parseJSON(element.attr('data-styles')),
		markers = $.parseJSON(element.attr('data-markers')),
		auto_center = $.parseJSON(element.attr('data-auto_center')) || false;

	zoom = zoom || $.parseJSON(element.attr('data-zoom'));

	var options = {
		center: new google.maps.LatLng(latitude, longitude),
		mapTypeControl: false,
		panControl: false,
		panControlOptions: {
			position: google.maps.ControlPosition.RIGHT_TOP
		},
		scaleControl: false,
		scrollwheel: true,
		streetViewControl: false,
		streetViewControlOptions: {
			position: google.maps.ControlPosition.RIGHT_TOP
		},
		zoom: zoom,
		zoomControl: true,
		zoomControlOptions: {
			style: google.maps.ZoomControlStyle.SMALL,
			position: google.maps.ControlPosition.RIGHT_TOP
		}
	};

//	options.disableDefaultUI = true;

	if (styles) {
		options.mapTypeId = 'Equinox';
	}

	this.map = new google.maps.Map(element.get(0), options);

	if (styles) {
		this.styles(styles);
	}

	if (markers) {
		this.markers(markers, auto_center);
	}
};

Map.styles = function(styles) {
	var options = {
		name: 'Equinox'
	};

	this.map.mapTypes.set('Equinox', new google.maps.StyledMapType(styles, options));
};

// TODO: Should be array of arrays, to allow different type of marker sets
Map._markers = [];

Map.markers = function(markers, auto_center) {
	var icon,
		locations,
		location,
		position,
		options = {},
		marker = {};

	if (auto_center) {
		var bounds = new google.maps.LatLngBounds();
	}

	for (var i = 0; i < markers.length; i++) {
		icon = markers[i].icon;
		locations = markers[i].locations;

		for (var n = 0; n < locations.length; n++) {
			location = locations[n];
			position = new google.maps.LatLng(location[0], location[1]);

			options = {
				icon: icon,
				map: this.map,
				position: position
			};

			if (location.length > 2) {
				options.title = location[2];
			}

			if (location.length > 3) {
				options.url = location[3];
			}

			if (auto_center) {
				bounds.extend(position);
			}

			marker = new google.maps.Marker(options);

			if ('url' in options) {
				google.maps.event.addListener(marker, 'click', function() {
					window.location = this.url;
				});
			}

			this._markers[location[2]] = marker;
		}
	}

	if (auto_center) {
		this.map.setCenter(bounds.getCenter());
		this.map.fitBounds(bounds);
	}
};

$('.map').each(function() {
	Map.init($(this));
});

ACC SHELL 2018