perliedman / geojson-path-finder

Find shortest path through a network of GeoJSON
https://www.liedman.net/geojson-path-finder/
ISC License
301 stars 87 forks source link

Trouble getting started #3

Closed SteveFirsake closed 8 years ago

SteveFirsake commented 8 years ago

Hello, let me start of by applauding this lovely package. I'm a noob when it comes to npm and node.js. What I am trying to achieve is to use your package in bootleaf (http://bmcbride.github.io/bootleaf/) or more precisely - https://github.com/bmcbride/bootleaf. : The folder structure is:

Project1 ----Data (has my geojson files) ----Assetts -----js (where my app.js resides) * all other folders as can be seen in Brian's repository

I have done the following:

  1. Correctly installed both Node and npm.
  2. Ran the installation line of code provided in the Readme file; it creates a directory in the folder (node-modules) in my js folder.

npm install --save geojson-path-finder

  1. Added the 'require' lines and picked two default co-ordinates

var PathFinder = require('geojson-path-finder'), geojson = require('./network.json'); var pathFinder = new PathFinder(geojson);

var path = pathfinder.findPath(c1, c2);

alert(path);

  1. attempted to bundle the script with browserify.....although I do not know whether this is what I should do; it raised an error on the ./network.json' part.. :) first time i'm using node or npm or browserify.

I'm trying to do this for a school project, please guide me on the steps I should take.

Thanks in advance.

perliedman commented 8 years ago

Hi there!

It looks like your almost on track.

You need to switch out the line that requires network.json to something that loads the GeoJSON you want to use for routing. It should be a GeoJSON containing a FeaureCollection of LineString features, but you can load it any way you want: the require statement is just one possibility.

Hope this is a clear enough explanation and good luck!

SteveFirsake commented 8 years ago

Hello, I have the following comments and observations:

  1. I noticed that this link: http://www.liedman.net/geojson-path-finder/ does NOT use geojson-path-finder library, it uses leaflet-routing-machine. Why did you use it as an example?
  2. I cannot find any geojson-path-finder example anywhere online. Can you zip up one simple example for me - like the http://www.liedman.net/geojson-path-finder/ one
  3. var path = pathFinder.findPath(start, finish); //this was the most confusing section. please give a sample geojson line for start and finish. I tried a couple of geojson point scripts e.g.

var finish = {

"type": "Point","crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } }, "features": [

"geometry":{
             "type": "Point",
             "coordinates": [36.97194311, -1.455614833]
           }
        ]

};

var start = {

"type": "Point", "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },

"features": [

"geometry":{
"type": "Point",
"coordinates": [36.9775,-1.4508]
}]
};

but these did not work.

Regards,

Steve

On Mon, Aug 8, 2016 at 3:37 PM, Per Liedman notifications@github.com wrote:

Closed #3 https://github.com/perliedman/geojson-path-finder/issues/3.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/perliedman/geojson-path-finder/issues/3#event-748318143, or mute the thread https://github.com/notifications/unsubscribe-auth/ASaFn8bcUq_NlcHAG2fFo3MiAWxOtlw_ks5qdyMagaJpZM4Jc1ql .

perliedman commented 8 years ago

http://www.liedman.net/geojson-path-finder/ does indeed use GeoJSON Path Finder. Note that GeoJSON path finder is just the path finding bit - I also use Leaflet Routing Machine for the user interface. LRM is a user interface for routing, and does no path finding in itself, GeoJSON Path Finder has no user interface, just path finding. Hence, they complement each other perfectly.

You can check the actual code it uses to verify this: https://github.com/perliedman/geojson-path-finder/blob/gh-pages/index.js

The "router", or the adapter between LRM and GeoJSON Path Finder, can be found here: https://github.com/perliedman/geojson-path-finder/blob/gh-pages/router.js

As far as I know, this is the only public example of GeoJSON Path Finder. I use it in some customer projects, but they are not public yet.