Skip to content

Commit

Permalink
-updated web worker samples
Browse files Browse the repository at this point in the history
-cleaned up MPWorker.js and multiPointTesterWebWorker.html
  • Loading branch information
Spinelli committed Oct 21, 2016
1 parent 01a34da commit 90049f9
Show file tree
Hide file tree
Showing 5 changed files with 310 additions and 376 deletions.
49 changes: 33 additions & 16 deletions web/js/src/MPWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ var e.data = {};
e.data.name = "Name";
e.data.description = "description";
e.data.symbolID = "SFGPU----------";//A 15 character symbolID corresponding to one of the graphics in the MIL-STD-2525C
e.data.points = controlPoints4;
e.data.points = controlPoints4;//like "66.26700036208742,30.62755038706961 66.27555681517738,30.64727776502703 66.25654247497746,30.64632704801704","x1,y1[,z1] [xn,yn[,zn]]...".
e.data.altMode = "absolute";//for 3D
e.data.scale = scale4;//for 3D
e.data.bbox = bbox4;
e.data.scale = scale4;//for 3D like 50000.0; a number corresponding to how many meters one meter of our map represents. A value "50000" would mean 1:50K which means for every meter of our map it represents 50000 meters of real world distance.
e.data.bbox = bbox4;//like "66.25,30.60,66.28,30.65";"lowerLeftX,lowerLeftY,upperRightX,upperRightY."
e.data.modifiers = modifiers;
e.data.format = format;
e.data.format = format;//0 for KML, 2 for GeoJSON, 6 for GeoSVG
e.data.pHeight = pixelHeight;//for 2D
e.data.pWidth = pixelWidth;//for 2D
e.data.converter l converter for canvas or datauri format
e.data.fontInfo
e.data.converter = {} optional converter object for custom geoToPixel Conversion
e.data.fontInfo = {} required for SVG format only. Get from RendererSettings.getMPFontInfo();
*/

/* return object for KML or GeoJSON
Expand All @@ -35,23 +35,29 @@ var e.data = {};
/* expected input format for batch
var e.data = {};
e.data.altMode = "absolute";//for 3D
e.data.scale = scale4;//for 3D
e.data.bbox = bbox4;
e.data.format = format
e.data.scale = scale4;//for 3D like 50000.0; a number corresponding to how many meters one meter of our map represents. A value "50000" would mean 1:50K which means for every meter of our map it represents 50000 meters of real world distance.
e.data.bbox = bbox4;//like "66.25,30.60,66.28,30.65";"lowerLeftX,lowerLeftY,upperRightX,upperRightY."
e.data.format = format;//0 for KML, 2 for GeoJSON, 6 for GeoSVG
e.data.pHeight = pixelHeight;//for 2D
e.data.pWidth = pixelWidth;//for 2D
e.data.converter = optional converter for SVG format
e.data.fontInfo = fontInfo//for SVG
e.data.converter = {} optional converter object for custom geoToPixel Conversion
e.data.fontInfo = {} required for SVG format only. Get from RendererSettings.getMPFontInfo();
e.data.batch = [{id:"ID",name:"name",description:"description",symbolID:"GFTPL-----****X",points:controlPoints,symStd:symStd,modifiers:{ModifiersTG.T_UNIQUE_DESIGNATION_1:"T",MilStdAttributes.LineColor:"#00FF00"}}];
*/

/* return object for batch
/* return objects for batch
{
//KML
[{id:batch.id,symbolID:symbolID,kml:"kml string"}]
//GeoJSON
[{id:batch.id,symbolID:symbolID,geojson:"geojson string"]
//SVG
[{id:batch.id,symbolID:symbolID,svg:dataURI,geoTL:geoCoordTL, geoBR:geoCoordBR, wasClipped:wasClipped}]
}
*/


//GeoCanvas doesn't work in a web worker due to its need for the DOM.
importScripts('m-c.js');//for strictly KML, GeoJSON and SVG(with hatch line and metoc fills, but no symbol fills)
//importScripts('svm-bc.js');//for strictly KML, GeoJSON and SVG(with hatch line and metoc fills, and symbol fills)
Expand Down Expand Up @@ -100,6 +106,7 @@ onmessage = function(e)
var output = null;
var converter = null;
var fontInfo = null;
var format = ["kml","json","geojson","","","","svg","svg"];

if(e.data.fontInfo !== null)
fontInfo = e.data.fontInfo;
Expand All @@ -109,6 +116,7 @@ onmessage = function(e)
var result = null;
var len = e.data.batch.length;
var items = e.data.batch;
var temp = null;
//output = new Array(len);
output = [];
try
Expand All @@ -130,10 +138,19 @@ onmessage = function(e)
}
if(result)
{
result.id = item.id;
result.symbolID = item.symbolID;
//output[i] = result;
output.push(result);
if(e.data.format === 6 || e.data.format === 7)//SVG
{
result.id = item.id;
result.symbolID = item.symbolID;
//output[i] = result;
output.push(result);
}
else//KML or GeoJSON return string
{
temp = {id:item.id, symbolID:item.symbolID}
temp[format[e.data.format]] = result;
output.push(temp);
}
}
}
}
Expand Down
59 changes: 40 additions & 19 deletions web/samples/multiPointTester1.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!-- Meta line required for IE-->
<!-- <meta http-equiv="X-UA-Compatible" content="IE=edge" /> -->

<script src="sm-bc.min.js" type="text/javascript" ></script>
<script src="sm-c.js" type="text/javascript" ></script>


