如何在图层增加点线面(不通过扩展MapComponent类实现

来源:百度文库 编辑:神马文学网 时间:2024/04/19 19:30:23
在实时在线系统中实现地图呈现,所以需根据用户新增操作实时的在地图上增加点线面,下面的代码执行后,不能成功添加对象,不知为什么,请版主帮忙分析一下layerName = "line_cqt@hzydMap" ;
  IMapService mapService = null;
  String mapName = "hzyd";
  int count = 6;
  Entity[] targetEntities = new Entity[1] ;
  targetEntities[0] = new Entity() ;
  //targetEntities[0].fieldNames = {""};
  //targetEntities[0].fieldValues = {""} ;
  String[] fieldNames = new String[1] ;
  String[] fieldValues = new String[1] ;
  fieldNames[0] = "SmUserId" ;
  fieldValues[0] = "1" ;
  Geometry geo = new Geometry() ;
  geo.feature = FeatureType.LINE ;
  
  MapCoord[] points = new MapCoord[2] ;
  MapCoord point = new MapCoord();
  point.x = new Double(120.1969) ;  point.y = new Double(30.31734) ;
  MapCoord point1 = new MapCoord();
  point1.x = new Double(120.29972) ;  point1.y = new Double(30.51861) ;
  points[0] = point ; points[1] = point ;
  geo.points = points;
  System.out.println(geo) ;
  
  targetEntities[0].shape = geo ;
  targetEntities[0].fieldNames = fieldNames ;
  targetEntities[0].fieldValues = fieldValues ;
  
     
  try {
        mapService = MapServiceFactory.getRemoteMapService("127.0.0.1", 8700, "mapService1", mapName);
        MapParam mapParam = mapService.getDefaultMapParam(mapName) ;
        //得到需添加的基站小区记录
        //调用相应方法在图层上添加地物
        EditResult er = new EditResult()  ;
        er = mapService.addEntity(mapName, layerName, targetEntities, mapParam) ;
        //mapService.u
        System.out.println(er.succeed) ;
        mapService = null ;
  }catch (Exception ex) {
        System.out.println("创建mapService失败") ;
           throw new InstantiationError("创建mapService失败");

  } 最后发现是本人粗心,少写了geo.points = points ;造成的