示例#1
0
        public ClusteredPin(LatLong loc, Bounds clusterArea)
        {
            pixelX = -1;
            pixelY = -1;
            Loc = loc;
            ClusterArea = clusterArea;

            ServiceCodeToTitle = new Dictionary<string, string>();
        }
示例#2
0
        public ClusteredPin(LatLong loc, Bounds clusterArea, int assessmentid)
        {
            pixelX = -1;
            pixelY = -1;
            Loc = loc;
            ClusterArea = clusterArea;
            assessmentids.Add(assessmentid);

            ServiceCodeToTitle = new Dictionary<string, string>();
        }
示例#3
0
        public ClusteredPin(LatLong loc, Bounds clusterArea, int assessmentid, NameValueCollection assessmentHeaderData)
        {
            pixelX = -1;
            pixelY = -1;
            Loc = loc;
            ClusterArea = clusterArea;
            assessmentids.Add(assessmentid);
              //  AssessmentHeaderData = assessmentHeaderData;

            ServiceCodeToTitle = new Dictionary<string, string>();
        }
示例#4
0
        public ClusteredPin(LatLong loc, Bounds clusterArea, int assessmentid, string pinType, NameValueCollection assessmentHeaderData, string themeParameter)
        {
            pixelX      = -1;
            pixelY      = -1;
            Loc         = loc;
            ClusterArea = clusterArea;
            assessmentids.Add(assessmentid);
            PinType = pinType;
            //  AssessmentHeaderData = assessmentHeaderData;
            //  ThemeParameter = themeParameter;

            ServiceCodeToTitle = new Dictionary <string, string>();
        }
示例#5
0
        public ClusteredPin(LatLong loc, Bounds clusterArea, int assessmentid, string pinType, NameValueCollection assessmentHeaderData, string themeParameter)
        {
            pixelX = -1;
            pixelY = -1;
            Loc = loc;
            ClusterArea = clusterArea;
            assessmentids.Add(assessmentid);
            PinType = pinType;
              //  AssessmentHeaderData = assessmentHeaderData;
              //  ThemeParameter = themeParameter;

            ServiceCodeToTitle = new Dictionary<string, string>();
        }
示例#6
0
 public Bounds()
 {
     //Set values to opposite to allow any new values to override
     NW = new LatLong(-90, 180);
     SE = new LatLong(90, -180);
 }
        /// <summary>
        /// Get Centerpoint For Bounds
        /// </summary>
        /// <param name="bounds"></param>
        /// <returns></returns>
        public LatLong GetCenterpointForBounds(Bounds bounds)
        {
            var latLong = new LatLong();

            latLong.Lat = (bounds.NW.Lat + bounds.SE.Lat) / 2;
            latLong.Lon = (bounds.SE.Lon + bounds.NW.Lon) / 2;

            return latLong;
        }
