Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have an application in OpenLayers which shows a number of devices (Feature) on a map. The devices are linked between each other by cables (MultiLineString).

searchBoxModule.functions.createConnection = function createConnection(from, to) {
var fromGeom = new OpenLayers.Geometry.Point(from.geometry.coordinates[0], from.geometry.coordinates[1]);
var toGeom = new OpenLayers.Geometry.Point(to.geometry.coordinates[0], to.geometry.coordinates[1]);
var multilineString = new OpenLayers.Geometry.MultiLineString([new OpenLayers.Geometry.LineString([fromGeom, toGeom])]);

var layer = MapView.getConnectionsLayers(); 

if (layer) {
    layer.addFeatures([new OpenLayers.Feature.Vector(multilineString)]);
}}

The issue is that MultiLineString is basically an array of points which have no relationship to the features. So, currently when I drag a feature to a different location on the map the lines (cables) visually connecting them don't change and it looks like the cables have been disconnected.

Did anyone had this kind of issue? Any recommended solutions to that?

share|improve this question
    
I think you will probably have to write a script to call a procedure to edit the cables data as the device is dragged. This in itself begs the question whether you have a simple cable route (straight line) or something more complex for which you might need curves. The simple solution could be as easy as updating the startpoint (or endpoint) geometry of your cable to match the relevant device's coordinates. Curves will be rather harder to control automatically for the to make sense in relation to other objects in your scene. –  MappaGnosis Sep 20 '12 at 8:49
    
The cable rote is quite complex - it includes vertexes and can have multiple joint points. –  Alexander Sep 21 '12 at 0:05
    
So, what I'm trying to do now is to set the "to" and "from" feature objects to each LineString as its attributes and will be updating it's location when one of the features have been dragged. Even if that will work fine, how can I update the LineString smoothly, meaning that it will look like it's being tied up to the feature and being expanded/relocated together with the feature all the time while it's being dragged, not just when the dragging has been completed. –  Alexander Sep 21 '12 at 0:13
    
Just an update, maybe that would be useful for someone: –  Alexander Oct 4 '12 at 4:10
    
continue: (it's so annoying the comment is being posted when 'Enter' key is pressed to go to the next line...). Just an update, maybe that would be useful for someone: I overridden OpenLayers.Layer.PointTrack class to tate advantage of custom feature creation by adding nodes to the layer. So, my class inline <code>OpenLayers.Layer.MultiPointTrack = OpenLayers.Class(OpenLayers.Layer.PointTrack, {addNodes: function(pointFeatures, attributes, options) {...}} </code> takes feature array and some properties and options as it's arguments and creates lines (cables) between them. –  Alexander Oct 4 '12 at 4:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.