Developer Reference ENC Features At Point

Because ENC charts can contain a great amount of detail and not all of it is included in the chart display you may want to allow your customers to pick a feature on your chart display and find out more.

ENCX can provide your application with HTML that can be displayed in a browser control. The information about the chart features for a particular position is navigated like a mini-website.

EncFeaturesAtPoint sample. The chart information is on the right hand side of this sample application.

The sample app is built around the FeaturesAtPoint class - it connects the HTML generation that ENCX does to a browser control (grab it and reuse it in your own application).

An instance of FeaturesAtPoint is initialized in form1.cs of the sample. Some default HTML, to be displayed before it is associated with a position on the chart, is given to this object . The object is given a reference to the WinForms browser control on the form.

When the user clicks on the chart surface:

private void OnControlMouseClick(object sender, MouseEventArgs e)
{
    _featuresAtPoint.SetPosition(m_draw, e.X, e.Y);
}

When the SetPosition method is called the FeaturesAtPoint object uses the ENCX.HTMLGenerator.S57PropertiesAtPoint method to build a properties at point website for that position on the display. It then works with the browser control to display that information. It has to handle Navigating events from the browser control and maintain browsing history (so that one can go forward or back).

The sample adds a context menu for the browser containing Home, Back and Forward menu items. The HTML also features Home and Back links so a context menu is not an essential feature of any implementation.

How it works

The HTMLGenerator class only has three methods but the interaction is quite complex. This is wrapped by the FeaturesAtPoint class and I would urge you to reuse that class if you can.

  • S57PropertiesAtPoint initializes the object to a particular S57Draw object and pixel position.
  • HTML returns the HTML for a given "URL" (e.g. "home" is the starting page).
  • ProcessEvent takes the URL that a browser control is seeking to navigate, generates HTML as appropriate and returns an enumerant.
  • FeaturesAtPoint.Navigating takes account of this enumerant and takes appropriate action.
ENCX.HTMLAction action = _htmlGenerator.ProcessEvent(s);
switch (action)
{
    case ENCX.HTMLAction.SHA_DoNothing:
    case ENCX.HTMLAction.SHA_UpdatePages:
        break;
    case ENCX.HTMLAction.SHA_MightBeUrl:
        GoToUrl(s);
        break;
    case ENCX.HTMLAction.SHA_GoHome:
    case ENCX.HTMLAction.SHA_UpdatePagesAndGoHome:
        GoHome();
        break;
    case ENCX.HTMLAction.SHA_GoBack:
        GoBack();
        break;
    case ENCX.HTMLAction.SHA_GoForward:
        GoForward();
        break;
    case ENCX.HTMLAction.SHA_UpdatePagesAndReloadCurrentPage:
        if (_browserHistoryCurrent >= 0 && _browserHistoryCurrent < _browserHistory.Count)
        {
            _browser.DocumentText = _htmlGenerator.HTML(_browserHistory[_browserHistoryCurrent]);
        }
        break;
}