X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2Fnodes%2FNetworkDrawingNode.java;fp=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2Fnodes%2FNetworkDrawingNode.java;h=6c13f90d254668444cf668ffc73ef2237df3ef84;hb=c6ddbec532645f52583c1ab9691cfb802724fca7;hp=35d76289b0ab000f18e36566e55e355c3c2a9042;hpb=a1fb6a041444504a126b01ad1137e14a4994fa30;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java index 35d76289..6c13f90d 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java @@ -30,6 +30,8 @@ import org.simantics.g2d.canvas.Hints; import org.simantics.g2d.canvas.ICanvasContext; import org.simantics.g2d.canvas.IToolMode; import org.simantics.g2d.diagram.IDiagram; +import org.simantics.maps.elevation.server.SingletonTiffTileInterface; +import org.simantics.maps.elevation.server.prefs.MapsElevationServerPreferences; import org.simantics.scenegraph.g2d.G2DNode; import org.simantics.scenegraph.g2d.events.EventTypes; import org.simantics.scenegraph.g2d.events.KeyEvent.KeyPressedEvent; @@ -40,9 +42,13 @@ import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent; import org.simantics.scenegraph.utils.GeometryUtils; import org.simantics.scenegraph.utils.NodeUtil; import org.simantics.utils.threads.ThreadUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class NetworkDrawingNode extends G2DNode { + private static final Logger LOGGER = LoggerFactory.getLogger(NetworkDrawingNode.class); + static class DrawingNode { private List routeNodes = new ArrayList<>(); @@ -166,6 +172,17 @@ public class NetworkDrawingNode extends G2DNode { double x = ModelledCRS.xToLongitude(pos.getX() / scale); double y = ModelledCRS.yToLatitude(-pos.getY() / scale); + double elevation = 0; + if (MapsElevationServerPreferences.useElevationServer()) { + // ok! we use new elevation API to resolve possible elevations for the starting points + try { + elevation = SingletonTiffTileInterface.lookup(x, y).doubleValue(); + } catch (Exception ee) { + LOGGER.error("Could not get elevation from tiff interface", ee); + } + } + final double felevation = elevation; + boolean leftButton = e.button == MouseEvent.LEFT_BUTTON; ThreadUtils.getNonBlockingWorkExecutor().schedule(() -> { @@ -183,7 +200,7 @@ public class NetworkDrawingNode extends G2DNode { if (mapping == null) { mapping = graph.getSingleObject(diagramResource, DistrictNetworkResource.getInstance(graph).VertexDefaultMapping); } - DistrictNetworkUtil.createVertex(graph, diagramResource, new double[] { x, y }, 0, mapping); // TODO: elevation can be fetched from e.g. elevation API + DistrictNetworkUtil.createVertex(graph, diagramResource, new double[] { x, y }, felevation, mapping); } }); }, 100, TimeUnit.MILLISECONDS); @@ -235,15 +252,28 @@ public class NetworkDrawingNode extends G2DNode { detailedGeometryCoords[i++] = lat; } + double startElevation = 0; + double endElevation = 0; + if (MapsElevationServerPreferences.useElevationServer()) { + // ok! we use new elevation API to resolve possible elevations for the starting points + try { + startElevation = SingletonTiffTileInterface.lookup(startLat, startLon).doubleValue(); + endElevation = SingletonTiffTileInterface.lookup(endLat, endLon).doubleValue(); + } catch (Exception e) { + LOGGER.error("Could not get elevation from tiff interface", e); + } + } + final double se = startElevation; + final double ee = endElevation; DNEdgeBuilder builder = new DNEdgeBuilder(diagramResource, diagram); Simantics.getSession().asyncRequest(new WriteRequest() { - + @Override public void perform(WriteGraph graph) throws DatabaseException { - builder.create(graph, startCoords, 0, endCoords, 0, detailedGeometryCoords, padding); + builder.create(graph, startCoords, se, endCoords, ee, detailedGeometryCoords, padding); } }); - + } @Override