示例#8
0
 public Bounds(LatLong nW, LatLong sE)
 {
     NW = nW;
     SE = sE;
 }
        /// <summary>
        /// Create geojson from markers (http://www.geojson.org/)
        /// </summary>
        /// <param name="pins"></param>
        /// <param name="zoomlevel"></param>
        /// <param name="centerPoint"></param>
        /// <param name="legend"></param>
        /// <param name="searchParameters"></param>
        /// <param name="assessmentCount"></param>
        /// <returns></returns>
        public string createMarkersGEOJSON(List<ClusteredPin> pins, int zoomlevel, LatLong centerPoint, string legend)
        {
            StringBuilder sb = new StringBuilder();

            //legend = "test";
            //sb.Append("<locations>");
            //sb.Append("{ \"locations\": [");
            //Add zoomlevel information only relevant for forst timt after wards it is 0;
            //sb.Append("<setting zoomlevel=\"" + zoomlevel + "\"  />");

            //var appServiceLayerResponseObject = new SerializedAppResponse();
            //ByBoolRequest bObj = new ByBoolRequest();

            ////get Database connectionstring name
            //bObj.DBConnName = ConfigurationManager.AppSettings["DbConnName"];
            ////get userId for Authenticated user
            //FormsIdentity formsIdentity = (FormsIdentity)HttpContext.Current.User.Identity;
            //bObj.AuthenticatedUserId = Convert.ToInt32(formsIdentity.Ticket.Name.Split(';')[1]);

            //bObj.BoolParam = true;

            //Hashtable ht = MapClientLibrary.AppServiceLayerObjects.GetAllVisibleFromCustom(bObj);

            int i = 0;
            StringBuilder pinsString = new StringBuilder();
            StringBuilder clusteredpinsString = new StringBuilder();
            StringBuilder polylineString = new StringBuilder();
            StringBuilder polygonString = new StringBuilder();

            foreach (ClusteredPin pin in pins)
            {

                if (pin.PinType.ToString().Contains("point")) //point and clusterpoint
                {
                    //sb.Append("\"pin\" :[{");
                    if (pin.Count <= 1)
                    {
                        pinsString.Append("{");
                        pinsString.Append("\"type\": \"Feature\",");
                        pinsString.Append("\"id\": \"" + pin.assessmentids[0].ToString() + "\",");
                        pinsString.Append("\"geometry\": {");
                        pinsString.Append("\"type\": \"Point\",");
                        pinsString.Append("\"coordinates\": [" + pin.Loc.Lon.ToString() + "," + pin.Loc.Lat.ToString() + "]},");
                        pinsString.Append("\"properties\": {");
                        pinsString.Append("\"clusterid\":\"" + i.ToString() + "\", ");
                        //pinsString.Append("\"guid\":\"" + pin.AssessmentHeaderData["guid"].ToString() + "\", ");
                        //pinsString.Append("\"sector\":\"" + pin.AssessmentHeaderData["sector"].ToString() + "\", ");
                        //pinsString.Append("\"assessment\":\"" + pin.AssessmentHeaderData["assessment"].ToString() + "\", ");
                        //pinsString.Append("\"dateassessed\":\"" + pin.AssessmentHeaderData["dateassessed"].ToString() + "\", ");
                        //pinsString.Append("\"dateposted\":\"" + pin.AssessmentHeaderData["dateposted"].ToString() + "\", ");
                        //pinsString.Append("\"icontype\":\"" + pin.AssessmentHeaderData["icontype"].ToString() + "\" ");

                        //Add service code/title pairs to properties...
                        pinsString.Append("\"serviceCodeToTitle\": {");
                        foreach (var serviceCode in pin.ServiceCodeToTitle)
                        {
                            pinsString.Append(String.Format("\"{0}\": \"{1}\",", serviceCode.Key, serviceCode.Value));
                        }
                        //Remove trailing ',', if indicated
                        if ( ',' == pinsString[pinsString.Length - 1])
                        {
                            pinsString.Remove(pinsString.Length - 1, 1);
                        }
                        pinsString.Append("}");

                        pinsString.Append("}},");
                        ////if ((pins.Count > 1)) sb.Append(",");
                    }
                    else
                    {
                        clusteredpinsString.Append("{");
                        clusteredpinsString.Append("\"type\": \"Feature\",");
                        clusteredpinsString.Append("\"id\": \"" + pin.assessmentids[0].ToString() + "\",");
                        clusteredpinsString.Append("\"geometry\": {");
                        clusteredpinsString.Append("\"type\": \"Point\",");
                        clusteredpinsString.Append("\"coordinates\": [" + pin.Loc.Lon.ToString() + "," + pin.Loc.Lat.ToString() + "]},");
                        clusteredpinsString.Append("\"properties\": {");

                        clusteredpinsString.Append("\"clusterid\":\"" + i.ToString() + "\", ");
                        clusteredpinsString.Append("\"count\":\"" + pin.Count + "\", ");
                        clusteredpinsString.Append("\"icontype\":\"cluster\", ");

                        //Add service code/title pairs to properties...
                        clusteredpinsString.Append("\"serviceCodeToTitle\": {");
                        foreach (var serviceCode in pin.ServiceCodeToTitle)
                        {
                            clusteredpinsString.Append(String.Format("\"{0}\": \"{1}\",", serviceCode.Key, serviceCode.Value));
                        }
                        //Remove trailing ',', if indicated
                        if (',' == clusteredpinsString[clusteredpinsString.Length - 1])
                        {
                            clusteredpinsString.Remove(clusteredpinsString.Length - 1, 1);
                        }
                        clusteredpinsString.Append("}");

                        clusteredpinsString.Append("}},");
                    }

                }
                if (pin.PinType.ToString() == "polyline")
                { }
                //if (pin.PinType.ToString() == "polygon")
                //{
                //    //parse answertext to get points
                //    //fix for not having a semicolon on end
                //   // string answertext = pin.AssessmentHeaderData["answertext"];
                //    //if (!answertext.EndsWith(";"))
                //    //{
                //    //    answertext = answertext + ";";
                //    //}

                //    //string[] pts = answertext.Split(';');
                //    string vertices = null;
                //    string[] pt = null;
                //    vertices += "\"coordinates\": [";
                //    for (int j = 0; j < pts.Length - 1; j++)
                //    {
                //        pt = pts[j].Split(',');
                //        vertices += "[" + pt[1].ToString() + ", " + pt[0].ToString() + "],";
                //    }

                //    //add the first one again to complete area.
                //    pt = pts[0].Split(',');
                //    vertices += "[" + pt[1].ToString() + ", " + pt[0].ToString() + "] ";
                //    vertices += " ],";

                //    polygonString.Append("{");
                //    polygonString.Append("\"type\": \"Feature\",");
                //    polygonString.Append("\"id\": \"" + pin.assessmentids[0].ToString() + "\",");
                //    polygonString.Append("\"geometry\": {");
                //    polygonString.Append("\"type\": \"Polygon\",");
                //    polygonString.Append(vertices);
                //    //polygonString.Append("\"coordinates\": [" + pin.Loc.Lat.ToString() + "," + pin.Loc.Lon.ToString() + "]},");
                //    polygonString.Append("\"properties\": {");

                //    polygonString.Append("\"guid\":\"" + pin.AssessmentHeaderData["guid"].ToString() + "\", ");
                //    polygonString.Append("\"sector\":\"" + pin.AssessmentHeaderData["sector"].ToString() + "\", ");
                //    polygonString.Append("\"assessment\":\"" + pin.AssessmentHeaderData["assessment"].ToString() + "\", ");
                //    polygonString.Append("\"dateassessed\":\"" + pin.AssessmentHeaderData["dateassessed"].ToString() + "\", ");
                //    polygonString.Append("\"dateposted\":\"" + pin.AssessmentHeaderData["dateposted"].ToString() + "\", ");
                //    polygonString.Append("\"answertext\":\"" + pin.AssessmentHeaderData["answertext"].ToString() + "\", ");
                //    polygonString.Append("\"strokeColor\": \"#000000\", ");
                //    polygonString.Append("\"strokeWeight\": \"2\", ");
                //    polygonString.Append("\"strokeOpacity\": \"0.8\", ");
                //    polygonString.Append("\"fillColor\": \"#EBEC78\", ");
                //    polygonString.Append("\"fillOpacity\": \"0.50\" ");
                //    polygonString.Append("}}},");

                //    //polygonString.Append("\"polygon\": [{ \"id\": \"" + pin.assessmentids[0].ToString() + "\", " +
                //    //            "\"answertext\": \"" + answertext.ToString() + "\", " +
                //    //            "\"guid\": \"" + pin.AssessmentHeaderData["guid"].ToString() + "\", " +
                //    //            "\"sector\": \"" + pin.AssessmentHeaderData["sector"].ToString() + "\", " +
                //    //            "\"assessment\": \"" + pin.AssessmentHeaderData["assessment"].ToString() + "\", " +
                //    //            "\"dateassessed\": \"" + pin.AssessmentHeaderData["dateassessed"].ToString() + "\", " +
                //    //            "\"dateposted\":\"" + pin.AssessmentHeaderData["dateposted"].ToString() + "\", " +
                //    //            "\"strokeColor\": \"#000000\", " +
                //    //            "\"strokeWeight\": \"2\", " +
                //    //            "\"strokeOpacity\": \"0.8\", " +
                //    //            "\"fillColor\": \"#EBEC78\", " +
                //    //            "\"fillColor\": \"#EBEC78\", " +
                //    //             vertices +
                //    //            " }]");

                //}
                i++;
            }

            //if (pinsString.Length > 0)
            //{
            //    pinsString.Remove(pinsString.Length - 1, 1); // remove last comma
            //    sb.Append(",\"pins\" : [ " + pinsString.ToString() + " ]");
            //}

            //if (clusteredpinsString.Length > 0)
            //{
            //    clusteredpinsString.Remove(clusteredpinsString.Length - 1, 1); // remove last comma
            //    sb.Append(",\"clusteredpins\" : [ " + clusteredpinsString.ToString() + " ]");
            //}

            //built json
            sb.Append("{");
            sb.Append("\"type\": \"FeatureCollection\",");
            sb.Append("\"features\": [");
            //add point features
            // remove last comma if no clustered markers
            if (pinsString.Length > 0) if (clusteredpinsString.Length == 0) { pinsString.Remove(pinsString.Length - 1, 1); }
            //append string for single markers
            sb.Append(pinsString);

            if (clusteredpinsString.Length > 0) if (polygonString.Length == 0) { clusteredpinsString.Remove(clusteredpinsString.Length - 1, 1); }
            //Append String for clustered markers
            //if ((pinsString.Length > 0) && (pins.Count > 1)) sb.Append(",");
            sb.Append(clusteredpinsString);
            if (polygonString.Length > 0) { polygonString.Remove(polygonString.Length - 1, 1); }
            sb.Append(polygonString);
            sb.Append("],");
            sb.Append("\"properties\": {");
            //string lblprogramTitle = (ht["program"] != null) ? ht["program"].ToString() : "program";
            sb.Append("\"zoomlevel\": \"" + zoomlevel + "\",");
            sb.Append("\"centerPoint\": \"" + centerPoint.Lat + " " + centerPoint.Lon + "\",");
            //sb.Append("\"programname\":\"" + lblprogramTitle + ": " + searchParameters.ProgramName + "\", ");

            ////legend = "<i>legend</i>";
            sb.Append("\"legend\" : \"" + legend + "\"");
            sb.Append("}");
            sb.Append("}");

            //sb.Append("]}");
            //sb.Append("</locations>");
            //sb.Replace("& ", "&amp;#38 ");
            string s = sb.ToString();
            //string s = Server.HtmlEncode(sb.ToString());
            return s;
        }
