Hi,
Can you please confirm where this code is to be added in my code. I have pasted my code below:
public layType AddCustomFeatureLayer(WpfMap wpfMap1, string location, string LayerName, string OverlayName,GeoColor fill, GeoColor outline)
{
layType layerType = new layType();
try
{
ShapeFileFeatureLayer customLayer = new ShapeFileFeatureLayer(@location);
customLayer.Name = LayerName;
if (System.IO.File.Exists(@location.Replace(“shp”, “idx”)) == false) //check if index exists
{
customLayer.RequireIndex = false;
customLayer.Open();
//ThinkGeo.MapSuite.Core.RectangleShape rect = customLayer.GetBoundingBox(); //get the extent of the current layer
if (customLayer.UsingSpatialIndex == false)
{
customLayer.Close();
ShapeFileFeatureSource.BuildIndexFile(@location, BuildIndexMode.Rebuild);
}
}
customLayer.RequireIndex = true;
//reproject the statesLayer to Spherical Mercator to match the base map’s projection.
Proj4Projection proj4 = new Proj4Projection();
string prjFileText = System.IO.File.ReadAllText(@location.Replace(“shp”, “prj”)); //get the text of the .prj file.
proj4.InternalProjectionParametersString = Proj4Projection.ConvertPrjToProj4(prjFileText); //set the internal projection. The new ConvertPrjToProj4 methid is the key to this process.
proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString(); //set the external projection. In this case, it’s Spherical Mercator (which google/bing, etc all use).
//Proj4Projection proj_EEZs = new Proj4Projection();
//proj_EEZs.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
//proj_EEZs.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
customLayer.FeatureSource.Projection = proj4; // proj_EEZs;
//customLayer.FeatureSource.Projection = proj_EEZs; // proj_EEZs;
//customLayer.WrappingMode = WrappingMode.WrapDateline;
//customLayer.WrappingExtent = new RectangleShape(WrapExtentMinX, WrapExtentMaxY, WrapExtentMaxX, WrapExtentMinY); //new RectangleShape(17897271, -1367305, 19514067, -2411741);
//customLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.FromArgb(100, GeoColor.SimpleColors.Green));
customLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(AreaStyles.CreateSimpleAreaStyle(fill, outline));
customLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
LayerOverlay staticOverlay = new LayerOverlay();
staticOverlay.WrappingMode = WrappingMode.WrapDateline;
staticOverlay.WrappingExtent = new RectangleShape(WrapExtentMinX, WrapExtentMaxY, WrapExtentMaxX, WrapExtentMinY); //new RectangleShape(17897271, -1367305, 19514067, -2411741);
staticOverlay.Name = OverlayName;
staticOverlay.Layers.Add(LayerName, customLayer);
staticOverlay.Layers.MoveToTop(OverlayName);
wpfMap1.Overlays.Add(staticOverlay);
//wpfMap1.CurrentExtent = rect;//GetFullExtentSingleLayer(customLayer);// GetFullExtent(staticOverlay.Layers);
// wpfMap1.CurrentExtent = GetFullExtentSingleLayer(customLayer);
if (wpfMap1.Overlays.Count == 1)
{
ZoomToLayer(wpfMap1, LayerName);
}
ShapeFileType shapefiletype = new ShapeFileType();
if (customLayer.IsOpen == false)
{
customLayer.Open();
}
shapefiletype = customLayer.GetShapeFileType();
switch (shapefiletype.ToString())
{
case “Point”:
layerType = layType.Point;
break;
case “PointM”:
layerType = layType.Point;
break;
case “PointZ”:
layerType = layType.Point;
break;
case “Line”:
layerType = layType.Line;
break;
case “Polyline”:
layerType = layType.Line;
break;
case “PolylineM”:
layerType = layType.Line;
break;
case “PolylineZ”:
layerType = layType.Line;
break;
case “Polygon”:
layerType = layType.Polygon; ;
break;
case “PolygonM”:
layerType = layType.Polygon; ;
break;
case “PolygonZ”:
layerType = layType.Polygon; ;
break;
case “Multipoint”:
layerType = layType.Point;
break;
case “MultipointM”:
layerType = layType.Point;
break;
case “MultipointZ”:
layerType = layType.Point;
break;
case “Multiline”:
layerType = layType.Line;
break;
case “Multipolygon”:
layerType = layType.Polygon;
break;
}
// customLayer.Close();
wpfMap1.Refresh();
}