Commit d9759ca1 authored by Deployer's avatar Deployer

Fixed direction demo and docs accorrding to API.

parent b0ca239a
...@@ -6,11 +6,13 @@ CedarMaps JS is a javascript library for building interactive maps. It's simply ...@@ -6,11 +6,13 @@ CedarMaps JS is a javascript library for building interactive maps. It's simply
- [Basic Usage](#basic-usage) - [Basic Usage](#basic-usage)
- [API](#api) - [API](#api)
- [Forward Geocoding](#forward-geocoding) - [Forward Geocoding](#forward-geocoding)
- [Forward Geocoding Sample Codes](#forward-geocoding-sample-codes) - [Forward Geocoding Sample Codes](#forward-geocoding-sample-code)
- [Reverse Geocoding](#reverse-geocoding) - [Reverse Geocoding](#reverse-geocoding)
- [Reverse Geocoding Sample Code](#reverse-geocoding-sample-codes) - [Reverse Geocoding Sample Code](#reverse-geocoding-sample-code)
- [Direction](#direction)
- [Direction Sample Code](#direction-sample-code)
- [Administrative Boundaries Lister](#administrative-boundaries-lister) - [Administrative Boundaries Lister](#administrative-boundaries-lister)
- [Administrative Boundaries Lister Sample Codes](#administrative-boundaries-lister-sample-codes) - [Administrative Boundaries Lister Sample Code](#administrative-boundaries-lister-sample-code)
- [Updating SDK](#updating-sdk) - [Updating SDK](#updating-sdk)
# Basic Usage # Basic Usage
...@@ -119,7 +121,7 @@ The results object's signature: ...@@ -119,7 +121,7 @@ The results object's signature:
} }
``` ```
### Forward Geocoding Sample Codes ### Forward Geocoding Sample Code
_Example_: Check out a [Live example of geocoder.query](https://demo.cedarmaps.com/websdk/demos/geocoder-control.html). _Example_: Check out a [Live example of geocoder.query](https://demo.cedarmaps.com/websdk/demos/geocoder-control.html).
Using a single query parameter: Using a single query parameter:
...@@ -153,7 +155,7 @@ Queries the reverse geocoder with a location `object`/`array`, and returns the a ...@@ -153,7 +155,7 @@ Queries the reverse geocoder with a location `object`/`array`, and returns the a
_Returns_: the geocoder object. The return value of this function is not useful - you must use a callback to get results. _Returns_: the geocoder object. The return value of this function is not useful - you must use a callback to get results.
### Reverse Geocoding Sample Codes ### Reverse Geocoding Sample Code
```javascript ```javascript
var geocoder = L.cedarmaps.geocoder('cedarmaps.streets'); var geocoder = L.cedarmaps.geocoder('cedarmaps.streets');
geocoder.reverseQuery({lat: 35.754592526442465, lng: 51.401896476745605}, function callback(err, res){}); geocoder.reverseQuery({lat: 35.754592526442465, lng: 51.401896476745605}, function callback(err, res){});
...@@ -161,6 +163,40 @@ geocoder.reverseQuery({lat: 35.754592526442465, lng: 51.401896476745605}, functi ...@@ -161,6 +163,40 @@ geocoder.reverseQuery({lat: 35.754592526442465, lng: 51.401896476745605}, functi
_Example_: Check out a [Live example of reverseQuery](https://demo.cedarmaps.com/websdk/demos/reverse-geocoder.html). _Example_: Check out a [Live example of reverseQuery](https://demo.cedarmaps.com/websdk/demos/reverse-geocoder.html).
### Direction
Calculates a route between a start and end point (and optionally some middle points) up to 100 points in GeoJSON format:
| Options | Value | Description |
| ---- | ---- | ---- |
| Profile (_required_) | String | Default and the only current available value: `cedarmaps.driving`. |
| LatLngs (_required_) | String | A pair of `lat` and `lng` points indicating start, middle and end, in format: `lat,lng;lat,lng;[lat,lng...]` (Up to 100 points) |
| callback (_required_) | function | A callback with passed params: `(error, result)`. |
_Returns_: the `direction` object. The return value of this function is not useful - you must use a callback to get the results.
### Direction Sample Code
```javascript
direction.route('cedarmaps.driving', '35.764335,51.365622;35.7604311,51.3939486;35.7474946,51.2429727', function(err, json) {
var RouteGeometry = json.result.routes[0].geometry;
var RouteLayer = L.geoJSON(RouteGeometry, {
// for more styling options check out:
// https://leafletjs.com/reference-1.3.0.html#path-option
style: function(feature) {
return {
color: '#f00',
weight: 5
}
}
}).addTo(map);
map.fitBounds(RouteLayer.getBounds());
});
});
```
_Example_: Check out a [Live example of Direction](https://demo.cedarmaps.com/websdk/demos/direction.html).
### Administrative Boundaries Lister ### Administrative Boundaries Lister
### `administrativeBoundaries.query(type, query, callback)` ### `administrativeBoundaries.query(type, query, callback)`
Lists administrative boundaries in 3 different levels: `province`, `city`, `locality` (aka. neighborhood). Lists administrative boundaries in 3 different levels: `province`, `city`, `locality` (aka. neighborhood).
...@@ -173,7 +209,7 @@ Lists administrative boundaries in 3 different levels: `province`, `city`, `loca ...@@ -173,7 +209,7 @@ Lists administrative boundaries in 3 different levels: `province`, `city`, `loca
_Returns_: the `L.cedarmaps.administrativeBoundaries` object. _Returns_: the `L.cedarmaps.administrativeBoundaries` object.
### Administrative Boundaries Lister Sample Codes ### Administrative Boundaries Lister Sample Code
```javascript ```javascript
var administrativeLister = L.cedarmaps.administrativeBoundaries(); var administrativeLister = L.cedarmaps.administrativeBoundaries();
// Get list of all provinces of Iran. // Get list of all provinces of Iran.
......
...@@ -53,12 +53,13 @@ ...@@ -53,12 +53,13 @@
*/ */
var direction = L.cedarmaps.direction(); var direction = L.cedarmaps.direction();
// you should provide start/end/middle points in the following format: lat,ln;lat,lng;lat,lng // Points should be separated by a semicolon. e.g.: lat,lng;lat,lng;lat,lng....
direction.route('cedarmaps.driving', '35.764335,51.365622;35.763316,51.365322', function(err, json) { // You can provide up to 100 stops (including start, middle and end points) for a direction request. Here we provided 3.
var geometry = json.result.routes[0].geometry; direction.route('cedarmaps.driving', '35.764335,51.365622;35.7604311,51.3939486;35.7474946,51.2429727', function(err, json) {
var RouteGeometry = json.result.routes[0].geometry;
var route = L.geoJSON(geometry, { var RouteLayer = L.geoJSON(RouteGeometry, {
// for more path options see: https://leafletjs.com/reference-1.3.0.html#path-option // for more styling options check out: https://leafletjs.com/reference-1.3.0.html#path-option
style: function(feature) { style: function(feature) {
return { return {
color: '#f00', color: '#f00',
...@@ -66,7 +67,8 @@ ...@@ -66,7 +67,8 @@
} }
} }
}).addTo(map); }).addTo(map);
map.fitBounds(route.getBounds());
map.fitBounds(RouteLayer.getBounds());
}); });
</script> </script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment