ThinkGeo.com    |     Documentation    |     Premium Support

Dynamic Marker Blazor

Hi. I have a problem with visualize marker on map
I have a code

public InMemoryMarkerOverlay markerOverlay;
private InMemoryFeatureSource inMemoryFeatureSource = new InMemoryFeatureSource();

    protected async override Task OnInitializedAsync()
    {
     
        var feature = new Feature(29.676284, -95.295779);
        var markerOverlay= new InMemoryMarkerOverlay("markerOverlay");

        markerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.VirtualPath = "imagePath";
        markerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.OffsetX = -6f;
        markerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.OffsetY = -12f;
        markerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.IsActive= true;
        markerOverlay.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
        markerOverlay.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
        markerOverlay.FeatureSource.InternalFeatures.Clear();
    
        inMemoryFeatureSource.InternalFeatures.Add(Guid.NewGuid().ToString(), feature);
      
    
        await base.OnInitializedAsync();
    }

}

<MarkerOverlaySetting>
    <InMemoryMarkerOverlay Id="InMemoryMarkerOverlay"
                           IsVisible="true"
                           @ref="@markerOverlay"
                           FeatureSource="@inMemoryFeatureSource">
    </InMemoryMarkerOverlay>
</MarkerOverlaySetting>

As I see overlay attached on map but marker doesn`t visualize

Hi,

  1. please put X ahead of Y when initializing a Feature. We usually do (Lat, Lon) for decimal degrees, but to make it consistent with different projections, we always accept X ahead of Y.
  2. Code issue: you initialize the local variable markerOverlay while what should be initialized is the instance variable “markerOverlay”. In your code, that instance variable markerOverlay is always null.

The Vehicle Tracking sample in HowDoI is using MarkerOverlay, please go ahead and ref that sample, which should be helpful.

Ben