| 44 | } |
| 45 | |
| 46 | public static void Main(string[] args) |
| 47 | { |
| 48 | |
| 49 | if (args.Length < 2) usage(); |
| 50 | |
| 51 | // creating a new map from scratch |
| 52 | mapObj map = new mapObj(null); |
| 53 | // adding a layer |
| 54 | layerObj layer = new layerObj(map); |
| 55 | layer.type = MS_LAYER_TYPE.MS_LAYER_POINT; |
| 56 | layer.status = mapscript.MS_ON; |
| 57 | layer.connectiontype = MS_CONNECTION_TYPE.MS_INLINE; |
| 58 | // define the attribute names from the inline layer |
| 59 | layer.addProcessing("ITEMS=attribute1,attribute2,attribute3"); |
| 60 | // define the class |
| 61 | classObj classobj = new classObj(layer); |
| 62 | classobj.template = "query"; // making the layer queryable |
| 63 | // setting up the text based on multiple attributes |
| 64 | classobj.setText("('Shape:' + '[attribute1]' + ' Color:' + '[attribute2]' + ' Size:' + '[attribute3]')"); |
| 65 | // define the label |
| 66 | classobj.label.outlinecolor = new colorObj(255, 255, 255, 0); |
| 67 | classobj.label.force = mapscript.MS_TRUE; |
| 68 | classobj.label.size = (double)MS_BITMAP_FONT_SIZES.MS_MEDIUM; |
| 69 | classobj.label.position = (int)MS_POSITIONS_ENUM.MS_LC; |
| 70 | classobj.label.wrap = ' '; |
| 71 | // set up attribute binding |
| 72 | classobj.label.setBinding((int)MS_LABEL_BINDING_ENUM.MS_LABEL_BINDING_COLOR, "attribute2"); |
| 73 | // define the style |
| 74 | styleObj style = new styleObj(classobj); |
| 75 | style.color = new colorObj(0, 255, 255, 0); |
| 76 | style.setBinding((int)MS_STYLE_BINDING_ENUM.MS_STYLE_BINDING_COLOR, "attribute2"); |
| 77 | style.setBinding((int)MS_STYLE_BINDING_ENUM.MS_STYLE_BINDING_SIZE, "attribute3"); |
| 78 | |
| 79 | Random rand = new Random((int)DateTime.Now.ToFileTime()); ; |
| 80 | |
| 81 | // creating the shapes |
| 82 | for (int i = 0; i < 10; i++) |
| 83 | { |
| 84 | shapeObj shape = new shapeObj((int)MS_SHAPE_TYPE.MS_SHAPE_POINT); |
| 85 | |
| 86 | // setting the shape attributes |
| 87 | shape.initValues(4); |
| 88 | shape.setValue(0, Convert.ToString(i)); |
| 89 | shape.setValue(1, new colorObj(rand.Next(255), rand.Next(255), rand.Next(255), 0).toHex()); |
| 90 | shape.setValue(2, Convert.ToString(rand.Next(25) + 5)); |
| 91 | |
| 92 | lineObj line = new lineObj(); |
| 93 | line.add(new pointObj(rand.Next(400) + 25, rand.Next(400) + 25, 0, 0)); |
| 94 | shape.add(line); |
| 95 | layer.addFeature(shape); |
| 96 | } |
| 97 | |
| 98 | map.width = 500; |
| 99 | map.height = 500; |
| 100 | map.setExtent(0,0,450,450); |
| 101 | map.selectOutputFormat(args[0]); |
| 102 | imageObj image = map.draw(); |
| 103 | image.save(args[1], map); |