While it is true that Leaflet does not have built-in support to check if a polygon is contained inside another one, there are alternative methods available. GeoScript offers such methods, but they may be complex and lacking in documentation.
Personally, I prefer using JTS (or its JavaScript version JSTS) for tasks like this. Converting coordinates from Leaflet or Google Maps to JSTS format is straightforward:
function _leafletLatLng2JTS (polygon) {
var coordinates = [];
var length = 0;
if (polygon && polygon.length) {
length = polygon.length;
}
for (var i = 0; i < length; i++) {
if (polygon.length) {
coordinates.push(new jsts.geom.Coordinate(polygon[i].lat, polygon[i].lng));
}
}
return coordinates;
}
You can then create two JSTS polygons and check if one is within the other with the following code:
function _isWithin (firstLayer, secondLayer) {
var firstInput = _leafletLatLng2JTS(firstLayer.getLatLngs()[0]),
secondInput = _leafletLatLng2JTS(secondLayer.getLatLngs()[0]),
geometryFactory = new jsts.geom.GeometryFactory();
firstInput.push(firstInput[0]);
secondInput.push(secondInput[0]);
var firstPolygon = geometryFactory.createPolygon(firstInput),
secondPolygon = geometryFactory.createPolygon(secondInput);
var isWithin = firstPolygon.contains(secondPolygon);
return isWithin;
}
To see how this can be applied with the Leaflet.Draw plugin, visit this jsFiddle. This example allows you to draw two layers on the map (rectangles or polygons) and determine if one is contained within the other.
UPDATE 30.10.2017:
You can also utilize turf.js for similar functions, such as the booleanContains method.