| MGViewChangingObserver.onViewChanging |
|
public abstract void onViewChanging(MGMap map)
The changing view observer method. This event is fired just before the map is refreshed.
This topic describes this event for Plug-In and Java Edition only. For ActiveX Control, see onViewChanging.
There are many useful actions you can execute with onViewChanging, for instance, customizing layer settings such as visibility, the SQL Where clause, or the data file to which a layer refers. If you just want to initialize layer settings the first time that Autodesk MapGuide Viewer displays a map, as opposed to every time that the map is refreshed, use the onMapLoaded event instead.
Note that Autodesk MapGuide disables the autoRefresh flag, set by setAutoRefresh, when it executes the onViewChanging event. Therefore, calling zoomGotoDlg, zoomGotoLocation, setUrl, or refresh in onViewChanging has no effect. Additionally, setAutoRefresh has no effect when called from within onViewChanging.
Plug-In and Java Edition only
map - The map object for which the event occurred.
none
To handle this event, a Java object that implements the MGViewChangingObserver interface must be established with a call to the setViewChangingObserver method. The observer Java object should include the following:
<class_definition> implements MGViewChangingObserver
{
// ...
public void onViewChanging(MGMap map)
{
// event handling code here, for example:
var lat = map.getLat();
var lon = map.getLon();
var point = map.lonlatToMcs(lon, lat);
var sdf = "urban.sdf";
if (point.getX() > 1000) sdf = "rural.sdf";
if (point.getX() < -1000) sdf = "rural.sdf";
if (point.getY() > 1000) sdf = "rural.sdf";
if (point.getY() < -1000) sdf = "rural.sdf";
var mapLayer = map.getMapLayer("streets");
mapLayer.getlayerSetup().setDataFile(sdf);
}
// ...
}
The simplest way to include the observer object in a Web page is to implement it as an applet. See Advanced Examples for a fully functional observer object that supports all of the observer interfaces by forwarding the events back to JavaScript functions that have identical semantics to the ActiveX Control event handlers.
getViewChangingObserver, setViewChangingObserver