Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const features = [];
while ((curIndex = csv.indexOf('\n', prevIndex)) > 0) {
const line = csv.substr(prevIndex, curIndex - prevIndex).split(',');
prevIndex = curIndex + 1;
if (prevIndex === 0) {
continue; // skip header
}
const coords = fromLonLat([parseFloat(line[4]), parseFloat(line[3])]);
features.push(new Feature({
mass: parseFloat(line[1]) || 0,
year: parseInt(line[2]) || 0,
geometry: new Point(coords)
}));
}
source.addFeatures(features);
};
client.send();
let prevIndex = 0;
while ((curIndex = csv.indexOf('\n', prevIndex)) > 0) {
const line = csv.substr(prevIndex, curIndex - prevIndex).split(',');
prevIndex = curIndex + 1;
// skip header
if (prevIndex === 0) {
continue;
}
const coords = fromLonLat([parseFloat(line[4]), parseFloat(line[3])]);
features.push(new Feature({
mass: parseFloat(line[1]) || 0,
year: parseInt(line[2]) || 0,
geometry: new Point(coords)
}));
}
vectorSource.addFeatures(features);
};
client.send();
it('moves feature to the new position', () => {
// the next line show this test isn't testing anything
// expect.assertions(1);
const coords = [0, 0];
const geom = new OlGeomPoint(coords);
const featToMove = new OlFeature(geom);
let map = TestUtil.createMap();
AnimateUtil.moveFeature(
map, featToMove, 100, 50, new OlStyleStyle()
).then((feat) => {
expect(feat.getGeometry().getCoordinates()).toEqual([50, 50]);
});
TestUtil.removeMap(map);
});
});
it("toFeature", () => {
var geo = new Point([116.407283, 39.904557]);
var attrs = {};
attrs.NAME = "北京市";
attrs.CON2009 = 22023;
var themeFeature = new ThemeFeature(geo, attrs);
var result = themeFeature.toFeature();
expect(result).not.toBeNull();
expect(result instanceof Vector).toBeTruthy();
expect(result.geometry).not.toBeNull();
expect(result.attributes).not.toBeNull();
expect(result.attributes.NAME).toBe('北京市');
expect(result.attributes.CON2009).toBe(22023);
expect(result.geometry.x).toBe(116.407283);
expect(result.geometry.y).toBe(39.904557);
});
});
for (var k = 0; k < meta.length; k++) {
if (meta[k].name == "GPSLongitude") {
pt[0] = meta[k].value;
found++;
}
if (meta[k].name == "GPSLatitude") {
pt[1] = meta[k].value;
found++;
}
}
if (found != 2) {
//console.log(att);
continue;
}
}
feature = new ol_Feature(new ol_geom_Point(ol_proj_transform(pt, "EPSG:4326", projection)));
att.imageinfo[0].title = att.title;
if (self.readFeature(feature, att.imageinfo[0])) {
features.push(feature);
}
}
self.addFeatures(features);
}
});
this.chicago.setStyle(new Style({
image: new Icon(({
color: '#8959A8',
crossOrigin: 'anonymous',
src: 'assets/vectorpoint.svg',
imgSize: [20, 20]
}))
}));
this.london = new Feature({
geometry: new Point(fromLonLat([-0.12755, 51.507222]))
});
this.madrid = new Feature({
geometry: new Point(fromLonLat([-3.683333, 40.4]))
});
this.london.setStyle(new Style({
image: new Icon(({
color: '#4271AE',
crossOrigin: 'anonymous',
src: 'assets/vectorpoint.svg',
imgSize: [20, 20]
}))
}));
this.madrid.setStyle(new Style({
image: new Icon(({
color: [113, 140, 0],
crossOrigin: 'anonymous',
src: 'assets/dot.png',
rotationBounds(bounds, rotationCenterPoi, angle) {
var ltPoi = new Point([bounds.left, bounds.top]);
var rtPoi = new Point([bounds.right, bounds.top]);
var rbPoi = new Point([bounds.right, bounds.bottom]);
var lbPoi = new Point([bounds.left, bounds.bottom]);
var ver = [];
ver.push(this.getRotatedLocation(ltPoi.getCoordinates()[0], ltPoi.getCoordinates()[1], rotationCenterPoi.x, rotationCenterPoi.y, angle));
ver.push(this.getRotatedLocation(rtPoi.getCoordinates()[0], rtPoi.getCoordinates()[1], rotationCenterPoi.x, rotationCenterPoi.y, angle));
ver.push(this.getRotatedLocation(rbPoi.getCoordinates()[0], rbPoi.getCoordinates()[1], rotationCenterPoi.x, rotationCenterPoi.y, angle));
ver.push(this.getRotatedLocation(lbPoi.getCoordinates()[0], lbPoi.getCoordinates()[1], rotationCenterPoi.x, rotationCenterPoi.y, angle));
//bounds旋转后形成的多边形节点数组
var quad = [];
for (var i = 0; i < ver.length; i++) {
quad.push({
"x": ver[i].x,
rotationBounds(bounds, rotationCenterPoi, angle) {
var ltPoi = new Point([bounds.left, bounds.top]);
var rtPoi = new Point([bounds.right, bounds.top]);
var rbPoi = new Point([bounds.right, bounds.bottom]);
var lbPoi = new Point([bounds.left, bounds.bottom]);
var ver = [];
ver.push(this.getRotatedLocation(ltPoi.getCoordinates()[0], ltPoi.getCoordinates()[1], rotationCenterPoi.x, rotationCenterPoi.y, angle));
ver.push(this.getRotatedLocation(rtPoi.getCoordinates()[0], rtPoi.getCoordinates()[1], rotationCenterPoi.x, rotationCenterPoi.y, angle));
ver.push(this.getRotatedLocation(rbPoi.getCoordinates()[0], rbPoi.getCoordinates()[1], rotationCenterPoi.x, rotationCenterPoi.y, angle));
ver.push(this.getRotatedLocation(lbPoi.getCoordinates()[0], lbPoi.getCoordinates()[1], rotationCenterPoi.x, rotationCenterPoi.y, angle));
//bounds旋转后形成的多边形节点数组
var quad = [];
for (var i = 0; i < ver.length; i++) {
quad.push({
"x": ver[i].x,
"y": ver[i].y
});
}
if (this.typeGeom_ == "Polygon") {
if (!this._feature.getGeometry()) {
this._feature.setGeometry(new ol_geom_Polygon([this.geom_]));
} else {
this._feature.getGeometry().setCoordinates([this.geom_]);
}
this.overlay_.getSource().addFeature(new ol_Feature(geom));
} else {
if (!this._feature.getGeometry()) {
this._feature.setGeometry(new ol_geom_LineString(this.geom_));
} else {
this._feature.getGeometry().setCoordinates(this.geom_);
}
}
this.overlay_.getSource().addFeature(this._feature);
var f = new ol_Feature( new ol_geom_Point (this.geom_.slice(-1).pop()) );
this.overlay_.getSource().addFeature(f);
}
};