Add lint to travis tests
This commit is contained in:
parent
71795b022b
commit
b40fada484
@ -153,7 +153,10 @@ export default class GoogleMapsApi {
|
|||||||
this.polies.push(poly);
|
this.polies.push(poly);
|
||||||
}
|
}
|
||||||
const path = poly.getPath();
|
const path = poly.getPath();
|
||||||
const start = this.markers.length;
|
let start = this.markers.length;
|
||||||
|
if (start > 0) {
|
||||||
|
this.removePoint(--start);
|
||||||
|
}
|
||||||
for (let i = start; i < track.length; i++) {
|
for (let i = start; i < track.length; i++) {
|
||||||
// set marker
|
// set marker
|
||||||
this.setMarker(i, track);
|
this.setMarker(i, track);
|
||||||
@ -256,6 +259,22 @@ export default class GoogleMapsApi {
|
|||||||
this.markers.push(marker);
|
this.markers.push(marker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} id
|
||||||
|
*/
|
||||||
|
removePoint(id) {
|
||||||
|
if (this.markers.length > id) {
|
||||||
|
this.markers[id].setMap(null);
|
||||||
|
this.markers.splice(id, 1);
|
||||||
|
if (this.polies.length) {
|
||||||
|
this.polies[0].getPath().removeAt(id);
|
||||||
|
}
|
||||||
|
if (this.viewModel.model.markerSelect === id) {
|
||||||
|
this.popupClose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open popup on marker with given id
|
* Open popup on marker with given id
|
||||||
* @param {number} id
|
* @param {number} id
|
||||||
|
@ -427,7 +427,10 @@ export default class OpenLayersApi {
|
|||||||
if (!track || !track.hasPositions) {
|
if (!track || !track.hasPositions) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const start = this.layerMarkers ? this.layerMarkers.getSource().getFeatures().length : 0;
|
let start = this.layerMarkers ? this.layerMarkers.getSource().getFeatures().length : 0;
|
||||||
|
if (start > 0) {
|
||||||
|
this.removePoint(--start);
|
||||||
|
}
|
||||||
for (let i = start; i < track.length; i++) {
|
for (let i = start; i < track.length; i++) {
|
||||||
this.setMarker(i, track);
|
this.setMarker(i, track);
|
||||||
}
|
}
|
||||||
@ -540,6 +543,25 @@ export default class OpenLayersApi {
|
|||||||
this.layerMarkers.getSource().addFeature(marker);
|
this.layerMarkers.getSource().addFeature(marker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} id
|
||||||
|
*/
|
||||||
|
removePoint(id) {
|
||||||
|
const marker = this.layerMarkers.getSource().getFeatureById(id);
|
||||||
|
if (marker) {
|
||||||
|
this.layerMarkers.getSource().removeFeature(marker);
|
||||||
|
if (this.layerTrack) {
|
||||||
|
const lineString = this.layerTrack.getSource().getFeatures()[0].getGeometry();
|
||||||
|
const coordinates = lineString.getCoordinates();
|
||||||
|
coordinates.splice(id, 1);
|
||||||
|
lineString.setCoordinates(coordinates);
|
||||||
|
}
|
||||||
|
if (this.viewModel.model.markerSelect === id) {
|
||||||
|
this.popupClose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Animate marker
|
* Animate marker
|
||||||
* @param id Marker sequential id
|
* @param id Marker sequential id
|
||||||
|
@ -177,6 +177,27 @@ describe('Google Maps map API tests', () => {
|
|||||||
expect(api.map).toBe(null);
|
expect(api.map).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should remove features by id', () => {
|
||||||
|
// given
|
||||||
|
const poly = new google.maps.Polyline();
|
||||||
|
const marker = new google.maps.Marker();
|
||||||
|
api.polies.push(poly);
|
||||||
|
api.markers.push(marker);
|
||||||
|
const path = {};
|
||||||
|
path.removeAt = () => {/* ignore */};
|
||||||
|
poly.getPath = () => path;
|
||||||
|
marker.setMap = () => {/* ignore */};
|
||||||
|
spyOn(marker, 'setMap');
|
||||||
|
spyOn(path, 'removeAt');
|
||||||
|
const id = 0;
|
||||||
|
// when
|
||||||
|
api.removePoint(id);
|
||||||
|
// then
|
||||||
|
expect(marker.setMap).toHaveBeenCalledWith(null);
|
||||||
|
expect(api.markers.length).toBe(0);
|
||||||
|
expect(path.removeAt).toHaveBeenCalledWith(id);
|
||||||
|
});
|
||||||
|
|
||||||
it('should clear map features', () => {
|
it('should clear map features', () => {
|
||||||
// given
|
// given
|
||||||
const poly = new google.maps.Polyline();
|
const poly = new google.maps.Polyline();
|
||||||
|
@ -224,6 +224,28 @@ describe('Openlayers map API tests', () => {
|
|||||||
expect(api.map).toBe(null);
|
expect(api.map).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should remove features with given index', () => {
|
||||||
|
// given
|
||||||
|
const id = 0;
|
||||||
|
const marker = new ol.Feature();
|
||||||
|
const lineString = new ol.geom.LineString([]);
|
||||||
|
lineString.appendCoordinate(ol.proj.fromLonLat([ 0, 0 ]));
|
||||||
|
const lineFeature = new ol.Feature({ geometry: lineString });
|
||||||
|
marker.setId(id);
|
||||||
|
api.layerTrack = new ol.layer.VectorLayer({ source: new ol.source.Vector() });
|
||||||
|
api.layerTrack.getSource().addFeature(lineFeature);
|
||||||
|
api.layerMarkers = new ol.layer.VectorLayer({ source: new ol.source.Vector() });
|
||||||
|
api.layerMarkers.getSource().addFeature(marker);
|
||||||
|
|
||||||
|
expect(lineString.getCoordinates().length).toBe(1);
|
||||||
|
expect(api.layerMarkers.getSource().getFeatures().length).toBe(1);
|
||||||
|
// when
|
||||||
|
api.removePoint(id);
|
||||||
|
// then
|
||||||
|
expect(lineString.getCoordinates().length).toBe(0);
|
||||||
|
expect(api.layerMarkers.getSource().getFeatures().length).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
it('should clear marker and track layers features', () => {
|
it('should clear marker and track layers features', () => {
|
||||||
// given
|
// given
|
||||||
api.layerTrack = new ol.layer.VectorLayer({ source: new ol.source.Vector() });
|
api.layerTrack = new ol.layer.VectorLayer({ source: new ol.source.Vector() });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user