📄 esri_task_printing.js
字号:
htmlStr += "</td></tr>"; htmlStr += "</table>"; htmlStr += "<span style='font-family: Arial,Helvetica,sans-serif; font-size: 10px; z-index:99'>"+printMapObj.getCopyrightText()+"</span>"; } return htmlStr; } /** * Generates the legend patch in a column row. * @param {Object} level * @param {Object} label * @param {Object} imageUrl */ function renderLegendPatchInHTML(level, label, imageUrl ) { var htmlStr = ""; if (level == 0) { htmlStr += "<td nowrap='' class='esriTocLabelDataFrame'>"; } else if (level == 1) { htmlStr += "<td nowrap='' class='esriTocLabelLayer'>"; } else if (level == 2 && imageUrl.length < 2 ) { htmlStr += "<td nowrap='' class='esriTocLabelField'>"; } else { htmlStr += "<td nowrap='' class='esriTocLabel'>"; } var indents = 5+5*level; htmlStr += "<img src='images/pixel.gif' style='width: "+indents+"px; height: 0px;'/>" ; if (imageUrl.length >1) { htmlStr += "<img src='images/pixel.gif' style='margin: 0px 4px 0px 0px; padding: 0px 4px 0px 0px; width: 9px; height: 0px;'/>"; htmlStr += "<img src="+imageUrl+" style='margin: 0px 4px 0px 0px; padding: 0px 4px 0px 0px;'/>"; } htmlStr += "<span>"+label+"</span>"; htmlStr += "</td>"; return htmlStr; } /** * The class represents a printing map object. * It wraps all information needed to generate a Printing page. * * @param {Object} xmlObj */ PrintMap = function(xmlObj) { this.taskId = getNodeValue(xmlObj, "task-id"); this.mapTitle = getNodeValue(xmlObj, "map-title"); this.mapWidth = getNodeValue(xmlObj, "map-width"); this.mapHeight = getNodeValue(xmlObj, "map-height"); this.mapUrl = getNodeValue(xmlObj, "map-url"); this.isPrintResultOnly = getNodeValue(xmlObj, "print-resultOnly"); this.isPrintLegend = getNodeValue(xmlObj, "print-legend"); this.copyrightText = getNodeValue(xmlObj, "map-copyright"); this.legendColumns = parseInt(getNodeValue(xmlObj, "legend-columns")); this.legendNodes = getLegendNodeArray(xmlObj); this.printResults = getThePrintResults(xmlObj); /* * Returns the node value */ function getNodeValue(xml, tagName){ var node = xml.getElementsByTagName(tagName); if (node !=null && node.length >0 && node.item(0).childNodes.length > 0) { return node.item(0).firstChild.nodeValue; } return ""; } /* * Return an array of legend nodes. */ function getLegendNodeArray(xml) { var legendNodes = xml.getElementsByTagName("node"); var nodeArray = new Array(); if (legendNodes.length > 0) { for(i=0; i<legendNodes.length; i++) { var legendNode = legendNodes.item(i); if (legendNode.hasChildNodes()) { var level = 0; var key = ' '; var label = ' '; var imageUrl = ' '; //extracts the level, patchUrl, and labelText values var legChildNodes = legendNode.childNodes; for (j=0; j< legChildNodes.length; j++) { var lcNode = legChildNodes.item(j); if (lcNode.nodeName == "level") { level = parseInt(lcNode.firstChild.nodeValue); } else if (lcNode.nodeName == "key") { key = lcNode.firstChild.nodeValue; } else if (lcNode.nodeName == "content") { if (lcNode.childNodes.length == 1) { var cccnode = lcNode.childNodes.item(0); if (cccnode.nodeName == "text" && cccnode.childNodes.length >0 ) { label = cccnode.firstChild.nodeValue; } else if (cccnode.nodeName == "image-url"){ imageUrl = cccnode.firstChild.nodeValue; } } if (lcNode.childNodes.length == 2){ if (lcNode.childNodes.item(0).hasChildNodes()) { label = lcNode.childNodes.item(0).firstChild.nodeValue; } if (lcNode.childNodes.item(1).hasChildNodes()) { imageUrl = lcNode.childNodes.item(1).firstChild.nodeValue; } } } } // end of for nodeArray.push(new LegendNode(level, key, label, imageUrl)); } } } //if (legendNodes.length > 0) { return nodeArray; } /* * Returns the PrintResult */ function getThePrintResults(xmlObj) { var print_Results = new Array(); var printResultNodes = xmlObj.getElementsByTagName("print-result"); if (printResultNodes.length > 0) { for(i=0; i<printResultNodes.length; i++) { var prname = printResultNodes[i].getAttribute("name"); var printResult = new PrintResult(prname); var layers = printResultNodes[i].getElementsByTagName("layer"); for(j=0; j<layers.length; j++) { var n = layers[j].getAttribute("name"); var c = layers[j].getAttribute("results"); var layerQueryResult = new LayerQueryResult(n, c); var details = layers[j].getElementsByTagName("details"); for (var m=0; m<details.length; m++) { var detail = details[m].getElementsByTagName("detail"); var keys = new Array(); var vals = new Array(); //generates the data for (var n=0; n<detail.length; n++) { keys.push(detail[n].getAttribute("key")); vals.push(detail[n].getAttribute("value")); } layerQueryResult.addDetail(keys, vals); } //end of for printResult.addLayerQueryResult(layerQueryResult); } print_Results.push(printResult); } //end of for } // end of if return print_Results; } } PrintMap.prototype.getTaskId = function() { return this.taskId; } PrintMap.prototype.getMapTitle = function() { return this.mapTitle; } PrintMap.prototype.getMapWidth = function() { return this.mapWidth; } PrintMap.prototype.getMapHeight = function() { return this.mapHeight; } PrintMap.prototype.getMapUrl = function() { return this.mapUrl; } PrintMap.prototype.getIsPrintResultOnly = function() { return this.isPrintResultOnly; } PrintMap.prototype.getIsPrintLegend = function() { return this.isPrintLegend; } PrintMap.prototype.getCopyrightText = function() { return this.copyrightText; } PrintMap.prototype.getLegendColumns = function() { return this.legendColumns; } PrintMap.prototype.getLegendNodes = function() { return this.legendNodes; } PrintMap.prototype.getPrintResults = function() { return this.printResults; } /* ===== End of the PrintMap class ===== */ /** * A Legend Node class. It stores all properties to represent a legend. * * @param {Object} level * @param {Object} key * @param {Object} label * @param {Object} imageUrl */ LegendNode = function(level, key, label, imageUrl) { this.level = (level != undefined) ? level : 0; this.key = (key != undefined) ? key : ""; this.label = (label != undefined) ? label : ""; this.imageUrl = (imageUrl != undefined) ? imageUrl : ""; } LegendNode.prototype.getLevel = function() { return this.level; } LegendNode.prototype.getKey = function() { return this.key; } LegendNode.prototype.getLabel = function() { return this.label; } LegendNode.prototype.getImageUrl = function() { return this.imageUrl; } /* ===== End of the legend node class ===== */ /** * The class represents the print-result tag data object. * @param {Object} name */ PrintResult = function(name) { this.name = (name != undefined) ? name : ""; this.LayerQueryResults = new Array(); } PrintResult.prototype.getName = function() { return this.name; } PrintResult.prototype.setName = function(na) { this.name = (na != undefined) ? na : "";; } PrintResult.prototype.getLayerQueryResults = function() { return this.LayerQueryResults; } PrintResult.prototype.addLayerQueryResult = function(layerQR) { this.LayerQueryResults.push(layerQR); } /** * The class represents a query result data object. * The object wraps the XML portions, * For example, * <layer name="usa" results="3"> * <details> * <detail key="name" value="riverside" /> * </details> * </layer> * @param {Object} name */ LayerQueryResult = function(name, count) { this.name = (name != undefined) ? name : ""; this.count = (count != undefined) ? count : 0; this.keysArray = new Array(); this.valuesArray = new Array(); } LayerQueryResult.prototype.getName = function() { return this.name; } LayerQueryResult.prototype.getCount = function() { return this.count; } LayerQueryResult.prototype.getKeys = function() { return this.keysArray; } LayerQueryResult.prototype.getValues = function() { return this.valuesArray; } LayerQueryResult.prototype.addDetail = function(keys, vals) { this.keysArray.push(keys); this.valuesArray.push(vals); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -