/*
FILE ARCHIVED ON 0:53:58 May 21, 2013 AND RETRIEVED FROM THE
INTERNET ARCHIVE ON 2:06:55 Feb 20, 2016.
JAVASCRIPT APPENDED BY WAYBACK MACHINE, COPYRIGHT INTERNET ARCHIVE.
ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C.
SECTION 108(a)(3)).
*/
var infoWindow;
var emajineMap = function(divmap)
{
infoWindow = new google.maps.InfoWindow;
this.map = new google.maps.Map(document.getElementById(divmap));
this.map.setMapTypeId(google.maps.MapTypeId.TERRAIN);
this.map.setOptions({zoom:1});
this.latlngbounds = new google.maps.LatLngBounds();
this.nbMarkers = 0;
google.maps.event.addListener(this.map, 'click', function() {
infoWindow.close();
});
}
// initialise les points du centre
emajineMap.prototype.setPoint = function(latitude, longitude)
{
this.point = new google.maps.LatLng(latitude, longitude);
this.latlngbounds.extend(this.point);
}
// initialise le zoom
emajineMap.prototype.setZoom = function(zoom)
{
this.zoom = zoom;
this.map.setOptions({zoom: zoom});
}
// creation du point centrale
emajineMap.prototype.setCenter = function()
{
if (typeof this.point === 'undefined') {
if (this.nbMarkers < 2) {
this.map.setCenter( this.latlngbounds.getCenter(), this.zoom ? this.zoom : 1 );
} else {
this.map.fitBounds(this.latlngbounds);
}
} else {
this.map.setCenter(this.point, this.zoom);
}
}
emajineMap.prototype.setType = function(type) {
this.map.setMapTypeId(type);
}
// Fixe les controles
// @deprecated
emajineMap.prototype.setControl = function(control)
{
return false;
}
emajineMap.prototype.setZoomControl = function(control)
{
var options = {};
options.zoomControl = true;
if (control == 'GLargeMapControl') {
options.zoomControlOptions = {style: google.maps.ZoomControlStyle.LARGE};
} else if (control == 'GSmallMapControl') {
options.zoomControlOptions = {style: google.maps.ZoomControlStyle.DEFAULT};
} else if (control == 'GSmallZoomControl') {
options.zoomControlOptions = {style: google.maps.ZoomControlStyle.SMALL};
}
this.map.setOptions(options);
}
emajineMap.prototype.setOptions = function(options) {
this.map.setOptions(options);
}
emajineMap.prototype.setGoogleBar = function(bool) {
// @deprecated
//if(bool) this.map.enableGoogleBar();
}
emajineMap.prototype.setDefaultControl = function() {
this.map.setOptions({scrollwheel: true, keyboardShortcuts: true});
}
//initialisation de l'image du marker
emajineMap.prototype.setIcon = function(icon)
{
this.tinyIcon = false;
if (icon) {
this.tinyIcon = {};
this.tinyIcon.url = icon;
this.tinyIcon.size = new google.maps.Size(32, 32);
this.tinyIcon.scaledSize = new google.maps.Size(32, 32);
this.tinyIcon.anchor = new google.maps.Point(16, 32);
}
}
// Creation d'un point
emajineMap.prototype.getMarker = function (latitude,longitude)
{
var point = new google.maps.LatLng(latitude, longitude);
this.latlngbounds.extend(point);
var marker = new google.maps.Marker();
marker.setPosition(point);
marker.setMap(this.map);
if (this.tinyIcon) {
marker.setIcon(this.tinyIcon);
}
return marker;
}
//Creation d'un point avec label
emajineMap.prototype.getLabeledMarker = function (latitude,longitude,label)
{
var point = new google.maps.LatLng(latitude, longitude);
this.latlngbounds.extend(point);
return new StyledMarker({styleIcon: new StyledIcon(StyledIconTypes.MARKER,{text:label}), position: point, map: this.map, icon: this.tinyIcon});
}
//Ajout du layer sur le marker (infobulle)
emajineMap.prototype.setMarker = function (marker,url) {
if(url) {
google.maps.event.addListener(marker, "click", function () {
marker = this;
var coord = marker.getPosition();
infoWindow.setContent('
Please wait...
');
infoWindow.open(this.map, marker);
displayFileContent(url, 'gMapWindowContent');
});
}
this.nbMarkers ++;
}
// layer pour afficher les coordonnées.
emajineMap.prototype.afficheCoord = function (marker){
var coord = marker.getLatLng();
var coord1 = coord.lat();
var coord2 = coord.lng();
var info = 'Coordonnées :
Latitude : '+coord1+'
Longitude : '+coord2+'';
infoWindow.setContent(info);
infoWindow.open(this.map, marker);
}
//Itineraire :
emajineMap.prototype.getDirection = function (divdirection)
{
document.getElementById(divdirection).innerHTML = '';
this.gdir = new google.maps.DirectionsService();
this.directionsDisplay = new google.maps.DirectionsRenderer({
'map': this.map,
'preserveViewport': true,
'draggable': true
});
this.directionsDisplay.setPanel(document.getElementById(divdirection));
var directionsDisplay = this.directionsDisplay;
google.maps.event.addListener(this.directionsDisplay, 'directions_changed',
function() {
currentDirections = directionsDisplay.getDirections();
});
}
emajineMap.prototype.setDirections = function (fromAddress, toAddress, locale)
{
var request = {
origin: fromAddress,
destination: toAddress,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
var direction = this.directionsDisplay;
var map = this.map;
this.gdir.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
direction.setDirections(response);
map.fitBounds(response.routes[0].bounds);
}
});
}
emajineMap.prototype.loadJsonSpots = function(url)
{
var latlngbounds = this.latlngbounds;
var defaultZoomLevel = this.zoom ? this.zoom : 1;
var emajineMap = this;
var map = this.map;
var centerPoint = this.point;
var nbSpot = this.nbMarkers
$.get(url, function(datas) {
datas = eval(datas);
var len = datas.length;
if (len>0) {
for (var i = 0; i < len;i++) {
if (typeof datas[i] != 'undefined') {
emajineMap.setIcon(datas[i].icon);
var m = emajineMap.getLabeledMarker(datas[i].latitude, datas[i].longitude, datas[i].label);
emajineMap.setMarker(m, datas[i].uri);
nbSpot ++;
}
}
}
if (typeof centerPoint === 'undefined') {
if (nbSpot < 2) {
map.setCenter(latlngbounds.getCenter(), defaultZoomLevel);
} else {
map.fitBounds(latlngbounds);
}
}
return;
});
}
var map, fieldId, mod, fieldHidden, fieldHtml, defCoord, _coord, _info, marker, mapOptions;
function loadFieldMap(fieldID, mode)
{
fieldId = fieldID;
mod = mode;
fieldHidden = document.getElementById(fieldId + 'idhidden');
fieldHtml = document.getElementById(fieldId+'span');
defCoord = document.getElementById(fieldId+'idhidden').value;
_coord='';// coordonnées sous la forme "latitude|longitude"
_info='';// coordonnées sous la forme "Latitude : latitude Longitude : longitude"
mapOptions=new Array();
if (mod=='address') {
initGeocoder(fieldId);
} else if(mod=='map') {
initMap();
} else {
initMap();
initGeocoder(fieldId, map);
}
mapOptions["map"]= map;
return mapOptions;
}
function initGeocoder(fieldId, map)
{
var geo = document.getElementById("search" + fieldId);
geo.onclick = function()
{
var geocoder = new google.maps.Geocoder();
var address = document.getElementById("adresse" + fieldId).value;
if (address != '') {
geocoder.geocode({'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
updateCoord(results[0].geometry.location);
if (typeof map !== 'undefined') {
initMarker(results[0].geometry.location);
}
} else {
alert(address + " _not_found_");
}
});
}else{
alert("_vous_devez_renseigner_le_champ_adresse_");
document.getElementById("adresse" + fieldId).focus();
}
}
}
function updateCoord(location)
{
var lat = location.lb ? location.lb : location.jb;
var lng = location.kb;
_coord = lat + '|' + lng;
_info = "Latitude"+' : '+lat+" Longitude"+' : '+lng;
updateFieldsMap(_coord, _info)
}
function displayFileContent(url, divID)
{
$.get(url, function(data) {
$('#' + divID).html(data);
});
}
function updateFieldsMap(coordhidden, coordhtml)
{
if(fieldHidden) fieldHidden.value=coordhidden;
if(fieldHtml) fieldHtml.innerHTML=coordhtml;
}
function initMap(defCoord)
{
map = new google.maps.Map(document.getElementById("map" + fieldId));
if(defCoord){
defCoord = defCoord.split('|');
var defPt = new google.maps.LatLng(defCoord[0], defCoord[1]);
updateCoord(defPt);
initMarker(defPt);
}else{
map.setCenter(new google.maps.LatLng(50.1217564, 3.9312299), 5);//fixe le centre de la carte sur Paris
}
map.setZoom(12);
var control = "GLargeMapControl"; var options = {};
options.zoomControl = true;
if (control == 'GLargeMapControl') {
options.zoomControlOptions = {style: google.maps.ZoomControlStyle.LARGE};
} else if (control == 'GSmallMapControl') {
options.zoomControlOptions = {style: google.maps.ZoomControlStyle.DEFAULT};
} else if (control == 'GSmallZoomControl') {
options.zoomControlOptions = {style: google.maps.ZoomControlStyle.SMALL};
}
map.setOptions(options);
map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
map.setOptions({mapTypeControl: true});
map.setOptions({keyboardShortcuts:true});
google.maps.event.addListener(map, "click", function(point) {
updateCoord(point.latLng);
initMarker(point.latLng);
});
}
function initMarker(location)
{
map.setCenter(location);
if (typeof marker !== 'undefined') {
marker.setMap(null);
}
marker = new google.maps.Marker({
map: map,
draggable: true,
position: location
});
google.maps.event.addListener(marker, 'dragend', function() {
updateCoord(marker.getPosition());
map.setCenter(marker.getPosition());
});
}