c# - Creating New layers in SHARPMAP -
i'm working on sharpmaps, have map of , how add new layers on maps ?
as need write name of state on basic layer , color each state different colours. possible achive goal in sharpmaps...?
you must use "custom them" color each state , "label layer" name of state
you must first 1 delegate method define.the delegate takes featuredatarow parameter , can handle custom style
for example
private sharpmap.styles.vectorstyle getcountrystyle(sharpmap.data.featuredatarow row) { sharpmap.styles.vectorstyle style = new sharpmap.styles.vectorstyle(); switch (row["name"].tostring().tolower()) { case "denmark": //if country name danmark, fill green style.fill = brushes.green; return style; case "united states": //if country name usa, fill blue , add red outline style.fill = brushes.blue; style.outline = pens.red; return style; case "china": //if country name china, fill red style.fill = brushes.red; return style; default: break; } //if country name starts s make yellow if (row["name"].tostring().startswith("s")) { style.fill = brushes.yellow; return style; } // if geometry (multi)polygon , area of polygon less 30, make cyan else if (row.geometry geoapi.geometries.ipolygonal && row.geometry.area < 30) { style.fill = brushes.cyan; return style; } else //none of above -> use default style return null; }
and set theme property of layer method
sharpmap.rendering.thematics.customtheme mytheme = new sharpmap.rendering.thematics.customtheme(getcountrystyle); myvectorlayer.theme = mytheme ;
and label layer must new layer labellayer define example
//name of table in database string tablename = "roads"; //name of object id column - must integer! string idcolumn = "gid"; //create layer sharpmap.layers.vectorlayer layroads= new sharpmap.layers.vectorlayer("roads"); layroads.datasource = datasource; //set road label layer sharpmap.layers.labellayer layroadlabel = new sharpmap.layers.labellayer("road labels"); //set datasource of layroads. layroadlabel.datasource = layroads.datasource; layroadlabel.enabled = true; //specifiy field contains label string. layroadlabel.labelcolumn = "roadofname"; //add layer map mymap.layers.add(layroads); //add label layer map mymap.layers.add(layroadlabel);
tells here
Comments
Post a Comment