Skip to main content

Create mapify app using Angularjs and other frameworks

Getting prepared
We will utilize the same code that we utilized as a part of the past case as a beginning stage. What’s more, it is suggested that you as of now have Bower introduced on your framework. On the off chance that you don’t have or know Bower, don’t stress, we will exhibit how to introduce it physically.
At the root project folder, open your terminal window and type:
bower install ngmap --save
To get the directive to work properly, you need to add the Google Maps script. In this example, we will use the code directly from the Google CDN through this
link: //maps.google.com/maps/api/js.
Open the index.html file and add the following script tag right after the mappingService.js script:
Add the ng-map script right after the Google Maps script: Don’t place any code inside the tag; when generators run any task, this block of code is always replaced. Open the app.js file and add the following highlighted code to the angularjs dependencies:
angular.module('yeomananddirectives', [ 'ngResource', 'ui.bootstrap', 'ngCookies', 'ngAnimate', 'ngTouch', 'ngSanitize', 'ui.router', 'mapping', 'ngMap', ])
At this point, we have our directive maps installed in our application. Now, let’s see the necessary steps to use the directive. Open mapping.html and add the following code:
Open mappingCtrl.js and add the following code:
var positions = [ { lat: -23.630153, lng: -46.563964 }, { lat: -23.625828, lng: -46.571946 }, { lat: -23.634006, lng: -46.576066 }, { lat: -23.624883 ,lng: -46.564209 } ]; $scope.positions = positions;
Let’s check the final result. Open your terminal window and type the following command: grunt dev Your default browser will open at the application welcome screen. Check the mapping URL
http://127.0.0.1:8000/#!/mapping.
Add the following code to the mappingService.js file inside the mapping module:
var positions = [ { lat: -23.630153, lng: -46.563964 }, { lat: -23.625828, lng: -46.571946 }, { lat: -23.634006, lng: -46.576066 }, { lat: -23.624883 ,lng: -46.564209 } ]; return { all: function() { return positions; } }
Now, add the mappingService factory to mappingCtrl as a dependency:
angular.module('mapping') .controller('MappingCtrl', ['$scope','MappingService', function ($scope, MappingService) { // Using a service $scope.positions = MappingService.all(); }]);
In this way, we have a greater flexibility to use this directive. Tip
Note that our service in a real application will be an endpoint to a server that returns the positions stored in a database.

Comments

Popular posts from this blog

Learn Nodejs

My favorite resource is "nodeschool.io!" "Install these choose-your-own-adventure style lessons and learn how to use node.js, npm and other related tools by writing code to solve realistic problems. The lessons run in your terminal and work on Windows, Mac and Linux."   Tutorials Hello World Hello World Web Server Node.js guide Build a blog with Node.js, express and mongodb Node.Js Tutorials At Project 70 Node.js for Beginners Learn Node.js Completely and with Confidence Videos Node tuts Introduction to Node.js with Ryan Dahl Node.js: Asynchronous Purity Leads to Faster Development Parallel Programming with Node.js Server-side JavaScript with Node, Connect & Express Node.js First Look Node.js with MongoDB Ryan Dahl's Google Tech Talk Screencasts Learn All The Nodes NodeTuts NodeCasts Books " The Node Beginner Book Mastering Node.js Up and Running with Node.js Node.js in Action Smashing Node.js: JavaScript Ev...
If you want lists, for back-end languages (in order of my ability to recall): If you want lists, for back-end languages (in order of my ability to recall): Java (and other JVM languages like Scala, Groovy, Clojure) PHP .NET (C#, VB) Ruby Python Perl Javascript (Node JS) Actionscript (Flash Media Server) CoffeeScript C (CGI) Erlang oh, and SQL for db queries For browser-based front-end languages, you're somewhat limited in what the browser can support (excluding launching out-of-browser applications). We could talk about: HTML Javascript CSS Actionscript CoffeeScript (compiled to Javascript) XML-based languages (X3D, SMIL, SVG, DITA, some interpreted by the browser, others transformed using XSL) VBScript Silverlight Java (applets) For native PC desktop front-ends, most popular front-end languages would probably be (I'm guessing, in no order): Visual Basic 6 (from my experience with big enterprises, I bet a lot of those are still out there, just like Windows Vista) .NET Jav...