Version avec modules séparés !
This commit is contained in:
49
modules/gmap/Gmap.php
Normal file
49
modules/gmap/Gmap.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
class gmap extends Module {
|
||||
//TODO rajouter les params en détail
|
||||
protected static $paramsList = array(
|
||||
'visibility'
|
||||
);
|
||||
|
||||
public $params = array();
|
||||
|
||||
public function __construct($params){
|
||||
$this->moduleName = get_class();
|
||||
$this->pathToModule = 'modules/'.$this->moduleName.'/';
|
||||
$this->setParams($params);
|
||||
echo '<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&language=fr"></script>
|
||||
<script type="text/javascript" src="'.$this->pathToModule.'js/'.$this->moduleName.'.js"></script>
|
||||
<link rel="stylesheet" href="'.$this->pathToModule.'css/'.$this->moduleName.'.css" type="text/css" />
|
||||
|
||||
<div id="myAdress"><label for="myAdressField"><img src="images/interface/map.png" /> Adresse pour Google Maps :</label><input type="text" name="myAdressField" id="myAdressField" /></div><a href="#map" id="gmapLink"></a><div id="map"><div id="mymap" style="width:400px;height:400px"></div></div>';
|
||||
}
|
||||
|
||||
private function setParams($params){
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
public static function start($params){
|
||||
$gmap = new gmap($params);
|
||||
}
|
||||
|
||||
public function setVisibility($visibility){
|
||||
// Saving the position and z-index of the note:
|
||||
$xmla = simplexml_load_file('../'.AccueilModules::CONFIG_FILE);
|
||||
|
||||
$path = $xmla->xpath("//item[@id='gmap']");
|
||||
$path[0]->visibility = $visibility;
|
||||
|
||||
$xmla->asXML('../'.AccueilModules::CONFIG_FILE);
|
||||
|
||||
echo "ok";
|
||||
}
|
||||
|
||||
public static function updateConfig($updated){
|
||||
foreach ($updated as $what=>$withWhat){
|
||||
if(in_array($what, self::$paramsList)){
|
||||
call_user_func(array(get_class(), "set".ucfirst($what)), $withWhat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
4
modules/gmap/css/gmap.css
Normal file
4
modules/gmap/css/gmap.css
Normal file
@@ -0,0 +1,4 @@
|
||||
#myAdress{float:right; margin:12px 10px 0 0;}
|
||||
#route {height: 130px;overflow-y: auto;}
|
||||
#global {text-align: center;margin-left: auto; margin-right: auto;}
|
||||
#route {height: 130px;overflow-y: auto;}
|
89
modules/gmap/js/gmap.js
Normal file
89
modules/gmap/js/gmap.js
Normal file
@@ -0,0 +1,89 @@
|
||||
|
||||
$(document).ready(function(){
|
||||
var geocoder = new google.maps.Geocoder();
|
||||
var map;
|
||||
var gmarkers = [];
|
||||
var infowindow;
|
||||
var directions = new google.maps.DirectionsRenderer();
|
||||
var directionsService = new google.maps.DirectionsService();
|
||||
var current_lat = 0;
|
||||
var current_lng = 0;
|
||||
function getCurrentLat() {
|
||||
return current_lat;
|
||||
}
|
||||
function getCurrentLng() {
|
||||
return current_lng;
|
||||
}
|
||||
function addMarker(latlng,title,content,category,icon) {
|
||||
var marker = new google.maps.Marker({
|
||||
map: map,
|
||||
title : title,
|
||||
icon: new google.maps.MarkerImage(icon, new google.maps.Size(57,34)),
|
||||
position: latlng
|
||||
});
|
||||
var html = '<div style="float:left;text-align:left;width:250;">'+content+'</div>'
|
||||
google.maps.event.addListener(marker, "click", function() {
|
||||
if (infowindow) infowindow.close();
|
||||
infowindow = new google.maps.InfoWindow({content: html});
|
||||
infowindow.open(map,marker);
|
||||
map.setCenter(new google.maps.LatLng(latlng.lat(),latlng.lng()),3);
|
||||
});
|
||||
marker.mycategory = category;
|
||||
gmarkers.push(marker);
|
||||
}
|
||||
function geocodeMarker(address,title,content,category,icon) {
|
||||
if (geocoder) {
|
||||
geocoder.geocode( { "address" : address}, function(results, status) {
|
||||
if (status == google.maps.GeocoderStatus.OK) {
|
||||
var latlng = results[0].geometry.location;
|
||||
addMarker(results[0].geometry.location,title,content,category,icon)
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
function geocodeCenter(address) {
|
||||
if (geocoder) {
|
||||
geocoder.geocode( { "address": address}, function(results, status) {
|
||||
if (status == google.maps.GeocoderStatus.OK) {
|
||||
map.setCenter(results[0].geometry.location);
|
||||
} else {
|
||||
alert("Geocode was not successful for the following reason: " + status);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
function initialize() {
|
||||
var myLatlng = new google.maps.LatLng(48.8792,2.34778);
|
||||
var myOptions = {
|
||||
zoom: 11,
|
||||
center: myLatlng,
|
||||
mapTypeId: google.maps.MapTypeId.ROADMAP
|
||||
}
|
||||
map = new google.maps.Map(document.getElementById("mymap"), myOptions);
|
||||
geocodeCenter("Paris France");
|
||||
google.maps.event.addListener(map,"click",function(event) { if (event) { current_lat=event.latLng.lat();current_lng=event.latLng.lng(); }}) ;
|
||||
directions.setMap(map);
|
||||
directions.setPanel(document.getElementById("route"))
|
||||
}
|
||||
initialize();
|
||||
$('#menu-bar').append($('#myAdress'));
|
||||
$('#map').css({'visibility':'hidden'});
|
||||
$('#gmapLink').fancybox({
|
||||
'transitionIn': 'elastic',
|
||||
'transitionOut': 'elastic',
|
||||
'onClosed': function(){$('#map').css({'visibility':'hidden'});},
|
||||
'onStart': function(){$('#map').css({'visibility':'visible'});}
|
||||
});
|
||||
$('#myAdressField').keydown(function(e){
|
||||
var code = (e.keyCode ? e.keyCode : e.which);
|
||||
if(code == 13) {
|
||||
e.preventDefault();
|
||||
var adress = $(this).val();
|
||||
geocodeMarker(adress,adress,adress,'','http://maps.gstatic.com/intl/fr_ALL/mapfiles/markers/marker_sprite.png');
|
||||
geocodeCenter(adress);
|
||||
$('#gmapLink').trigger('click');
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user