ThinkGeo.com    |     Documentation    |     Premium Support

Map popup is not working

I have an issue, Popup is not showing on map,and the reason I think is
that, popup array is empty in client side although I have initialized it
while creating map in server side.

Controller code:



        Map Map1 = null;

        public ActionResult Index3()

        {

            Map1 = new Map(“map”,

         new System.Web.UI.WebControls.Unit(100, System.Web.UI.WebControls.UnitType.Percentage), 510);

          





            Map1.MapTools.LoadingImage.ImageUri = new
Uri(Server.MapPath(@"~/ShapeFiles/loading_logofinal_by_zegerdon-d60eb1v.gif"));

            Map1.MapTools.LoadingImage.Enabled = true;

            Map1.MapTools.LoadingImage.Height = 64;

            Map1.MapTools.LoadingImage.Width = 64;

            Map1.MapTools.ScaleLine.Enabled = true;

            Map1.MapUnit = GeographyUnit.DecimalDegree;

            Map1.MapTools.MouseCoordinate.MouseCoordinateType = MouseCoordinateType.LongitudeLatitude;

            Map1.MapTools.MouseCoordinate.Enabled = true;

            Map1.Cursor = CursorType.Pointer;

            //Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.Swamp);





            ShapeFileFeatureLayer PakLayer = new ShapeFileFeatureLayer(Server.MapPath(@"~/ShapeFiles/PAK_adm0.shp"));

            PakLayer.ZoomLevelSet.ZoomLevel04.DefaultAreaStyle = AreaStyles.Country1;

            PakLayer.ZoomLevelSet.ZoomLevel04.DefaultTextStyle =
TextStyles.CreateSimpleTextStyle(“NAME_ENGLI”, “Arial”, 8,
DrawingFontStyles.Italic, GeoColor.StandardColors.Crimson, 3,
3);//TextStyles.Capital3(“NAME_1”);

            PakLayer.ZoomLevelSet.ZoomLevel04.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level05;

            ShapeFileFeatureLayer.BuildIndexFile(Server.MapPath(@"~/ShapeFiles/PAK_adm0.shp"));





            ShapeFileFeatureLayer capitalLayer = new ShapeFileFeatureLayer(Server.MapPath(@"~/ShapeFiles/PAK_adm1.shp"));

            capitalLayer.ZoomLevelSet.ZoomLevel06.DefaultAreaStyle =
AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.PaleGreen,
GeoColor.FromArgb(100, GeoColor.SimpleColors.BrightOrange));

            capitalLayer.ZoomLevelSet.ZoomLevel06.DefaultTextStyle =
TextStyles.CreateSimpleTextStyle(“NAME_1”, “Arial”, 8,
DrawingFontStyles.Italic, GeoColor.StandardColors.Green, 3,
3);//TextStyles.Capital3(“NAME_1”);

            capitalLayer.ZoomLevelSet.ZoomLevel06.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level06;



            ShapeFileFeatureLayer DivisionLayer = new ShapeFileFeatureLayer(Server.MapPath(@"~/ShapeFiles/PAK_adm2.shp"));

            DivisionLayer.ZoomLevelSet.ZoomLevel07.DefaultTextStyle =
TextStyles.CreateSimpleTextStyle(“Name_2”, “Arial”, 8,
DrawingFontStyles.Italic, GeoColor.StandardColors.Chocolate, 3, 3);

            DivisionLayer.ZoomLevelSet.ZoomLevel07.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level08;

            DivisionLayer.ZoomLevelSet.ZoomLevel07.DefaultAreaStyle =
AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.PaleOrange,
GeoColor.FromArgb(100, GeoColor.SimpleColors.BrightGreen));





            ShapeFileFeatureLayer districtLayer = new ShapeFileFeatureLayer(Server.MapPath(@"~/ShapeFiles/PAK_adm3.shp"));

            //districtLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.Capital3(“NAME_3”);

            districtLayer.ZoomLevelSet.ZoomLevel08.DefaultTextStyle =
TextStyles.CreateSimpleTextStyle(“NAME_3”, “Arial”, 8,
DrawingFontStyles.Italic, GeoColor.StandardColors.Black, 3, 3);

            districtLayer.ZoomLevelSet.ZoomLevel08.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level09;

            districtLayer.ZoomLevelSet.ZoomLevel08.DefaultAreaStyle =
AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.PastelYellow,
GeoColor.FromArgb(100, GeoColor.SimpleColors.DarkGreen));



            districtLayer.DrawingMarginPercentage = 50;

            ShapeFileFeatureLayer tahseelLayer = new
ShapeFileFeatureLayer(Server.MapPath(@"~/ShapeFiles/PAK_Tehsil_Boundary.shp"));

            //tahseelLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.Capital3(“NAME_3”);

           
tahseelLayer.ZoomLevelSet.ZoomLevel10.CustomStyles.Add(TextStyles.CreateSimpleTextStyle(“TEHSIL”,
“Arial”, 8, DrawingFontStyles.Italic, GeoColor.StandardColors.Black, 3,
3));

            tahseelLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

           
