﻿
//function to display the results on the map

function displaySearchPins(pins, rankedresult, name, desc) {
    if (pins != null && pins != undefined) {
        searchContentPins = "<tr><td style=\"width: 22px;\"><img src=\"back6.jpg\" style=\"cursor: pointer; width: 16px; height: 16px;\" onclick=\"SearchBackClick();\"/></td>" +
                            "<td ><p class=\"Panel\" onmouseover=\"onMouseOver(this);\" onclick=\"searchClearClick();\" onmouseout=\"onMouseOut(this);\">Clear</p></td></tr>";
    }
    Gmap.DeleteAllPushpins();
    // insetMap.DeleteAllPushpins();
    pushpinOnMap = false;
    Gmap.DeleteAllPolylines();
    polyOnMap = false;
    Gmap.DeleteAllPolygons();
    polygonOnMap = false;
    centerPoint = findCenter(rankedresult); //Find the center of the locality

    //+ Miyuru : Added the following code to make a pushpin on the map -->
    var pin = new VEPushpin('search', new VELatLong(centerPoint[1], centerPoint[0]), 'images/sites/searchpin.gif', name,
					"<div class=\"PushpinTop\">" + desc +
					"</div><br>" +
					"<div class=\"Pushpin\">" +
					"<table width=100% cellpadding=\"0px\" cellspacing= \"0px\" >" +
					"<tr align=left><td>" +
					"<a style=\"color:#1E90FF\" href= 'javascript:ZoomStreetLevel(\"" + centerPoint[1] + "\", \"" + centerPoint[0] + "\");'>Zoom to street level</a>" +
					"</td></tr>" +
					"<tr align=left><td>" +
					"<a style=\"color:#1E90FF\" href='javascript:ZoomCityLevel(\"" + centerPoint[1] + "\", \"" + centerPoint[0] + "\");'>Zoom to city level</a>" +
					"</td></tr>" +
					"</table>" +
					"</div>"
					);
    Gmap.AddPushpin(pin);
    //<--

    var isPointOnly = true; //False if result contains even one polyline or polygon
    var allpoints = new Array();

    for (i in rankedresult.Shapes) {
        var pts = new Array();
        for (j in rankedresult.Shapes[i].Points) {
            pts[j] = new VELatLong(rankedresult.Shapes[i].Points[j].Y, rankedresult.Shapes[i].Points[j].X);
        }


        allpoints = allpoints.concat(pts);


        if (rankedresult.Shapes[i].ShapeType == 0) {
           
            //document.getElementById("errorPanel").innerHTML = "The result is a point."
            showError("The result is a point.");
            Gmap.SetZoomLevel(14);
            Gmap.PanToLatLong(new VELatLong(rankedresult.Shapes[i].Points[0].Y, rankedresult.Shapes[i].Points[0].X));
        }
        else {
            isPointOnly = false;
            Gmap.PanToLatLong(new VELatLong(rankedresult.Shapes[i].Points[0].Y, rankedresult.Shapes[i].Points[0].X));
            if (rankedresult.Shapes[i].ShapeType == 1) {
               
             
                showError("The result is a point.");
                width = 10;
                var id = i;
                var color = new VEColor(0, 153, 153, 0.4);
                var polyline = new VEPolyline(id, pts, color, width);
                Gmap.AddPolyline(polyline);


                polyOnMap = true;
            }
            if (rankedresult.Shapes[i].ShapeType == 2) {
               
                var width = 4;
                var id = i;
                var outlineColor = new VEColor(153, 0, 102, .6);
                var fillColor = new VEColor(153, 0, 102, .1);

                if (pts[0] != pts[pts.length - 1])  //FOR REDMOND DATA (add start-point as last-point)
                {
                    pts[pts.length] = pts[0];
                }

                var polygon = new VEPolygon(id, pts, fillColor, outlineColor, width);
                Gmap.AddPolygon(polygon);


                polygonOnMap = true;
            }
        }


        Gmap.SetMapView(allpoints);
     
    }



}

//function to display results on the searchpanel

function displaySearchPanel(Content, Pin) {
    document.getElementById("searchPanel").innerHTML = "<table>" + Content + "</table><table>" + Pin + "</table>";
}
