Skip to content

Commit e421ddc

Browse files
committed
The handleResponse method of WMSGetFeatureInfo now considers if the content-type
of the response is 'application/json'. In the case that JSON is returned, the features array is constructed by parsing doc with OpenLayers.Format.GeoJSON. This prevents a null reference issue when asking for feature information from GeoServer on Internet Explorer 11.
1 parent 87d18fc commit e421ddc

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
/doc/apidocs/
66
/examples/example-list.js
77
/examples/example-list.xml
8+
*.swp

lib/OpenLayers/Control/WMSGetFeatureInfo.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,16 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
507507
if(!doc || !doc.documentElement) {
508508
doc = request.responseText;
509509
}
510-
var features = this.format.read(doc);
510+
511+
var features = [];
512+
var responseHeaders = request.getAllResponseHeaders();
513+
if(responseHeaders && this.infoFormat === "application/json" && responseHeaders.indexOf("application/json") !== -1) {
514+
features = new OpenLayers.Format.GeoJSON().read(doc);
515+
}
516+
else {
517+
features = this.format.read(doc);
518+
}
519+
511520
if (this.drillDown === false) {
512521
this.triggerGetFeatureInfo(request, xy, features);
513522
} else {
@@ -517,8 +526,9 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
517526
{url: url, features: features}
518527
);
519528
} else {
520-
this._features = (this._features || []).concat(features);
529+
this._features = (this._features || []).concat(features);
521530
}
531+
522532
if (this._requestCount === this._numRequests) {
523533
this.triggerGetFeatureInfo(request, xy, this._features.concat());
524534
delete this._features;

tests/Control/WMSGetFeatureInfo.html

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,47 @@
636636

637637
}
638638

639+
function test_handleResponse_JSON(t) {
640+
t.plan(5);
641+
642+
var clickCoordinate = {'xy': {'x': 50, 'y': 50}};
643+
var request = {
644+
'responseText': "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"id\":\"buildings.8359\",\"geometry\":{\"type\":\"MultiPolygon\",\"coordinates\":[[[[-1.3154005920528281E7,4044522.989129901],[-1.3154005851109248E7,4044516.519693766],[-1.3153997359215712E7,4044516.611228658],[-1.3153997376215957E7,4044518.0115422606],[-1.3153991465984887E7,4044518.073011226],[-1.315399104407448E7,4044477.984995398],[-1.3154005865324631E7,4044477.827667067],[-1.3154005904349212E7,4044481.415238877],[-1.3154007327546554E7,4044481.40174741],[-1.3154007326878684E7,4044480.991660189],[-1.315400926879267E7,4044480.9700426213],[-1.3154009229231585E7,4044476.979656877],[-1.3154014543494673E7,4044476.9229164813],[-1.3154014548324812E7,4044477.5916807987],[-1.3154018354806663E7,4044477.5484488346],[-1.3154018350072712E7,4044476.9388398607],[-1.3154023840985721E7,4044476.881804511],[-1.315402384562935E7,4044477.5098391017],[-1.315402758599418E7,4044477.4704705887],[-1.315402757752542E7,4044476.790681231],[-1.3154038257694557E7,4044476.6769741727],[-1.3154038262405435E7,4044477.3457386605],[-1.315404269041407E7,4044477.2978384267],[-1.315404286439716E7,4044493.7800058103],[-1.3154007524848279E7,4044494.155989673],[-1.3154007646710869E7,4044505.7094379417],[-1.3154022107703935E7,4044505.556316444],[-1.3154022094344625E7,4044504.170787319],[-1.3154018346731113E7,4044504.21016599],[-1.3154018290260306E7,4044498.878616157],[-1.315402591048427E7,4044498.795894118],[-1.315402596710939E7,4044504.145869147],[-1.3154023609634686E7,4044504.171931162],[-1.3154023626849018E7,4044505.7015852067],[-1.3154042883521369E7,4044505.4999371967],[-1.3154043053740704E7,4044521.893539395],[-1.3154034951699786E7,4044521.9808243145],[-1.3154034960102554E7,4044522.6938309614],[-1.3154027829018425E7,4044522.768359982],[-1.315402782070021E7,4044522.180937892],[-1.3154024176006297E7,4044522.220149225],[-1.3154024180475479E7,4044522.74114868],[-1.3154018700641066E7,4044522.798166171],[-1.3154018696220534E7,4044522.30686572],[-1.3154014871261876E7,4044522.350007108],[-1.3154014875893366E7,4044522.8968263282],[-1.3154005920528281E7,4044522.989129901]]]]},\"geometry_name\":\"the_geom\",\"properties\":{\"CODE\":\"Building\",\"BLD_ID\":\"511910864932\",\"HEIGHT\":26.76,\"ELEV\":677.3,\"AREA\":0,\"SOURCE\":\"LARIAC2\",\"DATE_\":\"2008\",\"AIN\":\"5313004018\",\"Shape_Leng\":830.711543857,\"Shape_Area\":13794.2724736}}],\"crs\":{\"type\":\"EPSG\",\"properties\":{\"code\":\"3857\"}}}",
645+
'getAllResponseHeaders': function() {
646+
return "application/json";
647+
}
648+
};
649+
var url = "http://localhost/wms";
650+
651+
var map = new OpenLayers.Map("map", {
652+
getExtent: function() {return(new OpenLayers.Bounds(-180,-90,180,90));}
653+
}
654+
);
655+
656+
var a = new OpenLayers.Layer.WMS(null, url, {
657+
layers: "a",
658+
version: "1.3.0"
659+
});
660+
map.addLayer(a);
661+
662+
var click = new OpenLayers.Control.WMSGetFeatureInfo({
663+
});
664+
click.infoFormat = "application/json";
665+
click.events.register('getfeatureinfo', click, function(evt) {
666+
t.ok(evt, "Event object exists");
667+
t.ok(evt.text, "Event text exists");
668+
t.ok(evt.features, "Event features exists");
669+
t.ok(evt.xy, "Event coordinate exists");
670+
671+
t.eq(evt.features.length, 1, "Should contain one element");
672+
});
673+
674+
map.addControl(click);
675+
click.activate();
676+
677+
click.handleResponse(clickCoordinate, request, url);
678+
}
679+
639680
</script>
640681
</head>
641682
<body>

0 commit comments

Comments
 (0)