Select to view content in your preferred language

polygon display not correct after zoom and pan the map

3831
8
12-05-2012 09:53 PM
JulieBiju
Deactivated User
Dear friends,

PLEASE HELP ME....STRUGGLING TO SOLVE THIS ISSUE

I developed one application for showing  googlemap in my silverlight based  ESRI application based on the code explaining here in this link

http://rexdotnet.blogspot.com/2010/09/use-google-maps-with-arcgis-silverlight.html

Everything working perfect except  one problem at the time of zoom and pan the map.

When I try to display a polygon on my googlemap,First time it is showing on correct location .But when I zoom or pan the map ,polygon is not moving with map.After pan the map polygon is showing in another location .


how to solve this issue?


Adding polygon using the following code

Private Sub AddPolygonGraphics(coordinateString1 As String, Gname As String, Gdesc As String)
        Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayer"), GraphicsLayer)

        Dim pointConverter As New PointCollectionConverter()
        Dim pointCollection1 As ESRI.ArcGIS.Client.Geometry.PointCollection =      TryCast(pointConverter.ConvertFromString(coordinateString1), ESRI.ArcGIS.Client.Geometry.PointCollection)
        Dim polygon1 As New ESRI.ArcGIS.Client.Geometry.Polygon()
        polygon1.Rings.Add(pointCollection1)
        _activeSymbol = TryCast(LayoutRoot.Resources("DefaultFillSymbolT"), Symbol)
        Dim graphic As New Graphic() With
            {
                .Geometry = mercator.FromGeographic(polygon1),
                .Symbol = _activeSymbol
            }
        polygon1.SpatialReference = New SpatialReference(4326)
        Dim strhotspot As String = ""
        strhotspot = Trim(Gname)
        If Gdesc <> "" Then
            strhotspot = strhotspot & "," & Trim(Gdesc)
        End If
        graphicsLayer.Graphics.Add(graphic)
        MyMap.ZoomTo(graphicsLayer.FullExtent)
    End Sub




USING THE BELOW CODE I AM CALLING THE MAP EACH TIME

Imports ESRI.ArcGIS.Client
Imports ESRI.ArcGIS.Client.Geometry

Public Class GoogleStaticMapLayer
    Inherits DynamicMapServiceLayer
    Private Shared mercator As New ESRI.ArcGIS.Client.Projection.WebMercator()

    Private Const cornerCoordinate As Double = 20037508.3427892
    Private Const WKID As Integer = 102100

    Public Sub New()
        MyBase.New()
    End Sub

    Private Property Lods() As Lod()
        Get
            Return m_Lods
        End Get
        Set(value As Lod())
            m_Lods = Value
        End Set
    End Property
    Private m_Lods As Lod()

    Public Overrides Sub Initialize()
        Me.FullExtent = New ESRI.ArcGIS.Client.Geometry.Envelope(-cornerCoordinate, -cornerCoordinate, cornerCoordinate, cornerCoordinate) With { _
         .SpatialReference = New SpatialReference(WKID) _
        }

        Me.SpatialReference = New SpatialReference(WKID)

        Lods = New Lod(20) {}
        Dim resolution As Double = cornerCoordinate * 2 / 256
        For i As Integer = 0 To Lods.Length - 1
            Lods(i) = New Lod() With { _
              .Resolution = resolution _
            }
            resolution /= 2
        Next

        MyBase.Initialize()
    End Sub

    Public Overrides Sub GetUrl(extent As ESRI.ArcGIS.Client.Geometry.Envelope, width As Integer, height As Integer, onComplete As DynamicMapServiceLayer.OnUrlComplete)
        Dim geogCenterPoint As MapPoint = Nothing
        Dim mapURL As String = Nothing

        Try
            Dim currentResolution As Double = extent.Width / width
            Dim currentLodIndex As Integer = 0
            Dim requestWidth As Integer = 0
            Dim requestHeight As Integer = 0
            For i As Integer = 0 To Lods.Length - 1
                Dim lod As Lod = Lods(i)
                currentLodIndex = i
                If CInt(lod.Resolution) <= CInt((currentResolution)) Then
                    requestWidth = CInt(extent.Width / lod.Resolution)
                    requestHeight = CInt(extent.Height / lod.Resolution)
                    Exit For
                End If
            Next

            geogCenterPoint = TryCast(mercator.ToGeographic(extent.GetCenter()), MapPoint)
            mapURL = String.Format("http://maps.google.com/maps/api/staticmap?center={0},{1}&zoom={2}&size={3}x{4}&scale=2&maptype=roadmap&sensor=false&key=AIzaSyDoFucUPlE1lpMxNqc1-cN-dihqGZuLYUw", geogCenterPoint.Y, geogCenterPoint.X, currentLodIndex, requestWidth, requestHeight)
           
        Catch ex As Exception
            Return
        End Try

        onComplete(mapURL, width, height, New ESRI.ArcGIS.Client.Geometry.Envelope() With { _
          .XMin = extent.XMin, _
          .YMin = extent.YMin, _
          .XMax = extent.XMax, _
          .YMax = extent.YMax _
        })
    End Sub
