📄 sldwizard.jsp
字号:
textFill = createFill(labelColor, 1.0); if (propertyName != null && propertyName != "none") SLDr += createTextSymbolizer(propertyName, textFont, halo, textFill); return SLDr;}function generatePolygonSLD(){ propertyName = document.getElementById('propertyName').value; labelColor = document.getElementById('labelColor').value; fillColor = document.getElementById('fillColor').value; fillOpacity = document.getElementById('fillOpacity').value; lineColor = document.getElementById('lineColor').value; lineOpacity = document.getElementById('lineOpacity').value; if (labelColor.length == 6) labelColor = '#'+labelColor; if (fillColor.length == 6) fillColor = '#'+fillColor; if (lineColor.length == 6) lineColor = '#'+lineColor; var halo; // check values to make sure they are in range and valid if (propertyName != "none" && (labelColor == null || labelColor == "") ) return "ERROR: label name specified, but no text color specified."; if (labelColor == null || labelColor == "") return "ERROR: Label color cannot be empty"; if (labelColor.length != 7) return "ERROR: Label color must be 7 characters long in hexadecimal (#00ff23)."; if (fillColor == null || fillColor == "") return "ERROR: Polygon fill color cannot be empty"; if (fillColor.length != 7) return "ERROR: Polygon fill color must be 7 characters long in hexadecimal (#00ff23)."; if (fillOpacity == null || fillOpacity == "") return "ERROR: Polygon color opacity cannot be empty"; if (fillOpacity < 0.0 || fillOpacity > 1.0) return "ERROR: Polygon fill opacity must be between 0.0 and 1.0"; if (lineColor == null || lineColor == "") return "ERROR: Polygon outline color cannot be empty"; if (lineColor.length != 7) return "ERROR: Polygon outline color must be 7 characters long in hexadecimal (#00ff23)."; if (lineOpacity == null || lineOpacity == "") return "ERROR: Polygon outline opacity cannot be empty"; if (lineOpacity < 0.0 || lineOpacity > 1.0) return "ERROR: Polygon outline opacity must be between 0.0 and 1.0"; // create fill polygonFill = createFill(fillColor, fillOpacity); // create stroke stroke = createStroke(lineColor, lineOpacity); XMLr = createSLDPolygonSymbolizer(polygonFill, stroke); textFill = createFill(labelColor, 1.0); textFont = createFont("Times New Roman", "Normal", 12); if (propertyName != null && propertyName != "none") XMLr += createTextSymbolizer(propertyName, textFont, halo, textFill); return XMLr;}/** * Perform the putStyles request */function saveStyle(SLD){ log("Saving style"); //kill any current requests! if (geo_xmlhttp !=null) { geo_xmlhttp.abort(); geo_xmlhttp = null; } // build XML POST query URL = "/geoserver/wms?request=putstyles";//"http://"+SERVERHOSTNAME+"/ getXML(URL,SLD,XMLProgressFunction); }function createSLDHeader(featureType){ log("Making sld for: "+featureType); XML = '<?xml version="1.0" encoding="UTF-8"?>'+"\n"; XML += '<StyledLayerDescriptor version="1.0.0"'+"\n"; XML += ' xmlns:gml="http://www.opengis.net/gml"'+"\n"; XML += ' xmlns:ogc="http://www.opengis.net/ogc"'+"\n"; XML += ' xmlns="http://www.opengis.net/sld">'+"\n"; XML += ' <NamedLayer>'+"\n"; XML += ' <Name>'+featureType+'</Name>'+"\n"; XML += ' <UserStyle>'+"\n"; XML += ' <Name>'+featureType+'_style</Name>'+"\n"; XML += ' <Title>geoserver style</Title>'+"\n"; XML += ' <Abstract>Generated by GeoServer</Abstract>'+"\n"; XML += ' <FeatureTypeStyle>'+"\n"; XML += ' <Rule>'+"\n"; //log(XML); return XML;}function createSLDFooter(){ XML = ' </Rule>'+"\n"; XML += ' </FeatureTypeStyle>'+"\n"; XML += ' </UserStyle>'+"\n"; XML += ' </NamedLayer>'+"\n"; XML += '</StyledLayerDescriptor>'; return XML;}function createSLDPointSymbolizer(graphic){ XML = ' <PointSymbolizer>'+"\n"; XML += ' '+graphic+"\n"; XML += ' </PointSymbolizer>'+"\n"; return XML;}function createSLDLineSymbolizer(stroke){ XML = ' <LineSymbolizer>'+"\n"; XML += stroke; XML += ' </LineSymbolizer>'+"\n"; return XML;}function createSLDPolygonSymbolizer(fill, stroke){ XML = ' <PolygonSymbolizer>'+"\n"; XML += fill; XML += stroke; XML += ' </PolygonSymbolizer>'+"\n"; return XML;}function createFill(color, opacity){ // add # to front of 'color' if(color.charAt(0) != "#") color = "#"+color; XML = ' <Fill>'+"\n"; XML += ' <CssParameter name="fill">'+color+'</CssParameter>'+"\n"; XML += ' <CssParameter name="fill-opacity">'+opacity+'</CssParameter>'+"\n"; XML += ' </Fill>'+"\n"; return XML;}function createStroke(color, opacity, width, linecap, linejoin, dasharray){ // add # to front of 'color' if(color.charAt(0) != "#") color = "#"+color; XML = ' <Stroke>'+"\n"; if(color) XML += ' <CssParameter name="stroke">'+color+'</CssParameter>'+"\n"; if(opacity) XML += ' <CssParameter name="stroke-opacity">'+opacity+'</CssParameter>'+"\n"; if(width) XML += ' <CssParameter name="stroke-width">'+width+'</CssParameter>'+"\n"; if(linecap) XML += ' <CssParameter name="stroke-linecap">'+linecap+'</CssParameter>'+"\n"; if(linejoin)XML += ' <CssParameter name="stroke-linejoin">'+linejoin+'</CssParameter>'+"\n"; if(dasharray)XML += ' <CssParameter name="stroke-dasharray">'+dasharray+'</CssParameter>'+"\n"; XML += ' </Stroke>'+"\n"; return XML;}// a note to figure out all possible line capsfunction getLineCaps(){}// a note to figure out all possible line joinsfunction getLineJoins(){}function createGraphic(shape, fill, stroke, size, opacity){ XML = '<Graphic>'+"\n"; XML += ' <Mark>'+"\n"; XML += ' <WellKnownName>'+shape+'</WellKnownName>'+"\n"; XML += fill; if(stroke) XML += stroke; XML += ' </Mark>'+"\n"; XML += ' <Opacity>'+opacity+'</Opacity>'+"\n"; XML += ' <Size>'+size+'</Size>'+"\n"; XML += '</Graphic>'+"\n"; return XML;}function createTextSymbolizer(columnName, font, halo, fill){ XML = ' <TextSymbolizer>'+"\n"; XML += ' <Label>'+"\n"; XML += ' <ogc:PropertyName>'+columnName+'</ogc:PropertyName>'+"\n"; XML += ' </Label>'+"\n"; if(font) XML += font; if(halo) XML += halo; if(fill) XML += fill; XML += ' </TextSymbolizer>'+"\n"; return XML;}function createFont(name, style, size, weight){ XML = ' <Font>'+"\n"; XML += ' <CssParameter name="font-family">'+name+'</CssParameter>'+"\n"; XML += ' <CssParameter name="font-style">'+style+'</CssParameter>'+"\n"; XML += ' <CssParameter name="font-size">'+size+'</CssParameter>'+"\n"; if (weight)XML += ' <CssParameter name="font-weight">'+weight+'</CssParameter>'+"\n"; XML += ' </Font>'+"\n"; return XML;}function createHalo(radius, fill){ XML = ' <Halo>'+"\n"; XML += ' <Radius>'+"\n"; XML += ' <ogc:Literal>'+radius+'</ogc:Literal>'+"\n"; XML += ' </Radius>'+"\n"; XML += fill; XML += ' </Halo>'+"\n"; return XML;}function createMinScaleDenominator(scale){ XML = '<MinScaleDenominator>'+scale+'</MinScaleDenominator>'+"\n"; return XML;}function createMaxScaleDenominator(scale){ XML = '<MaxScaleDenominator>'+scale+'</MaxScaleDenominator>'+"\n"; return XML;}/** * Send the XML request to GeoServer. Hands off control to procfunction method passed in. */function getXML(url,post,procfunction){ try { if (window.ActiveXObject) { // IE log("getXML through IE"); geo_xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); geo_xmlhttp.onreadystatechange = procfunction; geo_xmlhttp.open("POST", url, true); geo_xmlhttp.setRequestHeader('Content-Type', 'text/xml'); //correct request type geo_xmlhttp.setRequestHeader('Cache-Control', 'no-cache'); // don't cache the requests!!! //geo_xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); geo_xmlhttp.send(post); } else if (window.XMLHttpRequest) { // Mozilla and others //log("getXML through Mozilla etc."); geo_xmlhttp = new XMLHttpRequest(); //geo_xmlhttp.overrideMimeType('text/xml'); // <- bad? caused some serious problems at one point geo_xmlhttp.onreadystatechange = procfunction; geo_xmlhttp.open("POST", url, true); geo_xmlhttp.setRequestHeader('Content-Type', 'text/xml'); //correct request type geo_xmlhttp.setRequestHeader('Cache-Control', 'no-cache'); // don't cache the requests!!! geo_xmlhttp.send(post); } else log("Invalid browser format: not expecting this kind of browser."); } catch(e) { alert(e); alert("If you just got a security exception, its because you need to serve the .html file from the same server as where you're sending the XML requests to!"); }}/** * Waits for requests and handles them. */function XMLProgressFunction(){ if (geo_xmlhttp != null) { // add 'working' animation hideSuccessMessage(); } if ( (geo_xmlhttp.readyState == 4) && (geo_xmlhttp.status == 200) ) { log("XML reponse received"); //we got a good response. We need to process it! if (geo_xmlhttp.responseXML == null) { log("XMLProgressFunction(): abort 1"); //document.getElementById('working_anim_gnis_span').innerHTML = ''; // remove 'working' animation return; } log("response:\n"+geo_xmlhttp.responseText); // ug, temporary hack just so I can get it working if (window.ActiveXObject) { val = geo_xmlhttp.responseText.indexOf("success"); if (val > -1) { enableSuccessMessage(); log("PutStyles successful"); } } else { success_node = getElements(geo_xmlhttp.responseXML,"sld","success")[0]; if (success_node != null) { enableSuccessMessage(); log("PutStyles successful"); } } } else log("waiting for response...");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -