Search in sources :

Example 1 with MapEntity

use of aimax.osm.data.entities.MapEntity in project aima-java by aimacode.

the class DefaultEntityRenderer method printBufferedObjects.

// int awnodes = 0;
/** Prints all buffered entities according to their rendering informations. */
public void printBufferedObjects() {
    Collections.sort(areaBuffer, new MapAreaComparator());
    Comparator<MapEntity> comp = new MapEntityComparator();
    if (wayBuffer.size() < 10000)
        Collections.sort(wayBuffer, comp);
    if (nodeBuffer.size() < 10000)
        Collections.sort(nodeBuffer, comp);
    for (MapWay area : areaBuffer) printWay(area, (DefaultEntityViewInfo) area.getViewInfo(), true);
    for (MapWay way : wayBuffer) printWay(way, (DefaultEntityViewInfo) way.getViewInfo(), false);
    for (MapEntity node : nodeBuffer) {
        MapNode n;
        if (node instanceof MapWay) {
            List<MapNode> wayNodes = getWayNodes((MapWay) node);
            // needed to show icons for ways, whose abstraction is empty.
            if (wayNodes.isEmpty())
                wayNodes = ((MapWay) node).getNodes();
            n = wayNodes.get(0);
        } else
            n = (MapNode) node;
        printNode(n, (DefaultEntityViewInfo) node.getViewInfo());
    }
    for (Track track : trackBuffer) printTrack(track);
    // System.out.print("NamesOrg: " + nameInfoBuffer.size() + "\n");
    Collections.sort(nameInfoBuffer);
    // remove names whose positions are to close to each other
    int charSize = (int) (defaultFontSize * displayFactorSym);
    for (int i = 0; i < nameInfoBuffer.size(); ++i) {
        NameInfo info = nameInfoBuffer.get(i);
        for (int j = 0; j < i; ++j) {
            NameInfo info1 = nameInfoBuffer.get(j);
            int fac = (info.name.equals(info1.name)) ? 3 : 2;
            if (Math.abs(info.y - info1.y) < charSize * fac) {
                fac = (info.x < info1.x) ? info.name.length() : info1.name.length();
                if (Math.abs(info.x - info1.x) < charSize * fac) {
                    nameInfoBuffer.remove(i);
                    --i;
                    j = i;
                }
            }
        }
    }
    for (NameInfo textInfo : nameInfoBuffer) {
        imageBdr.setColor(textInfo.color);
        imageBdr.drawString(textInfo.name, textInfo.x, textInfo.y);
    }
// System.out.print("Areas: " + areaBuffer.size() + "  ");
// System.out.print("Ways: " + wayBuffer.size() + "  ");
// System.out.print("Nodes: " + nodeBuffer.size() + "  ");
// System.out.print("Names: " + nameInfoBuffer.size() + "\n");
}
Also used : MapWay(aimax.osm.data.entities.MapWay) MapEntity(aimax.osm.data.entities.MapEntity) MapNode(aimax.osm.data.entities.MapNode) Track(aimax.osm.data.entities.Track)

Example 2 with MapEntity

use of aimax.osm.data.entities.MapEntity in project aima-java by aimacode.

the class DefaultEntityRenderer method getNextNode.

/**
	 * Returns the map node which is the nearest with respect to the specified
	 * view coordinates among the currently displayed nodes.
	 */
public MapNode getNextNode(int x, int y) {
    Position pos = new Position(transformer.lat(y), transformer.lon(x));
    MapNode nextNode = null;
    MapNode tmp = null;
    for (int i = 0; i < 2; i++) {
        List<MapWay> ways = (i == 0) ? areaBuffer : wayBuffer;
        for (MapWay way : ways) {
            tmp = pos.selectNearest(way.getNodes(), null);
            if (nextNode == null || pos.getDistKM(tmp) < pos.getDistKM(nextNode)) {
                nextNode = tmp;
            }
        }
    }
    for (MapEntity node : nodeBuffer) {
        if (node instanceof MapNode) {
            tmp = (MapNode) node;
            if (tmp != null && tmp.getAttributeValue("marker") == null && (nextNode == null || pos.getDistKM(tmp) < pos.getDistKM(nextNode))) {
                nextNode = tmp;
            }
        }
    }
    return nextNode;
}
Also used : MapWay(aimax.osm.data.entities.MapWay) Position(aimax.osm.data.Position) MapNode(aimax.osm.data.entities.MapNode) MapEntity(aimax.osm.data.entities.MapEntity)

