private static MvcHtmlString GoogleMap(HtmlHelper helper, string id, Models.Map map, bool editor) { StringBuilder sbControlHtml = new StringBuilder(); using (StringWriter stringWriter = new StringWriter()) { using (HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter)) { //Generate container div control HtmlGenericControl divWrapperControl = new HtmlGenericControl("div"); HtmlGenericControl divMapControl = new HtmlGenericControl("div"); divMapControl.Attributes.Add("class", "map-container"); divMapControl.Attributes.Add("id", string.Format("map-{0}", id)); if (map.height > 0 || map.width > 0) { string widthStyle = "width:{0}px;"; if (map.width > 0) { widthStyle = string.Format(widthStyle, map.width); } else { widthStyle = string.Empty; } string heightStyle = "height:{0}px;"; if (map.height > 0) { heightStyle = string.Format(heightStyle, map.height); } else { heightStyle = string.Empty; } divMapControl.Attributes.Add("style", string.Concat(widthStyle, heightStyle)); } divWrapperControl.Controls.Add(divMapControl); //value input control HtmlInputHidden hidden = new HtmlInputHidden(); HtmlInputHidden hiddenValueControl = new HtmlInputHidden(); hiddenValueControl.ID = id; divWrapperControl.Controls.Add(hiddenValueControl); HtmlGenericControl scriptControl = new HtmlGenericControl("script"); scriptControl.Attributes.Add("type", "text/javascript"); scriptControl.InnerHtml = string.Format(@"$(document).ready(function(){{ $('#map-{0}').GoogleMapEditor($.extend({{}},{1},{{dataChange:function(sender, data){{ $(sender.container).next().next().val(data); }}}}));}});", id, map.ToJsonString()); divWrapperControl.Controls.Add(scriptControl); divWrapperControl.RenderControl(htmlWriter); sbControlHtml.Append(stringWriter.ToString()); divWrapperControl.Dispose(); } } return new MvcHtmlString(sbControlHtml.ToString()); }
public HttpResponseMessage GetMarkerEditForm(string filename, bool richtext = false) { string result = Common.GetResourceText(filename); StringBuilder sbFiles = new StringBuilder(); string folderPath = "/Umbraco/Images/MapPins/"; if (Directory.Exists(HttpContext.Current.Server.MapPath(folderPath))) { foreach (string file in Directory.GetFiles(HttpContext.Current.Server.MapPath(folderPath))) { using (StringWriter stringWriter = new StringWriter()) { using (HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter)) { HtmlGenericControl optionHtml = new HtmlGenericControl("option"); optionHtml.Attributes.Add("value", string.Concat(folderPath, Path.GetFileName(file))); optionHtml.InnerText = Path.GetFileName(file); optionHtml.RenderControl(htmlWriter); sbFiles.Append(stringWriter.ToString()); optionHtml.Dispose(); } } } } return new HttpResponseMessage() { Content = new StringContent(string.Format(result, sbFiles.ToString(), richtext ? "richtext-fix" : string.Empty), System.Text.Encoding.UTF8, "application/html") }; }