1 line
16 KiB
Plaintext
1 line
16 KiB
Plaintext
{"version":3,"sources":["geojson-utils/pre.js","geojson-utils/geojson-utils.js","geojson-utils/post.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gF;AACA,2E;AACA,sB;;;;;;;;;;;;;;;;;;;;ACFA,c;AACA,e;;AAEA,+C;AACA,wD;AACA,yB;AACA,G;;AAEA,gF;AACA,gD;AACA,wB;AACA,0D;AACA,4D;AACA,kB;AACA,kC;AACA,iC;AACA,U;AACA,gB;AACA,wC;AACA,uC;AACA,Y;AACA,gB;AACA,oC;AACA,mC;AACA,Y;AACA,gB;AACA,wC;AACA,uC;AACA,Y;AACA,+E;AACA,+E;AACA,8E;AACA,uB;AACA,8B;AACA,4B;AACA,yD;AACA,6B;AACA,8B;AACA,mF;AACA,e;AACA,W;AACA,S;AACA,O;AACA,K;AACA,mD;AACA,sB;AACA,G;;AAEA,iB;;AAEA,iD;AACA,4B;;AAEA,gD;AACA,gC;AACA,gC;AACA,K;;AAEA,qD;AACA,qD;;AAEA,iF;AACA,G;;AAEA,qD;AACA,uK;AACA,G;;AAEA,qB;AACA,gG;;AAEA,gC;AACA,wB;;AAEA,6C;AACA,kD;AACA,+B;AACA,O;AACA,sB;AACA,K;;AAEA,sB;AACA,oE;AACA,iK;AACA,K;;AAEA,iB;AACA,G;;AAEA,2C;AACA,mF;;AAEA,yB;AACA,6C;AACA,6F;AACA,K;AACA,gC;;AAEA,0B;AACA,6C;AACA,kF;AACA,K;;AAEA,qB;AACA,G;;AAEA,0C;AACA,kC;AACA,G;;AAEA,0C;AACA,kC;AACA,G;;AAEA,sC;AACA,kE;AACA,0E;AACA,4C;AACA,kC;AACA,iF;AACA,0B;AACA,wB;AACA,sC;AACA,qC;AACA,yC;AACA,iE;AACA,0E;AACA,mG;AACA,mG;AACA,mB;AACA,2C;AACA,2C;AACA,K;AACA,Y;AACA,wB;AACA,2B;AACA,M;AACA,G;;AAEA,iD;AACA,gD;AACA,wC;AACA,0B;AACA,wB;AACA,wB;AACA,wB;AACA,6B;AACA,6B;AACA,Y;AACA,sB;AACA,2D;AACA,M;AACA,G;;AAEA,4D;AACA,2C;AACA,kC;AACA,gC;AACA,gC;AACA,gC;AACA,6C;AACA,6C;AACA,8E;AACA,+E;AACA,yD;AACA,8B;AACA,+C;AACA,I;;AAEA,qD;AACA,0C;AACA,kE;AACA,mC;AACA,2D;AACA,6E;AACA,qB;AACA,sB;AACA,uC;AACA,gE;AACA,8C;AACA,c;AACA,2C;AACA,O;AACA,kC;AACA,2C;AACA,wD;AACA,uB;AACA,S;AACA,O;AACA,K;AACA,gB;AACA,G;;AAEA,wE;AACA,iC;AACA,iB;AACA,4C;AACA,wC;AACA,8B;AACA,e;;AAEA,iD;AACA,gB;AACA,wB;AACA,uB;AACA,Q;AACA,gB;AACA,wB;AACA,uB;AACA,Q;AACA,0B;AACA,0B;AACA,K;;AAEA,c;AACA,gB;AACA,I;;AAEA,wE;AACA,qC;AACA,iB;AACA,Y;AACA,4C;AACA,wC;AACA,8B;AACA,e;;AAEA,iD;AACA,gB;AACA,wB;AACA,uB;AACA,Q;AACA,gB;AACA,wB;AACA,uB;AACA,Q;AACA,oC;AACA,6B;AACA,6B;AACA,K;;AAEA,8B;AACA,Y;AACA,sB;AACA,mC;AACA,M;AACA,I;;AAEA,iF;AACA,sD;AACA,0G;AACA,sB;AACA,sC;AACA,c;AACA,8B;AACA,6B;AACA,O;AACA,O;;AAEA,sD;AACA,uC;AACA,oD;AACA,oC;AACA,kG;AACA,gF;AACA,8B;;AAEA,gC;;AAEA,mE;;AAEA,6C;;AAEA,6B;AACA,+E;AACA,yB;AACA,e;AACA,qB;AACA,8B;AACA,gB;;AAEA,2C;AACA,yB;;AAEA,uD;;AAEA,qC;AACA,iC;AACA,gB;;AAEA,8D;;AAEA,8D;AACA,yD;;AAEA,wD;AACA,wD;AACA,+D;AACA,uG;AACA,wC;;AAEA,4E;;AAEA,sD;AACA,sD;AACA,iE;AACA,uE;AACA,0C;;AAEA,oD;AACA,oD;AACA,iE;AACA,qE;AACA,0C;;AAEA,gD;AACA,qD;AACA,mG;AACA,sC;AACA,oB;AACA,kC;AACA,W;AACA,S;;AAEA,gF;AACA,uD;AACA,gC;AACA,mB;AACA,wF;AACA,oB;AACA,uC;AACA,qC;AACA,oB;AACA,yC;AACA,qC;AACA,S;AACA,gF;AACA,8B;AACA,iB;AACA,O;AACA,K;;AAEA,6B;AACA,iC;AACA,a;;AAEA,2B;AACA,wB;AACA,oC;AACA,+B;;AAEA,+B;AACA,c;AACA,sB;AACA,mC;AACA,O;AACA,O;AACA,G;;AAEA,iE;AACA,oD;AACA,qE;AACA,oC;;AAEA,qD;AACA,qD;;AAEA,yD;AACA,yE;AACA,8E;AACA,+E;AACA,iF;;AAEA,Y;AACA,sB;AACA,yE;AACA,M;AACA,I;;AAEA,K;;;;;;;;;;;;;;;;;;;AC3XA,4E;AACA,8E;AACA,yB","file":"/packages/geojson-utils.js","sourcesContent":["// Define an object named exports. This will cause geojson-utils.js to put `gju`\n// as a field on it, instead of in the global namespace. See also post.js.\nmodule = {exports:{}};\n\n","(function () {\n var gju = {};\n\n // Export the geojson object for **CommonJS**\n if (typeof module !== 'undefined' && module.exports) {\n module.exports = gju;\n }\n\n // adapted from http://www.kevlindev.com/gui/math/intersection/Intersection.js\n gju.lineStringsIntersect = function (l1, l2) {\n var intersects = [];\n for (var i = 0; i <= l1.coordinates.length - 2; ++i) {\n for (var j = 0; j <= l2.coordinates.length - 2; ++j) {\n var a1 = {\n x: l1.coordinates[i][1],\n y: l1.coordinates[i][0]\n },\n a2 = {\n x: l1.coordinates[i + 1][1],\n y: l1.coordinates[i + 1][0]\n },\n b1 = {\n x: l2.coordinates[j][1],\n y: l2.coordinates[j][0]\n },\n b2 = {\n x: l2.coordinates[j + 1][1],\n y: l2.coordinates[j + 1][0]\n },\n ua_t = (b2.x - b1.x) * (a1.y - b1.y) - (b2.y - b1.y) * (a1.x - b1.x),\n ub_t = (a2.x - a1.x) * (a1.y - b1.y) - (a2.y - a1.y) * (a1.x - b1.x),\n u_b = (b2.y - b1.y) * (a2.x - a1.x) - (b2.x - b1.x) * (a2.y - a1.y);\n if (u_b != 0) {\n var ua = ua_t / u_b,\n ub = ub_t / u_b;\n if (0 <= ua && ua <= 1 && 0 <= ub && ub <= 1) {\n intersects.push({\n 'type': 'Point',\n 'coordinates': [a1.x + ua * (a2.x - a1.x), a1.y + ua * (a2.y - a1.y)]\n });\n }\n }\n }\n }\n if (intersects.length == 0) intersects = false;\n return intersects;\n }\n\n // Bounding Box\n\n function boundingBoxAroundPolyCoords (coords) {\n var xAll = [], yAll = []\n\n for (var i = 0; i < coords[0].length; i++) {\n xAll.push(coords[0][i][1])\n yAll.push(coords[0][i][0])\n }\n\n xAll = xAll.sort(function (a,b) { return a - b })\n yAll = yAll.sort(function (a,b) { return a - b })\n\n return [ [xAll[0], yAll[0]], [xAll[xAll.length - 1], yAll[yAll.length - 1]] ]\n }\n\n gju.pointInBoundingBox = function (point, bounds) {\n return !(point.coordinates[1] < bounds[0][0] || point.coordinates[1] > bounds[1][0] || point.coordinates[0] < bounds[0][1] || point.coordinates[0] > bounds[1][1]) \n }\n\n // Point in Polygon\n // http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html#Listing the Vertices\n\n function pnpoly (x,y,coords) {\n var vert = [ [0,0] ]\n\n for (var i = 0; i < coords.length; i++) {\n for (var j = 0; j < coords[i].length; j++) {\n vert.push(coords[i][j])\n }\n vert.push([0,0])\n }\n\n var inside = false\n for (var i = 0, j = vert.length - 1; i < vert.length; j = i++) {\n if (((vert[i][0] > y) != (vert[j][0] > y)) && (x < (vert[j][1] - vert[i][1]) * (y - vert[i][0]) / (vert[j][0] - vert[i][0]) + vert[i][1])) inside = !inside\n }\n\n return inside\n }\n\n gju.pointInPolygon = function (p, poly) {\n var coords = (poly.type == \"Polygon\") ? [ poly.coordinates ] : poly.coordinates\n\n var insideBox = false\n for (var i = 0; i < coords.length; i++) {\n if (gju.pointInBoundingBox(p, boundingBoxAroundPolyCoords(coords[i]))) insideBox = true\n }\n if (!insideBox) return false\n\n var insidePoly = false\n for (var i = 0; i < coords.length; i++) {\n if (pnpoly(p.coordinates[1], p.coordinates[0], coords[i])) insidePoly = true\n }\n\n return insidePoly\n }\n\n gju.numberToRadius = function (number) {\n return number * Math.PI / 180;\n }\n\n gju.numberToDegree = function (number) {\n return number * 180 / Math.PI;\n }\n\n // written with help from @tautologe\n gju.drawCircle = function (radiusInMeters, centerPoint, steps) {\n var center = [centerPoint.coordinates[1], centerPoint.coordinates[0]],\n dist = (radiusInMeters / 1000) / 6371,\n // convert meters to radiant\n radCenter = [gju.numberToRadius(center[0]), gju.numberToRadius(center[1])],\n steps = steps || 15,\n // 15 sided circle\n poly = [[center[0], center[1]]];\n for (var i = 0; i < steps; i++) {\n var brng = 2 * Math.PI * i / steps;\n var lat = Math.asin(Math.sin(radCenter[0]) * Math.cos(dist)\n + Math.cos(radCenter[0]) * Math.sin(dist) * Math.cos(brng));\n var lng = radCenter[1] + Math.atan2(Math.sin(brng) * Math.sin(dist) * Math.cos(radCenter[0]),\n Math.cos(dist) - Math.sin(radCenter[0]) * Math.sin(lat));\n poly[i] = [];\n poly[i][1] = gju.numberToDegree(lat);\n poly[i][0] = gju.numberToDegree(lng);\n }\n return {\n \"type\": \"Polygon\",\n \"coordinates\": [poly]\n };\n }\n\n // assumes rectangle starts at lower left point\n gju.rectangleCentroid = function (rectangle) {\n var bbox = rectangle.coordinates[0];\n var xmin = bbox[0][0],\n ymin = bbox[0][1],\n xmax = bbox[2][0],\n ymax = bbox[2][1];\n var xwidth = xmax - xmin;\n var ywidth = ymax - ymin;\n return {\n 'type': 'Point',\n 'coordinates': [xmin + xwidth / 2, ymin + ywidth / 2]\n };\n }\n\n // from http://www.movable-type.co.uk/scripts/latlong.html\n gju.pointDistance = function (pt1, pt2) {\n var lon1 = pt1.coordinates[0],\n lat1 = pt1.coordinates[1],\n lon2 = pt2.coordinates[0],\n lat2 = pt2.coordinates[1],\n dLat = gju.numberToRadius(lat2 - lat1),\n dLon = gju.numberToRadius(lon2 - lon1),\n a = Math.pow(Math.sin(dLat / 2), 2) + Math.cos(gju.numberToRadius(lat1))\n * Math.cos(gju.numberToRadius(lat2)) * Math.pow(Math.sin(dLon / 2), 2),\n c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));\n // Earth radius is 6371 km\n return (6371 * c) * 1000; // returns meters\n },\n\n // checks if geometry lies entirely within a circle\n // works with Point, LineString, Polygon\n gju.geometryWithinRadius = function (geometry, center, radius) {\n if (geometry.type == 'Point') {\n return gju.pointDistance(geometry, center) <= radius;\n } else if (geometry.type == 'LineString' || geometry.type == 'Polygon') {\n var point = {};\n var coordinates;\n if (geometry.type == 'Polygon') {\n // it's enough to check the exterior ring of the Polygon\n coordinates = geometry.coordinates[0];\n } else {\n coordinates = geometry.coordinates;\n }\n for (var i in coordinates) {\n point.coordinates = coordinates[i];\n if (gju.pointDistance(point, center) > radius) {\n return false;\n }\n }\n }\n return true;\n }\n\n // adapted from http://paulbourke.net/geometry/polyarea/javascript.txt\n gju.area = function (polygon) {\n var area = 0;\n // TODO: polygon holes at coordinates[1]\n var points = polygon.coordinates[0];\n var j = points.length - 1;\n var p1, p2;\n\n for (var i = 0; i < points.length; j = i++) {\n var p1 = {\n x: points[i][1],\n y: points[i][0]\n };\n var p2 = {\n x: points[j][1],\n y: points[j][0]\n };\n area += p1.x * p2.y;\n area -= p1.y * p2.x;\n }\n\n area /= 2;\n return area;\n },\n\n // adapted from http://paulbourke.net/geometry/polyarea/javascript.txt\n gju.centroid = function (polygon) {\n var f, x = 0,\n y = 0;\n // TODO: polygon holes at coordinates[1]\n var points = polygon.coordinates[0];\n var j = points.length - 1;\n var p1, p2;\n\n for (var i = 0; i < points.length; j = i++) {\n var p1 = {\n x: points[i][1],\n y: points[i][0]\n };\n var p2 = {\n x: points[j][1],\n y: points[j][0]\n };\n f = p1.x * p2.y - p2.x * p1.y;\n x += (p1.x + p2.x) * f;\n y += (p1.y + p2.y) * f;\n }\n\n f = gju.area(polygon) * 6;\n return {\n 'type': 'Point',\n 'coordinates': [y / f, x / f]\n };\n },\n\n gju.simplify = function (source, kink) { /* source[] array of geojson points */\n /* kink\tin metres, kinks above this depth kept */\n /* kink depth is the height of the triangle abc where a-b and b-c are two consecutive line segments */\n kink = kink || 20;\n source = source.map(function (o) {\n return {\n lng: o.coordinates[0],\n lat: o.coordinates[1]\n }\n });\n\n var n_source, n_stack, n_dest, start, end, i, sig;\n var dev_sqr, max_dev_sqr, band_sqr;\n var x12, y12, d12, x13, y13, d13, x23, y23, d23;\n var F = (Math.PI / 180.0) * 0.5;\n var index = new Array(); /* aray of indexes of source points to include in the reduced line */\n var sig_start = new Array(); /* indices of start & end of working section */\n var sig_end = new Array();\n\n /* check for simple cases */\n\n if (source.length < 3) return (source); /* one or two points */\n\n /* more complex case. initialize stack */\n\n n_source = source.length;\n band_sqr = kink * 360.0 / (2.0 * Math.PI * 6378137.0); /* Now in degrees */\n band_sqr *= band_sqr;\n n_dest = 0;\n sig_start[0] = 0;\n sig_end[0] = n_source - 1;\n n_stack = 1;\n\n /* while the stack is not empty ... */\n while (n_stack > 0) {\n\n /* ... pop the top-most entries off the stacks */\n\n start = sig_start[n_stack - 1];\n end = sig_end[n_stack - 1];\n n_stack--;\n\n if ((end - start) > 1) { /* any intermediate points ? */\n\n /* ... yes, so find most deviant intermediate point to\n either side of line joining start & end points */\n\n x12 = (source[end].lng() - source[start].lng());\n y12 = (source[end].lat() - source[start].lat());\n if (Math.abs(x12) > 180.0) x12 = 360.0 - Math.abs(x12);\n x12 *= Math.cos(F * (source[end].lat() + source[start].lat())); /* use avg lat to reduce lng */\n d12 = (x12 * x12) + (y12 * y12);\n\n for (i = start + 1, sig = start, max_dev_sqr = -1.0; i < end; i++) {\n\n x13 = source[i].lng() - source[start].lng();\n y13 = source[i].lat() - source[start].lat();\n if (Math.abs(x13) > 180.0) x13 = 360.0 - Math.abs(x13);\n x13 *= Math.cos(F * (source[i].lat() + source[start].lat()));\n d13 = (x13 * x13) + (y13 * y13);\n\n x23 = source[i].lng() - source[end].lng();\n y23 = source[i].lat() - source[end].lat();\n if (Math.abs(x23) > 180.0) x23 = 360.0 - Math.abs(x23);\n x23 *= Math.cos(F * (source[i].lat() + source[end].lat()));\n d23 = (x23 * x23) + (y23 * y23);\n\n if (d13 >= (d12 + d23)) dev_sqr = d23;\n else if (d23 >= (d12 + d13)) dev_sqr = d13;\n else dev_sqr = (x13 * y12 - y13 * x12) * (x13 * y12 - y13 * x12) / d12; // solve triangle\n if (dev_sqr > max_dev_sqr) {\n sig = i;\n max_dev_sqr = dev_sqr;\n }\n }\n\n if (max_dev_sqr < band_sqr) { /* is there a sig. intermediate point ? */\n /* ... no, so transfer current start point */\n index[n_dest] = start;\n n_dest++;\n } else { /* ... yes, so push two sub-sections on stack for further processing */\n n_stack++;\n sig_start[n_stack - 1] = sig;\n sig_end[n_stack - 1] = end;\n n_stack++;\n sig_start[n_stack - 1] = start;\n sig_end[n_stack - 1] = sig;\n }\n } else { /* ... no intermediate points, so transfer current start point */\n index[n_dest] = start;\n n_dest++;\n }\n }\n\n /* transfer last point */\n index[n_dest] = n_source - 1;\n n_dest++;\n\n /* make return array */\n var r = new Array();\n for (var i = 0; i < n_dest; i++)\n r.push(source[index[i]]);\n\n return r.map(function (o) {\n return {\n type: \"Point\",\n coordinates: [o.lng, o.lat]\n }\n });\n }\n\n // http://www.movable-type.co.uk/scripts/latlong.html#destPoint\n gju.destinationPoint = function (pt, brng, dist) {\n dist = dist/6371; // convert dist to angular distance in radians\n brng = gju.numberToRadius(brng);\n\n var lat1 = gju.numberToRadius(pt.coordinates[0]);\n var lon1 = gju.numberToRadius(pt.coordinates[1]);\n\n var lat2 = Math.asin( Math.sin(lat1)*Math.cos(dist) +\n Math.cos(lat1)*Math.sin(dist)*Math.cos(brng) );\n var lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(dist)*Math.cos(lat1),\n Math.cos(dist)-Math.sin(lat1)*Math.sin(lat2));\n lon2 = (lon2+3*Math.PI) % (2*Math.PI) - Math.PI; // normalise to -180..+180º\n\n return {\n 'type': 'Point',\n 'coordinates': [gju.numberToDegree(lat2), gju.numberToDegree(lon2)]\n };\n };\n\n})();\n","// This exports object was created in pre.js. Now copy the `exports` object\n// from it into the package-scope variable `GeoJSON`, which will get exported.\nGeoJSON = module.exports;\n\n"]} |