ThinkGeo.com    |     Documentation    |     Premium Support

Multiple colored markes

Hello,


  I would like to show multiple markers, but of different colors.  I seem to be having difficulty doing so with the following code.  I have read that it is not recommended to use multiple marker layers.  Please advise as to how I may accomplish this.  Code follows:


        protected void Page_Load(object sender, EventArgs e)

        {

            if (!Page.IsPostBack)

            {

                Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#B3C6D4"));

                Map1.CurrentExtent = new RectangleShape(-88.1422, 42.4009, -87.5169, 41.4529);

                Map1.MapUnit = GeographyUnit.DecimalDegree;

                //Map1.MapTools.PanZoom.Enabled = true;

                Map1.MapTools.PanZoomBar.Enabled = true;


                ShapeFileFeatureLayer defaultLayer = new ShapeFileFeatureLayer(Server.MapPath("~/Map/ILlkA.shp"));

                defaultLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(LineStyles.LocalRoad1);

                defaultLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

                defaultLayer.Name = ("defaultLayer");


                ShapeFileFeatureLayer railLayer = new ShapeFileFeatureLayer(Server.MapPath("~/Map/ILlkB.shp"));

                railLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(LineStyles.Railway1);

                railLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;


                ShapeFileFeatureLayer defaultStreetsLabelLayer = new ShapeFileFeatureLayer(Server.MapPath("~/Map/ILlkA.shp"));

                defaultStreetsLabelLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.LocalRoad1("FENAME");

                defaultStreetsLabelLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

                defaultStreetsLabelLayer.DrawingMarginPercentage = 100;

                defaultStreetsLabelLayer.Name = ("defaultStreetsLabelLayer");


                Map1.StaticOverlay.Layers.Add(railLayer);

                Map1.StaticOverlay.Layers.Add(defaultLayer);

                Map1.StaticOverlay.TileType = TileType.MultipleTile;

                Map1.DynamicOverlay.Layers.Add(defaultStreetsLabelLayer);


                // The following two lines of code enable the client and server caching.   

                // If you enable these features it will greatly increase the scalability of your   

                // mapping application however there some side effects that may be counter intuitive.   

                // Please read the white paper on web caching or the documentation regarding these methods.  


                Map1.StaticOverlay.ClientCache.CacheId = "defaultOverlay";

                Map1.StaticOverlay.ServerCache.CacheDirectory = MapPath("~/ImageCache/" + Request.Path);


                InMemoryFeatureLayer shapeLayer = new InMemoryFeatureLayer();

                shapeLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle =

                    PointStyles.CreateSimplePointStyle(PointSymbolType.Circle, GeoColor.StandardColors.Blue, 5);

                shapeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

                Map1.DynamicOverlay.Layers.Add("pointShapeLayer", shapeLayer);


                CreatePoints(shapeLayer, "-87.8225020", "42.3754010");               

                CreatePoints(shapeLayer, "-88.08842", "42.19746");

                CreatePoints(shapeLayer, "-88.063", "42.21907");

                

                CreateARedMarker("1", -87.8225020, 42.3754010);

                CreateAGreenMarker("2", -88.08842, 42.19746);

                CreateAGreenMarker("3", -88.063, 42.21907);


                shapeLayer.Open();

                Map1.CurrentExtent = shapeLayer.GetBoundingBox();

                shapeLayer.Close();

            }

        }


        private void CreatePoints(InMemoryFeatureLayer layer, string lon, string lat)

        {

            Feature pointFeature = new Feature(new PointShape(

                double.Parse(lon, CultureInfo.InvariantCulture), double.Parse(lat, CultureInfo.InvariantCulture)));

            layer.InternalFeatures.Add(pointFeature.Id, pointFeature);

        }


        private void CreateAGreenMarker(string key, double lon, double lat)

        {

            StringBuilder contentHtml = new StringBuilder();

            contentHtml.Append("")

                .Append("This is a green sample hover popup")

                .Append("");


            Map1.MarkerOverlay.Features.Add(key, new Feature(lon, lat));

            Map1.MarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.WebImage = new WebImage("/MapTest/theme/default/img/marker_green.gif", 21, 25);

            Map1.MarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.ContentHtml = contentHtml.ToString();

            Map1.MarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.AutoSize = true;

            Map1.MarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.BorderWidth = 1;

            Map1.MarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.IsVisible = false;

            Map1.MarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.AutoPan = true;

            Map1.MarkerOverlay.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

        }


        private void CreateARedMarker(string key, double lon, double lat)

        {

            StringBuilder contentHtml = new StringBuilder();

            contentHtml.Append("")

                .Append("This is a red sample hover popup")

                .Append("");


            Map1.MarkerOverlay.Features.Add(key, new Feature(lon, lat));

            Map1.MarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.WebImage = new WebImage("/MapTest/theme/default/img/marker.gif", 21, 25);

            Map1.MarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.ContentHtml = contentHtml.ToString();

            Map1.MarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.AutoSize = true;

            Map1.MarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.BorderWidth = 1;

            Map1.MarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.IsVisible = false;

            Map1.MarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.AutoPan = true;

            Map1.MarkerOverlay.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

        }



Steven,



ValueMarkerStyle is what you need. Please see the attached code and screenshot of it.







Any questions please let me know.



Thanks,

Howard



982-DisplayASimpleMap.aspx.cs (2.6 KB)