天天看點

Mapxtreme for Java中添加自定義圖示

MapXtreme Java提供的圖示很少,做出的地圖看起來不美觀。MapXtreme Java中自定義符号

我目前想用這種方法:

将自定義的符号*.bmp儲存到C:/Documents and Settings/Administrator/Application Data/MapInfo/MapInfo/Professional/700/CustSymb即可在pro中使用,如果要在xtreme for java 中使用該符号,要首先将該bmp格式的圖示轉換為gif格式,然後放在程式目錄中并寫在屬性檔案裡

取出圖的檔案名

cximgurl=file:///d://cqyc//Jmap//images//XYCYJ.GIF

//循環DrawPoints/

      for(int i=0 ;i<jhtable.size();i++){

        Vector colvector = (Vector)jhtable.elementAt(i);

        String sjh = (String)colvector.elementAt(0);

        DoublePoint dpjw = (DoublePoint)colvector.elementAt(1);

        String si = i + "";

        if ((sjh!=null) && (dpjw!=null)) {

          DrawPoints(themeMap,sjh,dpjw,si,"Annotations");

        }

      }

// //畫一個單一的點對象 

private void DrawPoints(MapJ map, String jh,DoublePoint point,String key,String LayerName)

  {

    PrimaryKey primarykey;

    primarykey = new PrimaryKey();

    Vector columns = new Vector();

    int featlen = 0;

      try

      {

          Layer annotLayer = map.getLayers().getLayer(LayerName);

          if(annotLayer == null)

          {

              AnnotationTableDescHelper annTableDesc = new AnnotationTableDescHelper("Annotations");

              AnnotationDataProviderHelper dpHelper = new AnnotationDataProviderHelper();

              LocalDataProviderRef dpRef = new LocalDataProviderRef(dpHelper);

              annotLayer = map.getLayers().insert(dpRef, annTableDesc, 0, LayerName);

          }

          String imageurl = ConfigFile.chanj_imageurl;

          Feature retFeature = CreatePointFeature(map,point,key,imageurl);

          primarykey = annotLayer.addFeature(retFeature);

      }

      catch(Exception e)

      {

        WriteLog.writeForErrorDebug("HkjTheme.DrawPoints","繪制點異常!",e);

          e.printStackTrace();

      }

  }

//建立點的feature

  private Feature CreatePointFeature(MapJ map, DoublePoint point,String key,String imgurl)

  {

      FeatureFactory ff = map.getFeatureFactory();

      Attribute att[] = new Attribute[1];

      //att[0] = new Attribute("SearchFeature");

      att[0] = new Attribute(key);

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

      //Rendition rend = sysOpition.GetSystemPointRendition();

      //String imgurl = "http://localhost:8080/maptemp/pat.gif";

      Rendition rend = GetSystemPointRendition(Color.white,imgurl);

      Feature retFeature = null;

      DoublePoint dp = point;

      try

      {

          retFeature = ff.createPoint(dp, rend, att, pk);

      }

      catch(Exception exception) { }

      return retFeature;

    }

//根據傳過來的顔色和圖檔的url位址生成專題圖的樣式

    private com.mapinfo.dp.Rendition GetSystemPointRendition(Color color,String imgurl)

    {

        com.mapinfo.dp.Rendition rend = new com.mapinfo.dp.Rendition();

        rend.setValue(com.mapinfo.graphics.Rendition.FONT_FAMILY, "MapInfo Oil&Gas");

        rend.setValue(com.mapinfo.graphics.Rendition.FONT_SIZE, new Float(15F));

        rend.setValue(com.mapinfo.graphics.Rendition.FONT_WEIGHT, new Float(1.0F));

        rend.setValue(com.mapinfo.graphics.Rendition.FONT_STYLE, com.mapinfo.graphics.Rendition.FontStyle.NORMAL);

        //rend.setValue(com.mapinfo.graphics.Rendition.SYMBOL_MODE, com.mapinfo.graphics.Rendition.SymbolMode.FONT);

        //rend.setValue(com.mapinfo.graphics.Rendition.SYMBOL_STRING, sysOpition.GetStringValue(41));

        //調用自定義的圖檔

        rend.setValue(Rendition.SYMBOL_MODE, Rendition.SymbolMode.IMAGE);

        //rend.setValue(Rendition.SYMBOL_URL,"http://localhost:8080/images/hkj.gif");

        //rend.setValue(Rendition.SYMBOL_URL, ConfigFile.m_hkjurl);

        //System.out.println("2imgurl:"+imgurl);

        rend.setValue(Rendition.SYMBOL_URL, imgurl);

        rend.setValue(com.mapinfo.graphics.Rendition.SYMBOL_FOREGROUND, color);

        rend.setValue(com.mapinfo.graphics.Rendition.SYMBOL_BACKGROUND, Color.red);

        return rend;

    }