示例#10
0
        /// <summary>
        /// Create geojson from markers (http://www.geojson.org/)
        /// </summary>
        /// <param name="pins"></param>
        /// <param name="zoomlevel"></param>
        /// <param name="centerPoint"></param>
        /// <param name="legend"></param>
        /// <param name="searchParameters"></param>
        /// <param name="assessmentCount"></param>
        /// <returns></returns>
        public string createMarkersGEOJSON(List <ClusteredPin> pins, int zoomlevel, LatLong centerPoint, string legend)
        {
            StringBuilder sb = new StringBuilder();

            //legend = "test";
            //sb.Append("<locations>");
            //sb.Append("{ \"locations\": [");
            //Add zoomlevel information only relevant for forst timt after wards it is 0;
            //sb.Append("<setting zoomlevel=\"" + zoomlevel + "\"  />");

            //var appServiceLayerResponseObject = new SerializedAppResponse();
            //ByBoolRequest bObj = new ByBoolRequest();

            ////get Database connectionstring name
            //bObj.DBConnName = ConfigurationManager.AppSettings["DbConnName"];
            ////get userId for Authenticated user
            //FormsIdentity formsIdentity = (FormsIdentity)HttpContext.Current.User.Identity;
            //bObj.AuthenticatedUserId = Convert.ToInt32(formsIdentity.Ticket.Name.Split(';')[1]);

            //bObj.BoolParam = true;

            //Hashtable ht = MapClientLibrary.AppServiceLayerObjects.GetAllVisibleFromCustom(bObj);

            int           i                   = 0;
            StringBuilder pinsString          = new StringBuilder();
            StringBuilder clusteredpinsString = new StringBuilder();
            StringBuilder polylineString      = new StringBuilder();
            StringBuilder polygonString       = new StringBuilder();

            foreach (ClusteredPin pin in pins)
            {
                if (pin.PinType.ToString().Contains("point")) //point and clusterpoint
                {
                    //sb.Append("\"pin\" :[{");
                    if (pin.Count <= 1)
                    {
                        pinsString.Append("{");
                        pinsString.Append("\"type\": \"Feature\",");
                        pinsString.Append("\"id\": \"" + pin.assessmentids[0].ToString() + "\",");
                        pinsString.Append("\"geometry\": {");
                        pinsString.Append("\"type\": \"Point\",");
                        pinsString.Append("\"coordinates\": [" + pin.Loc.Lon.ToString() + "," + pin.Loc.Lat.ToString() + "]},");
                        pinsString.Append("\"properties\": {");
                        pinsString.Append("\"clusterid\":\"" + i.ToString() + "\", ");
                        //pinsString.Append("\"guid\":\"" + pin.AssessmentHeaderData["guid"].ToString() + "\", ");
                        //pinsString.Append("\"sector\":\"" + pin.AssessmentHeaderData["sector"].ToString() + "\", ");
                        //pinsString.Append("\"assessment\":\"" + pin.AssessmentHeaderData["assessment"].ToString() + "\", ");
                        //pinsString.Append("\"dateassessed\":\"" + pin.AssessmentHeaderData["dateassessed"].ToString() + "\", ");
                        //pinsString.Append("\"dateposted\":\"" + pin.AssessmentHeaderData["dateposted"].ToString() + "\", ");
                        //pinsString.Append("\"icontype\":\"" + pin.AssessmentHeaderData["icontype"].ToString() + "\" ");

                        //Add service code/title pairs to properties...
                        pinsString.Append("\"serviceCodeToTitle\": {");
                        foreach (var serviceCode in pin.ServiceCodeToTitle)
                        {
                            pinsString.Append(String.Format("\"{0}\": \"{1}\",", serviceCode.Key, serviceCode.Value));
                        }
                        //Remove trailing ',', if indicated
                        if (',' == pinsString[pinsString.Length - 1])
                        {
                            pinsString.Remove(pinsString.Length - 1, 1);
                        }
                        pinsString.Append("}");

                        pinsString.Append("}},");
                        ////if ((pins.Count > 1)) sb.Append(",");
                    }
                    else
                    {
                        clusteredpinsString.Append("{");
                        clusteredpinsString.Append("\"type\": \"Feature\",");
                        clusteredpinsString.Append("\"id\": \"" + pin.assessmentids[0].ToString() + "\",");
                        clusteredpinsString.Append("\"geometry\": {");
                        clusteredpinsString.Append("\"type\": \"Point\",");
                        clusteredpinsString.Append("\"coordinates\": [" + pin.Loc.Lon.ToString() + "," + pin.Loc.Lat.ToString() + "]},");
                        clusteredpinsString.Append("\"properties\": {");

                        clusteredpinsString.Append("\"clusterid\":\"" + i.ToString() + "\", ");
                        clusteredpinsString.Append("\"count\":\"" + pin.Count + "\", ");
                        clusteredpinsString.Append("\"icontype\":\"cluster\", ");

                        //Add service code/title pairs to properties...
                        clusteredpinsString.Append("\"serviceCodeToTitle\": {");
                        foreach (var serviceCode in pin.ServiceCodeToTitle)
                        {
                            clusteredpinsString.Append(String.Format("\"{0}\": \"{1}\",", serviceCode.Key, serviceCode.Value));
                        }
                        //Remove trailing ',', if indicated
                        if (',' == clusteredpinsString[clusteredpinsString.Length - 1])
                        {
                            clusteredpinsString.Remove(clusteredpinsString.Length - 1, 1);
                        }
                        clusteredpinsString.Append("}");

                        clusteredpinsString.Append("}},");
                    }
                }
                if (pin.PinType.ToString() == "polyline")
                {
                }
                //if (pin.PinType.ToString() == "polygon")
                //{
                //    //parse answertext to get points
                //    //fix for not having a semicolon on end
                //   // string answertext = pin.AssessmentHeaderData["answertext"];
                //    //if (!answertext.EndsWith(";"))
                //    //{
                //    //    answertext = answertext + ";";
                //    //}

                //    //string[] pts = answertext.Split(';');
                //    string vertices = null;
                //    string[] pt = null;
                //    vertices += "\"coordinates\": [";
                //    for (int j = 0; j < pts.Length - 1; j++)
                //    {
                //        pt = pts[j].Split(',');
                //        vertices += "[" + pt[1].ToString() + ", " + pt[0].ToString() + "],";
                //    }

                //    //add the first one again to complete area.
                //    pt = pts[0].Split(',');
                //    vertices += "[" + pt[1].ToString() + ", " + pt[0].ToString() + "] ";
                //    vertices += " ],";

                //    polygonString.Append("{");
                //    polygonString.Append("\"type\": \"Feature\",");
                //    polygonString.Append("\"id\": \"" + pin.assessmentids[0].ToString() + "\",");
                //    polygonString.Append("\"geometry\": {");
                //    polygonString.Append("\"type\": \"Polygon\",");
                //    polygonString.Append(vertices);
                //    //polygonString.Append("\"coordinates\": [" + pin.Loc.Lat.ToString() + "," + pin.Loc.Lon.ToString() + "]},");
                //    polygonString.Append("\"properties\": {");

                //    polygonString.Append("\"guid\":\"" + pin.AssessmentHeaderData["guid"].ToString() + "\", ");
                //    polygonString.Append("\"sector\":\"" + pin.AssessmentHeaderData["sector"].ToString() + "\", ");
                //    polygonString.Append("\"assessment\":\"" + pin.AssessmentHeaderData["assessment"].ToString() + "\", ");
                //    polygonString.Append("\"dateassessed\":\"" + pin.AssessmentHeaderData["dateassessed"].ToString() + "\", ");
                //    polygonString.Append("\"dateposted\":\"" + pin.AssessmentHeaderData["dateposted"].ToString() + "\", ");
                //    polygonString.Append("\"answertext\":\"" + pin.AssessmentHeaderData["answertext"].ToString() + "\", ");
                //    polygonString.Append("\"strokeColor\": \"#000000\", ");
                //    polygonString.Append("\"strokeWeight\": \"2\", ");
                //    polygonString.Append("\"strokeOpacity\": \"0.8\", ");
                //    polygonString.Append("\"fillColor\": \"#EBEC78\", ");
                //    polygonString.Append("\"fillOpacity\": \"0.50\" ");
                //    polygonString.Append("}}},");

                //    //polygonString.Append("\"polygon\": [{ \"id\": \"" + pin.assessmentids[0].ToString() + "\", " +
                //    //            "\"answertext\": \"" + answertext.ToString() + "\", " +
                //    //            "\"guid\": \"" + pin.AssessmentHeaderData["guid"].ToString() + "\", " +
                //    //            "\"sector\": \"" + pin.AssessmentHeaderData["sector"].ToString() + "\", " +
                //    //            "\"assessment\": \"" + pin.AssessmentHeaderData["assessment"].ToString() + "\", " +
                //    //            "\"dateassessed\": \"" + pin.AssessmentHeaderData["dateassessed"].ToString() + "\", " +
                //    //            "\"dateposted\":\"" + pin.AssessmentHeaderData["dateposted"].ToString() + "\", " +
                //    //            "\"strokeColor\": \"#000000\", " +
                //    //            "\"strokeWeight\": \"2\", " +
                //    //            "\"strokeOpacity\": \"0.8\", " +
                //    //            "\"fillColor\": \"#EBEC78\", " +
                //    //            "\"fillColor\": \"#EBEC78\", " +
                //    //             vertices +
                //    //            " }]");

                //}
                i++;
            }

            //if (pinsString.Length > 0)
            //{
            //    pinsString.Remove(pinsString.Length - 1, 1); // remove last comma
            //    sb.Append(",\"pins\" : [ " + pinsString.ToString() + " ]");
            //}

            //if (clusteredpinsString.Length > 0)
            //{
            //    clusteredpinsString.Remove(clusteredpinsString.Length - 1, 1); // remove last comma
            //    sb.Append(",\"clusteredpins\" : [ " + clusteredpinsString.ToString() + " ]");
            //}


            //built json
            sb.Append("{");
            sb.Append("\"type\": \"FeatureCollection\",");
            sb.Append("\"features\": [");
            //add point features
            // remove last comma if no clustered markers
            if (pinsString.Length > 0)
            {
                if (clusteredpinsString.Length == 0)
                {
                    pinsString.Remove(pinsString.Length - 1, 1);
                }
            }
            //append string for single markers
            sb.Append(pinsString);

            if (clusteredpinsString.Length > 0)
            {
                if (polygonString.Length == 0)
                {
                    clusteredpinsString.Remove(clusteredpinsString.Length - 1, 1);
                }
            }
            //Append String for clustered markers
            //if ((pinsString.Length > 0) && (pins.Count > 1)) sb.Append(",");
            sb.Append(clusteredpinsString);
            if (polygonString.Length > 0)
            {
                polygonString.Remove(polygonString.Length - 1, 1);
            }
            sb.Append(polygonString);
            sb.Append("],");
            sb.Append("\"properties\": {");
            //string lblprogramTitle = (ht["program"] != null) ? ht["program"].ToString() : "program";
            sb.Append("\"zoomlevel\": \"" + zoomlevel + "\",");
            sb.Append("\"centerPoint\": \"" + centerPoint.Lat + " " + centerPoint.Lon + "\",");
            //sb.Append("\"programname\":\"" + lblprogramTitle + ": " + searchParameters.ProgramName + "\", ");

            ////legend = "<i>legend</i>";
            sb.Append("\"legend\" : \"" + legend + "\"");
            sb.Append("}");
            sb.Append("}");


            //sb.Append("]}");
            //sb.Append("</locations>");
            //sb.Replace("& ", "&amp;#38 ");
            string s = sb.ToString();

            //string s = Server.HtmlEncode(sb.ToString());
            return(s);
        }
