this is my initmap.js
OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
defaultHandlerOptions: {
},
initialize: function (options) {
this.handlerOptions = OpenLayers.Util.extend(
{}, this.defaultHandlerOptions
);
OpenLayers.Control.prototype.initialize.apply(
this, arguments
);
this.handler = new OpenLayers.Handler.Click(
this, {
'click': this.trigger
}, this.handlerOptions
);
},
trigger: function (e) {
var lonlat = map.getLonLatFromPixel(e.xy).transform("EPSG:4326", "EPSG:900913");
alert("You clicked near " + lonlat.lat + " N, " +
+lonlat.lon + " E");
//document.getElementById("TextBox1").value = lonlat.lat;
//document.getElementById("TextBox2").value = lonlat.lon;
}
});
function init() {
size = new OpenLayers.Size(26, 30);
var mapOptions = {
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
//units: "m",
//maxResolution: 156543.0339,
//numZoomLevels: 18,
controls: [
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.NavToolbar(),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.LayerSwitcher({ 'ascending': false }),
//new OpenLayers.Control.Permalink(),
new OpenLayers.Control.ScaleLine(),
//new OpenLayers.Control.Permalink('Refresh'),
new OpenLayers.Control.MousePosition(),
new OpenLayers.Control.LayerSwitcher(),
new OpenLayers.Control.OverviewMap({
mapOptions: mapOptions,
maximized: true,
}),
]
};
map = new OpenLayers.Map('map', mapOptions);
nav = new OpenLayers.Control.NavigationHistory();
map.addControl(nav);
panel = new OpenLayers.Control.Panel(
{ div: document.getElementById("panel") }
);
panel.addControls([nav.next, nav.previous]);
map.addControl(panel);
//Ajouter les couche google
var gphy = new OpenLayers.Layer.Google(
"Google Physical",
{ type: google.maps.MapTypeId.TERRAIN }
);
var gmap = new OpenLayers.Layer.Google(
"Google Streets", // the default
{numZoomLevels: 20 }
);
var ghyb = new OpenLayers.Layer.Google(
"Google Hybrid",
{ type: google.maps.MapTypeId.HYBRID, numZoomLevels: 20, isBaseLayer: true }
);
var gsat = new OpenLayers.Layer.Google(
"Google Satellite",
{ type: google.maps.MapTypeId.SATELLITE, numZoomLevels: 20}
);
map.addLayers([gsat, ghyb, gmap, gphy]);
map.addControl(new OpenLayers.Control.MousePosition({ div: document.getElementById("LabelCoords"), numDigits: 5, prefix: "", separator: ",", mapOptions: mapOptions }));
map.setCenter(new OpenLayers.LonLat(-9.2, 31.9).transform("EPSG:4326", "EPSG:900913"), 7);
var click = new OpenLayers.Control.Click();
map.addControl(click);
click.activate();
}