disp_region=true;basic_map_colored=true;width = 1000,height = 500;if(widthmax_scale)cur_scale=max_scale;if(cur_scale40)cur_tilt=40;projection.rotate([r, cur_tilt]);sky.rotate([r, cur_tilt]);cur_angle=r;}function refresh() { svg.selectAll(".point").attr("d", path); svg.selectAll("#sphere").attr("d", path); svg.selectAll(".arc").attr("d", path) .attr("opacity", function(d) { return fade_at_edge(d) })}basic_map_colored=false;edit_fill_opacity=0.6;country_init_color="#dddddd";drawEditWorld();function drawEditWorld(){svg.selectAll(".edit_world_path").remove();svg.selectAll(".edit_country_path").remove();d3.json("../basic/json.php?json=0&id0=other", function(error, root) {if (error) return console.error(error);console.log(root.features);svg.append("g").selectAll(".edit_world_path").data( root.features ).enter().append("path").attr("class","edit_world_path").style("fill",country_init_color).style("opacity", edit_fill_opacity).attr("d", path ).on("mouseover",function(d,i){d3.event.stopPropagation();rotate=1;d3.select(this).style("fill", function(dd,j){return color(i);});p=d3.mouse(this);if(cur_scale>=(province_scale/2))drawEditCountry(d.properties.ID0);else{d3.selectAll(".edit_country_path").remove();disp_region_name(p,d.properties.name);}}).on("mouseout",function(d,i){if(d.properties.ID0!=49)d3.select(this).style("fill", country_init_color);}).call(zoom).on("mousedown.zoom",null);;});}drawEditChina();function drawEditChina(){d3.json("../basic/json.php?json=1&id0=49", function(error, root) {if (error) return console.error(error);console.log(root.features);china = svg.append("g");provinces = china.selectAll(".edit_china_path").data( root.features ).enter().append("path").attr("class","edit_china_path").style("fill", "#ffeeee").style("opacity", edit_fill_opacity).attr("d", path ).on("mouseover",function(d,i){d3.event.stopPropagation();p=d3.mouse(this);if( cur_scale>=province_scale){drawEditChinaProvince(d.properties.ID0,d.properties.ID1,d.properties.name);}else{disp_region_name(p,d.properties.name);}}).on("click",function(d,i){d3.event.stopPropagation();rotate=1;}).call(zoom).on("mousedown.zoom",null);});}function drawEditChinaProvince(id0,id1,proname){d3.selectAll(".province_path").remove();d3.json("../basic/json.php?json=2&id0="+id0+"&id1="+id1, function(error, root) {if (error) return console.error(error);console.log(root.features);province = svg.append("g");details = province.selectAll(".province_path").data( root.features ).enter().append("path").attr("class","province_path").style("opacity", edit_fill_opacity).style("fill","#bbbbbb").attr("d", path ).call(zoom).on("mousedown.zoom",null).on("mouseover",function(d,i){d3.event.stopPropagation();if( d.properties.N==1 && cur_scale>=county_scale){drawEditChinaCity(d.properties.ID0,d.properties.ID1,d.properties.ID2,proname,d.properties.name);}else{p=d3.mouse(this);disp_region_name(p,proname+d.properties.name);} });})}function drawEditChinaCity(id0,id1,id2,proname,cityname){d3.selectAll(".county_path").remove();d3.json("../basic/json.php?json=3&id0="+id0+"&id1="+id1+"&id2="+id2, function(error, root) {if (error) return console.error(error);console.log(root.features);province = svg.append("g");details = province.selectAll(".county_path").data( root.features ).enter().append("path").attr("class","county_path").style("opacity", edit_fill_opacity).attr("d", path ).call(zoom).on("mousedown.zoom",null).on("mouseover",function(d,i){d3.event.stopPropagation();d3.select(this).attr("fill", function(dd,j){return color(i);});p=d3.mouse(this);disp_region_name(p,proname+cityname+d.properties.name); });})}function drawEditCountry(id0){d3.selectAll(".edit_country_path").remove();d3.json("../basic/json.php?json=1&id0="+id0, function(error, root) {if (error) return console.error(error);console.log(root.features);country = svg.append("g");states = country.selectAll(".edit_country_path").data( root.features ).enter().append("path").attr("class","edit_country_path").style("fill","#888888").style("opacity", edit_fill_opacity).attr("d", path ).call(zoom).on("mousedown.zoom",null).on("mouseover",function(d,i){d3.event.stopPropagation();d3.select(this).style("fill", function(dd,j){return color(i);});if(d.properties.N==1 && cur_scale>=county_scale || (cur_scale>(province_scale*0.9) && id0==244)){drawEditCounty(d.properties.ID0,d.properties.ID1);}else{p=d3.mouse(this);disp_region_name(p,d.properties.name+"("+d.properties.ename+")");} });})}function drawEditCounty(id0,id1){d3.selectAll(".county_path").remove();d3.json("../basic/json.php?json=2&id0="+id0+"&id1="+id1, function(error, root) {if (error) return console.error(error);console.log(root.features);county = svg.append("g");details = county.selectAll(".county_path").data( root.features ).enter().append("path").attr("class","county_path").style("opacity", edit_fill_opacity).attr("d", path ).call(zoom).on("mousedown.zoom",null).on("mouseover",function(d,i){d3.event.stopPropagation();d3.select(this).attr("fill", function(dd,j){return color(i);});p=d3.mouse(this);disp_region_name(p,d.properties.name+"("+d.properties.ename+")"); });})}d3.timer(function() {edit_refresh();});function edit_refresh(){if(svg.selectAll(".world_path")!=null)svg.selectAll(".world_path").remove();if(svg.selectAll(".china_path")!=null)svg.selectAll(".china_path").remove();svg.selectAll(".edit_china_path").style("fill",edit_fill_opacity).attr("d",path);svg.selectAll(".edit_world_path").style("fill",edit_fill_opacity).attr("d",path);svg.selectAll(".edit_country_path").style("fill",edit_fill_opacity).attr("d",path);}function disp_region_name(p,name){if(disp_region){tooltip = d3.select("#tooltip").style("left", (p[0]+50) + "px").style("top", p[1] + "px");tooltip.select("#status").text(name);d3.select("#tooltip").classed("hidden", false);}}function drawCities(){d3.json("../city/cityjson.php?p=1000000", function(error, cities) {if (error) return console.error(error);console.log(cities.features);locations = svg.selectAll(".location").data(cities.features).enter().append("g").attr("class","location").attr("transform",function(d){coor = projection([d.geometry.coordinates[0], d.geometry.coordinates[1]]);return "translate("+ coor[0] + "," + coor[1] +")";});locations.append("circle").attr("class","city_circle").style("opacity", 0);locations.append("text").attr("class","city_title").style("opacity", 0.3).style("font-size", "0.5em").text("");});}function disp_city_name(p,name){if(disp_city){tooltip = d3.select("#tooltip").style("left", p[0] + "px").style("top", p[1] + "px");tooltip.select("#status").text(name);d3.select("#tooltip").classed("hidden", false);}}drawCities();d3.timer(function() {svg.selectAll(".location").attr("transform",function(d){coor = projection([d.geometry.coordinates[0], d.geometry.coordinates[1]]);return "translate("+ coor[0] + "," + coor[1] +")";});svg.selectAll(".city_circle").attr("r",function(d){r=0;if(cur_scale>province_scale){if(d.properties.POP>10000000)r=12;else if(d.properties.POP>5000000)r=8;else if(d.properties.POP>1000000)r=4;}else{if(d.properties.POP>10000000)r=4;}return r;}).style("opacity",function(d){offset=Math.round(cur_angle+180)+360;if(offset>0)offset=offset % 360;else{offset=0-((0-offset) % 360);}jingdu=Math.round(d.geometry.coordinates[0])+180;angle= (jingdu + offset);angle=angle % 360;if( (angle>270 || angle<90) )return 0.1;else{return 0;}});titles=svg.selectAll(".city_title").style("font-size", function(d){if(cur_scale>county_scale)return "1.5em";else if(cur_scale>province_scale)return "1em";else{return "0.5em";}}).text(function(d){offset=Math.round(cur_angle+180)+360;if(offset>0)offset=offset % 360;else{offset=0-((0-offset) % 360);}jingdu=Math.round(d.geometry.coordinates[0])+180;angle= (jingdu + offset);angle=angle % 360;if( (angle>270 || angle<90)){if(cur_scale>county_scale ){return d.properties.NAME;}else if( d.properties.POP>1000000 && cur_scale>province_scale){return d.properties.NAME;}else if( d.properties.POP>3000000 && cur_scale>(province_scale/2)){return d.properties.NAME;}else if(d.properties.POP>10000000){return d.properties.NAME;}}return "";});});disp_river=true;function drawRivers(){d3.json("../river/riverjson.php?f=china", function(error, rivers) {if (error) return console.error(error);console.log(rivers.features);svg.append("g").attr("class","rivers").selectAll("path").data(rivers.features).enter().append("path").attr("class", "river").attr("d", path);});}function disp_river_name(p,name){if(disp_river){tooltip = d3.select("#tooltip").style("left", p[0] + "px").style("top", p[1] + "px");tooltip.select("#status").text(name);d3.select("#tooltip").classed("hidden", false);}}drawRivers();d3.timer(function() { svg.selectAll(".river").attr("d", path).attr("stroke-width", function(d){ if(cur_scale>county_scale) return 6; else if(cur_scale>province_scale) return 2; return 1;}).style("opacity",function(d){if(cur_scale0)offset=offset % 360;else{offset=0-((0-offset) % 360);}c=path.centroid(d);c=projection.invert(c);if(c==null)return 0;jingdu=Math.round(c[0]+180);angle= (jingdu + offset);angle=angle % 360;if( (angle>270 || angle<90) )return 0.1;else{return 0.0;}}) ;});function drawLakes(){d3.json("../river/lakejson.php?f=china", function(error, lakes) {if (error) return console.error(error);console.log(lakes.features);svg.append("g").attr("class","lakes").selectAll("path").data(lakes.features).enter().append("path").attr("class", "lake").attr("d", path)});}drawLakes();d3.timer(function() { svg.selectAll(".lake").attr("d", path).style("opacity",function(d){offset=Math.round(cur_angle+180)+360;if(offset>0)offset=offset % 360;else{offset=0-((0-offset) % 360);}c=path.centroid(d);c=projection.invert(c);if(c==null)return 0;jingdu=Math.round(c[0]+180);angle= (jingdu + offset);angle=angle % 360;if( (angle>270 || angle<90) )return 0.1;else{return 0.0;}}) ;});_INIT_YEAR=0;_his_year= _INIT_YEAR;his_fill_opacity=0.8;d3.json("get_year.php", function(error, root) {if (error) return console.error(error);console.log(root.cur_year);_his_year=root.cur_year;div = document.getElementById("pop_info");if(div==null || div=="" ){}else{div.value=""+_his_year;}});caps=[];drawAllHisKingdoms();function drawAllHisKingdoms(){svg.append("g").selectAll(".edit_kingdom_path").remove();svg.append("g").selectAll(".edit_cap_path").remove();caps=[];d3.json("hisalljson.php?json=all", function(error, kingdoms) {if (error) return console.error(error);console.log(kingdoms.features);k=1;kingdoms.features.forEach(function(a){if(a.properties.code==a.properties.ccode)drawOneHisKingdom(-1,a.properties.code);else{drawOneHisKingdom(k,a.properties.code);}k++;});svg.append("g").selectAll(".edit_cap_path").data(kingdoms.features ).enter().append("path").attr("class","edit_cap_path").style("fill","#ff0000").style("opacity", 1).attr("d", path ).on("mouseover",function(d,i){d3.event.stopPropagation();d3.select(this).style("fill", function(dd,j){return color(k);});p=d3.mouse(this);disp_region_name(p,"都城:"+d.properties.cap);}).on("mouseout",function(d,i){d3.select(this).style("fill", function(dd,j){return "#ff0000";})}).call(zoom).on("mousedown.zoom",null);kingdoms.features.forEach(function(d){caps.push(d);});});}function drawCaps(){svg.selectAll(".cap_title").remove();svg.selectAll(".cap_title").data(caps).enter().append("text").attr('font-family', 'FontAwesome').attr("class","cap_title").style("opacity", 0.5).style("font-size", "1em").text(function(d){if(cur_scale>province_scale)return '\uf024'+d.properties.cap+'\uf132'+d.properties.dy;else{return '\uf024'+d.properties.dy;}}).attr("transform",function(d){centroid=path.centroid(d);if(isNaN(centroid[0]))return null;return "translate("+ centroid[0] + "," + centroid[1] +")";}).on("mouseover",function(d){d3.event.stopPropagation();d3.select(this).style("font-size", "2em");}).on("mouseout",function(d){d3.event.stopPropagation();d3.select(this).style("font-size", "1em");});}function drawOneHisKingdom(k,code){p="hisjson.php?code="+code+"&id0=other";d3.json(p, function(error, root) {if (error) return console.error(error);console.log(root.features);if(root.features.length>2){edit_fill_opacity=0.5;edit_refresh();}svg.append("g").selectAll(".edit_kingdom_path").data( root.features ).enter().append("path").attr("class","edit_kingdom_path").style("fill",function(d,i){if(k==-1)return "#dd0000";return color(k);}).style("opacity", his_fill_opacity).attr("d", path ).on("mouseover",function(d,i){d3.event.stopPropagation();d3.select(this).style("opacity", 0.6);p=d3.mouse(this);disp_region_name(p,d.properties.name);}).on("mouseout",function(d,i){d3.select(this).style("opacity", his_fill_opacity);}).call(zoom).on("mousedown.zoom",null);;});}drawCaps();d3.timer(function() {svg.selectAll(".edit_kingdom_path").attr("d",path);svg.selectAll(".edit_cap_path").attr("d",path);drawCaps();addClick();});function addClick(){svg.selectAll(".edit_kingdom_path").on("click",function(d,i){d3.event.stopPropagation();rotate=1;resetDrag(d.properties.ID0+":"+d.properties.ID1+":"+d.properties.ID2+":"+d.properties.ID3,d.properties.name);});svg.selectAll(".county_path").on("click",function(d,i){d3.event.stopPropagation();rotate=1;p=d3.mouse(this);rotate=1;resetDrag(d.properties.ID0+":"+d.properties.ID1+":"+d.properties.ID2+":"+d.properties.ID3,d.properties.name);});svg.selectAll(".province_path").on("click",function(d,i){d3.event.stopPropagation();rotate=1;resetDrag(d.properties.ID0+":"+d.properties.ID1+":"+d.properties.ID2,d.properties.name);});svg.selectAll(".edit_china_path").on("click",function(d,i){d3.event.stopPropagation();rotate=1;resetDrag(d.properties.ID0+":"+d.properties.ID1,d.properties.name);});svg.selectAll(".edit_country_path").on("click",function(d,i){d3.event.stopPropagation();rotate=1;resetDrag(d.properties.ID0+":"+d.properties.ID1,d.properties.name);});svg.selectAll(".edit_world_path").on("click",function(d,i){d3.event.stopPropagation();rotate=1;resetDrag(d.properties.ID0,d.properties.name);});svg.selectAll(".edit_cap_path").on("click",function(d,i){d3.event.stopPropagation();rotate=1;resetDrag(d.properties.p,d.properties.cap);});svg.selectAll(".cap_title").on("click",function(d,i){d3.event.stopPropagation();rotate=1;resetDrag(d.properties.p,d.properties.cap);});}get = {byId: function(id) {return typeof id === "string" ? document.getElementById(id) : id},byClass: function(sClass, oParent) {aClass = [];reClass = new RegExp("(^| )" + sClass + "( |$)");aElem = this.byTagName("*", oParent);for (i = 0; i < aElem.length; i++) reClass.test(aElem[i].className) && aClass.push(aElem[i]);return aClass},byTagName: function(elem, obj) {return (obj || document).getElementsByTagName(elem)}};dragMinWidth = 800;dragMinHeight = 600;php_path=".";function dragWin(oDrag, handle){disX = dixY = 0;oMin = get.byClass("min", oDrag)[0];oMax = get.byClass("max", oDrag)[0];oRevert = get.byClass("revert", oDrag)[0];oClose = get.byClass("close", oDrag)[0];handle = handle || oDrag;handle.style.cursor = "move";handle.onmousedown = function (event){event = event || window.event;disX = event.clientX - oDrag.offsetLeft;disY = event.clientY - oDrag.offsetTop;document.onmousemove = function (event){event = event || window.event;iL = event.clientX - disX;iT = event.clientY - disY;maxL = document.documentElement.clientWidth - oDrag.offsetWidth;maxT = document.documentElement.clientHeight - oDrag.offsetHeight;iL <= 0 && (iL = 0);iT <= 0 && (iT = 0);iL >= maxL && (iL = maxL);iT >= maxT && (iT = maxT);oDrag.style.left = iL + "px";oDrag.style.top = iT + "px";return false};document.onmouseup = function (){document.onmousemove = null;document.onmouseup = null;this.releaseCapture && this.releaseCapture()};this.setCapture && this.setCapture();return false};oMax.onclick = function (){oDrag.style.top = oDrag.style.left = 0;oDrag.style.width = document.documentElement.clientWidth - 2 + "px";oDrag.style.height = document.documentElement.clientHeight - 2 + "px";this.style.display = "none";oRevert.style.display = "block";};oRevert.onclick = function (){resetDrag("","");};oMin.onclick = oClose.onclick = function (){minDrag("");};oMin.onmousedown = oMax.onmousedown = oClose.onmousedown = function (event){this.onfocus = function () {this.blur()};(event || window.event).cancelBubble = true};};function resize(oParent, handle, isLeft, isTop, lockX, lockY){handle.onmousedown = function (event){event = event || window.event;disX = event.clientX - handle.offsetLeft;disY = event.clientY - handle.offsetTop;iParentTop = oParent.offsetTop;iParentLeft = oParent.offsetLeft;iParentWidth = oParent.offsetWidth;iParentHeight = oParent.offsetHeight;document.onmousemove = function (event){event = event || window.event;iL = event.clientX - disX;iT = event.clientY - disY;maxW = document.documentElement.clientWidth - oParent.offsetLeft - 2;maxH = document.documentElement.clientHeight - oParent.offsetTop - 2;iW = isLeft ? iParentWidth - iL : handle.offsetWidth + iL;iH = isTop ? iParentHeight - iT : handle.offsetHeight + iT;isLeft && (oParent.style.left = iParentLeft + iL + "px");isTop && (oParent.style.top = iParentTop + iT + "px");iW < dragMinWidth && (iW = dragMinWidth);iW > maxW && (iW = maxW);lockX || (oParent.style.width = iW + "px");iH < dragMinHeight && (iH = dragMinHeight);iH > maxH && (iH = maxH);lockY || (oParent.style.height = iH + "px");if((isLeft && iW == dragMinWidth) || (isTop && iH == dragMinHeight)) document.onmousemove = null;return false;};document.onmouseup = function (){document.onmousemove = null;document.onmouseup = null;};return false;}};window.onload = window.onresize = function (){oDrag = document.getElementById("drag");oTitle = get.byClass("title", oDrag)[0];oL = get.byClass("resizeL", oDrag)[0];oT = get.byClass("resizeT", oDrag)[0];oR = get.byClass("resizeR", oDrag)[0];oB = get.byClass("resizeB", oDrag)[0];oLT = get.byClass("resizeLT", oDrag)[0];oTR = get.byClass("resizeTR", oDrag)[0];oBR = get.byClass("resizeBR", oDrag)[0];oLB = get.byClass("resizeLB", oDrag)[0];minDrag("");dragWin(oDrag, oTitle);resize(oDrag, oLT, true, true, false, false);resize(oDrag, oTR, false, true, false, false);resize(oDrag, oBR, false, false, false, false);resize(oDrag, oLB, true, false, false, false);resize(oDrag, oL, true, false, false, true);resize(oDrag, oT, false, true, true, false);resize(oDrag, oR, false, false, false, true);resize(oDrag, oB, false, false, true, false);oDrag.style.left = (document.documentElement.clientWidth - oDrag.offsetWidth) / 4 + "px";oDrag.style.top = (document.documentElement.clientHeight - oDrag.offsetHeight) / 4 + "px";};function resetDrag(region,name){can_refresh=false;oDrag = document.getElementById("drag");oMax = get.byClass("max", oDrag)[0];oRevert = get.byClass("revert", oDrag)[0];oDrag.style.left = (document.documentElement.clientWidth - oDrag.offsetWidth) / 2 + "px";oDrag.style.top = (document.documentElement.clientHeight - oDrag.offsetHeight) / 6 + "px";frame = document.getElementById("info_edit");if(_his_year==_INIT_YEAR){frame.src=php_path+"/edit_year.php?r="+region+"&n="+name;}else{frame.src=php_path+"/edit_dynasty.php?r="+region+"&n="+name;}oDrag.style.display = "block";oMax.style.display = "block";};function capDrag(){can_refresh=false;oDrag = document.getElementById("drag");oMax = get.byClass("max", oDrag)[0];oRevert = get.byClass("revert", oDrag)[0];oDrag.style.left = (document.documentElement.clientWidth - oDrag.offsetWidth) / 2 + "px";oDrag.style.top = (document.documentElement.clientHeight - oDrag.offsetHeight) / 6 + "px";frame = document.getElementById("info_edit");frame.src=php_path+"/edit_capital.php";oDrag.style.display = "block";oMax.style.display = "block";}function minDrag(info){can_refresh=true;oDrag = document.getElementById("drag");oDrag.style.display = "none";icon = document.getElementById("pop_icon");if(icon==null || icon=="" ){icon = document.createElement("a");icon.className = "open";icon.id = "pop_icon";icon.href = "javascript:;";icon.title = "还原";document.body.appendChild(icon); }year_info = document.getElementById("year_info");icon.onclick = function (){oDrag.style.display = "block";frame = document.getElementById("info_edit");frame.src=php_path+"/help/help.html";document.body.removeChild(this);this.onclick = null;};year_info.onclick = function (){frame = document.getElementById("info_edit");frame.src=php_path+"/edit_year.php";oDrag.style.display = "block";v=document.getElementById("pop_icon");document.body.removeChild(v);};};function dynasty_click(code,level){oDrag = document.getElementById("drag");frame = document.getElementById("info_edit");if(code=="")frame.src=php_path+"/new_dynasty.php";else{frame.src=php_path+"/select_dynasty.php?code="+code;}oDrag.style.display = "block";v=document.getElementById("pop_icon");document.body.removeChild(v);}