Created
November 4, 2011 20:54
-
-
Save Nub/1340461 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Javascript Region Skimmer | |
| //Patch their lame code | |
| RS.maxPoolSize = 90000; | |
| var dataSet = { | |
| "Countries":{ | |
| } | |
| }; | |
| var countryCounter = 1; | |
| function skimCountry(){ | |
| var countryList = document.getElementById('SelectCountry'); | |
| var currentCountry = [countryList.options[countryCounter].value]; | |
| if(countryCounter > countryList.options.length-1){ | |
| return; | |
| } | |
| if (currentCountry != ".." && currentCountry){ | |
| dataSet['Countries'][currentCountry] = { | |
| "Code":"", | |
| "Polygon":"",//TODO:generate Polygon from regions | |
| "Regions":{} | |
| } | |
| countryList.value = currentCountry; | |
| countryList.onchange(); | |
| } | |
| countryCounter ++; | |
| } | |
| var regionCounter = 1; | |
| function skimRegion(){ | |
| var countryList = document.getElementById('SelectCountry'); | |
| var currentCountry = countryList.value; | |
| var regionList = document.getElementById('SelectRegion'); | |
| if(regionCounter > regionList.options.length-1){ | |
| regionCounter = 1; | |
| skimCountry();//go to next country | |
| } | |
| var currentRegion = regionList.options[regionCounter]; | |
| if (currentRegion.value != ".." && currentRegion){ | |
| regionList.value = currentRegion.value; | |
| regionList.onchange(); | |
| } | |
| regionCounter ++; | |
| } | |
| UpdateRegion = function(result){ | |
| var SelectRegion = document.getElementById("SelectRegion"); | |
| SelectRegion.options.length = 1; | |
| var regionArray = new Array(); | |
| regionArray = result.split("|"); | |
| var y=document.createElement("option"); | |
| y.text='default'; | |
| var i = 0; | |
| for(i=0;i<regionArray.length;i++){ | |
| y = document.createElement("option"); | |
| y.text = regionArray[i]; | |
| if (window.attachEvent) { // IE | |
| document.getElementById("SelectRegion").add(y); | |
| }else{ // firefox | |
| document.getElementById("SelectRegion").add(y,null); | |
| } | |
| } | |
| skimRegion(); | |
| } | |
| function parsePolygon(dataString){ | |
| if(!dataString) return "NULL"; | |
| var polygonDataPairs = dataString.split('|'); | |
| var polygonData = []; | |
| for(var i in polygonDataPairs){ | |
| var pairData = polygonDataPairs[i].split(','); | |
| polygonData[i] = { | |
| "lat":parseFloat(pairData[0]), | |
| "lon":parseFloat(pairData[1]) | |
| }; | |
| } | |
| return polygonData; | |
| } | |
| UpdateMap = function(result){ | |
| var countryList = document.getElementById('SelectCountry'); | |
| var currentCountry = countryList.value; | |
| var regionList = document.getElementById('SelectRegion'); | |
| var currentRegion = regionList.value; | |
| var dataArray = result.split("+"); | |
| var polygonCenterLat = dataArray[0]; | |
| var polygonCenterLon = dataArray[1]; | |
| var polygonDataString = dataArray[2]; | |
| dataSet['Countries'][currentCountry]['Regions'][currentRegion] = { | |
| "Code":"", | |
| "Polygon":parsePolygon(polygonDataString) | |
| } | |
| skimRegion() | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment