變壓器位置with範圍展示
yuanhung
2016-08-16 e2f1791e877f9c008055154361eac1d11b79c83f
1
function GJSonParser(options){var parserRule={},applySetting=function(e){parserRule.sourcePrj=e.sourcePrj||"EPSG:4326",parserRule.targetPrj=e.targetPrj||"EPSG:4326",parserRule.root0=e.root0||"",parserRule.rootGeom=e.rootGeom||"",parserRule.rootAttrib=e.rootAttrib||"",parserRule.attributeMapping=e.attributeMapping||[],parserRule.colX=e.colX||"X",parserRule.colY=e.colY||"Y"};applySetting(options||{}),this.getparserRule=function(){return parserRule},this.makeMapCol=function(e,t){return{src:e,tar:t}};var builder=function(){var e={};this.src=function(t){return e.sourcePrj=t,this},this.tar=function(t){return e.targetPrj=t,this},this.root0=function(t){return e.root0=t,this},this.rootGeom=function(t){return e.rootGeom=t,this},this.rootAttrib=function(t){return e.rootAttrib=t,this},this.colX=function(t){return e.colX=t,this},this.colY=function(t){return e.colY=t,this},this.addCol=function(t,r){return null==e.attributeMapping&&(e.attributeMapping=[]),e.attributeMapping.push({src:t,tar:r}),this},this.build=function(){return e}};this.optionsBuilder=function(){return new builder},this.parser=function(gJson,opt){dbgOption=opt,null==opt&&(opt={});var results=[],parserList=opt.attributeMapping||parserRule.attributeMapping,aResult,dx,dy,tempRootstr=opt.root0||parserRule.root0;tempRootstr.length>0&&(tempRootstr="."+tempRootstr);var Items=eval("gJson"+tempRootstr),tempGeomstr=opt.rootGeom||parserRule.rootGeom;tempGeomstr.length>0&&(tempGeomstr="."+tempGeomstr);var tempAttrstr=opt.rootAttrib||parserRule.rootAttrib;tempAttrstr.length>0&&(tempAttrstr="."+tempAttrstr);for(var aItemId in Items){var aItem=Items[aItemId];aResult={},dx=0,dy=0,dx=eval("aItem"+tempGeomstr+"."+(opt.colX||parserRule.colX)),dy=eval("aItem"+tempGeomstr+"."+(opt.colY||parserRule.colY));var aPropItem=eval("aItem"+tempAttrstr);if(0==parserList.length)for(var aCol in aPropItem)"string"==typeof aPropItem[aCol]?aResult[aCol]=aPropItem[aCol]:"number"==typeof aPropItem[aCol]&&(aResult[aCol]=aPropItem[aCol]);else for(var aCol in parserList)"string"==typeof parserList[aCol.src]?aResult[aCol.tar]=parserList[aCol.src]:"number"==typeof parserList[aCol.src]&&(aResult[aCol.tar]=parserList[aCol.src]);results.push({type:"Feature",geometry:{type:"Point",coordinates:[dx||0,dy||0]},properties:aResult})}var geoJosnParser=new OpenLayers.Format.GeoJSON({internalProjection:opt.targetPrj||parserRule.targetPrj,externalProjection:opt.sourcePrj||parserRule.sourcePrj});return console.log(geoJosnParser.internalProjection,"<--",geoJosnParser.externalProjection),geoJosnParser.read({type:"FeatureCollection",features:results})}}function createLayer(e,t){var r;switch(t.layerType){case"mapguide":var o={sphericalMercator:!0,transitionEffect:"resize",buffer:1,useOverlay:!1,useAsyncOverlay:!1,projection:tw97,singleTile:!0},n={mapdefinition:t.layerid,USERNAME:"Anonymous"};r=new OpenLayers.Layer.MapGuide2(e,t.content,n,o);break;case"wmts":for(var a=[],s=0;24>s;++s)a.push((t.projection||"EPSG:4326")+":"+s);r=new OpenLayers.Layer.WMTS({VERSION:"1.0.0",name:e,url:t.content,layer:t.layerid,matrixIds:a,matrixSet:t.projection||"EPSG:4326",style:"_null",format:"image/png"});break;case"wms":r=new OpenLayers.Layer.WMS(e,t.content,{LAYERS:t.layerid,STYLES:"",format:"image/png8",tiled:t.tiled||!0,transparent:t.transparent||!0,numZoomLevels:24,tileOptions:{eventListeners:{beforedraw:function(e){},loaderror:function(e){},loadend:function(e){},loadstart:function(e){}}}},{projection:new OpenLayers.Projection(t.projection),isBaseLayer:t.isBaselayer||!1,transparent:"true",buffer:0,displayOutsideMaxExtent:!0,displayInLayerSwitcher:!0,visibility:!1,transitionEffect:"resize"});break;case"awms":r=new OpenLayers.Layer.WMS(e,t.content+"/animate",{LAYERS:t.layerid,STYLES:"",FORMAT:"image/gif;subtype=animated",FORMAT_OPTIONS:"antialias:none;gif_loop_continuosly:true;gif_frames_delay:500",REQUEST:"getmap",SERVICE:"animate",transparent:t.transparent||!0,VERSION:"1.1.1",aparam:"cql_filter",avalues:"1=0;dt0=20150507,2=2;dt0=20000101",numZoomLevels:24,tileOptions:{eventListeners:{beforedraw:function(e){},loaderror:function(e){},loadend:function(e){},loadstart:function(e){}}}},{projection:new OpenLayers.Projection(t.projection),isBaseLayer:t.isBaselayer||!1,transparent:"true",buffer:0,displayOutsideMaxExtent:!0,displayInLayerSwitcher:!0,visibility:!1,transitionEffect:"resize"});break;case"google":r="undefined"==typeof google?new OpenLayers.Layer.Vector(e,{projection:epsg3857,transparent:"true",buffer:0,transitionEffect:"resize",displayOutsideMaxExtent:!0,isBaseLayer:!0,numZoomLevels:24,displayInLayerSwitcher:!0,visibility:!1}):new OpenLayers.Layer.Google(e,{type:t.content||google.maps.MapTypeId.ROADMAP,numZoomLevels:24,visibility:!1,transitionEffect:"resize"},{isBaseLayer:!0,buffer:0});break;case"vector":if("undefined"!=typeof t.styleMap){var i={styleMap:t.styleMap};"undefined"!=typeof t.projection&&(i.projection=t.projection),r=new OpenLayers.Layer.Vector(e,i)}else r=new OpenLayers.Layer.Vector(e,{styleMap:new OpenLayers.StyleMap({"default":OpenLayers.Util.applyDefaults({strokeWidth:3,graphicName:"triangle",pointRadius:6,rotation:"${angle}"},OpenLayers.Feature.Vector.style["default"]),select:OpenLayers.Util.applyDefaults({pointRadius:6},OpenLayers.Feature.Vector.style.select)})});break;default:console.log("Unsupply LayerType")}return r}function makeResolution(e,t){"undefined"!=typeof e.resolutions&&(e.resolutions.push(e.resolutions[e.resolutions.length-1]/2),e.resolutions.length<t&&makeResolution(e,t))}function makeScale(e,t){"undefined"!=typeof e.scales&&null!=e.scales&&(e.scales.push(e.scales[e.scales.length-1]/2),e.scales.length<t&&makeScale(e,t))}function findVectorBBox(e){var t={};if("undefined"!=typeof e)for(var r=0;r<e.length;r++)e[r].geometry.calculateBounds(),0==r?(t=e[r].geometry.getBounds(),t.left=e[r].geometry.bounds.left,t.right=e[r].geometry.bounds.right,t.top=e[r].geometry.bounds.top,t.bottom=e[r].geometry.bounds.bottom):(t.left=e[r].geometry.bounds.left<t.left?e[r].geometry.bounds.left:t.left,t.right=e[r].geometry.bounds.right>t.right?e[r].geometry.bounds.right:t.right,t.top=e[r].geometry.bounds.top<t.top?e[r].geometry.bounds.top:t.top,t.bottom=e[r].geometry.bounds.bottom>t.bottom?e[r].geometry.bounds.bottom:t.bottom);return t}OpenLayers.Projection.addTransform("EPSG:3857","EPSG:3826",OpenLayers.Projection.nullTransform);var AProto=function(e){var t=function(e){};this.setAction=function(r,o){e="undefined"==typeof o?e:o,t=r},this.callAction=function(e){t(e)},this.getConfig=function(t){return e}},extMapResultion=function(e,t){var r,o;for(r in e.layers){if(o=e.layers[r],makeResolution(o,t),makeScale(o,t),null==o.scales)return;"undefined"!=typeof o.scales&&(o.maxScale=o.scales[o.scales.length-1],o.minResolution=o.resolutions[o.resolutions.length-1],o.numZoomLevels=t)}},CtlCopyFeatures=function(e,t){"undefined"==typeof t&&(t={}),this.action=function(t){"undefined"==typeof t&&(t={});var r=new OpenLayers.Format.WKT({internalProjection:t.toprojection||e.projection,externalProjection:t.formprojection||e.projection});if(t.clearAll&&e.destroyFeatures(),"undefined"!=typeof t.features)for(var o=0;o<t.features.length;o++){var n=r.read(t.features[o].geometry.toString());if(n.attributes=t.features[o].attributes,"undefined"!=typeof t.features[o].attributes)for(var a in t.features[o].attributes)n.attributes[a]=t.features[o].attributes[a];e.addFeatures(n)}},this.cancel=function(t){"undefined"==typeof t&&(t={}),e.destroyFeatures()}},DGNParser=function(){var e=function(e,t){var r="";return e>=0&&99>=e&&t>=0&&99>=t&&(r=10>e?"0"+String(e):String(e),10>t?r=r+"0"+String(t):r+=String(t)),r};this.get1000=function(t,r){var o,n;return num="",o=parseInt((parseInt(t)-270400)/800),n=parseInt((parseInt(r)-2743500)/600),num=e(o,n),num},this.get500=function(t,r){var o,n,a,s,i="";return o=parseInt((parseInt(t)-270400)/800),n=parseInt((parseInt(r)-2743500)/600),i=e(o,n),a=parseInt((t-800*o-270400)/400),s=parseInt((r-600*n-2743500)/300),0!=a&&0!=s?i+="A":0!=a&&0==s?i+="B":0==a&&0==s?i+="C":0==a&&0!=s&&(i+="D"),i}},dgnParser=new DGNParser,CtlGetWKT=function(e,t){"undefined"==typeof t&&(t={}),this.parser=function(t,r){"undefined"==typeof r&&(r={});var o=new OpenLayers.Format.WKT({internalProjection:r.toprojection||tw97,externalProjection:r.formprojection||e.projection});if("featurePoint"==r.geometryType,!0){var n=o.read(t.geometry.toString()),a={wkt:n.geometry.toString()};return o.internalProjection==tw97&&(a.dgnid1000=dgnParser.get1000(n.geometry.x,n.geometry.y),a.dgnid500=dgnParser.get500(n.geometry.x,n.geometry.y)),a.point={x:n.geometry.x,y:n.geometry.y},a}},this.action=function(r){"undefined"==typeof r&&(r={});var o={},n=new OpenLayers.Format.WKT({internalProjection:r.toprojection||tw97,externalProjection:r.formprojection||e.projection}),a=t.srcLayer||"drawTemp",s=e.getLayersByName(a);if(0==s.length)return o;for(var i=[],u={left:0,right:0,top:0,buttom:0},l=0;l<s[0].features.length;l++){var p,f=n.read(s[0].features[l].geometry.toString());if("wkt"==t.resultFormat,f.geometry.calculateBounds(),0==l?(u.left=f.geometry.bounds.left,u.right=f.geometry.bounds.right,u.top=f.geometry.bounds.top,u.buttom=f.geometry.bounds.buttom):(f.top>u.top&&(u.top=f.top),f.right>u.right&&(u.right=f.right),f.left<u.left&&(u.left=f.left),f.buttom<u.buttom&&(u.buttom=f.buttom)),p={info:s[0].features[l].attributes,wkt:f.geometry.toString()},p.points=f.geometry.getVertices(),r.parser97DGNID){var y=f.geometry.getVertices();y.length>0&&(u.dgnid500=dgnParser.get500(y[0].x,y[0].y),u.dgnid1000=dgnParser.get1000(y[0].x,y[0].y))}i.push(p)}return{features:i,bounds:u}},this.cancel=function(t){"undefined"==typeof t&&(t={});var r=e.getLayersByName(t.layer||"drawTemp");r[0].destroyFeatures()}},CtlLocate=function(e,t){"undefined"==typeof t&&(t={}),this.action=function(r){var o=[],n=0,a=new OpenLayers.Format.WKT({internalProjection:e.projection,externalProjection:r.projection||tw97});if("undefined"!=typeof r.buffsize&&(n=parseFloat(buffsize)),"undefined"!=typeof r.point&&(o.push(parseFloat(r.point.x)),o.push(parseFloat(r.point.y))),"undefined"!=typeof r.points)for(var s=0;s<r.points.length;s++){var i=r.points[s];o.push(parseFloat(i.x)),o.push(parseFloat(i.y))}if("undefined"!=typeof r.pts)for(var s=0;s<r.pts.length;s+=2)o.push(parseFloat(r.pts[s])),o.push(parseFloat(r.pts[s+1]));var u,l=function(e){var t=null;if("undefined"!=typeof r.style&&(t=r.style,OpenLayers.Util.applyDefaults(t,OpenLayers.Feature.Vector.style["default"])),"undefined"!=typeof r.attributes)for(var o in r.attributes)e.attributes[o]=r.attributes[o];else e.attributes={};"undefined"==typeof e.attributes.descript&&(e.attributes.descript=""),"undefined"==typeof e.attributes.popup&&(e.attributes.popup=""),null!=t&&(e.style=t)},p=e.getLayersByName(t.layer||"markup");if(r.clearAll&&p[0].destroyFeatures(),"lineGrid"==r.drawAs){var i="LINESTRING(";if(2==o.length){var f=parseFloat(n>0?n:5);i+=o[0]-f+" "+o[1]-f+",",i+=o[0]+f+" "+o[1]-f+",",i+=o[0]+f+" "+o[1]+f+",",i+=o[0]-f+" "+o[1]+f+",",i+=o[0]-f+" "+o[1]-f+")"}else if(4==o.length){var f=parseFloat(n>0?n:0);i+=o[0]-f+" "+(o[1]-f+","),i+=o[2]+f+" "+(o[1]-f+","),i+=o[2]+f+" "+(o[3]+f+","),i+=o[0]-f+" "+(o[3]+f+","),i+=o[0]-f+" "+(o[1]-f+")")}else if(8==o.length||10==o.length){var f=parseFloat(n>0?n:0);i=i+o[0]-f+" "+o[1]-f+",",i=i+o[2]+f+" "+o[3]-f+",",i=i+o[4]+f+" "+o[5]+f+",",i=i+o[6]-f+" "+o[7]+f+",",i=i+o[0]-f+" "+o[1]-f+")"}else i+="0 0)";u=a.read(i),l(u),p[0].addFeatures(u)}else if("line"==r.drawAs){for(var i="LINESTRING(",f=0,s=0;s<o.length;s+=2)s>0&&(i+=","),i=i+o[s]+" "+o[s+1];i+=")",u=a.read(i),l(u),p[0].addFeatures(u)}else if("polygon"==r.drawAs){for(var i="POLYGON((",f=0,s=0;s<o.length;s+=2)s>0&&(i+=","),i=i+o[s]+" "+o[s+1];o[0]!=o[o.length-2]&&o[1]!=o[o.length-1]&&(i=i+","+o[0]+" "+o[1]),i+="))",u=a.read(i),l(u),p[0].addFeatures(u)}else if("point"==r.drawAs||"mpoint"==r.drawAs)for(var i,f=0,s=0;s<o.length;s+=2)i="POINT("+o[s]+" "+o[s+1]+")",u=a.read(i),l(u),p[0].addFeatures(u);else if("wkt"==r.drawAs){var i=r.wkt,f=0;"undefined"!=typeof i&&(u=a.read(i),l(u),p[0].addFeatures(u))}if(p[0].setVisibility(!0),r.zoomToCenter){var y=r.zoomLevel||19,c=findVectorBBox(p[0].features);e.setCenter(new OpenLayers.LonLat((c.left+c.right)/2,(c.top+c.bottom)/2),y)}else if(r.zoomToRange){var c=findVectorBBox(p[0].features),d=e.getZoomForExtent(c);e.setCenter(new OpenLayers.LonLat((c.left+c.right)/2,(c.top+c.bottom)/2),d)}r.drawTempLayer&&p[0].destroyFeatures()},this.cancel=function(t){"undefined"==typeof t&&(t={});var r=e.getLayersByName(t.layer||"markup");r[0].destroyFeatures()}};