Generate HTML in a loop and bind the event with Parameters

Source: Internet
Author: User

To be resolved.

Resolved.

CodeAs follows:

/* Query attributes */
VaR searchresultcontent = "";
VaR position = 0;
Function attquery (field, value, index, symbol, level, isclear, islocate, iscatagory ){

If (isclear = true) {
map. graphics. clear ();
}< br>
If (iscatagory = false);
{< br> searchresultcontent = ""
position = 0;
}

VaR url = "http: // Meng/ArcGIS/rest/services/statisticdata/mapserver/" + index;
VaR querytask = new ESRI. Tasks. querytask (URL );
VaR query = new ESRI. Tasks. Query ();
Query. returngeometry = true;
Query. outfields = ["zonename", "type"];
Query. Where = field + "like '%" + value + "% '";

Dojo. Connect (querytask, "oncomplete", function (featureset ){

VaR showxbextent;
Searchresultcontent = searchresultcontent + "

For (VAR I = 0, IL = featureset. features. length; I <il; I ++ ){
VaR graphic = featureset. features [I];
Graphic. setsymbol (Symbol );

Graphic. setinfotemplate (statinfotemplate );

map. graphics. add (graphic);
if (I = 0) {
showxbextent = graphic. geometry. getextent ();
}< br> else {
showxbextent = showxbextent. union (graphic. geometry. getextent ();
}

Searchresultcontent = searchresultcontent + "<a" +
"Onclick = lightengraphic (" + index + "," + Position + ");" +
"Onmouseout = unlightengraphic ();" +
"Href = \" javascript: void (0) \ ";>" + graphic. attributes ["zonename"] + "</a>" + ""; // Generate HTML elements cyclically and bind the event processing method added by zhangjun
Position = Position + 1;
}
Get_imagestatistics_infos (searchresultcontent );
If (islocate = true ){
If (showxbextent! = NULL ){
Map. setextent (showxbextent. Expand (1.5 ));
}
}
Else {
Fullextent ();
}
});


Dojo. Connect (querytask, "onerror", function (ERR ){
Alert (ERR. Name + ":" + err. Message );
});
Querytask.exe cute (query );
}

/* Add image statistics */
Function get_imagestatistics_infos (response ){
$ ('Statistics _ result'). style. Display = "Block ";
$ ('Statistics _ result'). innerhtml = response;
}

/* Highlight graphic */
Function lightengraphic (index, position ){

VaR A, value = "";
A = Document. getelementbyid ("statistics_result"). getelementsbytagname ("");
Value = A [position]. innerhtml;

VaR symbol;
Switch (INDEX ){
Case 0:
Symbol = new ESRI. symbol. simplefillsymbol (ESRI. symbol. simplefillsymbol. style_solid,
New ESRI. symbol. simplelinesymbol (ESRI. symbol. simplelinesymbol. style_solid,
New dojo. color ([0, 0, 0, 1]), 0.5), new dojo. color ([0,255,255, 1]);
Break;
Case 1:
Symbol = new ESRI. symbol. simplefillsymbol (ESRI. symbol. simplefillsymbol. style_solid,
New ESRI. symbol. simplelinesymbol (ESRI. symbol. simplelinesymbol. style_solid,
New dojo. color ([0, 0, 0, 1]), 0.5), new dojo. color ([255, 0, 0, 1]);
Break;

}

VaR lightsymbol = new ESRI. symbol. simplefillsymbol (ESRI. symbol. simplefillsymbol. style_solid,
New ESRI. symbol. simplelinesymbol (ESRI. symbol. simplelinesymbol. style_solid,
New dojo. color ([0, 0, 0, 1]), 0.5), new dojo. color ([255,255, 0, 1]);

For (var k = 0; k <map. Graphics. Graphics. length; k ++ ){
If (Map. Graphics. graphics [K]. attributes ["zonename"] = value ){
Map. Graphics. graphics [K]. setsymbol (lightsymbol );
Graphiclocation = K;
Map. setextent (Map. Graphics. graphics [K]. Geometry. getextent (). Expand (4 ));
SetTimeout ("recoversymbol (" + index + ")", 800); // 0.8 seconds
}
}

}

VaR graphiclocation;

/* Restore symbol */

Function recoversymbol (INDEX ){
VaR symbol;
Switch (INDEX ){
Case 0:
Symbol = new ESRI. symbol. simplefillsymbol (ESRI. symbol. simplefillsymbol. style_solid,
New ESRI. symbol. simplelinesymbol (ESRI. symbol. simplelinesymbol. style_solid,
New dojo. color ([0, 0, 0, 1]), 0.5), new dojo. color ([0,255,255, 1]);
Break;
Case 1:
Symbol = new ESRI. symbol. simplefillsymbol (ESRI. symbol. simplefillsymbol. style_solid,
New ESRI. symbol. simplelinesymbol (ESRI. symbol. simplelinesymbol. style_solid,
New dojo. color ([0, 0, 0, 1]), 0.5), new dojo. color ([255, 0, 0, 1]);
Break;

}
Map. Graphics. graphics [graphiclocation]. setsymbol (Symbol );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.