Skip to content

Commit

Permalink
1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyverbruggen@gmail.com committed Oct 3, 2015
1 parent 69847ad commit b9f4f53
Show file tree
Hide file tree
Showing 28 changed files with 520 additions and 23,456 deletions.
176 changes: 124 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,78 +1,150 @@
# NativeScript Maps - by Mapbox

ALMOST DONE, hang in there :)

TODO update these instructions for the 1.3.0 release

Wait until {N} 1.3.0 is released because now we need to:
- After installation copy ios/Podfile to platforms/ios and from the command prompt run `pod install`
- Then always use the xcworkspace file
- Manually add MGLMapboxAccessToken to .plist (1.3 merges correctly and is likely also to support passing in preferences dynamically)
- Same for NSLocationWhenInUseUsageDescription (=YES)
- Copy in Settings.bundle

Until then we can develop in XCode, but the {N} CLI can't run the project.



TODO all below


# NativeScript Mapbox

Awesome native OpenGL powered maps - by Mapbox

## Prerequisites
NativeScript 1.2.3 (`tns --version`) has solved many build issues, so please upgrade if you need to.

## Prerequisites for Android
Check if you have Android-19 installed (required for building the ZXing library), run this from the command prompt:
```
android list targets
```
NativeScript 1.3.0 (`tns --version`) is required for smooth installation, so please upgrade if you need to.

If it's not listed, run:
## Installation
From the command prompt go to your app's root folder and execute:
```
android
tns plugin add nativescript-mapbox
```

.. and install Android 4.2.2 > SDK Platform
## Usage

For a quick demo simply copy-paste the contents of the demo folder to your app, but here's the comprehensive list of supported functions:

## Installation
From the command prompt go to your app's root folder and execute:
### function: show
```js
var mapbox = require("nativescript-mapbox");

mapbox.show({
accessToken: 'YOUR_ACCESSTOKEN_HERE',
style: 'emerald', // light|dark|emerald|satellite|streets , default 'streets'
margins: {
left: 40, // default 0
right: 40, // default 0
top: 450, // default 0
bottom: 40 // default 0
},
center: { // optional without a default
lat: 52.3702160,
lng: 4.8951680
},
zoomLevel: 9.25, // 0-20, default 0
showUserLocation: true, // default false - requires location permissions on Android which you can remove from AndroidManifest.xml if you don't need them
hideAttribution: true, // a clickable info icon - default true (as it may crash Android when tapped)
hideLogo: true, // default false - required for the Mapbox 'starter' plan
hideCompass: false, // default false
disableRotation: false, // default false
disableScroll: false, // default false
disableZoom: false, // default false
markers: [ // optional without a default
{
'lat': 52.3732160, // mandatory
'lng': 4.8941680, // mandatory
'title': 'Nice location', // recommended to pass in
'subtitle': 'Really really nice location' // one line is available on iOS, multiple on Android
}
]
}).then(
function(result) {
console.log("Mapbox show done");
},
function(error) {
console.log("mapbox show error: " + error);
}
)
```
tns plugin add nativescript-barcodescanner

### function: hide
All further examples assume `mapbox` has been required.
Also, all functions support promises, but we're leaving out the `.then()` stuff for brevity where it doesn't add value.
```js
mapbox.hide()
```

## Usage
### function: addMarkers
```js
mapbox.addMarkers([
{
'lat': 52.3602160, // mandatory
'lng': 4.8891680, // mandatory
'title': 'One-line title here', // no popup unless set
'subtitle': 'Infamous subtitle!'
},
{
..
}
])
```

### function: scan
### function: setCenter
```js
var barcodescanner = require("nativescript-barcodescanner");
mapbox.setCenter(
{
lat: 52.3602160, // mandatory
lng: 4.8891680, // mandatory
animated: false // default true
}
)
```

barcodescanner.scan({
cancelLabel: "Stop scanning", // iOS only, default 'Close'
message: "Go scan something", // Android only, default is 'Place a barcode inside the viewfinder rectangle to scan it.'
preferFrontCamera: false, // Android only, default false
showFlipCameraButton: true // Android only, default false (on iOS it's always available)
}).then(
### function: getCenter
Here the promise callback makes sense, so adding it to the example:
```js
mapbox.getCenter().then(
function(result) {
console.log("Scan format: " + result.format);
console.log("Scan text: " + result.text);
console.log("Mapbox getCenter done, result: " + JSON.stringify(result));
},
function(error) {
console.log("No scan: " + error);
console.log("mapbox getCenter error: " + error);
}
)
```

### function: setZoomLevel
Here the promise callback makes sense, so adding it to the example:
```js
mapbox.setZoomLevel(
{
level: 6.5, // mandatory, 0-20
animated: true // default true
}
)
```

### function: available
Note that the Android implementation will always return `true` at the moment.
### function: getZoomLevel
```js
var barcodescanner = require("nativescript-barcodescanner");
mapbox.getZoomLevel().then(
function(result) {
console.log("Mapbox getZoomLevel done, result: " + JSON.stringify(result));
},
function(error) {
console.log("mapbox getZoomLevel error: " + error);
}
)
```

barcodescanner.available().then(
function(avail) {
console.log("Available? " + avail);
### function: addPolygon
Draw a shape (like a line/route, or star). Just connect the dots like we did as a child. The first person to tweet a snowman drawn with this function gets a T-shirt.
```js
// this is a boring triangle drawn near Amsterdam Central Station
mapbox.addPolygon({
points: [
{
'lat': 52.3832160, // mandatory
'lng': 4.8991680 // mandatory
},
{
'lat': 52.3632160,
'lng': 4.9011680
},
{
'lat': 52.3932160,
'lng': 4.8911680
}
);
]
})
```
5 changes: 3 additions & 2 deletions demo/main-page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
<Button text="Hide" tap="{{ hideMapTapAction }}" />
<Button text="Add markers" tap="{{ addMarkersTapAction }}" />
<Button text="Set center" tap="{{ setCenterTapAction }}" />
<Button text="Get center" tap="{{ getCenterTapAction }}" />
<Button text="Get center (see console)" tap="{{ getCenterTapAction }}" />
<Button text="Set zoom level" tap="{{ setZoomLevelTapAction }}" />
<Button text="Get zoom level" tap="{{ getZoomLevelTapAction }}" />
<Button text="Get zoom level (see console)" tap="{{ getZoomLevelTapAction }}" />
<Button text="Add polygon" tap="{{ addPolygonTapAction }}" />
</StackLayout>
</Page>
Loading

0 comments on commit b9f4f53

Please sign in to comment.