Sha256: b03f4c9a392d64a477ab2c27c97142a73cfd353a8766d440ac582a1488a7df1e

Contents?: true

Size: 1.94 KB

Versions: 67

Compression:

Stored size: 1.94 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

67 entries across 67 versions & 1 rubygems

Version Path
bhf-0.10.12 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.10.11 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.10.10 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.10.9 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.9.9 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.9.8 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.9.7 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.9.6 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.9.5 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.9.4 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.9.3 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.9.2 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.9.1 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.9.0 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.8.7 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.8.6 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.8.5 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.8.4 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.8.3 app/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.8.2 app/assets/javascripts/bhf/classes/Setlatlng.js