How to add your knowledge

Embedding a Viewer in Your Own Page

    Table of contents
    No headers

    The simplest way to incorporate a Viewer into your own site is to create a frame set that contains a frame for your own page layout and a frame for the Viewer. The Developer’s Guide samples use this technique. The main page for the samples, main.php, creates a frame set where the top frame in the set contains a site-specific page header, and the bottom frame in the set contains the embedded Viewer. The following code contains the important parts of main.php.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" 
    "http://www.w3.org/TR/html4/frameset.dtd">
    <?php
    require_once('common/common.php');
     
    try
    {
      // Initialize the web extensions,
      MgInitializeWebTier ($webconfigFilePath);
     
      // Connect to the site server and create a session
      $userInfo = new MgUserInformation("Author", "author");
      $site = new MgSite();
      $site->Open($userInfo);
    }
    catch (MgException $e)
    {
      echo "Could not connect to the MapGuide site server.";
        die();
    }
     
    try
    {
      $sessionId = $site->CreateSession();
     
      // Define some constants
      $webLayout = "Library://Samples/Layouts/SamplesPHP.WebLayout";
      $title = "Samples";
    }
    catch (MgException $e)
    {
      echo "ERROR: " . $e->GetMessage("eng") . "\n";
      echo $e->GetStackTrace("eng") . "\n";
    }
    ?>
     
    <html>
      <head>
        <title><?= $title ?></title>
      </head>
     
      <frameset rows="110,*">
        <frame src="common/Title.php?TitleText=<?= $title ?>" 
          name="TitleFrame" scrolling="NO" noresize />
        <frame
        src="/mapserver2012/mapviewerajax/?
        SESSION=<?= $sessionId ?>&
        WEBLAYOUT=<?= $webLayout ?>" name="ViewerFrame" />
      </frameset>
    </html>