missioncommand / mil-sym-js

(RETIRED) MIL-STD-2525 symbol rendering JavaScript library for modern web applications
Apache License 2.0
76 stars 25 forks source link

Missed armyc2.c2sd.renderer.utilities.GeoPixelConversion3D implementation #33

Closed ComBatVision closed 5 years ago

ComBatVision commented 5 years ago

Hello! Mil-sym-js module is missing armyc2.c2sd.renderer.utilities.GeoPixelConversion3D implementation from original Java code, which is very suitable to integrate mil-sym-js with WorldWindWeb GIS.

Could you, please, add this implementation to official release?

Code is taken from Java version of library.

  armyc2.c2sd.renderer.utilities.GeoPixelConversion3D = function() {};

  const pc = armyc2.c2sd.renderer.utilities.GeoPixelConversion3D;

  pc.inchPerMeter = 39.3700787;
  pc.pixelsPerInch = 96 ;
  pc.METERS_PER_DEG = 111319.49079327357264771338267056;

  pc.metersPerPixel = (scale: number): number => {
    const step1: number = scale / pc.pixelsPerInch;
    return step1 / pc.inchPerMeter;
  };

  pc.lat2y = (latitude: number, scale: number, latOrigin: number, metPerPix: number): number => {
    const latRem: number = Math.abs(latitude - latOrigin);
    let pixDis = 0;
    if (latRem > 0) {
      pixDis = latRem * pc.METERS_PER_DEG / metPerPix;
      if (latitude > latOrigin) {
        pixDis = -pixDis;
      }
    }
    return pixDis;
  };

  pc.y2lat = (yPosition: number, scale: number, latOrigin: number, metPerPix: number): number => {
    let latitude: number = latOrigin;
    if (yPosition !== 0) {
      latitude  = latOrigin - ((yPosition * metPerPix) / pc.METERS_PER_DEG) ;
    }
    return latitude;
  };

  pc.long2x = (longitude: number, scale: number, longOrigin: number, latitude: number, metPerPix: number): number => {
    const longRem: number = Math.abs(longitude - longOrigin);
    const metersPerDeg: number = pc.GetMetersPerDegAtLat(latitude);
    let pixDis = 0;
    if (longRem > 0) {
      pixDis = (longRem * metersPerDeg) / metPerPix;
      if (longitude < longOrigin) {
        pixDis = -pixDis;
      }
    }
    return pixDis;
  };

  pc.x2long = (xPosition: number, scale: number, longOrigin: number, latitude: number, metPerPix: number): number => {
    const metersPerDeg = pc.GetMetersPerDegAtLat(latitude);
    let longitude  = longOrigin;
    if (xPosition !== 0) {
      longitude = longOrigin + ((xPosition * metPerPix)  / metersPerDeg) ;
    }
    return longitude;
  };

  pc.Deg2Rad = (deg: number): number => {
    const conv_factor: number = (2.0 * Math.PI) / 360.0;
    return(deg * conv_factor);
  };

  pc.GetMetersPerDegAtLat = (lat: number): number => {
    // Convert latitude to radians
    lat = pc.Deg2Rad(lat);
    // Set up 'Constants'
    const p1 = 111412.84;       // longitude calculation term 1
    const p2 = -93.5;             // longitude calculation term 2
    const p3 = 0.118;             // longitude calculation term 3
    // Calculate the length of a degree of longitude in meters at given latitude
    return (p1 * Math.cos(lat)) + (p2 * Math.cos(3 * lat)) + (p3 * Math.cos(5 * lat));
  };
michael-spinelli commented 5 years ago

Looks like it already exists but wasn't being added into the release as part of the build script. I'll go ahead and fix that.

michael-spinelli commented 5 years ago

fixed in release v0.3.35

ComBatVision commented 5 years ago

Problem was not solved. Or there is related problem exists.

I am debugging the situation now.

Function GeoPixelConversion3D is present in build, but renderer fails to find Deg2Rad function in some cases.

I will tell result when will understand the reason.

clsUtility PointPixelsToLatLong
Severe: ReferenceError: Deg2Rad is not defined - Could not convert point to geo sm-bc.js:97230:21
LogException sm-bc.js:97230
PointPixelsToLatLong sm-bc.js:121050
PixelsToLatLong sm-bc.js:120713
FilterPoints2 sm-bc.js:122222
render_GE sm-bc.js:118995
renderWithPolylines sm-bc.js:118904 

Знімок екрану з 2019-03-15 17-21-38

ComBatVision commented 5 years ago

Could you please add "this." in line:

GetMetersPerDegAtLat: function(lat) {
        // Convert latitude to radians
        lat = Deg2Rad(lat);

Also could you replace in two places of the same file: armyc2.c2sd.renderer.utilities.GeoPixelConversion3D.GetMetersPerDegAtLat(latitude); to: this.GetMetersPerDegAtLat(latitude);

Thanks!

Знімок екрану з 2019-03-15 17-51-38

michael-spinelli commented 5 years ago

sm-bc.zip

michael-spinelli commented 5 years ago

Ok, checked in changes for GeoPixelConversion3D. let me know.

ComBatVision commented 5 years ago

Thanks. It works OK now. You may release.