I am using GetFeatureInfo with WMS layer to get the data behind. The request returns data only after zoom level 10 before that it returns empty features.

Does anyone having same issue?

I think it is not calculating correct X & Y until zoom level 10. If I look same on the OpenLayers demo viewer which comes with GeoServer it gives correct result.

Environment: -Leaflet 0.7.2 with GeoServer 2.5.1 serving WMS

Request sent on zoom level 9:


Request sent on zoom level 10:


Result on zoom level 10: enter image description here

  • Please add this post as a comment to the answer and not as an answer itself. – Germán Carrillo Jan 29 '15 at 17:07

Solved this by using calculated X & Y instead of using generated from leaflet provided function layerPointToContainerPoint

Giving Wrong X & Y

var X =map.layerPointToContainerPoint(e.layerPoint).x.toFixed(0);
var Y = map.layerPointToContainerPoint(e.layerPoint).y.toFixed(0);

Correct X & Y from calculation

    var bds = map.getBounds();
    var sz = map.getSize();
    var w = bds.getNorthEast().lng - bds.getSouthWest().lng;
    var h = bds.getNorthEast().lat - bds.getSouthWest().lat;
    var X2= (((e.latlng.lng - bds.getSouthWest().lng) / w) * sz.x).toFixed(0);
    var Y2 = (((bds.getNorthEast().lat - e.latlng.lat) / h) * sz.y).toFixed(0);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.