public static mapcontent createnewmapcontentofnolayer(string mapname, string server, string port, string username, string password, string database) { GeoDatabase gdb = PGGeoDatabase.GetGeoDatabase(server, port, username, password, database, new List <string>()); List <Layer> layerlist = new List <Layer>(); mapcontent map = new mapcontent(mapname, gdb, layerlist); return(map); }
/// <summary> /// /// </summary> /// <param name="gdb"></param> /// <param name="mapname"></param> /// <param name="stylepath">mapproject必须给相同数量的stylepath,如果没有value应该为null,key为layername</param> /// <returns></returns> public static mapcontent LoadMapContent(string mapname, Dictionary <string, string> datasourcepath, Dictionary <string, string> stylepath, string server, string port, string username, string password, string database) { List <Layer> layerlist = new List <Layer>(); GeoDatabase gdb = PGGeoDatabase.GetGeoDatabase(server, port, username, password, database, datasourcepath.Values.ToList()); //Dictionary<String, FeatureSource> dic = gdb.featureSources; foreach (string layername in datasourcepath.Keys) { //获取featuresoucre FeatureSource featuresource = null; if (!gdb.featureSources.TryGetValue(datasourcepath[layername], out featuresource)) { continue; } Layer layer = Layer.LoadLayer(featuresource, layername, stylepath[layername]); layerlist.Add(layer); } mapcontent map = new mapcontent(mapname, gdb, layerlist); return(map); }
/// <summary> /// 用户向已有gdb中添加一个新的图层,该图层必须已存在shp文件 /// 向该mapcontent中添加一个layer /// </summary> /// <param name="gdb"></param> /// <param name="layerpath"></param> /// <param name="stylepath"></param> /// <returns></returns> public string addLayer(string layerpath, string stylepath, string guid, string layername) { if (layerpath == null) { return(null); } FeatureSource featuresource = null; PGGeoDatabase gdb = (PGGeoDatabase)this.gdb; //string layername = gdb.AddSHPFeatureSource(layerpath, guid); if (!this.gdb.featureSources.TryGetValue(guid, out featuresource)) { return(null); } Style style = null; try { if (stylepath != null) { style = Style.parseStyleFile(stylepath); } } catch (Exception e) { } if (style == null) { style = Style.createSimpleStyle(featuresource); } Layer layer = new Layer(layername, featuresource, style); this.layerlist.Insert(0, layer); return(layername); }