UNPKG

zingchart

Version:

Our JavaScript charting library is a commercial product. But the full branded version is free to try, forever.

8 lines (7 loc) 5.67 kB
/* All of the code within the ZingChart software is developed and copyrighted by ZingChart, Inc., and may not be copied, replicated, or used in any other software or application without prior permission from ZingChart. All usage must coincide with the ZingChart End User License Agreement which can be requested by email at support@zingchart.com. Build 2.9.16-hf1 */ zingchart.setModule("maps-geojson"),zingchart.maps&&(zingchart.maps.loadGeoJSON=function(O){var A4D=O.id||"geojson"+parseInt(10+89*Math.random(),10),E9=O.url||"",oMappings=O.mappings||{id:"id",name:"name",abbr:"abbr",group:"group"},AC5=O.ignore||[],P=O.style||{};""===E9&&O.callback&&O.callback.call(),ZC.A4.ajax({type:"GET",url:E9,beforeSend:function(){},data:"",error:function(){O.callback&&O.callback.call()},success:function(KJ){var H,DD={};try{DD=JSON.parse(KJ)}catch(JB){try{DD=eval("("+KJ+")")}catch(JB){}}zingchart.maps[A4D]||(zingchart.maps[A4D]={}),zingchart.maps.data[A4D]||(zingchart.maps.data[A4D]={_GROUPS_:{},_DEFAULTS_:zingchart.maps._DEFAULTS_});var _COORDS_={},aFeatures,m,AAN,c,cLen,g,sGroupId,aBBox=[Number.MAX_VALUE,Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE];if(null===ZC._n_(aFeatures=DD.features)&&(DD.features=[DD]),null!==ZC._n_(aFeatures=DD.features)){for(var i=0,A6=aFeatures.length;i<A6;i++){var oFeature=aFeatures[i],oProperties=oFeature.properties||{};for(AAN=A4D.toUpperCase()+i,oMappings.id=oMappings.id instanceof Array?oMappings.id:[oMappings.id],oMappings.abbr=oMappings.abbr instanceof Array?oMappings.abbr:[oMappings.abbr],oMappings.name=oMappings.name instanceof Array?oMappings.name:[oMappings.name],oMappings.group=oMappings.group instanceof Array?oMappings.group:[oMappings.group],m=0;m<oMappings.id.length;m++)"function"==typeof oMappings.id[m]?AAN=oMappings.id[m].call(AAN):(AAN=oFeature[oMappings.id[m]]||AAN,AAN=oProperties[oMappings.id[m]]||AAN);null!==ZC._n_(AAN)&&""!==AAN||(AAN=A4D+"_item_"+i),AAN=(""+AAN).replace(/[^a-z0-9]/gi,"_");var sItemId_=AAN;if(-1===ZC.AV(AC5,AAN)){var sItemAbbr="";for(m=0;m<oMappings.abbr.length;m++)"function"==typeof oMappings.abbr[m]?sItemAbbr=oMappings.abbr[m].call(sItemAbbr):(sItemAbbr=oFeature[oMappings.abbr[m]]||sItemAbbr,sItemAbbr=oProperties[oMappings.abbr[m]]||sItemAbbr);var sItemName="";for(m=0;m<oMappings.name.length;m++)"function"==typeof oMappings.name[m]?sItemName=oMappings.name[m].call(sItemName):(sItemName=oFeature[oMappings.name[m]]||sItemName,sItemName=oProperties[oMappings.name[m]]||sItemName);for(sGroupId="",g=0;g<oMappings.group.length;g++)"function"==typeof oMappings.group[g]?sGroupId=oMappings.group[g].call(sGroupId):(sGroupId=oFeature[oMappings.group[g]]||sGroupId,sGroupId=oProperties[oMappings.group[g]]||sGroupId);if(""!==sItemAbbr||""!==sItemName){""!==sGroupId&&(zingchart.maps.data[A4D]._GROUPS_[sGroupId]=zingchart.maps.data[A4D]._GROUPS_[sGroupId]||[],zingchart.maps.data[A4D]._GROUPS_[sGroupId].push(AAN));var aGeometries=[];for(null!==ZC._n_(oFeature.geometry)?aGeometries="GeometryCollection"===oFeature.geometry.type?oFeature.geometry.geometries||[]:[oFeature.geometry]:null!==ZC._n_(oFeature.geometries)&&(aGeometries=oFeature.geometries),g=0;g<aGeometries.length;g++){aGeometries.length>1&&g>0&&(AAN=sItemId_+"_"+g),_COORDS_[AAN]=[];var oGeometry=aGeometries[g],AF="poly",aCoordinates=[];if("Polygon"===oGeometry.type)aCoordinates=oGeometry.coordinates;else if("MultiPolygon"===oGeometry.type)for(aCoordinates=[],c=0;c<oGeometry.coordinates.length;c++)aCoordinates=aCoordinates.concat(oGeometry.coordinates[c]);else"Point"===oGeometry.type?(AF="point",aCoordinates=[[oGeometry.coordinates]]):"LineString"===oGeometry.type?(AF="line",aCoordinates=[oGeometry.coordinates]):"MultiLineString"===oGeometry.type&&(AF="line",aCoordinates=oGeometry.coordinates);for(var j=0,JC=aCoordinates.length;j<JC;j++){for(var aCoords=aCoordinates[j],k=0,kLen=aCoords.length;k<kLen;k++)_COORDS_[AAN].push(aCoords[k]),aBBox[0]=Math.min(aBBox[0],aCoords[k][0]),aBBox[2]=Math.max(aBBox[2],aCoords[k][0]),aBBox[1]=Math.min(aBBox[1],aCoords[k][1]),aBBox[3]=Math.max(aBBox[3],aCoords[k][1]);j<JC-1&&_COORDS_[AAN].push(null)}var sLabelText=sItemAbbr||sItemName,iSort=0;"line"===AF?iSort=2:"point"===AF&&(iSort=4),_COORDS_[AAN].length&&(zingchart.maps.data[A4D][AAN]={sort:iSort,type:AF,coords:_COORDS_[AAN],tooltip:{text:sItemName},label:{text:sLabelText},style:{}},"poly"===AF&&null!==ZC._n_(P.poly)&&ZC._cp_(P.poly,zingchart.maps.data[A4D][AAN].style),"line"===AF&&null!==ZC._n_(P.line)&&ZC._cp_(P.line,zingchart.maps.data[A4D][AAN].style),"point"===AF&&null!==ZC._n_(P.point)&&ZC._cp_(P.point,zingchart.maps.data[A4D][AAN].style))}}}}var iDiffLon=aBBox[2]-aBBox[0],iDiffLat=aBBox[3]-aBBox[1],iMaxLon=10,iMaxLat=iMaxLon*iDiffLat/iDiffLon,fRatioLon=iMaxLon/iDiffLon,fRatioLat=iMaxLat/iDiffLat,iMax=Math.max(ZC._a_(aBBox[0]),ZC._a_(aBBox[1]),ZC._a_(aBBox[2]),ZC._a_(aBBox[3]));if(iMax>180.01)for(AAN in zingchart.maps.data[A4D])if(null!==ZC._n_(H=zingchart.maps.data[A4D][AAN].coords))for(c=0,cLen=zingchart.maps.data[A4D][AAN].coords.length;c<cLen;c++)null!==ZC._n_(H[c])&&(H[c][0]=(H[c][0]-aBBox[0])*fRatioLon,H[c][1]=(H[c][1]-aBBox[1])*fRatioLat);zingchart.maps.upgrade(A4D),zingchart.maps[A4D]=function(a,e,o){return zingchart.maps.convert({loader:this,loaderdata:e||{},graphid:"undefined"==typeof a.graphid?0:a.graphid,data:o,id:a.id||A4D,x:"undefined"==typeof a.x?0:a.x,y:"undefined"==typeof a.y?0:a.y,width:"undefined"==typeof a.width?1:a.width,height:"undefined"==typeof a.height?1:a.height,level:"undefined"==typeof a.level?1:a.level,groups:a.groups||[],items:a.items||[],ignore:a.ignore||[],bbox:a.bbox||null,map:zingchart.maps.data[A4D]})},O.callback&&O.callback.call()}}})});