Exemplo n.º 1
0
        public virtual void WriteInitializationScript(TextWriter writer)
        {
            var currentCulture = Thread.CurrentThread.CurrentCulture;

            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            var objectWriter = new ClientSideObjectWriter(Id, "GoogleMap", writer);

            objectWriter.Start();

            objectWriter.Append("clientId", Id);
            objectWriter.Append("disableDoubleClickZoom", DisableDoubleClickZoom, false);
            objectWriter.Append("draggable", Draggable, true);
            objectWriter.Append("enableMarkersClustering", EnableMarkersClustering, false);
            objectWriter.Append("markersFromAddress", MarkersGeocoding, false);
            objectWriter.Append("fitToMarkersBounds", FitToMarkersBounds, false);

            if (Address.HasValue())
            {
                objectWriter.AppendObject("center", new { Address });
            }
            else
            {
                objectWriter.AppendObject("center", new { Latitude, Longitude, UseCurrentPosition });
            }

            objectWriter.Append("mapTypeId", MapTypeId);
            objectWriter.Append("mapTypeControlPosition", MapTypeControlPosition, ControlPosition.TopRight);
            objectWriter.Append("mapTypeControlVisible", MapTypeControlVisible, true);
            objectWriter.Append("mapTypeControlStyle", MapTypeControlStyle, MapTypeControlStyle.Default);

            if (Layers.Any())
            {
                var layers = new List <IDictionary <string, object> >();

                Layers.Each(l => layers.Add(l.CreateSerializer().Serialize()));

                if (layers.Any())
                {
                    objectWriter.AppendCollection("layers", layers);
                }
            }

            if (ImageMapTypes.Any())
            {
                if (!ImageMapTypes.Select(mt => mt.MapTypeName).Contains(MapTypeId))
                {
                    throw new Exception("Cannot find the MapTypeId in the ImageMapTypes collection");
                }

                var mapTypes = new List <IDictionary <string, object> >();

                ImageMapTypes.Each(m => mapTypes.Add(m.CreateSerializer().Serialize()));

                if (mapTypes.Any())
                {
                    objectWriter.AppendCollection("imageMapTypes", mapTypes);
                }
            }

            if (StyledMapTypes.Any())
            {
                var mapTypes = new List <IDictionary <string, object> >();

                StyledMapTypes.Each(m => mapTypes.Add(m.CreateSerializer().Serialize()));

                if (mapTypes.Any())
                {
                    objectWriter.AppendCollection("styledMapTypes", mapTypes);
                }
            }

            objectWriter.Append("panControlPosition", PanControlPosition, ControlPosition.TopLeft);
            objectWriter.Append("panControlVisible", PanControlVisible, true);

            objectWriter.Append("overviewMapControlVisible", OverviewMapControlVisible, false);
            objectWriter.Append("overviewMapControlOpened", OverviewMapControlOpened, false);

            objectWriter.Append("streetViewControlVisible", StreetViewControlVisible, true);
            objectWriter.Append("streetViewControlPosition", StreetViewControlPosition, ControlPosition.TopLeft);

            objectWriter.Append("zoomControlVisible", ZoomControlVisible, true);
            objectWriter.Append("zoomControlPosition", ZoomControlPosition, ControlPosition.TopLeft);
            objectWriter.Append("zoomControlStyle", ZoomControlStyle, ZoomControlStyle.Default);


            objectWriter.Append("scaleControlVisible", ScaleControlVisible, false);
            objectWriter.Append("zoom", (Zoom == 0) ? 6 : Zoom, 6);
            objectWriter.Append("minZoom", MinZoom, 0);
            objectWriter.Append("maxZoom", MaxZoom, 0);

            if (EnableMarkersClustering)
            {
                objectWriter.AppendObject("markerClusteringOptions", MarkerClusteringOptions.Serialize());
            }

            if (Markers.Any())
            {
                var markers = new List <IDictionary <string, object> >();
                int i       = 0;
                Markers.Each(m =>
                {
                    if (String.IsNullOrWhiteSpace(m.Id))
                    {
                        m.Id = i.ToString();
                    }
                    markers.Add(m.CreateSerializer().Serialize());
                    i++;
                });

                if (markers.Any())
                {
                    objectWriter.AppendCollection("markers", markers);
                }

                objectWriter.AppendClientEventObject("markerEvents", this.MarkerClientEvents);
            }

            if (Polygons.Any())
            {
                var polygons = new List <IDictionary <string, object> >();

                Polygons.Each(p => polygons.Add(p.CreateSerializer().Serialize()));

                if (polygons.Any())
                {
                    objectWriter.AppendCollection("polygons", polygons);
                }
            }

            if (Circles.Any())
            {
                var circles = new List <IDictionary <string, object> >();

                Circles.Each(c => circles.Add(c.CreateSerializer().Serialize()));

                if (circles.Any())
                {
                    objectWriter.AppendCollection("circles", circles);
                }
            }

            this.ClientEvents.SerializeTo(objectWriter);

            //TODO: Call a virtual method OnCompleting to allow derived class to inject its own json objects

            objectWriter.Complete();

            Thread.CurrentThread.CurrentCulture = currentCulture;
        }
Exemplo n.º 2
0
        public virtual void WriteInitializationScript(TextWriter writer)
        {
            var currentCulture = Thread.CurrentThread.CurrentCulture;

            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            var objectWriter = new ClientSideObjectWriter(Id, "GoogleMap", writer);

            objectWriter.Start();

            objectWriter.Append("clientId", Id);
            objectWriter.Append("disableDoubleClickZoom", DisableDoubleClickZoom, false);
            objectWriter.Append("draggable", Draggable, true);
            objectWriter.Append("enableMarkersClustering", EnableMarkersClustering, false);
            objectWriter.Append("height", Height);

            if (Address.HasValue())
            {
                objectWriter.AppendObject("center", new { Address });
            }
            else
            {
                objectWriter.AppendObject("center", new { Latitude, Longitude, UseCurrentPosition });
            }

            objectWriter.Append("mapTypeId", MapTypeId);
            objectWriter.Append("mapTypeControlPosition", MapTypeControlPosition, ControlPosition.TopRight);
            objectWriter.Append("mapTypeControlVisible", MapTypeControlVisible, true);
            objectWriter.Append("mapTypeControlStyle", MapTypeControlStyle, MapTypeControlStyle.Default);

            if (ImageMapTypes.Any())
            {
                if (!ImageMapTypes.Select(mt => mt.MapTypeName).Contains(MapTypeId))
                {
                    throw new Exception("Cannot find the MapTypeId in the ImageMapTypes collection");
                }

                var mapTypes = new List <IDictionary <string, object> >();

                ImageMapTypes.Each(m => mapTypes.Add(m.CreateSerializer().Serialize()));

                if (mapTypes.Any())
                {
                    objectWriter.AppendCollection("imageMapTypes", mapTypes);
                }
            }

            if (StyledMapTypes.Any())
            {
                var mapTypes = new List <IDictionary <string, object> >();

                StyledMapTypes.Each(m => mapTypes.Add(m.CreateSerializer().Serialize()));

                if (mapTypes.Any())
                {
                    objectWriter.AppendCollection("styledMapTypes", mapTypes);
                }
            }

            objectWriter.Append("panControlPosition", PanControlPosition, ControlPosition.TopLeft);
            objectWriter.Append("panControlVisible", PanControlVisible, true);

            objectWriter.Append("overviewMapControlVisible", OverviewMapControlVisible, false);
            objectWriter.Append("overviewMapControlOpened", OverviewMapControlOpened, false);

            objectWriter.Append("streetViewControlVisible", StreetViewControlVisible, true);
            objectWriter.Append("streetViewControlPosition", StreetViewControlPosition, ControlPosition.TopLeft);

            objectWriter.Append("zoomControlVisible", ZoomControlVisible, true);
            objectWriter.Append("zoomControlPosition", ZoomControlPosition, ControlPosition.TopLeft);
            objectWriter.Append("zoomControlStyle", ZoomControlStyle, ZoomControlStyle.Default);


            objectWriter.Append("scaleControlVisible", ScaleControlVisible, false);
            objectWriter.Append("width", Width, 0);
            objectWriter.Append("zoom", (Zoom == 0) ? 6 : Zoom, 6);
            objectWriter.Append("minZoom", MinZoom, 0);
            objectWriter.Append("maxZoom", MaxZoom, 0);

            if (EnableMarkersClustering)
            {
                objectWriter.AppendObject("markerClusteringOptions", MarkerClusteringOptions.Serialize());
            }

            if (Markers.Any())
            {
                var markers = new List <IDictionary <string, object> >();

                Markers.Each(m => markers.Add(m.CreateSerializer().Serialize()));

                if (markers.Any())
                {
                    objectWriter.AppendCollection("markers", markers);
                }
            }

            if (Polygons.Any())
            {
                var polygons = new List <IDictionary <string, object> >();

                Polygons.Each(p => polygons.Add(p.CreateSerializer().Serialize()));

                if (polygons.Any())
                {
                    objectWriter.AppendCollection("polygons", polygons);
                }
            }

            if (Circles.Any())
            {
                var circles = new List <IDictionary <string, object> >();

                Circles.Each(c => circles.Add(c.CreateSerializer().Serialize()));

                if (circles.Any())
                {
                    objectWriter.AppendCollection("circles", circles);
                }
            }

            this.ClientEvents.SerializeTo(objectWriter);

            objectWriter.Complete();

            Thread.CurrentThread.CurrentCulture = currentCulture;
        }