示例#11
0
		public ActionResult updateMarkers(FormCollection collection)
		{
			if ( bFirstCall)
			{
				//First time called since last web site restart - log selected <appSettings> values...
				bFirstCall = false;

				dblogcontext.clearParameters();
				dblogcontext.clearReturns();

				dblogcontext.addParameter("ServiceUrl", ConfigurationManager.AppSettings["ServiceUrl"]);
				dblogcontext.addParameter("ServiceUrl_1_1_EndPoint", ConfigurationManager.AppSettings["ServiceUrl1_1_EndPoint"]);
				dblogcontext.addParameter("ByuUrl", ConfigurationManager.AppSettings["ByuUrl"]);
				dblogcontext.addParameter("MaxClustercount", ConfigurationManager.AppSettings["MaxClustercount"].ToString());
				dblogcontext.addParameter("maxAllowedTimeseriesReturn", ConfigurationManager.AppSettings["maxAllowedTimeseriesReturn"].ToString());
				dblogcontext.addParameter("maxCombinedExportValues", ConfigurationManager.AppSettings["maxCombinedExportValues"].ToString());
				dblogcontext.addParameter("blobContainer", ConfigurationManager.AppSettings["blobContainer"]);
				dblogcontext.addParameter("aspnet:MaxJsonDeserializerMembers", ConfigurationManager.AppSettings["aspnet:MaxJsonDeserializerMembers"].ToString());
				dblogcontext.addParameter("currentVersion", ConfigurationManager.AppSettings["currentVersion"].ToString());

				DateTime dtNow = DateTime.UtcNow;
				dblogcontext.createLogEntry(System.Web.HttpContext.Current, dtNow, dtNow, "updateMarkers(...)", "first call - selected appSettings values...", Level.Info);
			}

			var searchSettings = new SearchSettings();
			string markerjSON = string.Empty;
		   
			//get map geometry
			double xMin, xMax, yMin, yMax;
			int zoomLevel;

			int CLUSTERWIDTH = 50; //Cluster region width, all pin within this area are clustered
			int CLUSTERHEIGHT = 50; //Cluster region height, all pin within this area are clustered
			int CLUSTERINCREMENT = 5; //increment for clusterwidth 
			int MINCLUSTERDISTANCE = 25;
			int MAXCLUSTERCOUNT = Convert.ToInt32(ConfigurationManager.AppSettings["MaxClustercount"].ToString()); //maximum ammount of clustered markers

			UniversalTypeConverter.TryConvertTo<double>(collection["xMin"], out xMin);
			UniversalTypeConverter.TryConvertTo<double>(collection["xMax"], out xMax);
			UniversalTypeConverter.TryConvertTo<double>(collection["yMin"], out yMin);
			UniversalTypeConverter.TryConvertTo<double>(collection["yMax"], out yMax);
			Box box = new Box(xMin, xMax, yMin, yMax);
			UniversalTypeConverter.TryConvertTo<int>(collection["zoomLevel"], out zoomLevel);
			var activeWebservices = new List<WebServiceNode>();

			//Attempt to retrieve filtered timeseries ids, if indicated
			string strFilterAndSearchCriteria = collection["filterAndSearchCriteria"];

			clientFilterAndSearchCriteria filterAndSearchCriteria = null;

			if (!String.IsNullOrWhiteSpace(strFilterAndSearchCriteria))
			{
				filterAndSearchCriteria = JsonConvert.DeserializeObject<clientFilterAndSearchCriteria>(strFilterAndSearchCriteria);
			}

			//if it is a new request
			if (collection["isNewRequest"].ToString() == "true")
			{

				bool canConvert = false;

				var keywords = Regex.Split(collection["keywords"], @"##");
				var tileWidth = 10;
				var tileHeight = 10;
				List<int> webServiceIds = null;
				try
				{
					//Increase date range by one day to accomodate one day searches, if indicated...
					//Set begin date time to 00:00:00, set end date time to 23:59:59
					searchSettings.DateSettings.StartDate = Convert.ToDateTime(collection["startDate"]);
					searchSettings.DateSettings.StartDate = searchSettings.DateSettings.StartDate.Date.AddHours(0).AddMinutes(0).AddSeconds(0);

					searchSettings.DateSettings.EndDate = Convert.ToDateTime(collection["endDate"]);
					if (searchSettings.DateSettings.StartDate.Date == searchSettings.DateSettings.EndDate.Date)
					{
						searchSettings.DateSettings.EndDate = searchSettings.DateSettings.EndDate.Date.AddDays(1);
					}
					searchSettings.DateSettings.EndDate = searchSettings.DateSettings.EndDate.Date.AddHours(23).AddMinutes(59).AddSeconds(59);
					
					//Convert to int Array
					if (collection["services"].Length > 0)
					{
						webServiceIds = collection["services"].Split(',').Select(s => Convert.ToInt32(s)).ToList();
					}

					var dataWorker = new DataWorker();

					var allWebservices = dataWorker.getWebServiceList();


					//filter list
					if (webServiceIds != null)
					{
						activeWebservices = dataWorker.filterWebservices(allWebservices, webServiceIds);
					}
					Session["webServiceList"] = allWebservices;

					//Clear parameters...
					dblogcontext.clearParameters();
					dberrorcontext.clearParameters();

					//Add call parameters...
					dblogcontext.addParameter("box", box);
					dberrorcontext.addParameter("box", box);
					if (1 == keywords.Length && "" == keywords[0])
					{
						dblogcontext.addParameter("keywords", "All");
						dberrorcontext.addParameter("keywords", "All");
					}
					else
					{
						StringBuilder sb1 = new StringBuilder();
						foreach (string keyword in keywords)
						{
							sb1.AppendFormat("{0}, ", keyword);
						}

						dblogcontext.addParameter("keywords", sb1.ToString());
						dberrorcontext.addParameter("keywords", sb1.ToString());
					}

					dblogcontext.addParameter("tileWidth", tileWidth);
					dberrorcontext.addParameter("tileWidth", tileWidth);

					dblogcontext.addParameter("tileHeight", tileHeight);
					dberrorcontext.addParameter("tileHeight", tileHeight);

					dblogcontext.addParameter("startDate", searchSettings.DateSettings.StartDate);
					dberrorcontext.addParameter("startDate", searchSettings.DateSettings.StartDate);

					dblogcontext.addParameter("endDate", searchSettings.DateSettings.EndDate);
					dberrorcontext.addParameter("endDate", searchSettings.DateSettings.EndDate);

					if (0 >= activeWebservices.Count)
					{
						dblogcontext.addParameter("activeWebServices", "All");
						dberrorcontext.addParameter("activeWebServices", "All");
					}
					else
					{
						StringBuilder sb1 = new StringBuilder();
						activeWebservices.ForEach(wsn => sb1.AppendFormat("{0},", wsn.Title));

						dblogcontext.addParameter("activeWebServices", sb1.ToString());
						dberrorcontext.addParameter("activeWebServices", sb1.ToString());
					}

					DateTime startDtUtc = DateTime.UtcNow;

					var series = dataWorker.getSeriesData(box, keywords.ToArray(), tileWidth, tileHeight,
																	 searchSettings.DateSettings.StartDate,
																	  searchSettings.DateSettings.EndDate,
																	  activeWebservices);
					DateTime endDtUtc = DateTime.UtcNow;

					//Clear returns
					dblogcontext.clearReturns();

					//Add returned series count...
					dblogcontext.addReturn("seriesCount", series.Count);

					//Create log entry...
					dblogcontext.createLogEntry(System.Web.HttpContext.Current, startDtUtc, endDtUtc, "updateMarkers(...)", "calls dataWorker.getSeriesData(...)", Level.Info);

					var list = new List<TimeSeriesViewModel>();

					if (!EnvironmentContext.LocalEnvironment())
					{
						//Non-local environment - do not attempt to create debug files...
						//Watch out for similar loop code in 'else' block...
						if (series.Count > 0)
					{
						for (int i = 0; i < series.Count; i++)
						{
							var tvm = new TimeSeriesViewModel();
							tvm = mapDataCartToTimeseries(series[i], i);
							list.Add(tvm);
						}
					}
					}
					else
					{
						//Local environment - create debug files, if indicated...
#if (DEBUG)
						//BCC - Test - write data cart and time series objects to files...
						using (System.IO.StreamWriter swSdc = System.IO.File.CreateText(@"C:\CUAHSI\SeriesDataCart.json"))
						{
							using (System.IO.StreamWriter swTsvm = System.IO.File.CreateText(@"C:\CUAHSI\TimeSeriesViewModel.json"))
							{
								JsonSerializer jsonser = new JsonSerializer();

								swSdc.Write('[');	//Write start of array...
								swTsvm.Write('[');
#endif
								//Watch out for similar loop code in 'if' block...
								if (series.Count > 0)
								{
									for (int i = 0; i < series.Count; i++)
									{
										var tvm = new TimeSeriesViewModel();
										tvm = mapDataCartToTimeseries(series[i], i);
										list.Add(tvm);
#if (DEBUG)
										jsonser.Serialize(swSdc, series[i]);
										jsonser.Serialize(swTsvm, tvm);

										if ((i + 1) < series.Count)
										{
											swSdc.Write(',');	//Separate array element...
											swTsvm.Write(',');
										}
#endif
									}
								}
#if (DEBUG)
								swSdc.Write(']');	//Write end of array...
								swTsvm.Write(']');
							}
						}
#endif
					}

					var markerClustererHelper = new MarkerClustererHelper();

					//save list for later
					Session["Series"] = list;

					//transform list int clusteredpins
					var pins = transformSeriesDataCartIntoClusteredPin(list, filterAndSearchCriteria);

					var clusteredPins = markerClustererHelper.clusterPins(pins, CLUSTERWIDTH, CLUSTERHEIGHT, CLUSTERINCREMENT, zoomLevel, MAXCLUSTERCOUNT, MINCLUSTERDISTANCE);
					Session["ClusteredPins"] = clusteredPins;

					var centerPoint = new LatLong(0, 0);
					markerjSON = markerClustererHelper.createMarkersGEOJSON(clusteredPins, zoomLevel, centerPoint, "");
				}
			   
				catch (Exception ex)
				{
					//NOTE: Override 'standard' IIS error handling since we are using 'standard' HTTP error codes - RequestEntityTooLarge and RequestTimeout...
					//Sources:	http://stackoverflow.com/questions/22071211/when-performing-post-via-ajax-bad-request-is-returned-instead-of-the-json-resul
					//			http://stackoverflow.com/questions/3993941/in-iis7-5-what-module-removes-the-body-of-a-400-bad-request/4029197#4029197
					//			http://weblog.west-wind.com/posts/2009/Apr/29/IIS-7-Error-Pages-taking-over-500-Errors

					//Find the 'inner-most' exception...
					while (null != ex.InnerException)
					{
						ex = ex.InnerException;
					}

					if ( typeof (WebException) == ex.GetType())
					{
						//Web exception - return the error message...
						WebException wex = (WebException) ex;

						Response.StatusCode = (int) wex.Status;
						Response.StatusDescription = wex.Message;
						Response.TrySkipIisCustomErrors = true;	//Tell IIS to use your error text not the 'standard' error text!!
						//ALSO clues jQuery to add the parsed responseJSON object to the jqXHR object!!
						dberrorcontext.createLogEntry(System.Web.HttpContext.Current, DateTime.UtcNow, "updateMarkers(...)", wex, "Web Exception: " + wex.Message);

						return Json(new { Message = wex.Message }, "application/json");

					}
					else if ( typeof (System.InvalidOperationException) == ex.GetType() )
					{
						//Recover the returned error message...
						Response.StatusCode = (int)HttpStatusCode.RequestEntityTooLarge;
						Response.StatusDescription = ex.Message;
						Response.TrySkipIisCustomErrors = true;	//Tell IIS to use your error text not the 'standard' error text!!
																//ALSO clues jQuery to add the parsed responseJSON object to the jqXHR object!!
						dberrorcontext.createLogEntry(System.Web.HttpContext.Current, DateTime.UtcNow, "updateMarkers(...)", ex, "NON-Web Exception" + ex.Message);

						return Json(new { Message = ex.Message }, "application/json");
					}
					else
					{
						//Assume a timeout has occurred...
						string message = "The execution of the search took too long. Please limit search area and/or Keywords.";
						Response.StatusCode = (int)HttpStatusCode.RequestTimeout;
						Response.StatusDescription = message;
						Response.TrySkipIisCustomErrors = true;	//Tell IIS to use your error text not the 'standard' error text!!
																//ALSO clues jQuery to add the parsed responseJSON object to the jqXHR object!!
						dberrorcontext.createLogEntry(System.Web.HttpContext.Current, DateTime.UtcNow, "updateMarkers(...)", ex, "Defaults to timeout exception: " + message);

						return Json(new { Message = message }, "application/json");
					}
				}

				//var session2 =(List<BusinessObjects.Models.SeriesDataCartModel.SeriesDataCart>) Session["Series"];
			}
			else
			{
             	//BCC - 19-Nov-2015 - GitHub Issues #67 - Application unresponsive after session timeout and zoom out...
				var retrievedSeries = (List<TimeSeriesViewModel>)Session["Series"];

				if (null != retrievedSeries)	//If a session timeout has occurred, the new session object will not contain the 'Series' element!!
				{
					var markerClustererHelper = new MarkerClustererHelper();
					//transform list int clusteredpins
					var pins = transformSeriesDataCartIntoClusteredPin(retrievedSeries, filterAndSearchCriteria);

					var clusteredPins = markerClustererHelper.clusterPins(pins, CLUSTERWIDTH, CLUSTERHEIGHT, CLUSTERINCREMENT, zoomLevel, MAXCLUSTERCOUNT, MINCLUSTERDISTANCE);
					Session["ClusteredPins"] = clusteredPins;

					var centerPoint = new LatLong(0, 0);
					markerjSON = markerClustererHelper.createMarkersGEOJSON(clusteredPins, zoomLevel, centerPoint, "");
				}
				else
				{
					//Likely session timeout - return a Request Timeout error (408)...
					string message = "User session has expired!!";

					Response.StatusCode = (int) HttpStatusCode.RequestTimeout;
					Response.StatusDescription = message;
					Response.TrySkipIisCustomErrors = true;	//Tell IIS to use your error text not the 'standard' error text!!

					return Json(new { Message = message }, "application/json");
				}

			}
			return Json(markerjSON);

		}
示例#12
0
 public Bounds()
 {
     //Set values to opposite to allow any new values to override
     NW = new LatLong(-90, 180);
     SE = new LatLong(90, -180);
 }
示例#13
0
 public Bounds(LatLong nW, LatLong sE)
 {
     NW = nW;
     SE = sE;
 }