End Class


Please help me.It is very urgent...Thank UUUU
0 Kudos
8 Replies
JulieBiju
Deactivated User
Dear friends,can anybday share me some idea about this.


I think this issue is due to graphical layer and custom layeres spatial reference difference.But I dont know how to solve this.


 <esri:Map.Layers>
                <customLayers:MercatorSchemaTiledLayer Visible="False" />
                <customLayers:GoogleStaticMapLayer ID="roadmap" Visible="True"/>
                <customLayers:GoogleStaticMapLayerSatellite ID="satelite" Visible="False"/>
                <customLayers:GoogleStaticMapLayerTerrain ID="terrain" Visible="False"/>
                <customLayers:GoogleStaticMapLayerHybrid ID="hybrid" Visible="False"/>
                   <esri:GraphicsLayer ID="MyGraphicsLayer" />
            </esri:Map.Layers>
        </esri:Map>



Public Class GoogleStaticMapLayer
    Inherits DynamicMapServiceLayer
    Private Shared mercator As New ESRI.ArcGIS.Client.Projection.WebMercator()

    Private Const cornerCoordinate As Double = 20037508.3427892
    Private Const WKID As Integer = 102100
0 Kudos
JulieBiju
Deactivated User
Can anybdy help me to sort out my issue.

Please check the application link below.
http://www.kginfotech.com:8000/test/AlTareeqGeofencewithgoogle.aspx?un=I/wC56ckf4GV2F7NbOZfag==

Click View Geofence->Select Vehicle 77844->Geofencename select ghubra.

U can see the polygon over the roundabt correctly at the first display.But after zoom in and zoom out u can see the polygon is replacing to another location
0 Kudos
JulieBiju
Deactivated User
can anybdy have any suggestion ,plss
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I can't access to the application you provided. I get 'server internal error'.
0 Kudos
BradBoyd1
New Contributor
I have the same problem in a similar application that uses DynamicMapServiceLayer.  In my application I am creating a dynamic WMS layer by extending DynamicMapServiceLayer, as described in the DynamicMapServiceLayer Overview example.

The WMS layer displays correctly, and when I pan or zoom the WMS layer also pans and zooms with the BaseMap.  However, as soon as I stop panning or zooming, the WMS layer returns to the original extent so it is no longer in sync with the BaseMap.

Am I missing an event handler, or do I need to create one?

Here is a simple example.

<esri:Map x:Name="MyMap" WrapAround="true">
            <esri:ArcGISTiledMapServiceLayer ID="BaseLayer" 
                                            Url="http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_D/MapServer" />
            <customLayers:DynamicWmsLayer x:Name="MyWmsLayer" />
        </esri:Map>


using System;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Geometry;

namespace CustomLayers
{
    public class DynamicWmsLayer : DynamicMapServiceLayer
    {
        public DynamicWmsLayer() : base()
        { 

        }
        
        public override void Initialize()
        {
            this.FullExtent = new Envelope(-126, 24, -66, 50) { SpatialReference = new SpatialReference(4326) };
            this.SpatialReference = new SpatialReference(4326);
            base.Initialize();
        }

        public override void GetUrl(Envelope extent, int width, int height, OnUrlComplete onComplete)
        {
            string mapURL = "http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&LAYERS=nexrad-n0r,nexrad-n0r-900913,nexrad-n0r-900913-m05m,nexrad-n0r-900913-m10m,nexrad-n0r-900913-m15m,nexrad-n0r-900913-m20m,nexrad-n0r-900913-m25m,nexrad-n0r-900913-m30m,nexrad-n0r-900913-m35m,nexrad-n0r-900913-m40m,nexrad-n0r-900913-m45m,nexrad-n0r-900913-m50m,nexrad-n0r-m05m,nexrad-n0r-m10m,nexrad-n0r-m15m,nexrad-n0r-m20m,nexrad-n0r-m25m,nexrad-n0r-m30m,nexrad-n0r-m35m,nexrad-n0r-m40m,nexrad-n0r-m45m,nexrad-n0r-m50m&STYLES=&SRS=EPSG:4326&BBOX=-126,24,-66,50&WIDTH=600&HEIGHT=350&TRANSPARENT=TRUE&FORMAT=image/png";

            onComplete(mapURL, width, height, new ESRI.ArcGIS.Client.Geometry.Envelope()
            {
                XMin = extent.XMin,
                YMin = extent.YMin,
                XMax = extent.XMax,
                YMax = extent.YMax
            });
        }      
    }
}




