Sha256: 17336edc67e35412dd1a8808cbc13a8a37e4d05b90330a697f520b1b00cec2b2

Contents?: true

Size: 1.92 KB

Versions: 21

Compression:

Stored size: 1.92 KB

Contents

var Setlatlng = new Class({
	Implements: [Options, Events],

	options: {

	},

	initialize: function(elem){
		if (window.google) {
			this.setup(elem);
		}
		else {
			Setlatlng.GMapsCallback = function(){
				this.setup(elem);
			}.bind(this);
			Asset.javascript('http://maps.googleapis.com/maps/api/js?sensor=false&callback=Setlatlng.GMapsCallback');
		}
	},

	setup: function(elem){
		var latElem = elem;
		var lngElem = elem.getNext('.map_data_lng');
		var	setValues = function(lat, lng){
			latElem.value = lat;
			lngElem.value = lng;
		};
		var center = new google.maps.LatLng(
			latElem.value ? latElem.value : latElem.get('data-default-lat'),
			lngElem.value ? lngElem.value : latElem.get('data-default-lng')
		);

		var map = new google.maps.Map(new Element('div.map_canvas').inject(latElem, 'before'), {
			zoom: 14,
			mapTypeId: google.maps.MapTypeId.ROADMAP,
			center: center,
			mapTypeControl: true,
			zoomControl: true,
			zoomControlOptions: {
				style: google.maps.ZoomControlStyle.SMALL
			},
			streetViewControl: false,
			panControl: false,
			scaleControl: false,
			overviewMapControl: false
		});

		var marker = new google.maps.Marker({
			title: 'Location',
			draggable: true
		});

		if (latElem.value && lngElem.value) {
			marker.setPosition(new google.maps.LatLng(latElem.value, lngElem.value));
			marker.setMap(map);
		}
		else {
			if (navigator) {
				navigator.geolocation.getCurrentPosition(function(e){
					map.setCenter(new google.maps.LatLng(e.coords.latitude, e.coords.longitude));
				});
			}
			google.maps.event.addListener(map, 'click', function(e){
				marker.setPosition(e.latLng);
				marker.setMap(map);
				setValues(marker.getPosition().lat(), marker.getPosition().lng());
				google.maps.event.clearListeners(map, 'click');
			});
		}

		google.maps.event.addListener(marker, 'dragend', function(){
			var mPos = marker.getPosition();
			map.panTo(mPos);
			setValues(mPos.lat(), mPos.lng());
		});
	}
});

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
bhf-1.0.0.beta16 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-1.0.0.beta15 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-1.0.0.beta14 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-1.0.0.beta13 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-1.0.0.beta12 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-1.0.0.beta11 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-1.0.0.beta10 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-1.0.0.beta9 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-1.0.0.beta8 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-1.0.0.beta7 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-1.0.0.beta6 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-1.0.0.beta5 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-1.0.0.beta4 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-1.0.0.beta3 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-1.0.0.beta2 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-1.0.0.beta1 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.10.17 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.10.16 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.10.15 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.10.14 app/assets/javascripts/bhf/classes/Setlatlng.js