Version avec modules séparés !
This commit is contained in:
49
modules/mappy/Mappy.php
Normal file
49
modules/mappy/Mappy.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
class mappy extends Module {
|
||||
|
||||
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="'.$this->pathToModule.'js/'.$this->moduleName.'.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="'.$this->pathToModule.'css/'.$this->moduleName.'.css">';
|
||||
echo '<script src="http://axe.mappy.com/1v1/init/get.aspx?version=2.01&solution=ajax&auth=HbTTpMfC4//GWuldL2IsF+HJA4xVuTBsIQi0wcC7xRz+e17hobrJ+1947aq34rdjYAPy6nBYBQF8o56Qzdun9w=="></script>
|
||||
<div id="mymap"></div>
|
||||
<div id="myAdress"><input type="text" name="myAdressField" id="myAdressField" /></div>';
|
||||
}
|
||||
|
||||
private function setParams($params){
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
public static function start($params){
|
||||
|
||||
$mappy = new mappy($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='mappy']");
|
||||
$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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
2
modules/mappy/css/mappy.css
Normal file
2
modules/mappy/css/mappy.css
Normal file
@@ -0,0 +1,2 @@
|
||||
#mymap{display:none;z-index:900;width:400px;height:400px;}
|
||||
#myAdress{float:right; margin:12px 10px 0 0;}
|
34
modules/mappy/js/mappy.js
Normal file
34
modules/mappy/js/mappy.js
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
$(document).ready(function(){
|
||||
$('#menu-bar').append($('#myAdress'));
|
||||
$('#myAdressField').keydown(function(e){
|
||||
var code = (e.keyCode ? e.keyCode : e.which);
|
||||
if(code == 13) {
|
||||
var adress = $(this).val();
|
||||
geocode(adress);
|
||||
$('#mymap').show();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function geocode (addr)
|
||||
{
|
||||
var geo = new Mappy.api.geolocation.Geocoder();
|
||||
geo.geocode(addr, function (results)
|
||||
{
|
||||
var map = new Mappy.api.map.Map({
|
||||
container:"#mymap"
|
||||
});
|
||||
var scalePosition = new Mappy.api.map.tools.ToolPosition('lb', new Mappy.api.types.Point(10, 0));
|
||||
var scale = new Mappy.api.map.tools.Scale(scalePosition);
|
||||
map.addTool(scale);
|
||||
var latitude = results[0].Placemark.Point.coordinates[0];
|
||||
var longitude = results[0].Placemark.Point.coordinates[1];
|
||||
var markerLayer = new Mappy.api.map.layer.MarkerLayer(40);
|
||||
map.addLayer(markerLayer);
|
||||
var icon = new Mappy.api.ui.Icon(Mappy.api.ui.Icon.DEFAULT);
|
||||
var marker = new Mappy.api.map.Marker(new Mappy.api.geo.Coordinates(latitude, longitude), icon);
|
||||
markerLayer.addMarker(marker);
|
||||
map.setCenter(new Mappy.api.geo.Coordinates(latitude,longitude),7);
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user