<script type = "text/javascript">
Expand Down Expand Up @@ -48,40 +48,43 @@
//var rendererMP = new sec.web.renderer.SECWebRenderer();
var rendererMP = sec.web.renderer.SECWebRenderer;

if (rendererMP !== null) {
if (rendererMP !== null)
{

/*var foo = new java.lang.StringBuilder("test");
foo.append("ing");
console.log(foo);
console.log(foo.toString());*/


armyc2.c2sd.renderer.utilities.ErrorLogger.LogMessage("multiPoints3.html","testRender","AMBUSH");
armyc2.c2sd.renderer.utilities.ErrorLogger.LogMessage("multiPoints3.html","testRender","AMBUSH");
var modifiers = "";
//AMBUSH EXAMPLE
var symbolCode = "GHGPSLA-------X";//ambush
//var symbolCode = "GHGPGAA-------X"; //assembly area
var controlPoints = "66.26700036208742,30.62755038706961 66.27555681517738,30.64727776502703 66.25654247497746,30.64632704801704";
//var controlPoints = "66.26700036208742,30.62755038706961 66.27555681517738,30.64727776502703 66.25654247497746,30.64632704801704";
var controlPoints = "66.27555681517738,30.64727776502703 66.25654247497746,30.64632704801704 66.26700036208742,30.62755038706961";

//var bbox = "66.25,30.60,66.28,30.65";
var bbox = "66.25,30.60,66.28,30.65";
//var bbox = "-180.0,-90.0,180.0,90.0";
var scale = 50000.0;
var scale = 500000.0;

var formatJSON = 1;
var formatGeoSVG = 6;
var formatGeoCanvas = 3;
var formatGeoJSON = 2;
var formatKML = 0;
var pixelWidth = 800;
var pixelHeight = 600;

//change this to format JSON to see the different output.
//var format = formatJSON;
var format = formatKML;
//var format = formatGeoJSON;
//var format = formatKML;
var format = formatGeoCanvas;
//var format = formatGeoSVG;


//Not meant to be changed on the fly.
//Let's user choose between 2525Bch2 and 2525C.
var ms2525Bch2 = 0;
var ms2525C = 1;
var symStd = ms2525Bch2;
var symStd = ms2525C;
rendererMP.setDefaultSymbologyStandard(symStd);

//RenderSymbol2D recommended for 2D maps. KML or JSON format will work.
Expand All @@ -107,14 +110,31 @@

document.getElementById("contentSpan").innerHTML = "<br />AMBUSH: <br/>";

if(format == formatJSON)
if(format == formatGeoJSON)
{
document.getElementById("contentSpan").innerHTML += "JSON Format:<br/>";
if (json == null || json == "")
document.getElementById("contentSpan").innerHTML += "json empty";
else
document.getElementById("contentSpan").innerHTML += json;
}
else if(format === formatGeoCanvas)
{
var geoCanvas = json.image;//sec.web.renderer.MultiPointHandler.RenderShapeInfoToCanvas(json.paths, json.textInfos, json.bounds, json.geoTL, json.geoBR);
var preview = document.getElementById("preview");
preview.width = geoCanvas.width;
preview.height = geoCanvas.height;
var ctx = preview.getContext('2d');
ctx.drawImage(geoCanvas,0,0);
}
else if(format === formatGeoSVG || format === 7)
{ //return {svg:geoSVG, geoTL:geoCoordTL, geoBR:geoCoordBR, wasClipped:wasClipped};
var svg = json.svg;
var svgImage = document.getElementById("preview2");
svgImage.width = json.bounds.getWidth();
svgImage.height = json.bounds.getHeight();
svgImage.src = svg;
}
else// if formated as KML
{
document.getElementById("contentSpan").innerHTML += "KML Format:<br/>";
Expand Down Expand Up @@ -171,7 +191,7 @@

document.getElementById("contentSpan").innerHTML += "<br/><br/>Assembly Area: <br/>";

if(format == formatJSON)
if(format == formatGeoJSON)
{
document.getElementById("contentSpan").innerHTML += "JSON Format:<br/>";
if (json2 == null || json2 == "")
Expand Down Expand Up @@ -232,7 +252,7 @@
var timeSRF = (stop-start)/1000;
document.getElementById("contentSpan").innerHTML += "<br/><br/>Sector Range Fan: <br/>";

if(format == formatJSON)
if(format == formatGeoJSON)
{
document.getElementById("contentSpan").innerHTML += "JSON Format:<br/>";
if (json3 == null || json3 == "")
Expand Down Expand Up @@ -295,7 +315,7 @@
console.log('Render 1k symbols: ' + (time/1000));
document.getElementById("contentSpan").innerHTML += "<br/><br/>FLOT: <br/>";

if(format === formatJSON)
if(format === formatGeoJSON)
{
document.getElementById("contentSpan").innerHTML += "JSON Format:<br/>";
if (json4 === null || json4 === "")
Expand Down Expand Up @@ -349,8 +369,9 @@

</script>
</head>
<body>

<body bgcolor="Cyan">
Draw To Canvas Test:
<canvas id="preview" width="30" height="30"></canvas><img id="preview2" src="" alt="" height="30" width="30"><br>
<button type='button' onclick='testRender()'>Test Multipoint</button>
<button type='button' onclick='cleartext()'>Clear</button>

Expand Down
Loading

0 comments on commit 90049f9

Please sign in to comment.