📄 esri_maptip.js
字号:
setEventHandlers(el, f);
mapTipsVisibility[f.id].visibility = true;
mapTipElements.push(el);
}
else {
mapTipsVisibility[f.id].visibility = false;
}
}
}
function getMarkerSize(img) {
var src = img.src;
var anchor;
var size = (src.substring(src.lastIndexOf("-")+1,src.indexOf(".png"))).split("x");
img.height = parseInt(size[0]);
img.width = parseInt(size[1]);
return img;
}
function getMarkerOffsets(img) {
var src = img.src;
var anchor;
var offsets = {top:img.height/2,left:img.width/2};
if(src.indexOf("-tl-") > -1) {
offsets.top = 0;
offsets.left = 0;
}
else if(src.indexOf("-tr-") > -1) {
offsets.top = img.height;
offsets.left = 0;
}
else if(src.indexOf("-bl-") > -1) {
offsets.top = 0;
offsets.left = img.width;
}
else if(src.indexOf("-br-") > -1) {
offsets.top = img.height;
offsets.left = img.width;
}
else if(src.indexOf("-b-") > -1) {
offsets.left = img.width;
}
else if(src.indexOf("-t-") > -1) {
offsets.left = 0;
}
else if(src.indexOf("-l-") > -1) {
offsets.top = 0;
}
else if(src.indexOf("-r-") > -1) {
offsets.top = img.height;
}
return offsets;
}
function drawPolylines(g, features) {
for (var i = 0; i < features.length; i++) {
var f = features[i];
var gsymbol = new EsriGraphicsSymbol();
if(f.symbol) {
gsymbol.lineColor = f.symbol.lineColor;
gsymbol.lineOpacity = f.symbol.lineOpacity;
gsymbol.lineWidth = f.symbol.lineWidth;
}
else {
gsymbol.lineColor = invisible.color;
gsymbol.lineOpacity = invisible.transparency;
gsymbol.lineWidth = invisible.width;
}
if(!mapTipsVisibility[f.id]) mapTipsVisibility[f.id]={visibility:true};
if(mapTipsVisibility[f.id].visibility) {
for (var j = 0; j < f.geometry.length; j++) {
var el = g.drawPolyline(f.geometry[j],gsymbol);
el.name = f.id;
setEventHandlers(el, f);
mapTipElements.push(el);
mapTipsVisibility[f.id].visibility = true;
}
}
else
mapTipsVisibility[f.id].visibility = false;
}
}
function drawPolygons(g, features) {
for (var i = 0; i < features.length; i++) {
var f = features[i];
var gsymbol = new EsriGraphicsSymbol();
if(f.symbol) {
gsymbol.lineColor = f.symbol.lineColor;
gsymbol.lineOpacity = f.symbol.lineOpacity
gsymbol.lineWidth = f.symbol.lineWidth
gsymbol.fillColor = f.symbol.fillColor;
gsymbol.fillOpacity = f.symbol.fillOpacity
}
else {
gsymbol.lineColor = g.fillColor = invisible.color;
gsymbol.lineOpacity = g.fillOpacity = invisible.transparency;
gsymbol.lineWidth = invisible.width;
}
if(!mapTipsVisibility[f.id]) mapTipsVisibility[f.id]={visibility:true};
if(mapTipsVisibility[f.id].visibility) {
for (var j = 0; j < f.geometry.length; j++) {
var el = g.drawPolygon(f.geometry[j],gsymbol);
el.name = f.id;
setEventHandlers(el, f);
mapTipElements.push(el);
}
mapTipsVisibility[f.id].visibility = true;
}
else
mapTipsVisibility[f.id].visibility = false;
}
}
function getColorString(c) {
if(c && c.length > 0 && c != "")
return c.indexOf(",") > -1 ? "rgb(" + c + ")" : c;
return null;
}
function setEventHandlers(el, feature) {
el.onmouseover = handleFeatureMouseOver;
if(feature.content) {
el.onclick = handleFeatureClick;
}
}
function getPointFromXml(node) {
var pointEl = node.getElementsByTagName("point").item(0);
return new EsriPoint(parseInt(pointEl.getAttribute("x")) + map.viewBounds.left, parseInt(pointEl.getAttribute("y")) + map.viewBounds.top);
}
function getPolylinePointsFromXml(node) {
var paths = new Array();
var pathsEl = node.getElementsByTagName("path");
var ol = map.viewBounds.left;
var ot = map.viewBounds.top;
var path, pointELs, pointEL;
for(var i = 0; i < pathsEl.length; i++) {
pointEls = pathsEl[i].getElementsByTagName("point");
path = new Array(pointEls.length);
for(var j = 0; j < pointEls.length; j++) {
pointEl = pointEls[j];
path[j] = new EsriPoint(parseInt(pointEl.getAttribute("x")) + ol, parseInt(pointEl.getAttribute("y")) + ot);
}
paths[i] = path;
}
return paths;
}
function getPolygonPointsFromXml(node) {
var rings = new Array();
var ringsEl = node.getElementsByTagName("ring");
var ol = map.viewBounds.left;
var ot = map.viewBounds.top;
var pointEl;
for(var p = 0; p < ringsEl.length; p++) {
var pointEls = ringsEl[p].getElementsByTagName("point");
var ring = new Array(pointEls.length);
for(var q = 0; q < pointEls.length; q++) {
pointEl = pointEls[q];
ring[q] = new EsriPoint(parseFloat(pointEl.getAttribute("x")) + ol, parseFloat(pointEl.getAttribute("y")) + ot);
}
rings.push(ring);
}
return rings;
}
function getAttributesAsArray(el) { //pass <attributes><attribute/></attributes>
var attributes = new Array();
if(el) {
var attributeEls = el.getElementsByTagName("attribute");
if(attributeEls.length > 0) {
for(var i = 0; i < attributeEls.length; i++) {
var attributeEl = attributeEls.item(i);
attributes[attributeEl.getAttribute("name")] = attributeEl.getAttribute("value");
}
}
}
return attributes;
}
//transform(attributeList,"default"|{templateString,[startToken][endToken]})
this.transform = function(attributeList,template) {
var calloutContent = {header:"",content:"",footer:""};
if(template.templateString == undefined)
calloutContent = defaultTransform(attributeList);
else {
var text = "<?xml version='1.0' encoding='UTF-8'?>" + "<root>" + template.templateString + "</root>";
var xml = EsriUtils.stringToXml(text);
if(template.startToken == undefined) template.startToken = "\\${";
if(template.endToken == undefined) template.endToken = "}";
if(xml.getElementsByTagName("header").length > 0) {
template.templateString=text.substring(text.indexOf("<header>"),text.indexOf("</header>") + "</header>".length);
calloutContent.header = customTransform(attributeList,template);
}
if(xml.getElementsByTagName("body").length > 0) {
template.templateString=text.substring(text.indexOf("<body>"),text.indexOf("</body>") + "</body>".length);
calloutContent.content = customTransform(attributeList,template);
}
if(xml.getElementsByTagName("footer").length > 0) {
template.templateString=text.substring(text.indexOf("<footer>"),text.indexOf("</footer>") + "</footer>".length);
calloutContent.footer = customTransform(attributeList,template);
}
}
return calloutContent;
}
function defaultTransform(attributeList) {
var attribute, name, value, regex;
var isFirstField = true;
var fbody = [];
var ffooter = "";
var calloutContent = {header:"",content:"",footer:""};
var table = document.createElement("table");
table.className = "default-template";
var tbody = document.createElement("tbody");
for(var key in attributeList) {
if(key == "inheritsFrom" || key =="indexOf") continue;
name = key;
value = attributeList[key];
if(isFirstField) {
calloutContent.header = value;
isFirstField = false;
}
var tdKey = document.createElement("td");
var tdValue = document.createElement("td");
var tr = document.createElement("tr");
tdKey.className = "key-cell";
tdValue.className = "value-cell";
tdKey.appendChild(document.createTextNode(name));
tdValue.appendChild(document.createTextNode(value));
tr.appendChild(tdKey);
tr.appendChild(tdValue);
tbody.appendChild(tr);
}
table.appendChild(tbody);
var contentDiv = document.createElement("div");
contentDiv.appendChild(table);
calloutContent.content = contentDiv.innerHTML;
calloutContent.footer = ffooter;
return calloutContent;
}
function customTransform(attributeList,template) {
var attribute, name, value, regex;
var text = template.templateString;
for(var key in attributeList) {
if(key == "inheritsFrom" || key =="indexOf") continue;
name = key;
value = attributeList[key];
regex = new RegExp(template.startToken + name + template.endToken, "g");
if(text!=null)
text = text.replace(regex, value);
}
return text;
}
// callback functions
this.onFeatureFocus = null; //function(feature) { }
this.onFeatureBlur = null; //function(feature) { }
if(mapId)
this.init(mapId);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -