| Server IP : 54.36.91.62 / Your IP : 216.73.217.112 Web Server : Apache System : Linux webm013.cluster127.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 User : coopiak ( 151928) PHP Version : 8.3.23 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/coopiak/amisdesseniors-fr/sartrouville/components/com_community/assets/source/js/utils/ |
Upload File : |
define([ 'core' ], function() {
var API_KEY = window.joms_gmap_key,
$ = jQuery,
instance;
function GoogleMaps() {
if ( ! instance ) {
instance = this;
}
}
GoogleMaps.prototype = {
search: function( keyword ) {
var that = this;
return $.Deferred(function( defer ) {
that.autocompleteService().then(function( service ) {
service.getPlacePredictions({ input: keyword }, function( results, status ) {
if ( status === 'OK' ) {
defer.resolve( that.mapResult( results ) );
} else {
defer.reject( status );
}
});
});
});
},
mapResult: function( results ) {
var data = [];
if ( _.isArray( results ) ) {
_.each( results, function( item ) {
var id = item.place_id,
nameParts = item.description.split( /,\s(.+)?/ ),
name = nameParts[0],
description = nameParts[1] || '';
data.push({ id: id, name: name, description: description });
});
}
return data;
},
render: function( elem, place ) {
var $elem = $( elem ).show(),
map = $elem.data( 'joms-map' ),
marker = $elem.data( 'joms-map-marker' ),
name = place.formatted_address || '',
location, viewport;
if ( place.geometry ) {
location = place.geometry.location;
viewport = place.geometry.viewport;
} else {
location = new google.maps.LatLng( place.latitude, place.longitude );
}
if ( ! map ) {
$elem.data( 'joms-map', map = new google.maps.Map( elem, {
center: location,
zoom: 15,
draggable: false,
scrollwheel: false,
disableDefaultUI: true
}) );
}
if ( ! marker ) {
$elem.data( 'joms-map-marker', marker = new google.maps.Marker({
map: map,
position: location,
title: name
}) );
}
map.setCenter( location );
marker.setPosition( location );
if ( viewport ) {
map.fitBounds( viewport );
} else {
map.setZoom( 15 );
}
},
loadAPI: function() {
if(joms_maps_api == "openstreetmap"){
return this.loadAPI_OPENSTREET();
}else{
return this.loadAPI_GOOGLE();
}
},
loadAPI_OPENSTREET: function() {
this.callback = false;
var that = this;
return $.Deferred(function( defer ) {
var script, callback,script2,r;
r = false;
if(typeof openstreetmap == "undefined"){
script2 = document.createElement( 'script' );
script2.type = 'text/javascript';
script2.src = joms.ASSETS_URL+'source/js/utils/openstreet.js';
document.body.appendChild( script2 );
}
if ( window.L && window.L.map ) {
if(that.callback !== false){
that.callback();
}
defer.resolve();
return;
}
if ( that.loaded ) {
if(that.callback !== false){
that.callback();
}
defer.resolve();
return;
}
that.queue = that.queue || [];
that.queue.push( defer );
if ( that.loading ) {
return;
}
that.loading = true;
script = document.createElement( 'script' );
script.type = 'text/javascript';
script.src = 'https://unpkg.com/leaflet@1.3.4/dist/leaflet.js'
script.onload = script.onreadystatechange = function() {
if (!r && (!this.readyState || this.readyState == 'complete')) {
r = true;
that.callback();
}
};
jQuery("<link>")
.appendTo("head")
.attr({
type: "text/css",
rel: "stylesheet",
href: "https://unpkg.com/leaflet@1.3.4/dist/leaflet.css"
});
that.callback = function() {
that.loaded = true;
that.loading = false;
while ( that.queue.length ) {
( that.queue.shift() ).resolve();
}
that.callback = false;
};
document.body.appendChild( script );
});
},
loadAPI_GOOGLE: function() {
var that = this;
return $.Deferred(function( defer ) {
var script, callback;
if ( window.google && window.google.maps && window.google.maps.places ) {
defer.resolve();
return;
}
if ( that.loaded ) {
defer.resolve();
return;
}
that.queue = that.queue || [];
that.queue.push( defer );
if ( that.loading ) {
return;
}
that.loading = true;
callback = _.uniqueId( 'jomsCallback' );
script = document.createElement( 'script' );
script.type = 'text/javascript';
script.src = 'https://maps.googleapis.com/maps/api/js?libraries=places' +
( API_KEY ? ( '&key=' + API_KEY ) : '' ) + '&callback=' + callback;
window[ callback ] = function() {
that.loaded = true;
that.loading = false;
while ( that.queue.length ) {
( that.queue.shift() ).resolve();
}
delete window[ callback ];
};
document.body.appendChild( script );
});
},
autocompleteService: function() {
var that = this;
return $.Deferred(function( defer ) {
that.loadAPI().then(function() {
var cache = '_cacheAutocompleteService';
that[ cache ] = that[ cache ] || new google.maps.places.AutocompleteService();
defer.resolve( that[ cache ] );
});
});
},
placeService: function() {
var that = this;
return $.Deferred(function( defer ) {
that.loadAPI().then(function() {
var cache = '_cachePlaceService',
div = document.createElement( 'div' );
document.body.appendChild( div );
that[ cache ] = that[ cache ] || new google.maps.places.PlacesService( div );
defer.resolve( that[ cache ] );
});
});
},
placeDetail: function( id ) {
var that = this;
return $.Deferred(function( defer ) {
that.placeService().then(function( service ) {
var cache = '_cachePlaceDetail';
that[ cache ] = that[ cache ] || {};
if ( that[ cache ][ id ] ) {
defer.resolve( that[ cache ][ id ] );
} else {
service.getDetails({ placeId: id }, function( place, status ) {
if ( status === 'OK' ) {
that[ cache ][ id ] = place;
defer.resolve( place );
} else {
defer.reject( status );
}
});
}
});
});
}
};
// Export as `joms.util.map`.
joms.util || (joms.util = {});
joms.util.map = function( callback ) {
var gmap;
if ( typeof callback !== 'function' ) {
return;
}
gmap = new GoogleMaps();
gmap.loadAPI().done(function() {
callback();
});
};
joms.util.map.search = function( keyword ) {
return $.Deferred(function( defer ) {
var gmap = new GoogleMaps();
gmap.search( keyword ).done(function( results ) {
defer.resolve( results );
});
});
};
joms.util.map.detail = function( id ) {
return $.Deferred(function( defer ) {
var gmap = new GoogleMaps();
gmap.placeDetail( id ).done(function( place ) {
defer.resolve( place );
});
});
};
});