tahseelLayer.ZoomLevelSet.ZoomLevel10.CustomStyles.Add(AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.White,
GeoColor.FromArgb(100, GeoColor.SimpleColors.Black)));

            ShapeFileFeatureLayer.BuildIndexFile(Server.MapPath(@"~/ShapeFiles/PAK_Tehsil_Boundary.shp"));

            LayerOverlay staticOverlay = new LayerOverlay(“StaticOverlay”);

            staticOverlay.IsBaseOverlay = false;

            staticOverlay.Layers.Add(“PakLayer”, PakLayer);

            staticOverlay.Layers.Add(“CapitalLayer”, capitalLayer);

            staticOverlay.Layers.Add(“DivisionLayer”, DivisionLayer);

            staticOverlay.Layers.Add(“DistrictLayer”, districtLayer);

            staticOverlay.Layers.Add(“TahseelLayer”, tahseelLayer);





            districtLayer.Open();

            Map1.CurrentExtent = districtLayer.GetBoundingBox();

            Map1.CustomOverlays.Add(staticOverlay);







            InMemoryFeatureLayer highlightLayer = new InMemoryFeatureLayer();

            highlightLayer.ZoomLevelSet.ZoomLevel10.DefaultAreaStyle =
AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(165, 42, 42, 100),
GeoColor.GeographicColors.DeepOcean);

            highlightLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            InMemoryFeatureLayer highlightLayer2 = new InMemoryFeatureLayer();

            highlightLayer2.ZoomLevelSet.ZoomLevel07.DefaultAreaStyle =
AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(140, 50, 30, 120),
GeoColor.GeographicColors.Dirt);

            highlightLayer2.ZoomLevelSet.ZoomLevel07.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level07;

            InMemoryFeatureLayer highlightLayer3 = new InMemoryFeatureLayer();

            highlightLayer3.ZoomLevelSet.ZoomLevel08.DefaultAreaStyle =
AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(160, 86, 120, 160),
GeoColor.GeographicColors.Dirt);

            highlightLayer3.ZoomLevelSet.ZoomLevel08.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level09;

            LayerOverlay dynamicOverlay = new LayerOverlay(“HightLightDynamicOverlay”);

            dynamicOverlay.Layers.Add(“HighLightLayer”, highlightLayer);

            dynamicOverlay.Layers.Add(“HighLightLayer2”, highlightLayer2);

            dynamicOverlay.Layers.Add(“HighLightLayer3”, highlightLayer3);

            dynamicOverlay.IsBaseOverlay = false;

            Map1.CustomOverlays.Add(dynamicOverlay);

            Map1.Popups.Add(new CloudPopup(“information”) { AutoSize = true, IsVisible = false });



            ViewBag.map = Map1;

            Session[“map”] = Map1;

            return View();

        }



Client Side code screenshot showing that there is no Popup defined but that’s not true.



Hi Shehraz,  
  
 Please pass the position argument to Popup when create a new CloudPopup instance, because only the popup is contained in current extent will be rendered to client.  Maybe the code just like the following:  
 map.Popups.Add(new CloudPopup("information", map.CurrentExtent.GetCenterPoint()) { AutoSize = true, IsVisible = false }); 
  
 Thanks,  
 Peter

Thanks Peter You resolve my issue.

Hi Peter I Have another question.I have multiple layers on map and I want to get layer index where I clicked , It will be better if I get the name of layer where user clicked. If there is any way to do that please help me.

Hi Shehraz, 
  
 Please see the other posts thinkgeo.com/forums/tabid/143/aft/12971/Default.aspx 
  
 Thanks, 
 Peter

I’ve just upgraded to the v9 releases coupled with locally hosted JS files, see this topic:

using IsDefaultJavascriptLibraryDisabled=true for MVCEdition 9.0

After migrating to the JS files, popups no longer get populated in the client-side array.



Here is my server side popup initialization code where ret refers to the map object.

var sourcePoint = ret.CurrentExtent.GetCenterPoint();
CloudPopup cloudPopup = new CloudPopup(“IncidentInfo”, sourcePoint, “”, 450, 300, true, true);
cloudPopup.AutoSize = false;
cloudPopup.IsVisible = false;
ret.Popups.Add(cloudPopup);
On the client-side, the Map1.popups array is empty.

I’ve removed reference to the local JS files and I have gotten the latest MVC Prod Files, Daily Full Production 9.0.0.236, and there is no change.  The popups array is empty on the client.

Hi Thomas, 
  
 Sorry I can’t recreate the issue based on your information. In MVC Edition v9.0 it must be meet the conditions when renders the popups on the client: 
  
 1.  The popup should be added into the Popups collection of map before rendering the map. 
 2.  The popup’s position is contained in the current extent. 
  
 After then we can use the following code to render the popup on the client: 
    var infoPopup = Map1.getPopup(“IncidentInfo”); // get the popup added in the popups collection. 
    infoPopup.lonlat = xy; // set the location of popup. 
    infoPopup.show(); // show the popup 
  
  
 Please have a try. If it still does’t work, could you please append more information here? 
  
 Thanks, 
 Peter