📄 legendcontrol.js
字号:
///////////////////////////////////////////////////////////////////////////////
//
// (c) Pitney Bowes MapInfo Corporation, 2008. All rights reserved.
//
// The source code below is provided as sample code only. The end user of the
// Licensed Product that contains this code may use the code below for
// development purposes. This software is provided by Pitney Bowes MapInfo
// "as is" and any express or implied warranties, including, but not limited
// to, the implied warranties of merchantability and fitness for a particular
// purpose are disclaimed. In no event shall Pitney Bowes MapInfo be liable
// for any direct, indirect, incidental, special, exemplary, or consequential
// damages (including, but not limited to, procurement of substitute goods or
// services; loss of use, data or profits; or business interruption) however
// caused and whether in contract, strict liability, or tort (including
// negligence) arising in any way out of the use of this software, even if
// advised of the possibility of such damage.
//
///////////////////////////////////////////////////////////////////////////////
/*
LegendControl.js
This file contains methods which manage a web page legend control.
The legend is merely an <IMG> bitmap generated by the server in response
to requests from this "class". The image is not interactive.
There is a ShowLegend() method which will make the legend visible.
There is a HideLegend() method which will make the legend hidden.
Both of these methods will check to see if the parent HTML element
is a <DIV>, if so, the <DIV> will also be made visible or hidden.
This is because the legend control is often placed in a <DIV> tag
with style="overflow: auto" set so that it will automatically scroll
if the bitmap is larger than the size of the <DIV> tag. In this way,
the ShowLegend() and HideLegend() methods will also hide or show the
<DIV> and its scroll bars.
There is also an UpdateLegend() method which can be used to get a
fresh bitmap from the server. This should be called whenever the
page is used to update the map and its themes in such a way that the
legend might change.
*/
//server-side command name
DISPLAY_LEGEND_SRVCMD = "GetLegend";
/*
LegendClient()
This creates a LegendClient object. It's uniqueID will usually be
something like "LegendControl2LegendClient" where the "2" will be
one or more digits. There will usually be a global var with this
name. It can be used to call methods such as ShowLegend(), HideLegend(),
or UpdateLegend().
*/
function LegendClient(uniqueID, mapControlID, legendAlias, legendExportFormat, alt)
{
this.uniqueID = uniqueID;
this.legendImageID = uniqueID + "_Image";
this.mapControlID = mapControlID;
this.legendAlias = legendAlias;
this.legendExportFormat = legendExportFormat;
this.alt = alt;
this.srvCommandName = DISPLAY_LEGEND_SRVCMD;
this.mapImageID = this.mapControlID + "_Image";
this.mapImage = FindElement(this.mapImageID);
this.mapControl = FindElement(this.mapControlID);
this.mapAlias = this.mapImage["mapAlias"].value; // works for Firefox
if ( ! this.mapAlias)
{
this.mapAlias = this.mapImage.attributes["mapAlias"]; //works for IE
}
var legendControl = document.getElementById(this.uniqueID);
window.onload = this.LegendEventHandler("UpdateLegend", window.onload);
}
/*
These methods support creating the URL that is used to get the <IMG> bitmap
from the server.
*/
LegendClient.prototype.CreateUrl = function()
{
this.url = "MapController.ashx?Ran=" + Math.random();
this.AddParamToUrl("MapAlias", this.mapAlias);
}
LegendClient.prototype.AddParamToUrl = function(param, value)
{
this.url += "&" + param + "=" + value;
}
LegendClient.prototype.AddMapExportFormatToUrl = function(format)
{
this.url += "&ExportFormat=" + format;
}
LegendClient.prototype.AddSrvCommandNameToUrl = function(cmdName)
{
this.url += "&Command=" + cmdName;
}
/*
legendEventHandler()
This method is used to create a legend event handler function.
It should be passed the contents of the event to be set so that it
can arrange for the function currently in the event to be called
as well as the new function whose name is passed in as the first
parameter (this is typically the "UpdateLegend" method).
This method is typically used as follows:
window.onload = this.legendEventHandler("UpdateLegend", window.onload);
so it can be used to safely set any event with a LegendClient method.
*/
LegendClient.prototype.LegendEventHandler = function(newEventHandler, oldEventHandler)
{
var closure = this;
closure = closure;
return function()
{
if (oldEventHandler != null)
if (newEventHandler != null) { oldEventHandler();
return closure[newEventHandler](); }
else
return oldEventHandler();
else
if (newEventHandler != null) return closure[newEventHandler]();
}
}
/*
UpdateLegend()
This method gets the bitmap of the legend associated with this legend control,
places it into an <IMG> tag, and adds it to the web page where the browser
will display it.
*/
LegendClient.prototype.UpdateLegend = function()
{
this.CreateUrl();
this.AddSrvCommandNameToUrl(DISPLAY_LEGEND_SRVCMD);
this.AddParamToUrl("LegendAlias", this.legendAlias);
this.AddParamToUrl("LegendExportFormat", this.legendExportFormat);
var legendControl = document.getElementById(this.uniqueID);
var legendImage = document.getElementById(this.legendImageID);
legendControl.innerText = "";
//if there is already a legend image drawn, remove it.
if(legendImage != null)
legendControl.innerHTML = null;
// The last parameter, GALLERYIMG="no" is to suppress the image toolbar popped up by
// IE 6 when the cursor is over the legend image (if the image is large enough).
legendControl.innerHTML = "<img id='" + this.legendImageID + "' src='" + this.url + "' alt='" + this.alt + "' GALLERYIMG=\"no\"'/>";
}
/*
ShowLegend()
This method ensures that the legend image is visible.
If it is enclosed in a <DIV> tag, it will also ensure that the
<DIV> element is visible.
*/
LegendClient.prototype.ShowLegend = function()
{
var legendControl = document.getElementById(this.uniqueID);
legendControl.style.visibility = "visible";
if (legendControl.parentNode.tagName == "DIV")
{
legendControl.parentNode.style.visibility = "visible";
}
}
/*
HideLegend()
This method ensures that the legend image is hidden.
If it is enclosed in a <DIV> tag, it will also ensure that the
<DIV> element is hidden.
*/
LegendClient.prototype.HideLegend = function()
{
var legendControl = document.getElementById(this.uniqueID);
legendControl.style.visibility = "hidden";
if (legendControl.parentNode.tagName == "DIV")
{
legendControl.parentNode.style.visibility = "hidden";
}
}
/*
AppendLegendScriptToForm()
This method is inserted onto the web page by the LegendControl designer
so that it will be called when the page has been loaded.
*/
function AppendLegendScriptToForm(script)
{
var scr = document.createElement('script');
scr.type = 'text/javascript';
scr.text = script;
document.forms[0].appendChild(scr);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -