This is documentation of an archived release.
For documentation on the current version, please check Knowledge Base.

Examples

This page contains example code of how you can use FlashMap's public interface.

Loading the interface object

This is the most basic example. It just shows how to load the public interface, when embedding OFM using the ActionScript 2 MovieClipLoader class.

var ofmInterface:I_PublicInterface;
var mclListener:Object = new Object();
var mcl = new MovieClipLoader();
 
/* Called when OFM component is initialized */
mclListener.onLoadInit = function(target_mc:MovieClip) {
  target_mc.notifyOnPublicInterfaceSetup(interfaceLoaded);
};
 
/* Called when OFM public interface is setup and ready to use. */
function interfaceLoaded() {
  /* We store a reference */
  ofmInterface = ofm.getPublicInterface();
 
  /* ... startUsingPublicInterface(); */
}
 
mcl.addListener(mclListener);
mcl.loadClip("OrbitFlashMap_modern.swf", _root.ofm);

Loading a custom first view

The SKIP_FIRST_VIEW flashvar prevents OFM from loading its initial view automatically. If you do this, you must load a view yourself, using the zoomTo… methods after the client first enters “started” mode.

Start off by telling OFM to not load its first view by setting the following variable before loading the component :

  _root.SKIP_FIRST_VIEW = true;  

Then attach a clientState listener and handle it in the following fashion :

var firstViewLoaded:Boolean = false;
 
/** Called when FlashMap's status changes. */
function clientStateChanged() {
 
  /* Load initial view. */
  if (ofmInterface.getClientState() == "started" && _root.SKIP_FIRST_VIEW && firstViewLoaded == false) 
  {
    trace("DBG: Zooming to extent..");
    ofmInterface.zoomToExtent();
    firstViewLoaded = true;
  }
}

Set a Session Parameter

How to set a session parameter from flash? The important thing here is to wait until OFM enters the started client state.

This examples demonstrates setting the HighlightSelection parameter to false.

Assumptions :

  • OFM component available (OrbitFlashMap_modern.swf from project root)
  • _root.ofm clip contains placeholder for OFM component.
import com.orbitgis.ofm.I_PublicInterface;
 
var ofmInterface:I_PublicInterface;
 
var mcl = new MovieClipLoader();
var mclListener:Object = new Object();
 
mclListener.onLoadInit = function(target_mc:MovieClip) {
  _root.ofm.notifyOnPublicInterfaceSetup(interfaceLoaded);
};
 
mcl.addListener(mclListener);
mcl.loadClip("OrbitFlashMap_modern.swf", _root.ofm);
 
/**
 * Called when public interface loaded.
 */
function interfaceLoaded() {
  /* Get interface */
  ofmInterface = ofm.getPublicInterface();
  /* Add client state listener */
  ofmInterface.addClientStateChangedListener(clientStateChanged);
  /* In case client already started. */
  clientStateChanged();
}
 
/**
 * Called on client state changes.
 */
function clientStateChanged() {
  /* Only do something when client becomes started. */
  if (ofmInterface.getClientState() != "started") return;
  /* Set session parameter. */
  ofmInterface.setSessionParameter("HighlightSelection", "false");
  ofmInterface.removeClientStateChangedListener(clientStateChanged);
}

How to open a hyperlink when it gets clicked?

Assumptions :

  • OFM component available (OrbitFlashMap_modern.swf from project root)
  • _root.ofm clip contains placeholder for OFM component.
import com.orbitgis.ofm.I_PublicInterface;
 
var ofmInterface:I_PublicInterface;
 
var mcl = new MovieClipLoader();
var mclListener:Object = new Object();
 
mclListener.onLoadInit = function(target_mc:MovieClip) {
  _root.ofm.notifyOnPublicInterfaceSetup(interfaceLoaded);
};
 
mcl.addListener(mclListener);
mcl.loadClip("OrbitFlashMap_modern.swf", _root.ofm);
 
/**
 * Called when public interface loaded.
 */
function interfaceLoaded() {
  /* Get interface */
  ofmInterface = ofm.getPublicInterface();
  /* Add client state listener */
  ofmInterface.addNewHyperlinkListener(newHyperlink);
}
 
/**
 * Called when hyperlink changes.
 */
function newHyperlink() {
  /* Open hyperlink */
  getURL(ofmInterface.getHyperlink(), "_blank");
}

Copy view to clipboard

The following piece of HTML demonstrates how an image can be copied to the clipboard for IE. This operation is completely invisible to the user. All you need to do is call the copy(urlToCopy) function. The public interface's getViewURL() (more info) function can be used to get the appropriate URL.

Firefox allows access to the clipboard, but only for signed scripts running from the local chrome. Files can't be placed there without intensive user interaction (installing an extension). When you try to create the clipboard service object, you get a permission denied exception (more here). So firefox support seems impossible for now.

FIXME Missing piece : How to call a javascript function from flash? (ExternalInterface stuff)

<html>
<head>
<script>
 
  function copyToClipboard(urlToCopy) {
    var agent = navigator.userAgent.toLowerCase(); 
    if (agent.indexOf("msie") != -1) {
      var img = document.getElementById('divId');
      img.src = urlToCopy;
    } else {
      alert("Copy to clipboard is currently only supported on Internet Explorer.");
    }
  }
 
  function copy() {
    var img = document.getElementById('divId');
    img.contentEditable = 'true';
    var controlRange;
    if (document.body.createControlRange) {
     controlRange = document.body.createControlRange();
     controlRange.addElement(img);
     controlRange.execCommand('Copy');
    }
    img.contentEditable = 'false';
  }
 
</script>
</head>
<body>
 
  <img id="divId" onLoad="javascript:copy();" style="display:none;"/>
 
  <a href="javascript:copyToClipboard('one_word.jpg');">copy</a>
 
</body>
</html>
 
Last modified:: 2019/03/25 11:36