Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | 12x 12x 12x 2x 1x 1x 1x 12x 12x 11x 5x 6x 5x 1x 1x 1x 12x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 11x 11x 6x 5x 2x 3x 3x 1x 2x 1x 1x 6x 6x 6x 6x 6x 6x 6x 6x 6x 66x 66x 66x 66x 66x 6x 6x 6x 6x 6x 6x 6x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 8x 8x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 1x 1x 2x 1x 1x 1x 2x 1x 1x 1x 1x 1x 1x 3x 3x 1x 1x 1x 1x 2x 2x 6x 6x 2x 6x 1x 5x 1x 2x 3x 3x 3x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import Cartographic from "../Core/Cartographic.js";
import defined from "../Core/defined.js";
import DeveloperError from "../Core/DeveloperError.js";
import RuntimeError from "../Core/RuntimeError.js";
import ImageryLayerFeatureInfo from "./ImageryLayerFeatureInfo.js";
/**
* Describes the format in which to request GetFeatureInfo from a Web Map Service (WMS) server.
*
* @alias GetFeatureInfoFormat
* @constructor
*
* @param {string} type The type of response to expect from a GetFeatureInfo request. Valid
* values are 'json', 'xml', 'html', or 'text'.
* @param {string} [format] The info format to request from the WMS server. This is usually a
* MIME type such as 'application/json' or text/xml'. If this parameter is not specified, the provider will request 'json'
* using 'application/json', 'xml' using 'text/xml', 'html' using 'text/html', and 'text' using 'text/plain'.
* @param {Function} [callback] A function to invoke with the GetFeatureInfo response from the WMS server
* in order to produce an array of picked {@link ImageryLayerFeatureInfo} instances. If this parameter is not specified,
* a default function for the type of response is used.
*/
function GetFeatureInfoFormat(type, format, callback) {
//>>includeStart('debug', pragmas.debug);
Iif (!defined(type)) {
throw new DeveloperError("type is required.");
}
//>>includeEnd('debug');
this.type = type;
if (!defined(format)) {
if (type === "json") {
format = "application/json";
} else if (type === "xml") {
format = "text/xml";
} else Eif (type === "html") {
format = "text/html";
} else if (type === "text") {
format = "text/plain";
}
//>>includeStart('debug', pragmas.debug);
else {
throw new DeveloperError(
'format is required when type is not "json", "xml", "html", or "text".',
);
}
//>>includeEnd('debug');
}
this.format = format;
if (!defined(callback)) {
if (type === "json") {
callback = geoJsonToFeatureInfo;
} else if (type === "xml") {
callback = xmlToFeatureInfo;
} else Iif (type === "html") {
callback = textToFeatureInfo;
} else if (type === "text") {
callback = textToFeatureInfo;
}
//>>includeStart('debug', pragmas.debug);
else E{
throw new DeveloperError(
'callback is required when type is not "json", "xml", "html", or "text".',
);
}
//>>includeEnd('debug');
}
this.callback = callback;
}
function geoJsonToFeatureInfo(json) {
const result = [];
const features = json.features;
for (let i = 0; i < features.length; ++i) {
const feature = features[i];
const featureInfo = new ImageryLayerFeatureInfo();
featureInfo.data = feature;
featureInfo.properties = feature.properties;
featureInfo.configureNameFromProperties(feature.properties);
featureInfo.configureDescriptionFromProperties(feature.properties);
// If this is a point feature, use the coordinates of the point.
Eif (defined(feature.geometry) && feature.geometry.type === "Point") {
const longitude = feature.geometry.coordinates[0];
const latitude = feature.geometry.coordinates[1];
featureInfo.position = Cartographic.fromDegrees(longitude, latitude);
}
result.push(featureInfo);
}
return result;
}
const mapInfoMxpNamespace = "http://www.mapinfo.com/mxp";
const esriWmsNamespace = "http://www.esri.com/wms";
const wfsNamespace = "http://www.opengis.net/wfs";
const gmlNamespace = "http://www.opengis.net/gml";
function xmlToFeatureInfo(xml) {
const documentElement = xml.documentElement;
if (
documentElement.localName === "MultiFeatureCollection" &&
documentElement.namespaceURI === mapInfoMxpNamespace
) {
// This looks like a MapInfo MXP response
return mapInfoXmlToFeatureInfo(xml);
} else if (
documentElement.localName === "FeatureInfoResponse" &&
documentElement.namespaceURI === esriWmsNamespace
) {
// This looks like an Esri WMS response
return esriXmlToFeatureInfo(xml);
} else Iif (
documentElement.localName === "FeatureCollection" &&
documentElement.namespaceURI === wfsNamespace
) {
// This looks like a WFS/GML response.
return gmlToFeatureInfo(xml);
} else if (documentElement.localName === "ServiceExceptionReport") {
// This looks like a WMS server error, so no features picked.
throw new RuntimeError(
new XMLSerializer().serializeToString(documentElement),
);
} else if (documentElement.localName === "msGMLOutput") {
return msGmlToFeatureInfo(xml);
} else {
// Unknown response type, so just dump the XML itself into the description.
return unknownXmlToFeatureInfo(xml);
}
}
function mapInfoXmlToFeatureInfo(xml) {
const result = [];
const multiFeatureCollection = xml.documentElement;
const features = multiFeatureCollection.getElementsByTagNameNS(
mapInfoMxpNamespace,
"Feature",
);
for (let featureIndex = 0; featureIndex < features.length; ++featureIndex) {
const feature = features[featureIndex];
const properties = {};
const propertyElements = feature.getElementsByTagNameNS(
mapInfoMxpNamespace,
"Val",
);
for (
let propertyIndex = 0;
propertyIndex < propertyElements.length;
++propertyIndex
) {
const propertyElement = propertyElements[propertyIndex];
Eif (propertyElement.hasAttribute("ref")) {
const name = propertyElement.getAttribute("ref");
const value = propertyElement.textContent.trim();
properties[name] = value;
}
}
const featureInfo = new ImageryLayerFeatureInfo();
featureInfo.data = feature;
featureInfo.properties = properties;
featureInfo.configureNameFromProperties(properties);
featureInfo.configureDescriptionFromProperties(properties);
result.push(featureInfo);
}
return result;
}
function esriXmlToFeatureInfo(xml) {
const featureInfoResponse = xml.documentElement;
const result = [];
let properties;
const features = featureInfoResponse.getElementsByTagNameNS("*", "FIELDS");
if (features.length > 0) {
// Standard esri format
for (let featureIndex = 0; featureIndex < features.length; ++featureIndex) {
const feature = features[featureIndex];
properties = {};
const propertyAttributes = feature.attributes;
for (
let attributeIndex = 0;
attributeIndex < propertyAttributes.length;
++attributeIndex
) {
const attribute = propertyAttributes[attributeIndex];
properties[attribute.name] = attribute.value;
}
result.push(
imageryLayerFeatureInfoFromDataAndProperties(feature, properties),
);
}
} else {
// Thredds format -- looks like esri, but instead of containing FIELDS, contains FeatureInfo element
const featureInfoElements = featureInfoResponse.getElementsByTagNameNS(
"*",
"FeatureInfo",
);
for (
let featureInfoElementIndex = 0;
featureInfoElementIndex < featureInfoElements.length;
++featureInfoElementIndex
) {
const featureInfoElement = featureInfoElements[featureInfoElementIndex];
properties = {};
// node.children is not supported in IE9-11, so use childNodes and check that child.nodeType is an element
const featureInfoChildren = featureInfoElement.childNodes;
for (
let childIndex = 0;
childIndex < featureInfoChildren.length;
++childIndex
) {
const child = featureInfoChildren[childIndex];
if (child.nodeType === Node.ELEMENT_NODE) {
properties[child.localName] = child.textContent;
}
}
result.push(
imageryLayerFeatureInfoFromDataAndProperties(
featureInfoElement,
properties,
),
);
}
}
return result;
}
function gmlToFeatureInfo(xml) {
const result = [];
const featureCollection = xml.documentElement;
const featureMembers = featureCollection.getElementsByTagNameNS(
gmlNamespace,
"featureMember",
);
for (
let featureIndex = 0;
featureIndex < featureMembers.length;
++featureIndex
) {
const featureMember = featureMembers[featureIndex];
const properties = {};
getGmlPropertiesRecursively(featureMember, properties);
result.push(
imageryLayerFeatureInfoFromDataAndProperties(featureMember, properties),
);
}
return result;
}
// msGmlToFeatureInfo is similar to gmlToFeatureInfo, but assumes different XML structure
// eg. <msGMLOutput> <ABC_layer> <ABC_feature> <foo>bar</foo> ... </ABC_feature> </ABC_layer> </msGMLOutput>
function msGmlToFeatureInfo(xml) {
const result = [];
// Find the first child. Except for IE, this would work:
// const layer = xml.documentElement.children[0];
let layer;
const children = xml.documentElement.childNodes;
for (let i = 0; i < children.length; i++) {
if (children[i].nodeType === Node.ELEMENT_NODE) {
layer = children[i];
break;
}
}
Iif (!defined(layer)) {
throw new RuntimeError(
"Unable to find first child of the feature info xml document",
);
}
const featureMembers = layer.childNodes;
for (
let featureIndex = 0;
featureIndex < featureMembers.length;
++featureIndex
) {
const featureMember = featureMembers[featureIndex];
if (featureMember.nodeType === Node.ELEMENT_NODE) {
const properties = {};
getGmlPropertiesRecursively(featureMember, properties);
result.push(
imageryLayerFeatureInfoFromDataAndProperties(featureMember, properties),
);
}
}
return result;
}
function getGmlPropertiesRecursively(gmlNode, properties) {
let isSingleValue = true;
for (let i = 0; i < gmlNode.childNodes.length; ++i) {
const child = gmlNode.childNodes[i];
if (child.nodeType === Node.ELEMENT_NODE) {
isSingleValue = false;
}
if (
child.localName === "Point" ||
child.localName === "LineString" ||
child.localName === "Polygon" ||
child.localName === "boundedBy"
) {
continue;
}
if (
child.hasChildNodes() &&
getGmlPropertiesRecursively(child, properties)
) {
properties[child.localName] = child.textContent;
}
}
return isSingleValue;
}
function imageryLayerFeatureInfoFromDataAndProperties(data, properties) {
const featureInfo = new ImageryLayerFeatureInfo();
featureInfo.data = data;
featureInfo.properties = properties;
featureInfo.configureNameFromProperties(properties);
featureInfo.configureDescriptionFromProperties(properties);
return featureInfo;
}
function unknownXmlToFeatureInfo(xml) {
const xmlText = new XMLSerializer().serializeToString(xml);
const element = document.createElement("div");
const pre = document.createElement("pre");
pre.textContent = xmlText;
element.appendChild(pre);
const featureInfo = new ImageryLayerFeatureInfo();
featureInfo.data = xml;
featureInfo.description = element.innerHTML;
return [featureInfo];
}
const emptyBodyRegex = /<body>\s*<\/body>/im;
const wmsServiceExceptionReportRegex =
/<ServiceExceptionReport([\s\S]*)<\/ServiceExceptionReport>/im;
const titleRegex = /<title>([\s\S]*)<\/title>/im;
function textToFeatureInfo(text) {
// If the text is HTML and it has an empty body tag, assume it means no features were found.
Iif (emptyBodyRegex.test(text)) {
return undefined;
}
// If this is a WMS exception report, treat it as "no features found" rather than showing
// bogus feature info.
if (wmsServiceExceptionReportRegex.test(text)) {
return undefined;
}
// If the text has a <title> element, use it as the name.
let name;
const title = titleRegex.exec(text);
Eif (title && title.length > 1) {
name = title[1];
}
const featureInfo = new ImageryLayerFeatureInfo();
featureInfo.name = name;
featureInfo.description = text;
featureInfo.data = text;
return [featureInfo];
}
export default GetFeatureInfoFormat;
|