mohsen-angular-leaflet-directive
Version:
angular-leaflet-directive - An AngularJS directive to easily interact with Leaflet maps
72 lines (64 loc) • 2.48 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('MarkersCompiledWithoutIconController', [ '$scope', function($scope) {
$scope.setSourceMarker = function () {
alert($scope.markers.popup.lat + " " + $scope.markers.popup.lng)
}
$scope.setDestinationMarker = function () {
alert($scope.markers.popup.lat + " " + $scope.markers.popup.lng)
};
var getNewPopupMarker = function(lat, lng) {
return {
lat: lat,
lng: lng,
focus: true,
opacity: 1,
icon: {
iconUrl: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wsIFR0j2j5hUQAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAAADElEQVQI12P4//8/AAX+Av7czFnnAAAAAElFTkSuQmCC', // Transparent pixel
iconSize: [0, 0], // size of the icon
popupAnchor: [0, 0] // point from which the popup should open relative to the iconAnchor
},
message: "<button ' \
ng-click='setSourceMarker()'>First button</button> \
<button class='btn btn-danger btn-block' \
ng-click='setDestinationMarker()'>Second button</button>",
getMessageScope: function () {
return $scope;
},
};
};
$scope.$on("leafletDirectiveMap.click", function (event, args) {
var leafEvent = args.leafletEvent;
var lat = leafEvent.latlng.lat;
var lng = leafEvent.latlng.lng;
$scope.markers.popup.lat = lat;
$scope.markers.popup.lng = lng;
$scope.markers.popup.focus = true;
});
angular.extend($scope, {
chicago: {
lat: 41.85,
lng: -87.65,
zoom: 8
},
markers: {
popup: getNewPopupMarker(41.85, -87.65)
}
});
}]);
</script>
</head>
<body ng-controller="MarkersCompiledWithoutIconController">
<leaflet lf-center="chicago" lf-markers="markers" height="480px" width="100%"></leaflet>
<h1>Changing Icon Rotation</h1>
</div>
</body>
</html>