📄 page.js
字号:
var map = null;
var panAction = null;
var zoomInAction = null;
var zoomOutAction = null;
var pointQueryAction = null;
var former_index = 0;
var max_btn_number = 33;
function OnPageLoad() {
var params = new Object();
params.mapHandler = "http://localhost/mapHandler/";
//changchun
params.mapName = "changchun";
params.mapScales = [1/50000, 1/20000, 1/8000, 1/5000, 1/2000, 1/800, 1/200];
params.imageFormat = "gif";
params.x = 4860.567;
params.y = -4860.567;
//
// //chinaH,China_SIT
// params.mapName="china@china.sit";
// params.mapScales=[1/20000000, 1/8000000, 1/2000000, 1/800000, 1/200000, 1/100000, 1/50000];
// params.imageFormat="jpg";
// params.x = 683929;
// params.y = 2635385;
//
// //sjs
// with(params){
// mapName="SJS";
// mapScales=[1/100000, 1/50000, 1/20000, 1/10000, 1/5000, 1/2000, 1/1000];
// x=485500;
// y=307200;
// }
params.zoomLevel = 3;
params.fixedView = false;
params.buffer = 256; // 预先进行下载的视图范围。
map = new SuperMap.IS.MapControl($("myMap"), params);
map.AttachEvent("onerror", UpdateInfo);
map.Init();
map.AttachEvent("onenddynamicpan", UpdateInfo);
map.AttachEvent("onendzoom", UpdateInfo);
}
// Unload 的时候一定要调用这个方法,否则就会导致IE内存泄漏。
function OnPageUnload() {
map.Destroy();
map = null;
}
function UpdateInfo(eventArg)
{
var info = $("info");
if (!info) { return false; }
if(eventArg.param == null){
info.innerHTML = '<font color="red">error: ' + eventArg.error + '</font>';
return false;
}
info.innerHTML = 'mapName = ' + eventArg.param.mapName
+ ', zoomLevel=' + eventArg.param.zoomLevel
+ ', mapCenter = ' + eventArg.param.mapCenter.ToString()
+ ', pixelCenter = ' + eventArg.param.pixelCenter.ToString();
}
function DoPanUp() { map.DynamicPan(0, -10, 20); }
function DoPanDown() { map.DynamicPan(0, 10, 20); }
function DoPanLeft(str) { map.DynamicPan(-10, 0, 20); }
function DoPanRight() { map.DynamicPan(10, 0, 20); }
function DoZoomIn() { map.ZoomIn(); }
function DoZoomOut() { map.ZoomOut(); }
function ViewEntire() {
var mb = map.GetMapBounds();
map.ViewByBounds(mb.leftBottom.x, mb.leftBottom.y, mb.rightTop.x, mb.rightTop.y);
}
function SetZoomInAction() {
if (!zoomInAction){
zoomInAction = new SuperMap.IS.ZoomInAction();
}
map.SetAction(zoomInAction);
}
function SetZoomOutAction() {
if (!zoomOutAction) {
zoomOutAction = new SuperMap.IS.ZoomOutAction();
}
map.SetAction(zoomOutAction);
}
function SetPanAction() {
if (!panAction) {
panAction = new SuperMap.IS.PanAction();
}
map.SetAction(panAction);
}
function SetDrawLineAction() {
var drawLineAction = new SuperMap.IS.DrawLineAction();
map.SetAction(drawLineAction);
}
function SetPointQueryAction() {
var queryManager = map.GetQueryManager();
queryManager.RegisterHandler(onQueryComplete, onQueryError);
if(!pointQueryAction){
pointQueryAction = new SuperMap.IS.PointQueryAction(["School@changchun"], ["smid", "name"], 200);
}
map.SetAction(pointQueryAction);
}
function onQueryComplete(resultSet)
{
$("querypoint").innerHTML = "";
if (!resultSet || resultSet.totalCount < 1) {
onQueryError("查询结果为空。");
return false;
}
for (var i = 0; i < resultSet.recordsets.length; i++) {
for (var j = 0; j < resultSet.recordsets[i].records.length; j++) {
var record = resultSet.recordsets[i].records[j];
$("querypoint").innerHTML
+= '<div class="query" onclick="'
+ 'if(window.curMapControl.GetZoomLevel()<5){'
+ 'window.curMapControl.SetCenterAndZoom('
+ record.center.x + ',' + record.center.y + ',5);'
+ '}else{'
+ 'window.curMapControl.ViewByPoint('
+ record.center.x + ',' + record.center.y + ');'
+ '}'
+ 'window.curMapControl.CustomLayer.InsertMark(\'marker\','
+ record.center.x + ',' + record.center.y + ',10,10,'
+ '\'<img src=\\\'images/marker.gif\\\' alt=\\\'' + record.fieldValues[1] + '\\\' style=\\\'cursor:hand\\\' /> \');'
+ '">'
+ record.fieldValues[0] + ' '
+ record.fieldValues[1] + '</div>';
}
}
}
function onQueryError(responseText) {
$("querypoint").innerHTML = '提示:' + responseText;
}
// 切换按钮。 Switch button//
function SwitchBtn(index, action)
{
// when argument index is ignored
/*
if(typeof(index) == "undefined" || typeof(index) == "string") {
action = index;
index = Eve(event).id.replace("img0","").replace("img","");
}
*/
var prefix = "btn";
var current = "";
var rest = "";
if (index == -1) { //reset all buttons to off status
for (var i = 1; i < 10; i++) {
if (i != index && getImg("img0" + i)) {
getImg("img0" + i).src
= "images/" + prefix + "_0" + i + "_off.gif";
}
}
for (var i = 10; i <= max_btn_number; i++) {
if (i != index && getImg("img" + i)) {
getImg("img" + i).src
= "images/" + prefix + "_" + i + "_off.gif";
}
}
former_index = 0;
}
switch (action) {
case "Over":
current = "on";
rest = "off";
SwitchBtn_ChangeImg(current, rest, prefix, index, former_index);
break;
case "Out":
current = "off";
rest = "off";
SwitchBtn_ChangeImg(current, rest, prefix, index, former_index);
break;
case "Down":
current = "down";
rest = "off";
// 判断鼠标操作类型。 Judge the type of the mouse operating
if (index == 4 || index == 5 || index == 6 || index == 10
|| (index >= 13 && index <= 17)
|| index == 22 || index == 26 || (index >= 28 && index <= 32)) {
for (var i = 1; i < 10; i++) {
if (i != index && getImg("img0" + i)) {
getImg("img0" + i).src
= "images/" + prefix + "_0" + i + "_off.gif";
}
}
for (var i = 10; i <= max_btn_number; i++) {
if (i != index && getImg("img" + i)) {
getImg("img" + i).src
= "images/" + prefix + "_" + i + "_off.gif";
}
}
SwitchBtn_ChangeImg(current, rest, prefix, index, former_index);
former_index = index;
}
else {
SwitchBtn_ChangeImg(current, rest, prefix, index, former_index);
//former_index = index;
}
break;
}
}
function SwitchBtn_ChangeImg(current, rest, prefix, index, former_index)
{
if (former_index != index) {
if (getImg("img" + index)) {
getImg("img" + index).src = "images/" + prefix + "_" + index + "_" + current + ".gif";
}
if (getImg("img0" + index)) {
getImg("img0" + index).src = "images/" + prefix + "_0" + index + "_" + current + ".gif";
}
}
else {
if (current != "off") {
if (getImg("img" + index)) {
getImg("img" + index).src = "images/" + prefix + "_" + index + "_" + current + ".gif";
}
if (getImg("img0" + index)) {
getImg("img0" + index).src = "images/" + prefix + "_0" + index + "_" + current + ".gif";
}
}
else {
if (getImg("img" + index)) {
getImg("img" + index).src = "images/" + prefix + "_" + index + "_" + "down" + ".gif";
}
if (getImg("img0" + index)) {
getImg("img0" + index).src = "images/" + prefix + "_0" + index + "_" + "down" + ".gif";
}
}
}
}
function getImg(img)
{
if (document.all) {
return document.all(img);
} else if (document.getElementById) {
return document.getElementById(img);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -