ThinkGeo.com    |     Documentation    |     Premium Support

Cannot render a InMemoryFeatureLayer on top of OpenStreetMap layer

Hi, I am working on a project that uses shape file based map overlay and on top of that loads a InMemoryFeatureLayers overlay. Here is a screenshot. (Image 1)

The FeatureLayer consists of a number of encs (Electrical Navigational Chart) added as markers. Here is a screenshot of this layer without the map layer (Image 2)

Now i want to replace the shape file based map with OpenStreetMap. But when i load the open street map the FeatureLayer overlay is not shown. Here is how it looks (Image 3)

Here is how i load the map layers

private void InitMapLayers()
    {
        // Static layers
        AddBackgroundMap();

        _dynamicLayer = CreateDynamicLayer(); 

// dynamicLayer is a InMemoryFeatureLayer with ENC markers
_dynamicOverlay.Layers.Add(_dynamicLayer);

        // Default overlay (background map, countries, cities)
        mapSuiteControl.Overlays.Add(SHAPE_MAP_LAYER_KEY, _staticOverlay);

        // Dynamic overlay (ENC cells, etc..)
        mapSuiteControl.Overlays.Add("Markers", _dynamicOverlay);
        mapSuiteControl.Overlays.Add(_drawingOverlay);

        //AddOSMLayer();

        SetShapeLayersStyles();
    }

private void AddBackgroundMap()
    {
        _staticOverlay = new LayerOverlay() { IsBase = true };
        // Set a background brush
        mapSuiteControl.BackgroundOverlay.BackgroundBrush = new GeoLinearGradientBrush(
            GeoColor.FromArgb(255, 169, 196, 222), GeoColor.FromArgb(255, 73, 132, 182), GeoLinearGradientDirection.UpperRightToLowerLeft);

        // Then add world layer
        _baseMapLayer = new ShapeFileFeatureLayer(Constants.MapBaseShapeFile, ShapeFileReadWriteMode.ReadOnly)
            {
                FeatureSource = { Projection = _mapManager.Projection }
            };

        var pen = new GeoPen(GeoColor.StandardColors.OliveDrab);
        _baseMapLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new HueFamilyAreaStyle(pen, GeoColor.SimpleColors.PaleGreen, 6);
        _baseMapLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

        _staticOverlay.Layers.Add(MapLayer.BackgroundMap.ToString(), _baseMapLayer);

        ShapeFileFeatureLayer.BuildIndexFile(Constants.MapBaseShapeFile);
        _baseMapLayer.Open();
        _baseMapLayer.WrappingMode = WrappingMode.WrapDateline;
        _baseMapLayer.WrappingExtent = _baseMapLayer.GetBoundingBox();
        mapSuiteControl.CurrentExtent = _baseMapLayer.GetBoundingBox();
    }

private void AddOSMLayer()
    {
        OpenStreetMapOverlay _osmOvelerlay = new OpenStreetMapOverlay() { IsBase = true};
        mapSuiteControl.Overlays.Add(OPEN_STREET_LAYER_KEY, _osmOvelerlay);
        mapSuiteControl.MapUnit = GeographyUnit.Meter;
    }

When i run this code i get result as Image 1.
If i comment the following line i get Image 2.

mapSuiteControl.Overlays.Add(SHAPE_MAP_LAYER_KEY, _staticOverlay)

If i then uncomment the following line i get Image 3

//AddOSMLayer();

The open street map is shown but the Markers layer is not shown anymore.

What i am doing wrong here? I am a noob at ThinkGeo SDK so probably there is a silly mistake but i cant find it.

Hi Zaki_Choudhury,

If you want to use OSM replace your original shape file, the OSM should be the new background layer, so you don’t want to add it to map after the dynamic layer.

Please try to AddOSMLayer first then add the dynamic overlay.

Regards,

Don

Hi Don,

Thanks for the quick response. I have tried adding the OSM layer before adding any other layers but it does not help. Also have tried to move the OSM layer at the bottom of the Overlay collection in the MapSuiteControl. same result.

Best regards,
Zaki

Hi Zaki,

If you can upload a sample with data I can help you look into this.

Just from the information you provided, I think if adjust the render order still cannot solved this problem, that maybe should because the projection problem.

I don’t know what’s the projection your shape file and dynamic layer is using, but you should want to convert it to the OSM’s projection, so it can be rendered in the correct extent.

You can did a quickly test, comment OSM and background layer, still modify the mapSuiteControl.MapUnit = GeographyUnit.Meter; and then see whether the dynamic layer still be rendered.

Regards,

Don

Hi Don,

Thanks and sorry could not reply to you earlier. I was on vacation.
I did the quick check by turning off both the map layer and setting map unit to Meter. The result is dynamic layer does not render. So it seems its not really due to OSM rather the projection and other settings like you predicted.

Best regards,
Zaki.

Hi Zaki,

If when you turn off OSM map and set map unit to meter, the dynamic layer still not render. That should be a projection problem.

I think your original map should be use DecimalDegree as map unit right?

If so, please set the projection like this and let me know whether the dynamic layer render now:

ManagedProj4Projection proj4 = new ManagedProj4Projection();
        proj4.InternalProjectionParametersString = ManagedProj4Projection.GetDecimalDegreesParametersString();
        proj4.ExternalProjectionParametersString = ManagedProj4Projection.GetGoogleMapParametersString();

        ShapeFileFeatureLayer yourDynamicLayer;
        yourDynamicLayer.FeatureSource.Projection = proj4;

        RectangleShape rect = new RectangleShape("Your original decimal degree bouding box");
        winformsMap1.CurrentExtent = proj4.ConvertToExternalProjection(rect) as RectangleShape;

Wish it’s helpful.

Regards,

Don

Hi Don,

Yeah the original map (shape file based) used Decimal Degrees.
I set the projection and the result is now It seems the dynamic layer is being loaded along with OSM (I can see the marker tooltips of the dynamic layer) but the markers are not shown. Only OSM layer is shown. I though about layer orders and tried to change the orders with no luck.

One other question, can I set a projection to OSM layer? I am using the class ‘ThinkGeo.MapSuite.DesktopEdition.OpenStreetMapOverlay’ and it does not have any FeatureSource or Projection property available to set the projection.
Again thanks for your help!

Best regards,
Zaki

Hi Zaki,

This class have a property named: ProjectionFromSphericalMercator

When you want to use it, you need to set the SphericalMercator as internal projection, and target projection as external projection, then assign the projection to this property.

I don’t know how you render your marker, but I think you should want to reset the coordinate of your markers so they can be render in correct location under meter. (You can reprojection the marker coordinates)

Regards,

Don