====== Example : Working with a WKT Area layer ====== This example assumes you have successfully [[example_embed|embedded the component]] and [[example_checklicense|validated the license]]. This example shows you how to add a polygon layer using WKT data. WKT is a standard for encoding geometries using plain text. The geometries can be expressed in any CRS and can be rendering using a custom legend. * About WKT Support in WebClient : [[developer/webclient/wkt]] * About WKT in General : [[http://en.wikipedia.org/wiki/Well-known_text]] Steps to take : - Prepare a Legend - Prepare attribute definitions - Add a layer - Add objects to a layer - Remove a layer ===== 1. Prepare a legend ===== var legend = {}; legend.fillColor = "102.0.0"; // default = 0.102.0 legend.fillTransparency = 1.0; // default = 0.5 legend.lineColor = "255.0.0"; // default = 0.255.0 legend.lineTransparency = 0.2; // default = 0.0 legend.lineWidth = 3.0; // default = 1.0 ===== 2. Prepare attribute definitions ===== If you want your objects to have certain attributes, they need to be declared when adding the layer. Declaring attributes involves defining a name and type for every attribute : var attributeDefs = []; attributeDefs.push({name:"id",type:8/*string*/}); attributeDefs.push({name:"position",type:4/*int*/}); ===== 3. Add a layer ===== For this example we're using this WKT data : POLYGON Z ((133837.75075689898 206170.68672386 66.75229158891386, 133837.87326465631 206170.879064952 70.83002653990947, 133838.30827833957 206167.78262598623 70.71889750730033, 133838.25977460685 206167.70199663375 66.79471098851391)) To add a new WKT layer we use the ''addWKTLayer()'' function : var crs = "31370"; var legend = {}; legend.fillColor = "255.0.0"; legend.fillTransparency = 0.5; legend.lineColor = "255.0.0"; legend.lineTransparency = 0.2; legend.lineWidth = 3.0; var wktData = "POLYGON Z ((133837.75075689898 206170.68672386 66.75229158891386, 133837.87326465631 206170.879064952 70.83002653990947, 133838.30827833957 206167.78262598623 70.71889750730033, 133838.25977460685 206167.70199663375 66.79471098851391))"; var attributeDefs = []; attributeDefs.push({name:"id",type:4/*int*/}); attributeDefs.push({name:"material",type:8/*string*/}); var attributes = new Array(); attributes.push([1,"glass"]); viewer.addWKTLayer("WKT Areas",wktData,"31370"/*crs*/,legend,attributeDefs,attributes); The last 2 arguments for specifying attribute data are optional and can be ommitted. As defined in the [[180:developer:webclient:core_types]], the available attribute definition types are : * 8 : * 4 : * 6 : * 1 : ===== 4. Add objects to a layer ===== New objects can be added to an existing WKT layer. Legend or attribute definitions don't need to be provided because they are already present. var attributes = new Array(); attributes.push([2,"brick"]); var wktData = "POLYGON Z ((133837.64392282325 206169.81406293903 65.3584886604712, 133838.01128612863 206168.19463629555 65.3584886604712, 133838.0112696399 206168.1946569197 63.59289970688925, 133837.6439063346 206169.81408356223 63.59289970688925))"; viewer.addWKTToWKTLayer("WKT Areas",wktData,"31370"/*crs*/,attributes); ===== 5. Remove a layer ===== When you don't need a layer anymore, you can remove it : viewer.removeLayer("WKT Areas"); ===== Example =====