namespace CustomLayers
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            MyWmsLayer = new DynamicWmsLayer();
            MyWmsLayer.Initialize();

            MyMap.Extent = new Envelope(-126, 24, -66, 50) { SpatialReference = new SpatialReference(4326) };
        }
    }
}
0 Kudos
BradBoyd1
New Contributor
I don't know if this helps you, meenu.monu, but for me the problem was in the onComplete() code.  Once I changed onComplete() to the following code, it started working.

            onComplete(mapURL, width, height, new Envelope()
            {
                XMin = this.FullExtent.XMin,
                YMin = this.FullExtent.YMin,
                XMax = this.FullExtent.XMax,
                YMax = this.FullExtent.YMax
            });
0 Kudos
DominiqueBroux
Esri Frequent Contributor
string mapURL = http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap...;


Your BBOX parameter is defined statically whatever the expected extent. So you will always get the same image which will be stretched to the expected extent (if the right image extent is returned by the OnComplete callback).
It would be better to set dynamically the bbox depending on the extent.

Sidenote: the toolkit provides a WMSLayer class which is doing that job.
0 Kudos
JulieBiju
Deactivated User


Dear friend,Thank u so much for ur help,But it is not success in my case.

At last I found out the problem,If we use googlemap height and width <=640 then No issue,Everything will work perfectly.
But If I will use more than that of height and width,Then the graphics will show out of the location after zoom and pan.

I dont know how to solve this issue!!!!!!I need googlemap with morethan 640 height and width in my application.


Can  anyone help me to solve this?

using System;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Geometry;

namespace CustomLayers
{
    public class GoogleStaticMapLayer : DynamicMapServiceLayer
    {
        private static ESRI.ArcGIS.Client.Projection.WebMercator mercator =
                new ESRI.ArcGIS.Client.Projection.WebMercator();

        private const double cornerCoordinate = 20037508.3427892;
        private const int WKID = 102100;

        public GoogleStaticMapLayer() : base(){ }

        private Lod[] Lods { get; set;}
        
        public override void Initialize()
        {
            this.FullExtent =
            new ESRI.ArcGIS.Client.Geometry.Envelope(-cornerCoordinate, -cornerCoordinate, cornerCoordinate, cornerCoordinate)
            {
                SpatialReference = new SpatialReference(WKID)
            };

            this.SpatialReference = new SpatialReference(WKID);
            
            Lods = new Lod[21];
            double resolution = cornerCoordinate * 2 / 256;
            for (int i = 0; i < Lods.Length; i++)
            {
                Lods = new Lod() { Resolution = resolution };
                resolution /= 2;
            }

            base.Initialize();
        }

        public override void GetUrl(ESRI.ArcGIS.Client.Geometry.Envelope extent, int width, int height,
            DynamicMapServiceLayer.OnUrlComplete onComplete)
        {
            MapPoint geogCenterPoint = null;
            string mapURL = null;            
            
            try
            {
                //if (width > 640 || height > 640) 
                //    throw new Exception("Width or height greater than 640");
                
                double currentResolution = extent.Width / width;
                int currentLodIndex = 0;
                int requestWidth = 0;
                int requestHeight = 0;
                for (int i = 0; i < Lods.Length; i++)
                {
                    Lod lod = Lods;
                    currentLodIndex = i;
                    if ((int)lod.Resolution <= (int)currentResolution)
                    {
                        requestWidth = (int)(extent.Width / lod.Resolution);
                        requestHeight = (int)(extent.Height / lod.Resolution);
                        break;
                    }
                }

                //if (requestWidth > 640 || requestHeight > 640) 
                //    throw new Exception("Request width or height greater than 640");                

                geogCenterPoint = mercator.ToGeographic(extent.GetCenter()) as MapPoint;

                mapURL = string.Format
                  ("http://maps.google.com/maps/api/staticmap?center={0},{1}&zoom={2}&size={3}x{4}&maptype=roadmap&sensor=false",
                   geogCenterPoint.Y, geogCenterPoint.X, currentLodIndex, requestWidth, requestHeight);

            }
            catch (Exception ex)
            {
                // Message box just for debug purposes
                //System.Windows.MessageBox.Show( ex.Message,"Error: Google Static Map not generated", System.Windows.MessageBoxButton.OK); 
                return;
            }

            onComplete(mapURL, width, height, new ESRI.ArcGIS.Client.Geometry.Envelope()
            {
                XMin = extent.XMin,
                YMin = extent.YMin,
                XMax = extent.XMax,
                YMax = extent.YMax
            });
        }      
    }
}
0 Kudos