Example 3 with MapEntity

use of aimax.osm.data.entities.MapEntity in project aima-java by aimacode.

the class MapPaneCtrl method showMapEntityInfoDialog.

/**
     * Finds the visible entity next to the specified view coordinates and shows
     * informations about it.
     *
     * @param debug
     *            Enables a more detailed view.
     */
private void showMapEntityInfoDialog(MapEntity entity, boolean debug) {
    List<MapEntity> entities = new ArrayList<>();
    if (entity.getName() != null || entity.getAttributes().length > 0 || debug)
        entities.add(entity);
    if (entity instanceof MapNode) {
        MapNode mNode = (MapNode) entity;
        for (WayRef ref : mNode.getWayRefs()) {
            MapEntity me = ref.getWay();
            if (me.getName() != null || me.getAttributes().length > 0 || debug)
                entities.add(me);
        }
    }
    for (MapEntity me : entities) {
        String header = (me.getName() != null) ? me.getName() : "";
        StringBuilder content = new StringBuilder();
        if (debug)
            header += " (" + ((me instanceof MapNode) ? "Node " : "Way ") + me.getId() + ")";
        if (me instanceof MapNode) {
            content.append("Lat: ").append(((MapNode) me).getLat()).append(" Lon: ").append(((MapNode) me).getLon()).append(" ");
        }
        if (me.getAttributes().length > 0) {
            EntityAttribute[] atts = me.getAttributes();
            content.append("Attributs: ");
            for (EntityAttribute att : atts) {
                content.append(att.getKey()).append("=").append(att.getValue()).append(" ");
            }
        }
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setTitle("Map Entity Info");
        alert.setHeaderText(header);
        alert.setContentText(content.toString());
        Optional<ButtonType> result = alert.showAndWait();
        if (!result.isPresent())
            break;
    }
}
Also used : WayRef(aimax.osm.data.entities.WayRef) EntityAttribute(aimax.osm.data.entities.EntityAttribute) ArrayList(java.util.ArrayList) Alert(javafx.scene.control.Alert) MapEntity(aimax.osm.data.entities.MapEntity) MapNode(aimax.osm.data.entities.MapNode) ButtonType(javafx.scene.control.ButtonType)

Example 4 with MapEntity

use of aimax.osm.data.entities.MapEntity in project aima-java by aimacode.

the class UnifiedMapDrawer method drawMap.

public void drawMap(IMAGE_TYPE image, boolean adjustToFit) {
    imageBdr.initialize(image);
    imageBdr.setColor(UColor.WHITE);
    imageBdr.setAreaFilled(true);
    imageBdr.drawRect(0, 0, imageBdr.getWidth(), imageBdr.getHeight());
    if (imageBdr.getWidth() > 0 && map != null) {
        if (adjustToFit)
            getTransformer().adjustTransformation(getMap().getBoundingBox(), imageBdr.getWidth(), imageBdr.getHeight());
        float latMin = transformer.lat(imageBdr.getHeight());
        float lonMin = transformer.lon(0);
        float latMax = transformer.lat(0);
        float lonMax = transformer.lon(imageBdr.getWidth());
        float scale = transformer.computeScale();
        BoundingBox vbox = new BoundingBox(latMin, lonMin, latMax, lonMax);
        float viewScale = scale / renderer.getDisplayFactor();
        renderer.initForRendering(imageBdr, transformer, map);
        map.visitEntities(renderer, vbox, viewScale);
        for (MapEntity entity : map.getVisibleMarkersAndTracks(viewScale)) entity.accept(renderer);
        renderer.printBufferedObjects();
        if (renderer.isDebugModeEnabled() && map instanceof DefaultMap) {
            List<double[]> splits = ((DefaultMap) map).getEntityTree().getSplitCoords();
            imageBdr.setColor(UColor.LIGHT_GRAY);
            imageBdr.setLineStyle(false, 1f);
            imageBdr.setAreaFilled(false);
            CoordTransformer trans = renderer.getTransformer();
            for (double[] split : splits) imageBdr.drawLine(renderer.getTransformer().x(split[1]), trans.y(split[0]), trans.x(split[3]), trans.y(split[2]));
        }
    }
    image = imageBdr.getResult();
}
Also used : BoundingBox(aimax.osm.data.BoundingBox) MapEntity(aimax.osm.data.entities.MapEntity) DefaultMap(aimax.osm.data.impl.DefaultMap)

