Author Archives: om

Cesiumjs – How to access the coordinates

phpmind-cesiumjs-access-the-coordinates

 var entities = dataSource.entities.values; 
                console.log("entities_positions"); 
                for (var i = 0; i < entities.length; i++) { 
                    entity =  entities[i]; 
                      var cartesianPositions = entity.polyline.positions; 
                      var cartographicPositions = viewer.scene.globe.ellipsoid.cartesianArrayToCartographicArray(cartesianPositions._value); 
                      var longitude = cartographicPositions[0].longitude; 
                      var latitude = cartographicPositions[0].latitude; 
                      var height = cartographicPositions[0].height; 
                      console.log(longitude); 
                      console.log(latitude); 

                } 

Those coordinates are given in radians. You can convert them back to degrees with Cesium.Math.toDegrees(radianValue).

Share

Cesiumjs – Show and hide multiple entity/labels

How can i toggle multiple labels/entities ?

phpmind-cesiumjs-show-hide

var viewer = new Cesium.Viewer('cesiumContainer', { infoBox : false });
var entities = viewer.entities;

var labels = entities.add(new Cesium.Entity());

var longitude = - 106;
for (var i = 0; i < 5; ++i) {
    entities.add({
        parent : labels,
        position : Cesium.Cartesian3.fromDegrees(longitude, 45.0),
        label : {
            text : i.toString()
        }
    });
    longitude++;
}

viewer.zoomTo(viewer.entities);

Sandcastle.addToolbarButton('Toggle Labels', function(){
    labels.show = !labels.show;
});
Share

cesiumjs – How to Make Multicolor Polyline

How does segmenting a polyline into different colors work.

Cesiumjs-Multicolor-Polyline

var viewer = new Cesium.Viewer('cesiumContainer');

var primitive = new Cesium.Primitive({
  geometryInstances : new Cesium.GeometryInstance({
    geometry : new Cesium.PolylineGeometry({
      positions : [
        Cesium.Cartesian3.fromElements(-2822918.76, -1347627.64, 5539750.33),
        Cesium.Cartesian3.fromElements(-2860091, -1790883.7, 6104936.09),
        Cesium.Cartesian3.fromElements(-2869994.31, -2212991.67, 6598178.01)
      ],
      width : 2.0,
      vertexFormat : Cesium.PolylineColorAppearance.VERTEX_FORMAT,
      colors: [Cesium.Color.RED, Cesium.Color.BLUE],
      colorsPerVertex: false
    })
  }),
  appearance : new Cesium.PolylineColorAppearance({
    translucent : false
  })
});

viewer.scene.primitives.add(primitive);
Share

How to enable cross-origin resource sharing using php

I was working on parsing KML data file from different resources which had different urls and Cesiumjs was unable to read/parse, that is how i come to know enabling cross-origin resource sharing.
It is also called CORS. Here is more details .

Following these steps you can enable “CORS”.
1. First check if you have apache module installed, using php.

  

2. Use command line to check if you have “Access-Control-Allow-Origin: *”

Command is - curl -I http://yourwebsite.com

3. If you don’t see this line “Access-Control-Allow-Origin: *” in curl -I output you need to add and enable it in either in PHP file ot .htacces file.

HTTP/1.1 302 Found
Date: Sat, 19 Sep 2015 00:31:41 GMT
Server: Apache
Access-Control-Allow-Origin: *
Set-Cookie: PHPSESSID=k1ejs4ra2gsu2id387h472one2; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Location: https://phpmind.com/index.php
Content-Type: text/html; charset=UTF-8
Set-Cookie: BIGipServer~DART-Dev~DART=1241032896.20480.0000; path=/

4. Now its time to add code and enable your missing part!

In .htaccess

 

    Header set Access-Control-Allow-Origin "*"

In PHP file

header("Access-Control-Allow-Origin: *"); // for all

header('Access-Control-Allow-Origin: http://www.rnai.technology'); // For particular URL
header('Access-Control-Allow-Origin: http://phpmind.com');
header('Access-Control-Allow-Origin: http://maps.google.com');

After that you need to test using

Command is - curl -I http://yourwebsite.com

You must see Access-Control-Allow-Origin: *” with headers.

Share

How to check which apache modules are installed using php?

