发表用户:讨论贴
收集整理:James.Liu
相关讨论:http://www.mygis.com.cn/forum/dispbbs.asp?BoardID=11&id=3322
信息原始来源:James MapInfo技术论坛

文章标题:请问在MapXtreme for Java下我该如何创建标注呢?

jendy

请问我该如何创建标注呢?我是菜鸟啦,能不能该电源代码!!!?
我现在是刚开始学习这个东西,需要做地图标注,但是,对此还不大清楚,有哪位仁兄做过,能不能解释一下,或者给些相关代码呢?非常谢谢了!!!

kitter

如果只是要显示地图标注,可以先用mapinfo制作
如果要设置更多的状态,建议先看看《guide》中关于label的一章

jendy

谢谢,不过我是对标注属性无法控制哦,比如说,我想标注符号,怎么办?
能给写可参考的源代码吗?或者讲一下关于标注的概念?谢谢仁兄啦:)!!!

uestcwlh

public FeatureLayer creatAnnotationFeatureLayer(MapJ mapper)
    {
        FeatureLayer annotationLayer = null;
        AbstractLayer abstractLayer = mapper.getLayers().get("Annotation");
        if(abstractLayer != null)
        {
            annotationLayer = (FeatureLayer)abstractLayer;
        }
        else
        {
            String columns[] =
                {
                "uniqid", "名称"};

            int types[] =
                {
                TableInfo.COLUMN_TYPE_STRING,
                TableInfo.COLUMN_TYPE_STRING};
            int keys[] = {0};

            CoordSys coord = mapper.getDisplayCoordSys();
            TableInfoImpl tableInfo = new TableInfoImpl("AnnotationTable",
                coord,
                columns, types, 2, keys, false);
            try
            {
                AnnotationDataProviderHelper dph = new
                    AnnotationDataProviderHelper(
                    tableInfo);
                AnnotationTableDescHelper tdh = new AnnotationTableDescHelper(
                    "AnnotationTable");
                LocalDataProviderRef dpr = new LocalDataProviderRef(dph);
                annotationLayer = (FeatureLayer) mapper.getLayers().insertLayer(
                    dpr,
                    tdh, 0,
                    "Annotation");
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }

        return annotationLayer;
    }

    public void drawPoint(MapJ mapper, DoublePoint point, int symnbolType,
                          String label)
    {

        FeatureLayer annotationLayer = creatAnnotationFeatureLayer(mapper);

        Attribute attrib[] = new Attribute[2];
       
        attrib[0] = new Attribute(label);
        attrib[1] = new Attribute(label);

        PrimaryKey pk = new PrimaryKey(attrib[0]);

        //设置临时图层的标注样式
        LabelPropertiesToolkit lpt = new LabelPropertiesToolkit();
        LabelProperties lp = lpt.getLabelProperties(annotationLayer);

        BaseLabelProperties blp = new BaseLabelProperties(lp);
        annotationLayer.setLabelProperties(blp);
        annotationLayer.setAutoLabel(true);

        //设置点的样式
        RenditionToolkit renditionTool = new RenditionToolkit();
        Rendition pointRendition = renditionTool.getFontRendition(symnbolType);
        Feature newPoint = null;

        try
        {
            newPoint = mapper.getFeatureFactory().createPoint(point,
                pointRendition, lp.getRendition(), attrib, pk);
            annotationLayer.addFeature(newPoint);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        annotationLayer.setAutoLabel(true);

    }