Follow by Email

How to save current map window image in your had drive

In this tutorial i will show you that how can we save  the current map window image to your hard drive.

private void button1_Click (object sender, EventArgs e)
{
MapInfo.Mapping.MapExport exportObject = new MapInfo.Mapping.MapExport (this.mapControl1.Map.Clone () as MapInfo.Mapping.Map);
exportObject.ExportSize = new MapInfo.Mapping.ExportSize (this.mapControl1.Map.Size.Width, this.mapControl1.Map.Size.Height);
exportObject.Format = MapInfo.Mapping.ExportFormat.Bmp;  / / Save to the clipboard
System.Windows.Forms.Clipboard.SetDataObject (exportObject.Export ()); / / Save to your hard drive
exportObject.Export (@ "D: \ Image.bmp");
MessageBox.Show ("Save successful!");
}

How to decide visibility of the layers using check boxes

In this small tutorial i will show you that how can we decide visibility of the layers depending on check boxes in MapInfo

  
code is very simple as shown bellow.

   private void checkBox1_CheckedChanged (object sender, EventArgs e)
         {
             this.mapControl1.Map.Layers [checkBox1.Text.ToString ()]. ​​Enabled = checkBox1.Checked;
         }

How to make a layer selectable or not selectable in MapInfo MapXtreme

In this tutorial i will show you that how can we make a layer selectable  or not selectable

/ / All the layers are not optional
                 MapInfo.Mapping.LayerHelper.SetSelectable (item, false);
   / / A layer is not optional
             foreach (MapInfo.Mapping.IMapLayer layer in mapControl1.Map.Layers)
             {
                 if (object.ReferenceEquals (layer, mapControl1.Map.Layers ["GZ_River_LL"]))
                 {
                     MapInfo.Mapping.LayerHelper.SetSelectable (layer, false);
                 }
         }

How to obtain current mouse co ordinates in MapInfo MapXtreme

Here i will show you that how can we get the current mouse co ordinates in the MapInfo MapXtreme

private void mapControl1_MouseMove (object sender, MouseEventArgs e)
         {
             System.Drawing.PointF DisplayPoint = new PointF (eX, eY); / / create two-dimensional midpoint of x and y coordinates of the ordered pair
             MapInfo.Geometry.DPoint MapPoint = new MapInfo.Geometry.DPoint (); // create a point layer
             MapInfo.Geometry.DisplayTransform converter =
              this.mapControl1.Map.DisplayTransform; converter.FromDisplay (DisplayPoint, out MapPoint); / / display coordinates of a point into the map coordinates of the point or layer
             this.statusBar1.Text = "Cursor Location:" + MapPoint.x.ToString () + "," + MapPoint.y.ToString ();
         }

 
Explanation:

DisplayTransform.FromDisplay method (Rectangle, DRect)
Will display the coordinates of the rectangle into a map or a layer of rectangular coordinates.
public void FromDisplay (
Rectangle srcRect,out DRect destRect)
Rectangle srcRect :  display coordinates of the rectangle.
out DRect destRect : map or a layer of rectangular coordinates.



DisplayTransform.ToDisplay method (DPoint, Point) Point of the map or layer into a display point.
public void ToDisplay (
DPoint pntSrc,out Point pntDest )
DPoint pntSrc : maps or layers points out Point pntDest  : display points.

Solving Unable to update the EntitySet 'TestInstanceName' because it has a DefiningQuery and no element exists in the element to support the current operation. Problem


Hello,

If you get this error while working with entity framework ...

"Unable to update the EntitySet 'TestInstanceName' because it has a DefiningQuery and no <DeleteFunction> element exists in the <ModificationFunctionMapping> element to support the current operation."

then there is only one thing that you are missing is "Primary Key" in database table  or you are not passing primary key value while updating your data.

how to bind the dropdown list with Webgrid in ASP.NET MVC3, Razor

In this tutorial i will show you that how can we create the dynamic webgrid on dropdown selected index change in MVC & razor using JSON ....



What we will do is that on dropdown change event we will call the jquery which will take the value of the selected item of dropdown list & will pass it to Action....


DropDown list is ...