Example 5 with MapEntity

use of aimax.osm.data.entities.MapEntity in project aima-java by aimacode.

the class DefaultEntityFinder method find.

/**
	 * Searches for entities which comply to the current search specification
	 * and stores them as results.
	 */
@Override
protected void find(boolean findMore) {
    BestMatchFinder bmf = new BestMatchFinder(pattern);
    List<MapEntity> results = getResults();
    BoundingBox bb = new BoundingBox(position, nextRadius);
    if (!results.isEmpty())
        bmf.checkMatchQuality(results.get(0));
    if (mode.equals(Mode.ENTITY) || mode.equals(Mode.NODE)) {
        for (MapNode node : getStorage().getPois(bb)) {
            int match = bmf.checkMatchQuality(node);
            if (match >= 0) {
                if (match > 0) {
                    results.clear();
                    bmf.useAsReference(node);
                }
                if (position.insertInAscendingDistanceOrder(results, node))
                    if (results.size() > 100)
                        results.remove(99);
            }
        }
    }
    if (mode.equals(Mode.ENTITY) || mode.equals(Mode.WAY)) {
        for (MapWay way : getStorage().getWays(bb)) {
            int match = bmf.checkMatchQuality(way);
            if (match >= 0) {
                if (match > 0) {
                    results.clear();
                    bmf.useAsReference(way);
                }
                if (position.insertInAscendingDistanceOrder(results, way))
                    if (results.size() > 100)
                        results.remove(99);
            }
        }
    }
    if (mode.equals(Mode.ADDRESS)) {
        List<MapEntity> iResults = getIntermediateResults();
        StringTokenizer tokenizer = new StringTokenizer(pattern, ",");
        String placeName = null;
        String wayName = null;
        if (tokenizer.hasMoreElements())
            placeName = tokenizer.nextToken();
        if (tokenizer.hasMoreElements())
            wayName = tokenizer.nextToken().trim();
        if (placeName != null && !findMore) {
            for (MapNode place : getStorage().getPlaces(placeName)) {
                position.insertInAscendingDistanceOrder(iResults, place);
                if (iResults.size() > 100)
                    iResults.remove(99);
            }
            nextRadius = -1;
        }
        if (iResults.size() == 1 && wayName != null) {
            MapNode place = (MapNode) iResults.get(0);
            findWay(wayName, new Position(place.getLat(), place.getLon()), null);
        }
    } else {
        nextRadius *= 2;
        if (results.isEmpty() && getIntermediateResults().isEmpty() && nextRadius <= getMaxRadius())
            find(true);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) MapWay(aimax.osm.data.entities.MapWay) Position(aimax.osm.data.Position) BoundingBox(aimax.osm.data.BoundingBox) MapEntity(aimax.osm.data.entities.MapEntity) MapNode(aimax.osm.data.entities.MapNode)

Aggregations

MapEntity (aimax.osm.data.entities.MapEntity)7 MapNode (aimax.osm.data.entities.MapNode)5 Position (aimax.osm.data.Position)3 MapWay (aimax.osm.data.entities.MapWay)3 BoundingBox (aimax.osm.data.BoundingBox)2 EntityAttribute (aimax.osm.data.entities.EntityAttribute)2 WayRef (aimax.osm.data.entities.WayRef)2 ArrayList (java.util.ArrayList)2 Track (aimax.osm.data.entities.Track)1 DefaultMap (aimax.osm.data.impl.DefaultMap)1 Dimension (java.awt.Dimension)1 StringTokenizer (java.util.StringTokenizer)1 Alert (javafx.scene.control.Alert)1 ButtonType (javafx.scene.control.ButtonType)1 JScrollPane (javax.swing.JScrollPane)1 JTable (javax.swing.JTable)1