mohsen-angular-leaflet-directive
Version:
angular-leaflet-directive - An AngularJS directive to easily interact with Leaflet maps
86 lines (84 loc) • 3.17 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.js"></script>
<link rel="stylesheet" href="../bower_components/leaflet/dist/leaflet.css" />
<style>
.map {
float: left;
margin-right: 1em;
}
</style>
<script>
var app = angular.module("demoapp", ["leaflet-directive"]);
app.controller("BasicDoubleMapToggleController", [ "$scope", "leafletLogger", "leafletData", function($scope, leafletLogger, leafletData) {
angular.extend($scope, {
center: {
lat: 51.505,
lng: -0.09,
zoom: 5
},
paths: {
p1: {
color: 'blue',
weight: 8,
latlngs: [{
lat: 51.50,
lng: -0.082
}, {
lat: 48.83,
lng: 2.37
}, {
lat: 41.91,
lng: 12.48
}]
}
},
});
angular.extend($scope, {
center2: {
lat: 51.505,
lng: -0.09,
zoom: 5
},
tiles2: {
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'
}
},
paths2: {
p1: {
color: 'red',
weight: 8,
latlngs: [{
lat: 51.50,
lng: -0.082
}, {
lat: 48.83,
lng: 2.37
}, {
lat: 41.91,
lng: 12.48
}]
}
},
});
}]);
</script>
</head>
<body ng-controller="BasicDoubleMapToggleController">
<leaflet ng-show="togglemap" id="map1" lf-center="center" lf-paths="paths" width="100%" height="480px"></leaflet>
<leaflet ng-show="!togglemap" id="map2" lf-center="center2" lf-tiles="tiles2" lf-paths="paths2" width="100%" height="480px"></leaflet>
<h1>Toggle between two maps on screen</h1>
<p>View javascript console while toggling map</p>
<button ng-click="togglemap = !togglemap">Toggle Map</button>
</div>
</body>
</html>