@Html.DropDownListFor
(model => @Model.ListId, new SelectList(Model.Lists, "ListId""Name"), "--Select a list--")



also we have to one empty Div like this...
<div id="grid">   </div>

Jquery is ....

    <script type="text/javascript">
        $(function() {
            $('#ListId').change(function() {
                var customDataListId = $("#ListId").val();
     $.getJSON('@Url.Action("Data")', { id: ListId}, function (result) {
                    var customDataList = $('#grid');
                    customDataList.empty();
                    customDataList.append(result.Data);
                });
            });
        });
    </script>
 
Where....  "#ListId" is Name property of the Dropdown list...
     ......    "Data" is action name 
     .....    "result" is result returned from the action .....  see bellow for action method
      .......   "#grid" is id of the empty grid

Now We will write ActionMethod....
 
[AcceptVerbs(HttpVerbs.Get)] 
        public JsonResult CustomData(int id)
        {
            // here I get the data from the database in result
            var result = _customDataListRepository.GetCustomDataWithId(id).ToList(); 
 
//now I create the new webgrid ,also i will pass result as it parameter
            var grid = new WebGrid(result);
 
//now i create the columns of the grid ....
var htmlString = grid.GetHtml
(tableStyle: "paramTable", htmlAttributes: new {id = "grid"},
                                          columns: grid.Columns(
                                              grid.Column("Name""MyName"),
                                              grid.Column("CustomValue""MyCustomValue")
                                              ));
// while returning i am passing this grid as htmlstring...
            return Json(new
                            {
                                Data = htmlString.ToHtmlString()
                            }
                , JsonRequestBehavior.AllowGet);
        } 

By doing this .... every time new grid will be created & old grid will be deleted .....
 
Also if you want to show whole table which u get from the database  then....
[AcceptVerbs(HttpVerbs.Get)] 
        public JsonResult CustomData(int id)
        {
            // here I get the data from the database in result
            var result = _customDataListRepository.GetCustomDataWithId(id).ToList();   
//now I create the new webgrid ,also i will pass result as it parameter
            var grid = new WebGrid(result); //now i create the columns of the grid ....
var htmlString = grid.GetHtml();// while returning i am passing this grid as htmlstring...
            return Json(new
                            {
                                Data = htmlString.ToHtmlString()
                            }
                , JsonRequestBehavior.AllowGet);
        }
 
 
Like this we can create dynamic webgrid using JSON with dropdown list 

How to change color or background of the menu tab of current page using css & jquery

Hello,
In this tutorial i will show you that how can we change the color or background of the menu tab when we are on that page.
<div class="menu">
            <ul>
                <li><a href="/Home">Home</a></li>
                <li><a href="/About Me">Forms</a></li>
                <li><a href="/Contact Me">Look &amp; Feel</a></li>
                <li><a href="/Blog">Security</a></li>
            </ul>
        </div>
 
 The css is somthing like this....
 
.menu ul{
    width100%;
    height21px;
    list-stylenone;
    margin0px;
    padding0px 0px 0px 3px;
}
  .menu ul li {
    displayblock;
    floatleft;
    text-aligncenter;
    margin-left3px;
    margin-right3px;
    border-radius5px 5px 0px 0px;
    -moz-border-radius5px 5px 0px 0px;
    -webkit-border-radius5px 5px 0px 0px;
    border-left1px solid black;
    border-right1px solid black;
    border-top : 1px solid black;
    background-color#ececec;
}  
 
 
 .menu ul li a{
    text-decorationnone;
    width90%;
    colorblack;
    padding-left29px;
    padding-right29px;
    
 } 
 
  .menu ul li a:hover{
     colorblue;
     text-decorationunderline;
 } 
 
 .menu ul li.active a{
    border-bottom2px solid white;
    background-colorwhite;
}
 
 
and a samll jquery which does all magic is ...
<script>
        $(".menu ul li").removeClass("active");
        $(function () {
            var url = window.location.pathname;  
            var activePage = url.substring(url.lastIndexOf('/') + 1);
            $('.menu ul li a').each(function () {
       var currentPage = this.href.substring(this.href.lastIndexOf('/') + 1);
             if (activePage == currentPage) {
               $(this).parent().addClass('active');
                }
            });
        });
</script>