import { Enum } from '../Util/Util.js'; import { dist, AABB } from '../Geometry/Geometry.js'; class Node { constructor(x, y) { this.moveTo(x, y); } moveTo(x, y) { this.x = x; this.y = y; } } class ShapeType extends Enum { constructor(name) { super('Shape', name); } } class Shape { static Point = new ShapeType('Point'); static Path = new ShapeType('Path'); static Polygon = new ShapeType('Polygon'); static Text = new ShapeType('Text'); constructor(type, nodes) { this.type = type; this.nodes = nodes; this.boundingBox = this.computeBoundingBox(); } computeBoundingBox() { let xMin = Infinity; let xMax = -Infinity; let yMin = Infinity; let yMax = -Infinity; for (let node of this.nodes) { if (node.x < xMin) xMin = node.x; if (node.x > xMax) xMax = node.x; if (node.y < yMin) yMin = node.y; if (node.y > yMax) yMax = node.y; } return new AABB(xMin, yMin, xMax-xMin, yMax-yMin); } } class Point extends Shape { constructor(node) { super(Shape.Point, [node]); } } class Path extends Shape { constructor(nodes) { super(Shape.Path, nodes); } } class Polygon extends Shape { constructor(nodes) { super(Shape.Polygon, nodes); } } class Text extends Shape { constructor(node, text, fontSize) { super(Shape.Text, [node]); this.text = text; this.fontSize = fontSize; } } class ZoomLevel extends Enum { static Globe = new ZoomLevel('Globe'); static Nation = new ZoomLevel('Nation'); static Province = new ZoomLevel('Province'); static City = new ZoomLevel('City'); static Neighborhoot = new ZoomLevel('Neighborhood'); static Building = new ZoomLevel('Building'); constructor(name) { super('ZoomLevel', name); } } class MapObject { constructor(core, layerId, minZoom, maxZoom=minZoom) { this.core = core; this.layerId = layerId; this.minZoom = minZoom; this.maxZoom = maxZoom; this.shapes = []; this.boundingBox = this.computeBoundingBox(); } computeBoundingBox() { let xMin = Infinity; let xMax = -Infinity; let yMin = Infinity; let yMax = -Infinity; for (let shape of this.shapes) { const box = shape.boundingBox; if (box.x < xMin) xMin = box.x; if (box.x + box.width > xMax) xMax = box.x + box.width; if (box.y < yMin) yMin = box.y; if (box.y + box.height > yMax) yMax = box.y + box.height; } return new AABB(xMin, yMin, xMax-xMin, yMax-yMin); } } export { Node, Shape, Point, Path, Polygon, Text, ZoomLevel, MapObject };