[OpenLayers-Users] event handler on top of google map
Alessandro Ferrucci
alessandroferrucci at gmail.com
Wed Oct 21 13:17:13 EDT 2009
Hello,
I have google hybrid as base map, I have some POI's that I store in my own
postGIS database that I overlay on top of google base map. I want to attach
click mouse handler on POI layer for GetFeatureInfo. Whenever I click the
mouse, I don't get any features back. I think it has something to do with
projection and mouse location ? ...not quite sure.
Just as an aside, when I view my POI layer using Geoserver's demo
functionality, it gets back all features fine, this is reason I think it has
something to do with projection that I attach to my mouse handler or
something.
here is relevant code:
<html>
<head>
<title>CIRA GIS</title>
<script src="http://openlayers.org/api/OpenLayers.js"
type="text/javascript"></script>
<link rel="stylesheet" href="../css/google.css" type="text/css" />
<script src="
http://maps.google.com/maps?file=api&v=2&sensor=true&key=ABQIAAAAo2c5r7VgSxo43IHrZeBAoBQamh927W1qenomYTPDD5XN6kDJqBTSmynWaZ9MUgwOTtaOkIJeFZSMjQ"
type="text/javascript"></script>
<script defer="defer" type="text/javascript">
function setHTML(response){
document.getElementById('nodelist').innerHTML =
response.responseText;
};
function init()
{
var options = {
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
units: "m",
numZoomLevels: 30,
maxResolution: 156543.0339,
maxExtent: new OpenLayers.Bounds(-20037508, -20037508,
20037508, 20037508.34),
controls: []
};
var map = new OpenLayers.Map( 'map', options );
var cira_addresses_layer = new OpenLayers.Layer.WMS(
"ACS Addresses",
"localhost:8080/geoserver/wms",
{
layers: 'cira:addresses',
transparent: true
},
{buffer:0, ratio: 1, transitionEffect: 'resize', isBaseLayer:
false}
);
var ghyb = new OpenLayers.Layer.Google(
"Google Hybrid",
{sphericalMercator: true, type: G_HYBRID_MAP, numZoomLevels: 20}
);
// build up all controls
map.addControl(new OpenLayers.Control.PanZoomBar({ position: new
OpenLayers.Pixel(2, 15) }));
map.addControl(new OpenLayers.Control.Navigation());
map.addControl(new OpenLayers.Control.Scale($('scale')));
map.addControl(new OpenLayers.Control.MousePosition({element:
$('location')}));
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.events.register('click', map, function (e) {
document.getElementById('nodelist').innerHTML =
"Loading... please wait...";
var params = {
REQUEST: "GetFeatureInfo",
EXCEPTIONS: "application/vnd.ogc.se_xml",
BBOX: map.getExtent().toBBOX(),
X: e.xy.x,
Y: e.xy.y,
INFO_FORMAT: 'text/html',
QUERY_LAYERS: map.layers[1].params.LAYERS,
FEATURE_COUNT: 50,
Layers: 'cira:addresses',
Styles: '',
Srs: 'EPSG:4326',
WIDTH: map.size.w,
HEIGHT: map.size.h,
format: 'image/jpeg'};
//updateFeatureInfoFilters(params);
OpenLayers.loadURL("http://localhost:8080/geoserver/wms",
params, this, setHTML, setHTML);
OpenLayers.Event.stop(e);
// alert("layer: " + map.layers[1].params.LAYERS);
alert("mouse pos: " + e.xy);
});
map.addLayers([ghyb,cira_addresses_layer]);
map.zoomToMaxExtent();
}
</script>
</head>
<body onload="init()">
<div style="width:100%; height:100%" id="map"></div>
<div id="nodelist">
<em>Click on the map to get feature info</em>
</div>
</body>
</html>
Thank you very much !
--
Signed,
Alessandro Ferrucci
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20091021/0198961b/attachment.html
More information about the Users
mailing list