UNPKG

mohsen-angular-leaflet-directive

Version:

angular-leaflet-directive - An AngularJS directive to easily interact with Leaflet maps

76 lines (74 loc) 3.06 kB
<!DOCTYPE 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> <script src="../bower_components/leaflet.draw/dist/leaflet.draw.js"></script> <link rel="stylesheet" href="../bower_components/leaflet/dist/leaflet.css" /> <link rel="stylesheet" href="../bower_components/leaflet.draw/dist/leaflet.draw.css" /> <script> var app = angular.module("demoapp", ["leaflet-directive"]); app.controller("ControlsDrawController", [ "$scope", "leafletData", function($scope, leafletData) { angular.extend($scope, { london: { lat: 51.505, lng: -0.09, zoom: 4 }, controls: { draw: {} }, layers: { baselayers: { mapbox_light: { name: 'Mapbox Light', url: 'http://api.tiles.mapbox.com/v4/{mapid}/{z}/{x}/{y}.png?access_token={apikey}', type: 'xyz', layerOptions: { apikey: 'pk.eyJ1IjoiYnVmYW51dm9scyIsImEiOiJLSURpX0pnIn0.2_9NrLz1U9bpwMQBhVk97Q', mapid: 'bufanuvols.lia22g09' }, layerParams: { showOnSelector: false } } }, overlays: { draw: { name: 'draw', type: 'group', visible: true, layerParams: { showOnSelector: false } } } } }); leafletData.getMap().then(function(map) { leafletData.getLayers().then(function(baselayers) { var drawnItems = baselayers.overlays.draw; map.on('draw:created', function (e) { var layer = e.layer; drawnItems.addLayer(layer); console.log(JSON.stringify(layer.toGeoJSON())); }); }); }); }]); </script> <style> input { width: 120px; margin-right: 10px; } </style> </head> <body ng-controller="ControlsDrawController"> <leaflet lf-center="london" lf-controls="controls" lf-layers="layers" width="100%" height="400"></leaflet> <h1>Draw control example</h1> <p>Draw a shape and a geoJSON data structure will be shown on the console.log.</p> </body> </html>