Manually show information pop up on click on a Marker graphic

2762
4
12-12-2014 12:12 PM
ZahidCheema
New Contributor III

When we click on a marker graphics, a popup show information about the pop. I want to do the same thing manually. I mean, I ll give lat and lon input and a pop up should show on a button click.

4 Replies
JamesFitzgerald
Occasional Contributor II
C#
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel.Web;
using System.Runtime.Serialization.Json;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Geometry;
using ESRI.ArcGIS.Client.Symbols;
namespace AddPointTest
{
    public partial class MainPage : UserControl
    {
        private static ESRI.ArcGIS.Client.Projection.WebMercator mercator =
            new ESRI.ArcGIS.Client.Projection.WebMercator();
        public MainPage()
        {
            InitializeComponent();
            AddMarkerGraphics();
        }
        void AddMarkerGraphics()
        {
            string jsonCoordinateString = "{'Coordinates':[{'X':13,'Y':55.59},{'X':72.83,'Y':18.97}]}";
            CustomCoordinateList coordinateList = DeserializeJson<CustomCoordinateList>(jsonCoordinateString);
            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
            for (int i = 0; i < coordinateList.Coordinates.Count; i++)
            {
                Graphic graphic = new Graphic()
                {
                    Geometry = mercator.FromGeographic(new MapPoint(coordinateList.Coordinates.X, coordinateList.Coordinates.Y)),
                    Symbol = i > 0 ? LayoutRoot.Resources["RedMarkerSymbol"] as Symbol : LayoutRoot.Resources["BlackMarkerSymbol"] as Symbol
                };
                graphicsLayer.Graphics.Add(graphic);
            }
        }
        internal static T DeserializeJson<T>(string json)
        {
            T objectInstance = Activator.CreateInstance<T>();
            System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(System.Text.Encoding.Unicode.GetBytes(json));
            System.Runtime.Serialization.Json.DataContractJsonSerializer jsonSerializer =
               new System.Runtime.Serialization.Json.DataContractJsonSerializer(objectInstance.GetType());
               objectInstance = (T)jsonSerializer.ReadObject(memoryStream);
               memoryStream.Close();
               return objectInstance;
        }
    }
    [DataContract]
    public class CustomCoordinateList
    {
        [DataMember]
        public List<CustomCoordinate> Coordinates = new List<CustomCoordinate>();
    }
    [DataContract]
    public class CustomCoordinate
    {
        public CustomCoordinate() { }
        public CustomCoordinate(double x, double y)
        {
            this.X = x;
            this.Y = y;
        }
        [DataMember]
        public double X { get; set; }
        [DataMember]
        public double Y { get; set; }
    }
   }
JamesFitzgerald
Occasional Contributor II
XAML
<UserControl x:Class="AddPointTest.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.Resources>
            <esri:SimpleMarkerSymbol x:Key="RedMarkerSymbol" Color="Red" Size="12" Style="Circle" />
            <esri:SimpleMarkerSymbol x:Key="BlackMarkerSymbol" Color="Black" Size="14" Style="Diamond" />
        </Grid.Resources>
        
        <esri:Map x:Name="MyMap" WrapAround="True" Background="White">
            <esri:ArcGISTiledMapServiceLayer ID="PhysicalTiledLayer" 
                      Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/>
            <esri:GraphicsLayer ID="MyGraphicsLayer" />
        </esri:Map>
    </Grid>
</UserControl>

ZahidCheema
New Contributor III

Dear thanks for you reply. Actually t looks a bit helpless for me. I just want to perform click event on a marker on the map by giving Latitude and Longitude as input to this event in Java.

JamesFitzgerald
Occasional Contributor II

Hello Zahid,

Here is the code and it works. I am not sure which programming language you are using but you could convert it.

Thanks,

James