1.0.13 • Published 5 years ago

angularjs-mapbox v1.0.13

Weekly downloads
18
License
ISC
Repository
github
Last release
5 years ago

angular-mapbox

AngularJS MapBox library

Installation

$   npm install angularjs-mapbox

Quick Start

  1. In your html, import the library <script src="node_modules/angularjs-mapbox/index.js"></script>
  2. Include the css (or scss) in your html <link rel="stylesheet" href="node_modules/angularjs-mapbox/angular-mapbox.css"></link>

HTML Example:

<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet" href="node_modules/angularjs-mapbox/angular-mapbox.css">
</head>
<body ng-app="baseApp">
    <h2>Your amazing site goes here</h2>
    <div ng-controller="mapController">
        ...
    </div>

    <script src = "node_modules/angular/angular.min.js"></script>
    <script src="node_modules/angularjs-mapbox/index.js"></script>
    <script src="/path/to/your/javascript.js"></script>
</body>
</html>
  1. Import in the global modules' section:
var app = angular.module('baseApp', [
    'angularMapbox'
]);
  1. Add the key in the config section:
app.config(
    [
        'angularMapboxConfigProvider', 
        function(angularMapboxConfigProvider) {
            angularMapboxConfigProvider.config({
                accessToken: '<YOUR ACCESS TOKEN>'
            });
        }
    ]
);
  1. In your controller, declare some variables you'll use in the map for center and zoom
app.controller('mapController', function($scope) {
    $scope.map = {
        zoom: 12,
        center: [ -74.804486, 10.980780 ]
    };
});
  1. Create a new map!
<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet" href="node_modules/angularjs-mapbox/angular-mapbox.css">
</head>
<body ng-app="baseApp">
    <h2>Your amazing site goes here</h2>
    <div ng-controller="mapController">
        <angular-mapbox-map zoom="map.zoom" center="map.center" design="'mapbox://styles/mapbox/dark-v9'">
        </angular-mapbox-map>
    </div>

    <script src="node_modules/angular/angular.min.js"></script>
    <script src="node_modules/angularjs-mapbox/index.js"></script>
    <script src="/path/to/your/javascript.js"></script>
</body>
</html>

Marker Example

You can create one or more markers in the map:

<angular-mapbox-map zoom="map.zoom" center="map.center" design="'mapbox://styles/mapbox/dark-v9'">
    <angular-mapbox-marker ng-repeat="marker in markers" model="marker" identificator="'id'"></angular-mapbox-marker>
</angular-mapbox-map>
app.controller('mapController', function($scope) {
    $scope.map = {
        zoom: 12,
        center: [ -74.804486, 10.980780 ]
    };

    $scope.markers = [{
        id: 'marker-1',
        lat: -74.804486,
        lng: 10.980780
    }, {
        id: 'marker-2',
        lat: -74.812486,
        lng: 10.985781
    }];
});

You can see more examples here

Directive Reference

Map angular-mapbox-map

attributetypevalue
zoomnumericThe number of zoom
centerarraylongitude, latitude
eventsobjectRefer to documentation for more information. See examples of how to use it.
designstringSome of predefined styles: - mapbox://styles/mapbox/streets-v10 - mapbox://styles/mapbox/outdoors-v10 - mapbox://styles/mapbox/light-v9 - mapbox://styles/mapbox/dark-v9 - mapbox://styles/mapbox/satellite-v9 - mapbox://styles/mapbox/satellite-streets-v10 - mapbox://styles/mapbox/navigation-preview-day-v2 - mapbox://styles/mapbox/navigation-preview-night-v2 - mapbox://styles/mapbox/navigation-guidance-day-v2 - mapbox://styles/mapbox/navigation-guidance-night-v2

Marker angular-mapbox-marker

attributetypevalue
modelobjectan object with the required values: lat, lng and additional a id field that should be unique. See examples for more information
identificatorstringthe value inside the model who has the identificator name (unique). Example: 'id'
eventsobjectRefer to documentation for more information. See ./examples of how to use it. Additional, you can set events like click to the addEventListener include on the market itself. See this documentation

Circle angular-mapbox-circle

attributetypevalue
centerArrayAn array with longitude, latitude
identificatorstringA unique name for the object. Example: 'my-circle-id'
radiusnumberThe radius of the circle (see unit)
unitstringunit used on the radius: px (pixels), m (meters), km (kilometers)
layoutobjectOptions for layout (See documentation)
paintobjectOptions for paint (See documentation)

GeoJSON angular-mapbox-geojson

attributetypevalue
identificatorstringthe value inside the model who has the identificator name (unique). Example: 'id'
typestringThe type of the Layer you want to create (See documentation)
dataobjectThe source of the geojson. See documentation
layoutobjectOptions for layout (See documentation)
paintobjectOptions for paint (See documentation)

To Do

  • Finish Examples
  • Finish documentation for geojson
  • Finish documentation for popup
  • Develop more stuff for mapboxgl library
1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago