/* JSON2.js http://www.JSON.org/json2.js 2011-01-18 Public Domain. NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. See http://www.JSON.org/js.html */ if(!this.JSON){this.JSON={};} (function(){function f(n){return n<10?'0'+n:n;} if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+ f(this.getUTCMonth()+1)+'-'+ f(this.getUTCDate())+'T'+ f(this.getUTCHours())+':'+ f(this.getUTCMinutes())+':'+ f(this.getUTCSeconds())+'Z':null;};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf();};} var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4);})+'"':'"'+string+'"';} function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key);} if(typeof rep==='function'){value=rep.call(holder,key,value);} switch(typeof value){case'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';} gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==='[object Array]'){length=value.length;for(i=0;i will be used to determine the appropriate * dictionary. Dictionaries are stored in . * * Parameters: * key - {String} The key for an i18n string value in the dictionary. * context - {Object} Optional context to be used with * . * * Returns: * {String} A internationalized string. */ i18n: function(key, context) { var message = SGLang.lang[key]; if(!message) { // Message not found, fall back to message key message = key; } if(context) { message = SGLang.format(message, context); } return message; }, i18nFile: function(file) { var code = this.getCode(); if(code == "0" || code == "1033") return file; return code + "/" + file; }, format: function(template, context, args) { if(!context) { context = window; } // Example matching: // str = ${foo.bar} // match = foo.bar var replacer = function(str, match) { var replacement; // Loop through all subs. Example: ${a.b.c} // 0 -> replacement = context[a]; // 1 -> replacement = context[a][b]; // 2 -> replacement = context[a][b][c]; var subs = match.split(/\.+/); for (var i=0; i< subs.length; i++) { if (i == 0) { replacement = context; } replacement = replacement[subs[i]]; } if(typeof replacement == "function") { replacement = args ? replacement.apply(null, args) : replacement(); } // If replacement is undefined, return the string 'undefined'. // This is a workaround for a bugs in browsers not properly // dealing with non-participating groups in regular expressions: // http://blog.stevenlevithan.com/archives/npcg-javascript if (typeof replacement == 'undefined') { return 'undefined'; } else { return replacement; } }; return template.replace(SGLang.tokenRegEx, replacer); }, /** * Property: SGLang.tokenRegEx * Used to find tokens in a string. * Examples: ${a}, ${a.b.c}, ${a-b}, ${5} */ tokenRegEx: /\$\{([\w.]+?)\}/g }; //------------------- // load requested lang file (function() { document.write(""); var code = SGLang.getCode(); document.write(""); })(); // hide document body, so that TextXXX won't be visible until we replace them on document ready $(document.body).hide(); //------------------- $(document).ready(function () { $(document.body).hide(); var translateDocument = function() { document.title = SGLang.i18n(document.title); $(".i18n").each(function () { if (this.tagName == "INPUT") { this.value = SGLang.i18n(this.value); } else if (this.tagName == "IMG") { $(this).attr("src",SGLang.i18n($(this).attr("src"))); $(this).attr("alt", SGLang.i18n($(this).attr("alt"))); $(this).attr("title", SGLang.i18n($(this).attr("title"))); } else { $(this).attr("title", SGLang.i18n($(this).attr("title"))); $(this).attr("alt", SGLang.i18n($(this).attr("alt"))); // set element html only if it does not contain any other html elements. // otherwise it will erase them. if ($(this).children().length == 0) { $(this).html(SGLang.i18n($.trim($(this).text()))); } } }); $(".i18nFile").each(function () { if (this.tagName == "IMG") { $(this).attr("src",SGLang.i18nFile($(this).attr("src"))); } }); $(document.body).show(); } // make sure that hiding document body really worked. // I am not sure if IE will update the document view, until the function has finished executing. // so I am giving it here a few milliseconds of unused time. setTimeout(translateDocument,1); }); //------------------- // DisplayHelpPopup function DisplayHelpPopup(HTMLSrc, title) { if (title == null || title == "") title = "?"; var Cont = TE.interface("IContainer2"); Cont.HTMLPopup(1, 5, 5, 650, 500, title, abspath() + "/" + HTMLSrc, 10, -1); } //------------------- // DisplayHelpPopup6 function DisplayHelpPopup6(HTMLSrc, title) { if (title == null || title == "") title = "?"; var popup = SGWorld.Creator.CreatePopupMessage(title, abspath() + "/" + HTMLSrc, 5, 5, 650, 500); popup.AllowDrag = true; popup.AllowResize = true; SGWorld.Window.ShowPopup(popup); } //------------------- // CloseTool function CloseTool (ToolName) { var Cont = TE.interface("IContainer2"); Cont.RemoveURL (1,ToolName); } //------------------- // SGAPIDisplayHelpPopup function SGAPIDisplayHelpPopup(HTMLSrc,title) { //globe.teCore.IContainer.HTMLPopup (1, 5,5,500,500,"Help", SGAPI.toAbspath(HTMLSrc), 10, -1 ); if (title == null || title == "") title = "?"; var popup = new SGPopup(title, HTMLSrc,0,0,650,500); popup.align = "TopLeft"; globe.showPopup(popup); } //------------------- // SGAPICloseTool function SGAPICloseTool (ToolName) { globe.teCore.IContainer.RemoveURL (1,ToolName); } //-------------- // abspath function abspath() { var abspath = unescape(window.location.href); // Remove query String var index=abspath.indexOf("?"); if (index > 0) abspath = abspath.substr (0,index-1); index=abspath.lastIndexOf("/"); var index2 = abspath.lastIndexOf("\\"); index = (index > index2) ? index : index2; if (index <= 0) return abspath; abspath = abspath.substring(0,index); if(abspath.substring(0,1) == "/") abspath = abspath.slice(1); var re = /file:\/\/\//gi; if (abspath.match(re) != null) abspath = abspath.replace(re,""); // if this is indeed a local file, we strip the "file://" prefix from it. return(abspath); } // GetParamValue function GetParamValue(findParam, defaultValue) { var arr = document.location.href.split("?"); if (arr.length <= 1) return defaultValue; arr = arr[1].split("&"); for (var i = 0; i < arr.length; i++) { if (arr[i].indexOf(findParam) == 0 && arr[i].indexOf("=") == findParam.length) { arr = arr[i].split("="); return arr[1]; } } return defaultValue; } //----------------- // validateNumber function validateNumber(strNum) { strNum = strNum.replace(/,/, "."); return parseFloat (strNum); } //******************************************** //---------- // DrawPolyLButtonDown //---------- function DrawPolyLButtonDown(Flags, X, Y) { var CursorCoord = SGWorld.Window.pixelToWorld(X, Y); if (CursorCoord == null) return false; if (gPolyObj == null) { // We always start with a polyline and change it to Polygon (for area) after the second click) var myGeometry = SGWorld.Creator.GeometryCreator.CreateLineStringGeometry([CursorCoord.Position.x, CursorCoord.Position.y, 0, CursorCoord.Position.x, CursorCoord.Position.y, 0]) gPolyObj = SGWorld.Creator.createPolyline(myGeometry, SGWorld.Creator.CreateColor(0, 255, 0, 1), 2, -1, gPolylineText); gPolyObj.LineStyle.Width = -2; gPolyObj.Geometry.StartEdit(); } else { if (gPolyMethod == 2) // Polygon { if (gPolyObj.ObjectType == 1) { // Deleting the temporary line var x = gPolyObj.Geometry.Points.Item(0).X; var y = gPolyObj.Geometry.Points.Item(0).Y; SGWorld.Creator.DeleteObject(gPolyObj.ID); // Creating the polygon var myGeometry = SGWorld.Creator.GeometryCreator.CreateLinearRingGeometry([x, y, 0, CursorCoord.Position.x, CursorCoord.Position.y, 0, CursorCoord.Position.x, CursorCoord.Position.y, 0]) gPolyObj = SGWorld.Creator.createPolygon(myGeometry, SGWorld.Creator.CreateColor(0, 255, 0, 1), SGWorld.Creator.CreateColor(0, 255, 0, 0.5), 2, -1, gPolygonText); gPolyObj.LineStyle.Width = -2; gPolyObj.Terrain.GroundObject = true; gPolyObj.Geometry.StartEdit(); } else { gPolyObj.Geometry.Rings(0).Points.Item(gPolyObj.Geometry.Rings(0).Points.count - 1).X = CursorCoord.Position.x; gPolyObj.Geometry.Rings(0).Points.Item(gPolyObj.Geometry.Rings(0).Points.count - 1).Y = CursorCoord.Position.y; gPolyObj.Geometry.Rings(0).Points.Item(gPolyObj.Geometry.Rings(0).Points.count - 1).Z = 0; gPolyObj.Geometry.Rings(0).Points.AddPoint(CursorCoord.Position.x, CursorCoord.Position.y, 0); } } else { gPolyObj.Geometry.Points.Item(gPolyObj.Geometry.Points.count - 1).X = CursorCoord.Position.x; gPolyObj.Geometry.Points.Item(gPolyObj.Geometry.Points.count - 1).Y = CursorCoord.Position.y; gPolyObj.Geometry.Points.Item(gPolyObj.Geometry.Points.count - 1).Z = 0; gPolyObj.Geometry.Points.AddPoint(CursorCoord.Position.x, CursorCoord.Position.y, 0); } } if (gDrawPolyClick != null) gDrawPolyClick(gPolyObj.Geometry, gPolyObj.ObjectType); return true; } //----------- // onFrame //----------- function DrawPolyOnFrame() { if (gPolyObj != null) { try { var mouseInfo = SGWorld.Window.GetMouseInfo() var CursorCoord = SGWorld.Window.pixelToWorld(mouseInfo.X, mouseInfo.Y); if (CursorCoord == null) return false; if (gPolyObj.ObjectType == 2) { gPolyObj.Geometry.Rings(0).Points.Item(gPolyObj.Geometry.Rings(0).Points.count - 1).X = CursorCoord.Position.x; gPolyObj.Geometry.Rings(0).Points.Item(gPolyObj.Geometry.Rings(0).Points.count - 1).Y = CursorCoord.Position.y; gPolyObj.Geometry.Rings(0).Points.Item(gPolyObj.Geometry.Rings(0).Points.count - 1).Z = 0; } else { gPolyObj.Geometry.Points.Item(gPolyObj.Geometry.Points.count - 1).X = CursorCoord.Position.x; gPolyObj.Geometry.Points.Item(gPolyObj.Geometry.Points.count - 1).Y = CursorCoord.Position.y; gPolyObj.Geometry.Points.Item(gPolyObj.Geometry.Points.count - 1).Z = 0; } } catch (e) { } } } //------------- //DrawPolyInputModeChanged function DrawPolyInputModeChanged(NewMode) { if (NewMode != 1) if (gPolyObj != null) Reset(0, 1); } //------------- // DrawPolyRButtonUp function DrawPolyRButtonUp(Flags, X, Y) { if (gPolyObj == null || ((gPolyObj.ObjectType == 1 && gPolyObj.Geometry.Points.count <= 2) || (gPolyObj.ObjectType == 2 && gPolyObj.Geometry.Rings(0).Points.count <= 3))) { Reset(0, 0); return false; } if (gPolyObj.ObjectType == 1) gPolyObj.Geometry.Points.DeletePoint(gPolyObj.Geometry.Points.count - 1); else gPolyObj.Geometry.Rings(0).Points.DeletePoint(gPolyObj.Geometry.Rings(0).Points.count - 1); gPolyObj.Geometry.EndEdit(); gEndDrawPoly(gPolyObj.Geometry, gPolyObj.ObjectType, null); Reset(0, 0); return true; } //------------------- //searchGeometries function searchGeometries2(parentNode, callbackFunc) { SGWorld.ProjectTree.EnableRedraw(0); searchGeometriesLeaf2(parentNode, callbackFunc); SGWorld.ProjectTree.EnableRedraw(1); } //------------------- // searchGeometries function searchGeometriesLeaf2(parentNode, callbackFunc) { if (SGWorld.ProjectTree.IsLayer(parentNode)) // Layer { var layer = SGWorld.ProjectTree.GetLayer(parentNode); var featureGroups = layer.FeatureGroups; for (var i = 0; i < featureGroups.Count; i++) // Traverse all sub-layers { var featureGroup = featureGroups.Item(i); var altitudeType = featureGroup.GetProperty("Altitude Method") for (var j = 0; j < featureGroup.Count; j++) { var ret = callbackFunc(featureGroup.Item(j).Geometry, featureGroup.GeometryType, altitudeType); if (!ret) return; } } } else { var node = SGWorld.ProjectTree.GetNextItem(parentNode, 11); while (node != -1 && node != 0) { if (SGWorld.ProjectTree.IsGroup(node) || SGWorld.ProjectTree.IsLayer(node)) searchGeometriesLeaf2(node, callbackFunc); else { var Object = SGWorld.ProjectTree.GetObject(node); if (Object != null) { var altitudeType = Object.Position.AltitudeType; var ret = callbackFunc(Object.Geometry, Object.ObjectType, altitudeType); if (!ret) return; } } node = SGWorld.ProjectTree.GetNextItem(node, 13); } } }