📄 v1.js
字号:
"UpperBoundary": function(node, filter) { filter.upperBoundary = this.readOgcExpression(node); } } }, /** * Method: readOgcExpression * Limited support for OGC expressions. * * Parameters: * node - {DOMElement} A DOM element that contains an ogc:expression. * * Returns: * {String} A value to be used in a symbolizer. */ readOgcExpression: function(node) { var obj = {}; this.readChildNodes(node, obj); var value = obj.value; if(!value) { value = this.getChildValue(node); } return value; }, /** * Property: cssMap * {Object} Object mapping supported css property names to OpenLayers * symbolizer property names. */ cssMap: { "stroke": "strokeColor", "stroke-opacity": "strokeOpacity", "stroke-width": "strokeWidth", "stroke-linecap": "strokeLinecap", "fill": "fillColor", "fill-opacity": "fillOpacity" }, /** * Method: getCssProperty * Given a symbolizer property, get the corresponding CSS property * from the <cssMap>. * * Parameters: * sym - {String} A symbolizer property name. * * Returns: * {String} A CSS property name or null if none found. */ getCssProperty: function(sym) { var css = null; for(var prop in this.cssMap) { if(this.cssMap[prop] == sym) { css = prop; break; } } return css; }, /** * Method: getGraphicFormat * Given a href for an external graphic, try to determine the mime-type. * This method doesn't try too hard, and will fall back to * <defautlGraphicFormat> if one of the known <graphicFormats> is not * the file extension of the provided href. * * Parameters: * href - {String} * * Returns: * {String} The graphic format. */ getGraphicFormat: function(href) { var format, regex; for(var key in this.graphicFormats) { if(this.graphicFormats[key].test(href)) { format = key; break; } } return format || this.defautlGraphicFormat; }, /** * Property: defaultGraphicFormat * {String} If none other can be determined from <getGraphicFormat>, this * default will be returned. */ defaultGraphicFormat: "image/png", /** * Property: graphicFormats * {Object} Mapping of image mime-types to regular extensions matching * well-known file extensions. */ graphicFormats: { "image/jpeg": /\.jpe?g$/i, "image/gif": /\.gif$/i, "image/png": /\.png$/i }, /** * Method: write * * Parameters: * sld - {Object} An object representing the SLD. * * Returns: * {DOMElement} The root of an SLD document. */ write: function(sld) { return this.writers.sld.StyledLayerDescriptor.apply(this, [sld]); }, /** * Property: writers * As a compliment to the readers property, this structure contains public * writing functions grouped by namespace alias and named like the * node names they produce. */ writers: { "sld": { "StyledLayerDescriptor": function(sld) { var root = this.createElementNSPlus( "StyledLayerDescriptor", {attributes: { "version": this.VERSION, "xsi:schemaLocation": this.schemaLocation }} ); // add in optional name if(sld.name) { this.writeNode(root, "Name", sld.name); } // add in optional title if(sld.title) { this.writeNode(root, "Title", sld.title); } // add in optional description if(sld.description) { this.writeNode(root, "Abstract", sld.description); } // add in named layers for(var name in sld.namedLayers) { this.writeNode(root, "NamedLayer", sld.namedLayers[name]); } return root; }, "Name": function(name) { return this.createElementNSPlus("Name", {value: name}); }, "Title": function(title) { return this.createElementNSPlus("Title", {value: title}); }, "Abstract": function(description) { return this.createElementNSPlus( "Abstract", {value: description} ); }, "NamedLayer": function(layer) { var node = this.createElementNSPlus("NamedLayer"); // add in required name this.writeNode(node, "Name", layer.name); // optional sld:LayerFeatureConstraints here // add in named styles if(layer.namedStyles) { for(var i=0; i<layer.namedStyles.length; ++i) { this.writeNode( node, "NamedStyle", layer.namedStyles[i] ); } } // add in user styles if(layer.userStyles) { for(var i=0; i<layer.userStyles.length; ++i) { this.writeNode( node, "UserStyle", layer.userStyles[i] ); } } return node; }, "NamedStyle": function(name) { var node = this.createElementNSPlus("NamedStyle"); this.writeNode(node, "Name", name); return node; }, "UserStyle": function(style) { var node = this.createElementNSPlus("UserStyle"); // add in optional name if(style.name) { this.writeNode(node, "Name", style.name); } // add in optional title if(style.title) { this.writeNode(node, "Title", style.title); } // add in optional description if(style.description) { this.writeNode(node, "Abstract", style.description); } // add isdefault if(style.isDefault) { this.writeNode(node, "IsDefault", style.isDefault); } // add FeatureTypeStyles this.writeNode(node, "FeatureTypeStyle", style); return node; }, "IsDefault": function(bool) { return this.createElementNSPlus( "IsDefault", {value: (bool) ? "1" : "0"} ); }, "FeatureTypeStyle": function(style) { var node = this.createElementNSPlus("FeatureTypeStyle"); // OpenLayers currently stores no Name, Title, Abstract, // FeatureTypeName, or SemanticTypeIdentifier information // related to FeatureTypeStyle // add in rules for(var i=0; i<style.rules.length; ++i) { this.writeNode(node, "Rule", style.rules[i]); } return node; }, "Rule": function(rule) { var node = this.createElementNSPlus("Rule"); // add in optional name if(rule.name) { this.writeNode(node, "Name", rule.name); } // add in optional title if(rule.title) { this.writeNode(node, "Title", rule.title); } // add in optional description if(rule.description) { this.writeNode(node, "Abstract", rule.description); } // add in LegendGraphic here // add in optional filters if(rule.elseFilter) { this.writeNode(node, "ElseFilter"); } else if(rule.filter) { this.writeNode(node, "ogc:Filter", rule.filter); } // add in scale limits if(rule.minScaleDenominator != undefined) { this.writeNode( node, "MinScaleDenominator", rule.minScaleDenominator ); } if(rule.maxScaleDenominator != undefined) { this.writeNode( node, "MaxScaleDenominator", rule.maxScaleDenominator ); } // add in symbolizers (relies on geometry type keys) var types = OpenLayers.Style.SYMBOLIZER_PREFIXES; var type, symbolizer; for(var i=0; i<types.length; ++i) { type = types[i]; symbolizer = rule.symbolizer[type]; if(symbolizer) { this.writeNode( node, type + "Symbolizer", symbolizer ); } } return node; }, "ElseFilter": function() { return this.createElementNSPlus("ElseFilter"); }, "MinScaleDenominator": function(scale) { return this.createElementNSPlus( "MinScaleDenominator", {value: scale} ); }, "MaxScaleDenominator": function(scale) { return this.createElementNSPlus( "MaxScaleDenominator", {value: scale} ); }, "LineSymbolizer": function(symbolizer) { var node = this.createElementNSPlus("LineSymbolizer"); this.writeNode(node, "Stroke", symbolizer); return node; }, "Stroke": function(symbolizer) { var node = this.createElementNSPlus("Stroke"); // GraphicFill here // GraphicStroke here // add in CssParameters if(symbolizer.strokeColor != undefined) { this.writeNode( node, "CssParameter", {symbolizer: symbolizer, key: "strokeColor"} ); } if(symbolizer.strokeOpacity != undefined) { this.writeNode( node, "CssParameter", {symbolizer: symbolizer, key: "strokeOpacity"} ); } if(symbolizer.strokeWidth != undefined) { this.writeNode( node, "CssParameter", {symbolizer: symbolizer, key: "strokeWidth"} ); } return node; }, "CssParameter": function(obj) { // not handling ogc:expressions for now return this.createElementNSPlus("CssParameter", { attributes: {name: this.getCssProperty(obj.key)}, value: obj.symbolizer[obj.key] }); }, "PolygonSymbolizer": function(symbolizer) { var node = this.createElementNSPlus("PolygonSymbolizer"); this.writeNode(node, "Fill", symbolizer); this.writeNode(node, "Stroke", symbolizer); return node; }, "Fill": function(symbolizer) { var node = this.createElementNSPlus("Fill"); // GraphicFill here // add in CssParameters if(symbolizer.fillColor) { this.writeNode( node, "CssParameter", {symbolizer: symbolizer, key: "fillColor"} ); } if(symbolizer.fillOpacity) { this.writeNode( node, "CssParameter", {symbolizer: symbolizer, key: "fillOpacity"} ); } return node; }, "PointSymbolizer": function(symbolizer) { var node = this.createElementNSPlus("PointSymbolizer"); this.writeNode(node, "Graphic", symbolizer); return node; }, "Graphic": function(symbolizer) { var node = this.createElementNSPlus("Graphic"); if(symbolizer.externalGraphic != undefined) { this.writeNode(node, "ExternalGraphic", symbolizer); } else if(symbolizer.graphicName) { this.writeNode(node, "Mark", symbolizer); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -