Skip to content
This repository
Browse code

fix #103 Added Lambert Conformal Conic Projection

  • Loading branch information...
commit 6dd2cc6a1e4c0c4b012d09fc76d0dbdc9c206d6b 1 parent a0a7330
Kirill Lebedev authored

Showing 2 changed files with 30 additions and 3 deletions. Show diff stats Hide diff stats

  1. +29 3 lib/proj.js
  2. +1 0  lib/world-map.js
32 lib/proj.js
@@ -41,8 +41,8 @@ jvm.Proj = {
41 41 aea: function(lat, lng, c){
42 42 var fi0 = 0,
43 43 lambda0 = c / 180 * Math.PI,
44   - fi1 = 45.5 / 180 * Math.PI,
45   - fi2 = 29.5 / 180 * Math.PI,
  44 + fi1 = 29.5 / 180 * Math.PI,
  45 + fi2 = 45.5 / 180 * Math.PI,
46 46 fi = lat / 180 * Math.PI,
47 47 lambda = lng / 180 * Math.PI ,
48 48 n = (Math.sin(fi1)+Math.sin(fi2)) / 2,
@@ -52,8 +52,34 @@ jvm.Proj = {
52 52 ro0 = Math.sqrt(C-2*n*Math.sin(fi0))/n;
53 53
54 54 return {
55   - x: ro*Math.sin(theta) / (2 * Math.PI) * jvm.WorldMap.circumference,
  55 + x: ro * Math.sin(theta) / (2 * Math.PI) * jvm.WorldMap.circumference,
56 56 y: - (ro0 - ro * Math.cos(theta)) / (2 * Math.PI) * jvm.WorldMap.circumference
57 57 }
  58 + },
  59 +
  60 + /**
  61 + * Converts point on sphere to the Cartesian coordinates using Lambert conformal
  62 + * conic projection
  63 + * @see <a href="http://mathworld.wolfram.com/LambertConformalConicProjection.html">Lambert Conformal Conic Projection</a>
  64 + * @param {Number} lat Latitude in degrees
  65 + * @param {Number} lng Longitude in degrees
  66 + * @param {Number} c Central meridian in degrees
  67 + */
  68 + lcc: function(lat, lng, c){
  69 + var fi0 = 0,
  70 + lambda0 = c / 180 * Math.PI,
  71 + lambda = lng / 180 * Math.PI,
  72 + fi1 = 33 / 180 * Math.PI,
  73 + fi2 = 45 / 180 * Math.PI,
  74 + fi = lat / 180 * Math.PI
  75 + n = Math.log( Math.cos(fi1) * (1 / Math.cos(fi2)) ) / Math.log( Math.tan( Math.PI / 4 + fi2 / 2) * (1 / Math.tan( Math.PI / 4 + fi1 / 2) ) ),
  76 + F = ( Math.cos(fi1) * Math.pow( Math.tan( Math.PI / 4 + fi1 / 2 ), n ) ) / n,
  77 + ro = F * Math.pow( 1 / Math.tan( Math.PI / 4 + fi / 2 ), n ),
  78 + ro0 = F * Math.pow( 1 / Math.tan( Math.PI / 4 + fi0 / 2 ), n );
  79 +
  80 + return {
  81 + x: ro * Math.sin( n * (lambda - lambda0) ) / (2 * Math.PI) * jvm.WorldMap.circumference,
  82 + y: - (ro0 - ro * Math.cos( n * (lambda - lambda0) ) ) / (2 * Math.PI) * jvm.WorldMap.circumference
  83 + }
58 84 }
59 85 };
1  lib/world-map.js
@@ -762,6 +762,7 @@ jvm.WorldMap.prototype = {
762 762 }
763 763
764 764 point = jvm.Proj[proj.type](lat, lng, centralMeridian);
  765 + console.log(point);
765 766
766 767 inset = this.getInsetForPoint(point.x, point.y);
767 768 if (inset) {

0 comments on commit 6dd2cc6

Please sign in to comment.
Something went wrong with that request. Please try again.