Skip to main content

Posts

Showing posts from January, 2017

A leaflet template for ionic

Leaflet is a very useful javascript library to insert map into an app. It has lots of extensions, which simplify it's use. I use it mainly in ionic's app, so I have created a repo on GitHub as a start point. It's extends the  side menu template  with leaflet. The key points are: Get a GeoJson  through an api call (markersApi.js) Create a map (with OSM as baselayer). Add the GeoJson to the map (using the  marker-cluster library ). Add a marker on tap. Add the map to the html To add leaflet map in ionic (and angular) there is a directive to simplify it: angular-leaflet-directive  (or you can use ui-leaflet ). In the html you can just put: <leaflet data-tap-disabled="true" defaults="map.defaults" id="map" layers="map.layers" lf-center="map.center"></leaflet> And after you have incluse in the app's model dependencies, the angular-leaflet directive, and have defined an object in the controlle

My notes on JavaScript

I started study JavaScript about one years ago, I studied the basic rule and then, due to my work, I moved quickly to use some framework ( Ionic and Angular ) so I omitted to study it in depth and also  the best practise... Because of this bad start, this December, I re-started to study and I'm writing some notes (mainly on different things than other languages). Variables keyword const, to declare a constant. Number : Number. NEGATIVE_INFINITY < Number.MIN_VALUE < Number.MAX_VALUE < Number.POSITIVE_INFINITY . Math is an "object" with the most common mathematic functions. Some useful method of Number: parseInt(), parseFloat(), isNaN(), isInfinite(). Multiline string , useful to include variable values into the string: var a=2; var b=2; var myString=`this is my value ${a+b} `; The if statement To test if an array is empty, simply use if( myArray.length ) not if( myArray.length>0 ). To test if a string is vo