📄 esri_maptip.js
字号:
/*
COPYRIGHT 1995-2005 ESRI
TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
Unpublished material - all rights reserved under the
Copyright Laws of the United States.
For additional information, contact:
Environmental Systems Research Institute, Inc.
Attn: Contracts Dept
380 New York Street
Redlands, California, USA 92373
email: contracts@esri.com
*/
function EsriMapTip(mapId) {
var lastClicked = null;
var mapTipFeatures = null;
var map = null;
var blankImage;
var invisible;
var mapTipElements = [];
var mapTipsVisibility =[];
var self = this;
var mapTipTimer = null;
var calloutNode = {};
var eventsEnabled = true;
var prevHighlight = true;
this.init = function(mapId) {
map = EsriControls.maps[mapId];
map.addUpdateListener("updateMapTips", this.updateMapTips);
mapTipFeatures = new Array();
map.callOut.onDismiss = function() {
if(calloutNode.feature) {
if(self.onFeatureBlur)
self.onFeatureBlur(calloutNode.feature);
unHighlightFeatures(calloutNode.feature);
clearTimeout(mapTipTimer);
calloutNode.sourceElement.onmouseover = handleFeatureMouseOver;
mapTipTimer = null;
}
map.callOut.hide();
}
blankImage = new Image();
blankImage.src = EsriControls.contextPath + "images/pixel.png";
blankImage.width = blankImage.height = 32;
invisible = {};
invisible.color = "red";
invisible.transparency = 0.0;
invisible.width = 10;
}
this.updateMapTips = function() {
if(!map.enableMapTips) return;
var g = map.graphics;
for(var i=0, il=mapTipElements.length; i<il; i++) g.remove(mapTipElements[i]);
mapTipElements = [];
var fId = map.formId;
var url = EsriUtils.getServerUrl(fId);
var params = "getMapTipInfo=getMapTipInfo&formId=" + fId + "&mapId=" + map.id + "&" + EsriUtils.buildRequestParams(fId);
EsriUtils.sendAjaxRequest(url, params, false, mapTipHandler);
}
this.setEventsEnabled = function(bool) {
eventsEnabled = bool;
}
this.isEventsEnabled = function() {
return eventsEnabled;
}
function handleFeatureClick(e) {
if(eventsEnabled===false) return;
EsriUtils.stopEvent(e);
var el = EsriUtils.getEventSource(e);
el.onmousemove = null;
if(mapTipFeatures[el.name].isCallout) {
if(!map.callOut.isVisible())
lastClicked = null;
if(lastClicked == el)
lastClicked = null;
else {
var offsets = getCalloutOffsets();
calloutNode.pt = EsriUtils.getXY(e).offset(offsets.top, offsets.left);
lastClicked = el;
}
map.callOut.expand();
calloutNode.sourceElement = el;
el.onmouseout = null;
el.onmouseover=null;
if(self.onFeatureBlur)
self.onFeatureBlur(calloutNode.feature);
}
}
function toLiteral(a) { var o = {}; for(var i = 0; i < a.length; i++){ o[a[i]]=''; } return o; }
function getElementIndex(id) {
for(var i=0,i1=mapTipElements.length;i<i1;i++)
if(mapTipElements[i].name==id) return i;
return -1;
}
function showMapTip(g,id) {
if(mapTipElements[getElementIndex(id)]){
for(var i=0,i1=mapTipElements.length;i<i1;i++)
if(mapTipElements[i].name==id) EsriUtils.showElement(mapTipElements[i]);
}
else {
var f=mapTipFeatures[id];
var farray = [];
farray.push(f);
if(f.type=="Polygon")
drawPolygons(g,farray);
else if(f.type=="Polyline")
drawPolylines(g,farray);
else if(f.type=="Point")
drawPoints(g,farray);
}
}
function hideMapTip(g,id) {
for(var i=0,i1=mapTipElements.length;i<i1;i++)
if(mapTipElements[i].name==id) EsriUtils.hideElement(mapTipElements[i]);
}
this.toggleFeaturesByLevel = function (ids,show,level) {
var oIds = toLiteral(ids);
var g = map.graphics;
var visObj;
if(show) {
if(level==2) { //child
visObj = mapTipsVisibility[ids];
visObj.lastLevel = level; //update
visObj.childChecked = show;
if(visObj.layerChecked !=false) {
visObj.visibility = show;
mapTipsVisibility[ids] = visObj;
showMapTip(g,ids);
}
mapTipsVisibility[ids] = visObj;
}
else { // layer||root
for(i = 0,i1=ids.length;i<i1;i++) {
visObj = mapTipsVisibility[ids[i]];
visObj.lastLevel = level;
if(level==0) visObj.rootChecked = show;
else
visObj.layerChecked = show;
if(visObj.childChecked!=false && visObj.layerChecked!=false && visObj.rootChecked!=false) {
visObj.visibility = show;
showMapTip(g,ids[i]);
mapTipsVisibility[ids] = visObj;
}
mapTipsVisibility[ids[i]]=visObj;
}
}
}//true
else {
if(level == 2) { //child
hideMapTip(g,ids);
if(mapTipsVisibility[ids]== undefined) visObj = {};
else visObj = mapTipsVisibility[ids];
visObj.lastLevel = level;//this will give the parent|child
visObj.childChecked = show;// this will give the visibility
visObj.visibility = show;
mapTipsVisibility[ids]=visObj;
}
else { // layer||root
for(i = 0,i1=ids.length;i<i1;i++) {
hideMapTip(g,ids[i]);
if(mapTipsVisibility[ids[i]]== undefined) visObj = {};
else visObj = mapTipsVisibility[ids[i]];
visObj.lastLevel = level;//this will give the parent|child
if(level==0) visObj.rootChecked = show;
else
visObj.layerChecked = show;
visObj.visibility = show;
mapTipsVisibility[ids[i]]=visObj;
}
}
}// false
}
this.highlightFeaturesById = function(id) {
if(mapTipsVisibility[id] && mapTipsVisibility[id].visibility === true)
if(mapTipFeatures[id]) highlightFeatures(mapTipFeatures[id]);
}
this.unHighlightFeaturesById = function(id) {
if(mapTipsVisibility[id] && mapTipsVisibility[id].visibility === true)
if(mapTipFeatures[id]) unHighlightFeatures(mapTipFeatures[id]);
}
this.toggleFeatures = function(ids, show) {
var oIds = toLiteral(ids);
var display = "none";
var g = map.graphics;
if(show) display = "block";
for(var i=0, il=mapTipElements.length; i<il; i++)
if(mapTipElements[i].name in oIds)
mapTipElements[i].style.display = display;
}
function highlightFeatures(feature) {
var g = map.graphics;
var gsymbol;
for(var i=0, il=mapTipElements.length; i<il; i++) {
if(feature.symbol) {
if(mapTipElements[i].name == feature.id) {
gsymbol = updateFeatureSymbol(mapTipElements[i],feature,true);
g.updateSymbol(mapTipElements[i], gsymbol);
}
}
}
}
function unHighlightFeatures(feature) {
var g = map.graphics;
var gsymbol;
for(var i=0, il=mapTipElements.length; i<il; i++) {
if(feature.symbol) {
if(mapTipElements[i].name == feature.id) {
gsymbol = updateFeatureSymbol(mapTipElements[i],feature,false);
g.updateSymbol(mapTipElements[i], gsymbol);
}
}
}
}
function updateFeatureSymbol(element,feature,isHighlight) {
var gsymbol = new EsriGraphicsSymbol();
if(isHighlight) {
gsymbol.fillColor=feature.symbol.highlightFillColor;
gsymbol.fillOpacity=feature.symbol.highlightFillOpacity;
gsymbol.lineWidth=feature.symbol.highlightLineWidth;
gsymbol.lineColor=feature.symbol.highlightLineColor;
gsymbol.lineOpacity=feature.symbol.highlightLineOpacity;
}
else {
gsymbol.fillColor=feature.symbol.fillColor;
gsymbol.fillOpacity=feature.symbol.fillOpacity;
gsymbol.lineWidth=feature.symbol.lineWidth;
gsymbol.lineColor=feature.symbol.lineColor;
gsymbol.lineOpacity=feature.symbol.lineOpacity;
}
if(feature.symbol.highlightMarker || feature.symbol.marker) {
if(prevHighlight != isHighlight)
updateMarkerOffsets(element,feature,gsymbol,isHighlight);
prevHighlight = isHighlight;
}
return gsymbol;
}
function updateMarkerOffsets(element,feature,gsymbol,isHighlight) {
var oldImg,img,oldOffsets,offsets;
oldImg = new Image();
img = new Image();
if(isHighlight) {
oldImg.src = feature.symbol.marker;
img.src = feature.symbol.highlightMarker;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -