Accueil/modules/mappy/js/mappy.js

34 lines
1.1 KiB
JavaScript
Raw Normal View History

$(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);
});
}