- Geospatial Drawing: Draw points, lines, polygons, rectangles, and circles on a map.
- Advanced Visualizations: Create Delaunay triangulations, Voronoi diagrams, convex hulls, and more.
- Grid and Contour Visualization: Render grids, contours, and heatmaps from geospatial data.
- Geospatial Analysis: Perform operations like polygon intersection, point-in-polygon checks, and area calculations.
- Customizable Styling: Customize the appearance of drawn elements with colors, opacity, and stroke weights.
- Integration with Maps: Seamlessly integrate with mapping libraries like Baidu Maps (BMapGL).
npm install rvgeo
Initialize a map using a mapping library like Baidu Maps (BMapGL):
const map = new BMapGL.Map("allmap");
map.centerAndZoom(new BMapGL.Point(-105.7220660521329, 39.0119712026557), 8);
map.enableScrollWheelZoom(true);
Draw multiple points and their centroid on the map:
const points = mockPoints(30, myMBR1); // Generate random points
const multiPoint = new RVGeo.MultiPoint(points);
drawPoint2BLMap(multiPoint.centroid(), map); // Draw centroid
drawMultiPoint2BLMap(multiPoint, map, innerIcon(0)); // Draw points
Visualize a Delaunay triangulation from a set of points:
const delaunay = RVGeo.Delaunator.from(multiPoint.toXY());
const triangles = RVGeo.fillIndexArray(delaunay.getTriangleIndices(), multiPoint.coordinates);
drawTriangleEdge2BLMap(triangles, map, { strokeColor: 'blue' });
Generate and draw a Voronoi diagram:
const voronoi = new RVGeo.Voronoi(delaunay);
const clippedVoronoi = voronoi.cutVoronoiByMBR(myMBR1);
drawEdgeMap2BLMap(clippedVoronoi, map, { strokeColor: "green", strokeWeight: 2, strokeOpacity: 0.5 }, true);
function example1() {
removeAllOverlay(map);
let icon = innerIcon(0);
drawPoint2BLMap(mps.centroid(), map);
drawMultiPoint2BLMap(mps, map, icon);
}
function example2() {
removeAllOverlay(map);
let del = RVGeo.Delaunator.from(mps.toXY());
let trs = RVGeo.fillIndexArray(del.getTriangleIndices(), mps.coordinates);
drawTriangleEdge2BLMap(trs, map, { strokeColor: 'blue' });
}
function example5() {
removeAllOverlay(map);
let voronoi = new RVGeo.Voronoi(delaunay);
let clippedVoronoi = voronoi.cutVoronoiByMBR(myMBR1);
drawEdgeMap2BLMap(clippedVoronoi, map, { strokeColor: "green", strokeWeight: 2, strokeOpacity: 0.5 }, true);
}
drawPoint2BLMap(point, map, options)
: Draw a point on the map.drawMultiPoint2BLMap(multiPoint, map, icon)
: Draw multiple points on the map.drawLineString2BLMap(lineString, map, options)
: Draw a line string on the map.drawPolygon2BLMap(polygon, map, options)
: Draw a polygon on the map.drawTriangleEdge2BLMap(triangles, map, options)
: Draw triangle edges on the map.drawVoronoi2BLMap(voronoi, map, options)
: Draw a Voronoi diagram on the map.
RVGeo.convexHull(points)
: Compute the convex hull of a set of points.RVGeo.intersectionPolygon(polygon1, polygon2)
: Compute the intersection of two polygons.RVGeo.pointInEdge(point, lineStart, lineEnd)
: Check if a point lies on a line segment.
drawGrid2d(canvas, data, rect, statistics, colorBand)
: Draw a 2D grid on a canvas.drawCountour(canvas, contour, rect, color)
: Draw contours on a canvas.
We welcome contributions! If you'd like to contribute, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Submit a pull request with a detailed description of your changes.
This project is licensed under the MIT License. See the LICENSE file for details.
Happy mapping! 🌍