I'm not able to get information with Getfeatureinfo when clicking on point & line layers. For polygons it works fine.
I'm using the code below to execute the wms service
google.maps.event .addListener( map, "click", function(event) { // event.latLng.lng() + "%2C" + event.latLng.lat() + "%2C" + event.latLng.lng() + "%2C" + event.latLng.lat() var myLatLng = event.latLng; var lat = myLatLng.lat(); var lng = myLatLng.lng(); //var latlng = new google.maps.LatLng(lat, lng); //var bounds = new google.maps.LatLngBounds(southWest, northEast); var bounds = new google.maps.LatLngBounds( new google.maps.LatLng(lat, lng), new google.maps.LatLng(lat, lng)); //var bbox = lat + "," + lng + "," + lat + "," + lng; var projectionMap = new MercatorProjection(); var point = projectionMap .fromLatLngToPoint(event.latLng); var lULP = new google.maps.Point(point.x * 256, (point.y + 1) * 256); var lLRP = new google.maps.Point((point.x + 1) * 256,point.y * 256); var lULg = projectionMap.fromDivPixelToSphericalMercator(lULP, 8); var lLRg = projectionMap.fromDivPixelToSphericalMercator(lLRP, 8); var lUL_Latitude = lULg.y; var lUL_Longitude = lULg.x; var lLR_Latitude = lLRg.y; var lLR_Longitude = lLRg.x; //GJ: there is a bug when crossing the -180 longitude border (tile does not render) - this check seems to fix it if (lLR_Longitude < lUL_Longitude) { lLR_Longitude = Math.abs(lLR_Longitude); } var bbox = lUL_Longitude + "," + lUL_Latitude + "," + lLR_Longitude + "," + lLR_Latitude; var projection = map.getProjection(); var ulw = projection.fromPointToLatLng(lULP); var lrw = projection.fromPointToLatLng(lLRP); $.ajax({ "url" : 'http://localhost:8080/geoserver/WORKSPACE_X/wms?LAYERS=WORKSPACE_X:LAYER_X&QUERY_LAYERS=WORKSPACE_X:LAYER_X&STYLES=&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&BBOX='+bbox+'&FEATURE_COUNT=10&HEIGHT=539&WIDTH=1803&FORMAT=image%2Fpng&INFO_FORMAT=text%2Fhtml&SRS=EPSG%3A900913&X='+Math.round(point.x)+'&Y='+Math.round(point.y), //"url" : url, "data" : "", "type" : "POST", "success" : function(data) { infowindow.setContent(data); infowindow .setPosition(event.latLng); infowindow.open(map); }, "error" : function(xhr, status, error) { alert(" Can't do because: " + error); } }); }); /* Document : wms.js Created on : Feb 16, 2011, 3:25:27 PM Author : "Gavin Jackson " Refactored code from http://lyceum.massgis.state.ma.us/wiki/doku.php?id=googlemapsv3:home */ function bound(value, opt_min, opt_max) { if (opt_min != null) value = Math.max(value, opt_min); if (opt_max != null) value = Math.min(value, opt_max); return value; } function degreesToRadians(deg) { return deg * (Math.PI / 180); } function radiansToDegrees(rad) { return rad / (Math.PI / 180); } function MercatorProjection() { var MERCATOR_RANGE = 256; this.pixelOrigin_ = new google.maps.Point(MERCATOR_RANGE / 2, MERCATOR_RANGE / 2); this.pixelsPerLonDegree_ = MERCATOR_RANGE / 360; this.pixelsPerLonRadian_ = MERCATOR_RANGE / (2 * Math.PI); }; MercatorProjection.prototype.fromLatLngToPoint = function(latLng, opt_point) { var me = this; var point = opt_point || new google.maps.Point(0, 0); var origin = me.pixelOrigin_; point.x = origin.x + latLng.lng() * me.pixelsPerLonDegree_; // NOTE(appleton): Truncating to 0.9999 effectively limits latitude to // 89.189. This is about a third of a tile past the edge of the world tile. var siny = bound(Math.sin(degreesToRadians(latLng.lat())), -0.9999, 0.9999); point.y = origin.y + 0.5 * Math.log((1 + siny) / (1 - siny)) * -me.pixelsPerLonRadian_; return point; }; MercatorProjection.prototype.fromDivPixelToLatLng = function(pixel, zoom) { var me = this; var origin = me.pixelOrigin_; var scale = Math.pow(2, zoom); var lng = (pixel.x / scale - origin.x) / me.pixelsPerLonDegree_; var latRadians = (pixel.y / scale - origin.y) / -me.pixelsPerLonRadian_; var lat = radiansToDegrees(2 * Math.atan(Math.exp(latRadians)) - Math.PI / 2); return new google.maps.LatLng(lat, lng); }; MercatorProjection.prototype.fromDivPixelToSphericalMercator = function( pixel, zoom) { var me = this; var coord = me.fromDivPixelToLatLng(pixel, zoom); var r = 6378137.0; var x = r * degreesToRadians(coord.lng()); var latRad = degreesToRadians(coord.lat()); var y = (r / 2) * Math.log((1 + Math.sin(latRad)) / (1 - Math.sin(latRad))); return new google.maps.Point(x, y); }; Did someone face the same issue ?
Thanks
أكثر...
I'm using the code below to execute the wms service
google.maps.event .addListener( map, "click", function(event) { // event.latLng.lng() + "%2C" + event.latLng.lat() + "%2C" + event.latLng.lng() + "%2C" + event.latLng.lat() var myLatLng = event.latLng; var lat = myLatLng.lat(); var lng = myLatLng.lng(); //var latlng = new google.maps.LatLng(lat, lng); //var bounds = new google.maps.LatLngBounds(southWest, northEast); var bounds = new google.maps.LatLngBounds( new google.maps.LatLng(lat, lng), new google.maps.LatLng(lat, lng)); //var bbox = lat + "," + lng + "," + lat + "," + lng; var projectionMap = new MercatorProjection(); var point = projectionMap .fromLatLngToPoint(event.latLng); var lULP = new google.maps.Point(point.x * 256, (point.y + 1) * 256); var lLRP = new google.maps.Point((point.x + 1) * 256,point.y * 256); var lULg = projectionMap.fromDivPixelToSphericalMercator(lULP, 8); var lLRg = projectionMap.fromDivPixelToSphericalMercator(lLRP, 8); var lUL_Latitude = lULg.y; var lUL_Longitude = lULg.x; var lLR_Latitude = lLRg.y; var lLR_Longitude = lLRg.x; //GJ: there is a bug when crossing the -180 longitude border (tile does not render) - this check seems to fix it if (lLR_Longitude < lUL_Longitude) { lLR_Longitude = Math.abs(lLR_Longitude); } var bbox = lUL_Longitude + "," + lUL_Latitude + "," + lLR_Longitude + "," + lLR_Latitude; var projection = map.getProjection(); var ulw = projection.fromPointToLatLng(lULP); var lrw = projection.fromPointToLatLng(lLRP); $.ajax({ "url" : 'http://localhost:8080/geoserver/WORKSPACE_X/wms?LAYERS=WORKSPACE_X:LAYER_X&QUERY_LAYERS=WORKSPACE_X:LAYER_X&STYLES=&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&BBOX='+bbox+'&FEATURE_COUNT=10&HEIGHT=539&WIDTH=1803&FORMAT=image%2Fpng&INFO_FORMAT=text%2Fhtml&SRS=EPSG%3A900913&X='+Math.round(point.x)+'&Y='+Math.round(point.y), //"url" : url, "data" : "", "type" : "POST", "success" : function(data) { infowindow.setContent(data); infowindow .setPosition(event.latLng); infowindow.open(map); }, "error" : function(xhr, status, error) { alert(" Can't do because: " + error); } }); }); /* Document : wms.js Created on : Feb 16, 2011, 3:25:27 PM Author : "Gavin Jackson " Refactored code from http://lyceum.massgis.state.ma.us/wiki/doku.php?id=googlemapsv3:home */ function bound(value, opt_min, opt_max) { if (opt_min != null) value = Math.max(value, opt_min); if (opt_max != null) value = Math.min(value, opt_max); return value; } function degreesToRadians(deg) { return deg * (Math.PI / 180); } function radiansToDegrees(rad) { return rad / (Math.PI / 180); } function MercatorProjection() { var MERCATOR_RANGE = 256; this.pixelOrigin_ = new google.maps.Point(MERCATOR_RANGE / 2, MERCATOR_RANGE / 2); this.pixelsPerLonDegree_ = MERCATOR_RANGE / 360; this.pixelsPerLonRadian_ = MERCATOR_RANGE / (2 * Math.PI); }; MercatorProjection.prototype.fromLatLngToPoint = function(latLng, opt_point) { var me = this; var point = opt_point || new google.maps.Point(0, 0); var origin = me.pixelOrigin_; point.x = origin.x + latLng.lng() * me.pixelsPerLonDegree_; // NOTE(appleton): Truncating to 0.9999 effectively limits latitude to // 89.189. This is about a third of a tile past the edge of the world tile. var siny = bound(Math.sin(degreesToRadians(latLng.lat())), -0.9999, 0.9999); point.y = origin.y + 0.5 * Math.log((1 + siny) / (1 - siny)) * -me.pixelsPerLonRadian_; return point; }; MercatorProjection.prototype.fromDivPixelToLatLng = function(pixel, zoom) { var me = this; var origin = me.pixelOrigin_; var scale = Math.pow(2, zoom); var lng = (pixel.x / scale - origin.x) / me.pixelsPerLonDegree_; var latRadians = (pixel.y / scale - origin.y) / -me.pixelsPerLonRadian_; var lat = radiansToDegrees(2 * Math.atan(Math.exp(latRadians)) - Math.PI / 2); return new google.maps.LatLng(lat, lng); }; MercatorProjection.prototype.fromDivPixelToSphericalMercator = function( pixel, zoom) { var me = this; var coord = me.fromDivPixelToLatLng(pixel, zoom); var r = 6378137.0; var x = r * degreesToRadians(coord.lng()); var latRad = degreesToRadians(coord.lat()); var y = (r / 2) * Math.log((1 + Math.sin(latRad)) / (1 - Math.sin(latRad))); return new google.maps.Point(x, y); }; Did someone face the same issue ?
Thanks
أكثر...