Slayes Slayes - 4 years ago 65
Javascript Question

ol3 bind feature point and feature type linestring

I didn't succeed to find a sample code or something like that to help me to code a functionality. To explicate shortly, on a map I added 3 features :

  • 2 type point

  • 1 type linestring between both
    I enabled the drag capacity.

I don't know if it is possible, I would like bind directly the features 'point' to the feature 'linestring'. I would like drag a feature and that the linestring redraw automatically.

I already tried to code with 'Drag.prototype.handleDragEvent ', but I think that the latency is not really good.

Answer Source

It was easier than I thought (initially). See demo.

Make use of translating of ol.interaction.Translate and then tell you linestring that the current coordinate is its last coordinate.

The relevant code is:

translate1.on('translatestart', function (evt) {
  coordMarker2 = marker2.getCoordinates();

translate1.on('translating', function (evt) {
  line.setCoordinates([coordMarker2, evt.coordinate]);

translate2.on('translatestart', function (evt) {
  coordMarker1 = marker1.getCoordinates();

translate2.on('translating', function (evt) {
  line.setCoordinates([coordMarker1, evt.coordinate]);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download