function show(category) {
for (var a=0; a<gpolylines.length; a++) {
if (gpolylines[a].mycategory == category) {
gpolylines[a].show();
}
}
for (var i=0; i<pts.length; i++) {
if (pts[i].mycategory == category) {
pts[i].show();
}
}
}
function hide(category) {
for (var a=0; a<gpolylines.length; a++) {
if (gpolylines[a].mycategory == category) {
gpolylines[a].hide();
}
}
for (var i=0; i<pts.length; i++) {
if (pts[i].mycategory == category) {
pts[i].hide();
}
}
}
// this variable will collect the html which will eventually be placed in the sidebar
function togglePoly(category) {
if (document.getElementById(category)) {
if (document.getElementById(category).checked) {
show(category);
} else {
hide(category);
}
}
}
function createClickablePolyline(poly, html, name,category) {
gpolys.push(poly);
var poly_num = gpolys.length - 1;
var category = lines[a].getAttribute("category");
midLineArrows(pts, category);
GEvent.addListener(poly,'click', function(point) {
if (!point) point = poly.getVertex(Math.floor(poly.getVertexCount()/2));
map.openInfoWindowHtml(point,html);
});
// add a line to the sidebar html
label = "<a href='javascript:GEvent.trigger(gpolys["+poly_num+"],\"click\");'>"+label+"</a>";
sidebar_html += '<input type="checkbox" id="'+category+'" checked="checked" onclick="togglePoly('+category+');">' + label + '<br />';
}
document.getElementById("sidebar").innerHTML = sidebar_html;
ah. I wasn't sure how much code to post within the actual post, but I can see how the context is confusing. That's the bit where the arrows are assigned the same category as the lines, so that when you show a line you show its arrows, too. Here's that bit in context:
Code:
var lines = xmlDoc.documentElement.getElementsByTagName("line");
var pts = [];
for (var i=0; i< pts.length-1; i++) {
var category = lines[a].getAttribute("category");
}
// read each line
for (var a = 0; a < lines.length; a++) {
// get any line attributes
var geodesic = lines[a].getAttribute("geodesic");
var name = lines[a].getAttribute("name");
var label = lines[a].getAttribute("name");
var category = lines[a].getAttribute("category");
var opacity = lines[a].getAttribute("opacity");
var colour = lines[a].getAttribute("colour");
var width = parseFloat(lines[a].getAttribute("width"));
var html = GXml.value(lines[a].getElementsByTagName("infowindow")[0]);
function createClickablePolyline(poly, html, name,category) {
gpolys.push(poly);
var poly_num = gpolys.length - 1;
midLineArrows(pts, category);
GEvent.addListener(poly,'click', function(point) {
if (!point) point = poly.getVertex(Math.floor(poly.getVertexCount()/2));
map.openInfoWindowHtml(point,html);
});
// add a line to the sidebar html
label = "<a href='javascript:GEvent.trigger(gpolys["+poly_num+"],\"click\");'>"+label+"</a>";
sidebar_html += '<input type="checkbox" id="'+category+'" checked="checked" onclick="togglePoly('+category+');">' + label + '<br />';
}
// read each point on that line
var points = lines[a].getElementsByTagName("point");
var pts = [];
for (var i = 0; i < points.length; i++) {
pts[i] = new GLatLng(parseFloat(points[i].getAttribute("lat")),
parseFloat(points[i].getAttribute("lng")));
}
var poly = new GPolyline(pts,colour,width,opacity,[category]);
createClickablePolyline(poly, html, name,category);
poly.mycategory = category;
map.addOverlay(poly);
}
document.getElementById("sidebar").innerHTML = sidebar_html;
});
}
and here you can see it working, in a slightly different way
Bookmarks