Sha256: f9b837fa48ba416e01ab8de3f29920c28d89129d2bdd0b8e738c3e563be14f67

Contents?: true

Size: 1.66 KB

Versions: 18

Compression:

Stored size: 1.66 KB

Contents

var Setlatlng = new Class({
	Implements: [Options, Events],
	
	options: {
		
	},
	
	initialize: 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

18 entries across 18 versions & 1 rubygems

Version Path
bhf-0.5.10 vendor/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.5.9 vendor/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.5.8 vendor/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.5.7 vendor/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.5.6 vendor/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.5.5 vendor/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.5.4 vendor/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.5.3 vendor/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.5.2 vendor/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.5.1 vendor/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.5.0 vendor/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.4.36 vendor/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.4.35 vendor/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.4.34 vendor/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.4.33 vendor/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.4.32 vendor/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.4.31 vendor/assets/javascripts/bhf/classes/Setlatlng.js
bhf-0.4.30 vendor/assets/javascripts/bhf/classes/Setlatlng.js