Giter VIP home page Giter VIP logo

Comments (3)

Raruto avatar Raruto commented on June 2, 2024

Hi @jarod46,

talk is cheap, show me the code..

👋 Raruto

from leaflet-elevation.

jarod46 avatar jarod46 commented on June 2, 2024

Ha, it's a generaly question, I'm not sure what I need to share, basically I have a timer which regularly call an ajax function which query if there is new locations to add to the current track.

I tried with several functions like controlElevation.load, controlElevation._addData, controlElevation.addData, controlElevation.loadLayer...

function updateLocations(data) {
  if (data && Array.isArray(data) && data.length > 0) {

    var newFeature = {
      "type": "Feature",
      "geometry": {
        "type": "LineString",
        "coordinates": []
      },
      "properties": {
        "name": "KTrackPlus",
        "description": "",
        "coordTimes": [],
      }
    };

    for (var i = 0; i < data.length; i++) {

      if (i > 1000) break;

      var newCoords = [Number(data[i].lng), Number(data[i].lat), Number(data[i].alt), Number(data[i].timestamp)];
      newFeature.geometry.coordinates.push(newCoords);
      var date = new Date(Number(data[i].timestamp) * 1000);
      newFeature.properties.coordTimes.push(date.toISOString());
      mostRecentTT = data[i].timestamp;
      locs.push(newCoords);

    }
    controlElevation._loadLayer(newFeature);
    /*if (firstTime) {
      //var jsonStr = JSON.stringify(newFeature);
      //controlElevation.load(jsonStr);
      trackLayer = controlElevation._loadLayer(newFeature);

    }
    else {
      controlElevation.addData(newFeature, trackLayer);
      controlElevation._initMapIntegrations(trackLayer);

    }*/


    controlElevation.redraw();

  }
}

Full page (witthout php part) https://pastebin.com/DemqTPUj

from leaflet-elevation.

Raruto avatar Raruto commented on June 2, 2024

I tried with several functions like controlElevation.load, controlElevation._addData, controlElevation.addData, controlElevation.loadLayer...

I think you are already on the right path: addData_addData_addGeoJSONData_addPoint ...

You probably just need to dive a little deeper into the code's flow and choose the one that's right for you:

/*
* Parsing of GeoJSON data lines and their elevation in z-coordinate
*/
_addGeoJSONData(coords, properties, nestingLevel) {
// "coordinateProperties" property is generated inside "@tmcw/toGeoJSON"
let props = (properties && properties.coordinateProperties) || properties;
coords.forEach((point, i) => {
// GARMIN_EXTENSIONS = ["hr", "cad", "atemp", "wtemp", "depth", "course", "bearing"];
point.meta = point.meta ?? { time: null, ele: null };
point.prev = (attr) => (attr ? this._data[i > 0 ? i - 1 : 0][attr] : this._data[i > 0 ? i - 1 : 0]);
this.fire("elepoint_init", { point: point, props: props, id: i, isMulti: nestingLevel });
this._addPoint(
point.lat ?? point[1],
point.lng ?? point[0],
point.alt ?? point.meta.ele ?? point[2]
);
this.fire("elepoint_added", { point: point, index: this._data.length - 1 });
if (this._yCoordMax < this._data[this._data.length - 1][this.options.yAttr]) this._yCoordMax = this._data[this._data.length - 1][this.options.yAttr];
});
this.fire("eletrack_added", { coords: coords, index: this._data.length - 1 });
},

/*
* Parse and push a single (x, y, z) point to current elevation profile.
*/
_addPoint(x, y, z) {
if (this.options.reverseCoords) {
[x, y] = [y, x];
}
this._data.push({
x: x,
y: y,
z: z,
latlng: L.latLng(x, y, z)
});
this.fire("eledata_updated", { index: this._data.length - 1 });
},

NB: As you go further and further down, you will have to handle everything else by yourself, eg: _addLayer, _fireEvt, ...

/*
* Add data to the diagram either from GPX or GeoJSON and update the axis domain and data
*/
addData(d, layer) {
this.import(this.__D3)
.then(() => {
if (this._modulesLoaded) {
layer = layer ?? (d.on && d);
this._addData(d);
this._addLayer(layer);
this._fireEvt("eledata_added", { data: d, layer: layer, track_info: this.track_info });
} else {
this.once('modules_loaded', () => this.addData(d,layer));
}
});
},

👋 Raruto

from leaflet-elevation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.