Amplification of GIS Secondary Development

Source: Internet
Author: User

I just started to study the secondary development of GIS. I recorded several translation methods in the previous article. Today I will look at the functional code of map enlargement.

We also look at several different methods when implementing amplification (triggered in the event of the button, and compiled as DLL by using COM technology and registered to the machine ).

The first method is compiled into DLL registration.

Code

Public mapzoomin ()
{
String [] res = GetType (). Assembly. getmanifestresourcenames ();

Base. m_bitmap = new system. Drawing. Bitmap (GetType (). Assembly. getmanifestresourcestream ("commands.zoomin.bmp "));
Base. m_caption = "zoom in map ";
Base. m_category = "toolbar ";
Base. m_message = "zoom in map ";
Base. m_name = "toolbar_mappan ";
Base. m_tooltip = "zoom in ";
M_zoominstrart = true;
M_feedback = NULL;
Try
{
Base. m_cursor = new system. Windows. Forms. cursor (GetType (). Assembly. getmanifestresourcestream ("commands. zoomin. cur "));
}
Catch (exception ex)
{

}
}

Public override void oncreate (Object hook)
{
M_hookhelper.hook = hook;
Try
{
M_pactiveview = m_hookhelper.activeview as iactiveview;
}
Catch {}
}

Public override void onmousedown (INT button, int shift, int X, int y)
{
If (null = m_pactiveview) return;
M_ppoint = m_pactiveview.screendisplay.displaytransformation.tomappoint (x, y );
M_zoominstrart = true;
}

Public override void onmousemove (INT button, int shift, int X, int y)
{
If (null = m_pactiveview) return;
If (! M_zoominstrart) return;
If (Button = 1) // drag
{
If (null = m_feedback)
{
M_feedback = new newenvelopefeedbackclass ();
M_feedback.display = m_pactiveview.screendisplay;
M_feedback.start (m_ppoint );
}
}
M_feedback.moveto (m_pactiveview.screendisplay.displaytransformation.tomappoint (x, y ));
}

Public override void onmouseup (INT button, int shift, int X, int y)
{
If (null = m_pactiveview) return;
If (! M_zoominstrart) return;
Ienvelope m_penvelope = new envelopeclass ();
If (null = m_feedback) // point Scaling
{
M_penvelope = m_pactiveview.extent;
M_penvelope.expand (0.5, 0.5, true );
M_pactiveview.extent.centerat (m_ppoint );
}
Else // rectangular Scaling
{
Try
{
M_penvelope = m_feedback.stop ();
If (m_penvelope.height = 0 | m_penvelope.width = 0)
{
M_feedback = NULL;
M_zoominstrart = false;
}
}
Catch
{
M_penvelope = m_pactiveview.extent;
M_penvelope.expand (0.5, 0.5, true );
M_pactiveview.extent.centerat (m_ppoint );
}
}
M_pactiveview.extent = m_penvelope;

M_pactiveview.partialrefresh (esriviewdrawphase. esriviewgeography, null, null );

M_feedback = NULL;
Marshal. releasecomobject (m_feedback );
M_zoominstrart = false;
}

Public override void onkeydown (INT keycode, int shift)
{
If (keycode = 27)
{
M_zoominstrart = false;
Base. m_cursor = system. Windows. Forms. cursors. default;
}
}

 

The main code is in the up, down, and move events of the mouse. When the pull box is enlarged, the inewenvelopefeedback interface is used to inherit from idisplayfeedback. You can refer to the examples in this document.

The advantage of the above method is that it can integrate the controlsmapzoomintool and controlsmapzoominfixedcommand functions. First, we know that controlsmapzoomintool is used to enlarge the pull box, while controlsmapzoominfixedcommand is used to enlarge the click. The second method below is to describe their implementation code.

Method 2: directly trigger the button event (add a button on the main interface, such as button, register its event, and write the following code in the event)

①: Zoom In the pull box

Code

/// <Summary>
/// Zoom in
/// </Summary>
Private void btnzoomin_click (Object sender, eventargs E)
{
Controlsmapzoomintool mapzoomin = new controlsmapzoomintool ();
Mapzoomin. oncreate (axmapmain. Object );
Axmapmain. currenttool = mapzoomin as itool;
}

 

②: Click to zoom in

Code

/// <Summary>
/// Zoom in
/// </Summary>
Private void btnzoomin_click (Object sender, eventargs E)
{
Controlsmapzoominfixedcommand mapzoomin = new controlsmapzoominfixedcommand ();
Mapzoomin. oncreate (axmapmain. Object );
Mapzoomin. onclick ();
}

 

Remember to read this sentence in the ESRI Forum: "the corresponding command function can be written directly in the button event, the functions of the tool can be written by using the mousemove, mousedown, and mouseup events. "(this means that the original post cannot be found ), the controlsmappantool can be used in the previous article "the translation of GIS secondary development" to complete the translation with the help of the mouse event. (The amplification here can be achieved without the help of the mouse event ). It can serve as a guide for future study.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.