ThinkGeo.com    |     Documentation    |     Premium Support

Getting location of mouse with wrapping mode enabled

I have all of my layers/overlays set to WrappingMode.WrapDateline.

I also have some code that displays the current lat/long of the mouse location using this:

Point currentPoint = e.GetPosition(Map);
PointShape worldPoint = ExtentHelper.ToWorldCoordinate(Map.CurrentExtent, new ScreenPointF((float)currentPoint.X, (float)currentPoint.Y), (float)Map.ActualWidth, (float)Map.ActualHeight);

The problem is that it seems like this code doesn’t take into effect the wrapping mode. Here’s an example after I panned the map to the left a few times:

In the lower left corner, you can see the longitude is a bogus number. I tried restricting the extent to -180, 180, 90, -90 but that didn’t do anything.

Hi Dan,

I think the code as below can solve your problem:

            Point currentPoint = e.GetPosition(map);
        PointShape worldPoint = ExtentHelper.ToWorldCoordinate(map.CurrentExtent, new ScreenPointF((float)currentPoint.X, (float)currentPoint.Y), (float)map.ActualWidth, (float)map.ActualHeight);

        if (worldPoint.X < -180 || worldPoint.X > 180)
        {
            worldPoint = new PointShape(worldPoint.X % 180, worldPoint.Y);
        }   

Regards,

Ethan

Thanks Ethan! On the same note, how would I be able to get a scalelineadornmentlayer to appear with wrapping mode? Right now, the layer only appears on the “main” world, but if you pan to the right or left it disappears. I don’t see any wrapping mode property for the adornment layer or overlay. Here’s how I’m setting it up:

ScaleLineAdornmentLayer scaleLineAdornmentLayer = new ScaleLineAdornmentLayer();
scaleLineAdornmentLayer.Location = AdornmentLocation.LowerLeft;
MyMap.AdornmentOverlay.Layers.Add(scaleLineAdornmentLayer);

Hi Dan,

I did a simple test, the scale line works for wrapdateline mode.

map.AdornmentOverlay.Layers.Add(new ScaleLineAdornmentLayer());

If that don’t works in your machine, I think a sample can reproduce it is helpful.

Regards,

Ethan