When adding an airplane to the map, the airplane picture and the airplane number appear. The airplane number is offset above the airplane picture.The position of the aircraft picture and the aircraft number is updated and changed in real time. There is a requirement that the aircraft number can be moved, and after the aircraft number is moved to the new position, it will continue to move with the aircraft picture.
I used the method of ol. Interaction.Translate
to realize the drag of the aircraft number, but it was impossible to realize the real-time movement of the aircraft number following the picture of the aircraft
let newLocation = ol.proj.fromLonLat([obj.longitude, obj.latitude]);
let aircraft = vectorSource.getFeatureById(obj.aircraftNum);
aircraft.setGeometry(new ol.geom.Point(newLocation));//Update aircraft image location
let newPoint;
translate = new ol.interaction.Translate({
features:new ol.Collection([featureSimpleSign])
});
map.addInteraction(translate);
translate.on('translatestart', function (evt) {
coordSign = aircraft.getGeometry().getCoordinates();
});
translate.on('translating', function (evt) {
indexWire.setCoordinates([coordSign, evt.coordinate]);
});
translate.on('translateend',function(evt){
let dd2 = map.getPixelFromCoordinate(evt.coordinate);
let newX = dd2[0]-0;//Minus the offset of the plane number
let newY = dd2[1]-(-30);
newPoint = map.getCoordinateFromPixel([newX,newY]);
indexWire.setCoordinates([coordSign,evt.coordinate]);
})
startPoint = aircraft.getGeometry().getCoordinates();
indexWire.setCoordinates([startPoint,newPoint]);