- 积分
- 229
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2013-10-17
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 ycjtj1dx202ly 于 2013-11-5 11:23 编辑
此次教程先实现Mask Out功能,即屏蔽指定的区域之外的图形,MapView有MaskOut属性,可以设置SetMaskOut和MaskLayer(必须是Polygon图层,不要太复杂)。
首先将图层shaded_PS中加入aLayer.setMaskOut(true);
创建好菜单好,输入下列代码:
- private void jMenuItem_MaskOutActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- MaskOut mo = layersLegend1.getActiveMapFrame().getMapView().getMaskOut();
- mo.setMask(true);
- mo.setMaskLayer("china.shp");
- layersLegend1.getActiveMapFrame().getMapView().paintLayers();
- }
调试结果如下:
Mask Out之前
Mask Out之后
接下来实现创建点图层。创建一个VectorLayer图层需要给图层对象增加属性字段,并添加相应的Shape对象及属性值。具体代码如下:
- private void jMenuItem_CreatePointLayerActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- //New layer
- VectorLayer aLayer = new VectorLayer(ShapeTypes.Point);
- aLayer.setLayerName("New_Point_Layer");
- aLayer.setLegendScheme(LegendManage.createSingleSymbolLegendScheme(ShapeTypes.Point, Color.black, 10));
- aLayer.setVisible(true);
- //Add fields
- aLayer.editAddField("STATION", DataTypes.String);
- aLayer.editAddField("LON", DataTypes.Double);
- aLayer.editAddField("LAT", DataTypes.Double);
- aLayer.editAddField("DATA", DataTypes.Double);
- //Prepare coordinate data
- double[] X = {120.0, 110.0};
- double[] Y = {42.0, 35.0};
- double[] data = {100.0, 80.0};
- //Add shape
- for (int i = 0; i < 2; i++) {
- PointShape aPS = new PointShape();
- PointD aPoint = new PointD();
- aPoint.X = X;
- aPoint.Y = Y;
- aPS.setPoint(aPoint);
- int shapeNum = aLayer.getShapeNum();
- try {
- if (aLayer.editInsertShape(aPS, shapeNum)) {
- //Edit record value
- aLayer.editCellValue("STATION", shapeNum, "St1");
- aLayer.editCellValue("LON", shapeNum, aPoint.X);
- aLayer.editCellValue("LAT", shapeNum, aPoint.Y);
- aLayer.editCellValue("DATA", shapeNum, data);
- }
- } catch (Exception ex) {
- Logger.getLogger(FrmMain.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- //Add Label
- aLayer.getLabelSet().setFieldName("DATA");
- aLayer.getLabelSet().setLabelFont(new Font("Arial", Font.PLAIN, 18));
- aLayer.getLabelSet().setYOffset(30);
- aLayer.addLabels();
- //Add layer
- layersLegend1.getActiveMapFrame().addLayer(aLayer);
- layersLegend1.getActiveMapFrame().getMapView().paintLayers();
- layersLegend1.repaint();
- }
上述代码的调试结果如下:
|
|