getsmap / smap-responsive

A JavaScript framework for simple creation of web maps with responsive design supporting a range of different browsers and devices
GNU General Public License v3.0
14 stars 12 forks source link

Parse GetfeatureInfo response to correct format #185

Open jakelund opened 8 years ago

jakelund commented 8 years ago

Länsstyrelsens WMS has wrong formatting for sMap popups. Their ArcGIS server doesn't support gml. I need to parse it with a template so that sMap can handle it and create my popup window. See below for request and response example in text/plain:

Request http://kartor.lund.se/proxy.py?url=http%3A%2F%2Fext-geoservices.lansstyrelsen.se%2FArcGIS%2Fservices%2Friksintressen%2FMapServer%2FWMSServer%3Fservice%3DWMS%26request%3DGetFeatureInfo%26bbox%3D12.82379150390625%252C55.249380642767875%252C13.918304443359375%252C56.0697358954469%26layers%3D62%26styles%3D%26typename%3D62%26query_layers%3D62%26info_format%3Dtext%252Fplain%26feature_count%3D20%26x%3D266%26y%3D636%26buffer%3D10%26width%3D797%26height%3D1059%26srs%3DEPSG%253A4326%26exceptions%3Dapplication%25252Fvnd.ogc.se_xml%26version%3D1.1.1

Response @ID ATTRIBUT1;ATTRIBUT2;ATTRIBUT3;...;VALUE1;VALUE2;VALUE3;

johanlahti commented 8 years ago

I have modified the SelectWMS plugin (see below) so that you can create a custom parser when you specify the layer config:

// SelectWMS.js row 534
if (typeof info_format === "function") {
    out = info_format.call(this, resp);
}

So instead of specifying an info_format as a mime type, like "text/plain" or "application/json", you specify a function (a parser) which takes one argument, which is the getfeatureinfo response. E g:

info_format: function(responseText) {
    // This function should return a key-value object like: {id: 1, name: "Some object"}
    var rows = responseText.split("\n"); // etc…
    return {}; // the key-value object
}