mohsen-angular-leaflet-directive
Version:
angular-leaflet-directive - An AngularJS directive to easily interact with Leaflet maps
73 lines (70 loc) • 3.44 kB
HTML
<html ng-app="demoapp">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="../bower_components/angular/angular.min.js"></script>
<script src="../bower_components/leaflet/dist/leaflet.js"></script>
<script src="../dist/angular-leaflet-directive.min.js"></script>
<link rel="stylesheet" href="../bower_components/leaflet/dist/leaflet.css" />
<script>
var app = angular.module("demoapp", ["leaflet-directive"]);
app.controller('BasicTilesController', [ '$scope', function($scope) {
var tilesDict = {
openstreetmap: {
url: "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
options: {
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}
},
opencyclemap: {
url: "http://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png",
options: {
attribution: 'All maps © <a href="http://www.opencyclemap.org">OpenCycleMap</a>, map data © <a href="http://www.openstreetmap.org">OpenStreetMap</a> (<a href="http://www.openstreetmap.org/copyright">ODbL</a>'
}
},
mapbox_outdoors: {
name: 'Mapbox Outdoors',
url: 'http://api.tiles.mapbox.com/v4/{mapid}/{z}/{x}/{y}.png?access_token={apikey}',
type: 'xyz',
options: {
apikey: 'pk.eyJ1IjoiYnVmYW51dm9scyIsImEiOiJLSURpX0pnIn0.2_9NrLz1U9bpwMQBhVk97Q',
mapid: 'bufanuvols.lia3no0m'
}
},
mapbox_wheat: {
name: 'Mapbox Wheat Paste',
url: 'http://api.tiles.mapbox.com/v4/{mapid}/{z}/{x}/{y}.png?access_token={apikey}',
type: 'xyz',
options: {
apikey: 'pk.eyJ1IjoiYnVmYW51dm9scyIsImEiOiJLSURpX0pnIn0.2_9NrLz1U9bpwMQBhVk97Q',
mapid: 'bufanuvols.lia35jfp'
}
}
};
angular.extend($scope, {
london: {
lat: 51.505,
lng: -0.09,
zoom: 8
},
tiles: tilesDict.mapbox_wheat
});
$scope.changeTiles = function(tiles) {
$scope.tiles = tilesDict[tiles];
};
} ]);
</script>
</head>
<body ng-controller="BasicTilesController">
<leaflet lf-center="london" lf-tiles="tiles" lf-defaults="defaults" width="100%" height="480px"></leaflet>
<h1>Changing tiles example</h1>
<p>Change tiles clicking in the buttons below:</p>
<p>
<button ng-click="changeTiles('opencyclemap')" class="btn btn-default">OpenCycleMaps</button>
<button ng-click="changeTiles('openstreetmap')" class="btn btn-default">OpenStreetMaps</button>
<button ng-click="changeTiles('mapbox_outdoors')" class="btn btn-default">Mapbox Outdoors</button>
<button ng-click="changeTiles('mapbox_wheat')" class="btn btn-default">Mapbox Wheat Paste</button>
</p>
<p>Current TileLayer Url: <strong ng-bind="tiles.url"></strong></p>
</body>
</html>