If you don’t have command line access use this code to see which apache modules are installed.

  

This will show a list like that.
By the way this not my server 🙂

Array
(
[0] => core
[1] => prefork
[2] => http_core
[3] => mod_so
[4] => mod_auth_basic
[5] => mod_auth_digest
[6] => mod_authn_file
[7] => mod_authn_alias
[8] => mod_authn_anon
[9] => mod_authn_dbm
[10] => mod_authn_default
[11] => mod_authz_host
[12] => mod_authz_user
[13] => mod_authz_owner
[14] => mod_authz_groupfile
[15] => mod_authz_dbm
[16] => mod_authz_default
[17] => util_ldap
[18] => mod_authnz_ldap
[19] => mod_include
[20] => mod_log_config
[21] => mod_logio
[22] => mod_env
[23] => mod_ext_filter
[24] => mod_mime_magic
[25] => mod_expires
[26] => mod_deflate
[27] => mod_headers
[28] => mod_usertrack
[29] => mod_setenvif
[30] => mod_mime
[31] => mod_dav
[32] => mod_status
[33] => mod_autoindex
[34] => mod_info
[35] => mod_dav_fs
[36] => mod_vhost_alias
[37] => mod_negotiation
[38] => mod_dir
[39] => mod_actions
[40] => mod_speling
[41] => mod_userdir
[42] => mod_alias
[43] => mod_substitute
[44] => mod_rewrite
[45] => mod_proxy
[46] => mod_proxy_balancer
[47] => mod_proxy_ftp
[48] => mod_proxy_http
[49] => mod_proxy_ajp
[50] => mod_proxy_connect
[51] => mod_cache
[52] => mod_suexec
[53] => mod_disk_cache

Share

What is MapReduce?


About MapReduce
MapReduce is the heart of Hadoop®. It is this programming paradigm that allows for massive scalability across hundreds or thousands of servers in a Hadoop cluster. The MapReduce concept is fairly simple to understand for those who are familiar with clustered scale-out data processing solutions.

For people new to this topic, it can be somewhat difficult to grasp, because it’s not typically something people have been exposed to previously. If you’re new to Hadoop’s MapReduce jobs, don’t worry: we’re going to describe it in a way that gets you up to speed quickly.
The term MapReduce actually refers to two separate and distinct tasks that Hadoop programs perform. The first is the map job, which takes a set of data and converts it into another set of data, where individual elements are broken down into tuples (key/value pairs). The reduce job takes the output from a map as input and combines those data tuples into a smaller set of tuples. As the sequence of the name MapReduce implies, the reduce job is always performed after the map job.

An example of MapReduce
Let’s look at a simple example. Assume you have five files, and each file contains two columns (a key and a value in Hadoop terms) that represent a city and the corresponding temperature recorded in that city for the various measurement days. Of course we’ve made this example very simple so it’s easy to follow. You can imagine that a real application won’t be quite so simple, as it’s likely to contain millions or even billions of rows, and they might not be neatly formatted rows at all; in fact, no matter how big or small the amount of data you need to analyze, the key principles we’re covering here remain the same. Either way, in this example, city is the key and temperature is the value.
Toronto, 20
Whitby, 25
New York, 22
Rome, 32
Toronto, 4
Rome, 33
New York, 18
Out of all the data we have collected, we want to find the maximum temperature for each city across all of the data files (note that each file might have the same city represented multiple times). Using the MapReduce framework, we can break this down into five map tasks, where each mapper works on one of the five files and the mapper task goes through the data and returns the maximum temperature for each city. For example, the results produced from one mapper task for the data above would look like this:
(Toronto, 20) (Whitby, 25) (New York, 22) (Rome, 33)
Let’s assume the other four mapper tasks (working on the other four files not shown here) produced the following intermediate results:
(Toronto, 18) (Whitby, 27) (New York, 32) (Rome, 37)(Toronto, 32) (Whitby, 20) (New York, 33) (Rome, 38)(Toronto, 22) (Whitby, 19) (New York, 20) (Rome, 31)(Toronto, 31) (Whitby, 22) (New York, 19) (Rome, 30)
All five of these output streams would be fed into the reduce tasks, which combine the input results and output a single value for each city, producing a final result set as follows:
(Toronto, 32) (Whitby, 27) (New York, 33) (Rome, 38)
As an analogy, you can think of map and reduce tasks as the way a census was conducted in Roman times, where the census bureau would dispatch its people to each city in the empire. Each census taker in each city would be tasked to count the number of people in that city and then return their results to the capital city. There, the results from each city would be reduced to a single count (sum of all cities) to determine the overall population of the empire. This mapping of people to cities, in parallel, and then combining the results (reducing) is much more efficient than sending a single person to count every person in the empire in a serial fashion.

Share

How to add days in a date string using JavaScript ?

This is how you can add number of days in a date string using JavaScript.
In this example i have added 6 days in a date. Please check the demo.

	var someDate = new Date("2014-06-20");
	var numberOfDaysToAdd = 6; // add 6 days
	someDate.setDate(someDate.getDate() + numberOfDaysToAdd);

	var dd = someDate.getDate();
	var mm = someDate.getMonth() + 1;
	var y = someDate.getFullYear();

	var someFormattedDate = y +'-'+ mm +'-'+dd;
// output 2014-06-25

Another example using php.
You can add any number of days if you want to reduce number of days use minus(-) sign instead.


Demo

Share

How to Convert Seconds to Minute ?

There are 2 ways to convert Seconds into minute. Its super simple.

One - 
$seconds = "110";
$minutes = floor($seconds/60);
$secondsleft = $seconds%60;
if($minutes<10)
    $minutes = "0" . $minutes;
if($secondsleft<10)
    $secondsleft = "0" . $secondsleft;
echo "$minutes:$secondsleft Sec";
echo "
"; Two - echo gmdate("i.s", $seconds);
Share

How to Use CSS3 Transitions ?

  • transition:

    On this property, effect take place in an element smoothly over a given time period. Specifying duration is compulsory to see the effect. We need to specify transition-property, transition-duration, transition-timing-function and finally transition-delay.

    Web designers can easily provide beautiful effects with the help of transition withoutusing jquery.

  • Browser support: Firefox, Chrome, Opera, IE10+, and Safari. Add prefix -webkit- for chrome 25 and its earlier versions and safari.
    Add prefix -moz- for firefox.
    Add prefix -ms- for IE.

    1. Transition-properties: Lists the properties which you need to be transitioned. Some properties which can be trasitioned are border, font-size, background-color, line-height, letter spacing etc. Whole list of the properties is mentioned on the w3c website.
      .div
      { 
      border-radius:90px; 
      width:120px; 
      height:120px; 
      background:#F60;
      }
      .div:hover
      { 
      width:150px;
      height:150px;
      transition-property:width;
      -webkit-transition-property: width, height; /* Safari */
      -moz-transition-property: width, height; /* Firefox 4 */
      -o-transition-property:width, height; /* Opera */
      transition-duration: 3s;
      -webkit-transition-duration: 3s; /* Safari */
      }
      

      Here transition property is applies to width and height.

    2. Transition-duration: This sets the time or the duration of the effect.
    3. Transition-timing-function: Six options are available in this function. Ease, ease-in, ease-out, linear, ease-in-out and cubic-bezier. By default ease is selected. You can use cubic bezier if you are looking for very fine effect. It helps you to choose your own value for the effect.
      1. Linear: Animation carries same speed from start to an end.

        Linear
      2. Ease: Speed is fast in the begining and slow down at the end.

        Ease
      3. Ease-out: Ease-out is quite similar to the ease. But it is slower in beginning in comparison to ease.

        Ease-out
      4. Ease-in: Ease-in gives the smooth effect to the animation.
        Ease-in
      5. Ease-in-out: Speed of an animation is slow in the beginning and at the end.
        Ease-in-out
      6. Cubic-bezier: The function can be customized by using the values of your own.
        Cubic-bezier
    4. transition-delay: This function sets the time before animation begins.
      .div
      {
      position:absolute;
      left:0;
      opacity: 1;
      transition: opacity 2s ease-in 2s;
      -o-transition: opacity 2s ease-in  2s;
      -webkit-transition: opacity 2s ease-in 2s;
      -moz-transition: opacity 2s ease-in 2s;
      -ms-transition: opacity 2s ease-in 2s;				
      }
      

      In the above example image fading starts after 2 seconds.

Share