Wednesday, April 11, 2012

Why mouseover event not dispatching for polyline in google map?

I've a complex flow where I've to attach mouseover event for every polyline on the map. The code for attaching the event is simple:


google.maps.event.addListener(polyline, "mouseover", function() {
             console.log('event fired');
 
         });
 


But the event is attaching to few polylines and not to others. What might be the reason?


Edit


Following is some more code that is before the above code and used for defining polyline:


    this.polyline = new google.maps.Polyline({
                 path : [fromPosition, toPosition],
                 strokeColor : '#CCCCCC',
                 strokeOpacity : 1.0,
                 strokeWeight : 2
             });
    var polyline = this.polyline;
 


Edit 05-Apr-2012


Following is the code that creates problem, Please explain why it's happening and recommend any solution. Thanks


function Link(from, to) {
         this.from = from;
         this.to = to;
     }
 
 
     Link.prototype.show = function() {
         this.line = new google.maps.Polyline({
             path : [this.from, this.to],
             strokeColor : "#0000FF",
             strokeOpacity : 0.5,
             strokeWeight : 6
         });
 
         this.line.setMap(map);
 
         google.maps.event.addListener(this.line, 'mouseover', function() {
             this.line.setOptions({
                 strokeOpacity : 1
             });
         });
 
         google.maps.event.addListener(this.line, 'mouseout', function() {
             this.line.setOptions({
                 strokeOpacity : 0.5
             });
         });
     }
     var links = [];
     var link2 = new Link(new google.maps.LatLng(-3.5999999999999996, 23.4), new google.maps.LatLng(-4.5, 23.4)), link1 = new Link(new google.maps.LatLng(-3.5999999999999996, 23.4), new google.maps.LatLng(-3.5999999999999996, 18));
     links.push(link1);
     links.push(link2);
 
     // I've a long list of links, so I'll prefer a loop
     for(var i = 0; i < links.length; i++) {
             links[i].show();
     }
 


JSFiddle Demo : http://jsfiddle.net/wasimbhalli/9bg6x/



Answer:

I managed to work around this using the method described below. If I understood you correctly, the loop in which you attach a listener to a polyline does not in fact get "attached" to the polyline that way, but instead, you need a new class instance that contains the polyline and the listeners. This way, each polyline gets it's own listener.
Please, see the explanation below.
EDIT 5.4.2012
Here's also a crude JSFiddle demonstration of the code in action. Link to JSFiddle demo
function initialize() {

    // initialize Google Maps canvas normally

    var polylines = [];

    // Data set of the polylines you want to present on the map, 
    // e.g. [ { lat:"...",lon:"..." }, ...]

    var polylineData = [{ ... }] 

    for ( i in polylineData ) {
         var line = new google.maps.Polyline({ 
             path: [/*coordinates as google.maps.LatLng objects*/] 
         });

         // Create a new myPolyLineClass instance that contains the polyline data
         // and push it to polylines array.

         polylines.push(new myPolyLineClass(line));
    }

    // Set all the polylines and their individual listeners on map

    for ( i in polylines) {
        polylines[i].line.setMap(map);
    }
}
function MyPolylineClass(lineData) {
    this.line = lineData;

    // + all other data you want the polylines to contain

    // Add listeners using google.maps.event.addListener to all class instances
    // when they are constructed.

    // for instance:

    google.maps.event.addListener(line, 'mouseover', function() {
            line.setOptions({ [options you want to set when area is hovered 
            and selected] });
    });

    // Add listeners also for when polyline is not hovered anymore, respectively,
    // and other methods you might want to call when polylines are being interacted with.
};
Hope this helps!

(yet another) modify git history to add a very first commit

I am modifying someone else's (non-git) code. I downloaded the original, ensued my modifications, and jumped the gun and made the modified version my first commit. This was a mistake, I should have added the original downloaded code as my first commit.


Then to add insult to injury, I added the original code as a branch off of my first edit.. In other words it is a big mess now :(


In simple terms, what I have looks like the blue graph below. C5 is the actual original code, C1,C2-C6 are my gradual modifications (C4 is redundant). I'd rather have the green be my history.


enter image description here


Any ideas how to modify history to accomplish this?


Thanks many,


sly


Answer:

I have done this completely at the command-line, but am going to insert screenshots from SourceTree to illustrate what's going on.
First get the first 7 or 8 digits of commit id (50da9c3) from the C5 commit and put in on your clipboard or in textedit or something - you'll need it later
For confirmation, Here is our starting state:
enter image description here
Here are the steps to get where you want:
Create a new non-rooted branch to start building commits off of named base
git symbolic-ref HEAD refs/heads/base
Now remove all files and directories from git
git rm --cached -r .
Now that all the files are 'untracked' remove them from the local working directory
git clean -d --force
Now create a commit with nothing in it (this will be the commit on which everything else will be built).
git commit --allow-empty -m'Initial Commit'
Your tree should look like this now:
enter image description here
Now cherry pick the c5 commit (what you had on the clipboard)
git cherry-pick 50da9c3
enter image description here
Now re-root the master branch on to the base branch
git rebase --onto base --root master
enter image description here
Now you can delete the base and c4-c5 branches
git branch -d base
enter image description here
git branch -D c4-c5branch
enter image description here
Keep in mind the the 'Initial Commit' is an empty commit with no files, so don't be fooled. The C5 commit is actually the first content based commit.

plot extending several years

In the following example I have two years worth of data denoted by data_2007 and data_2008 which have a corresponding array of dates:


clear all
 DateTime_2007 = datestr(datenum('2007-01-01 00:00','yyyy-mm-dd HH:MM'):1/24:...
     datenum('2007-12-31 23:57','yyyy-mm-dd HH:MM'),...
     'yyyy-mm-dd HH:MM');
 DateTime_2007 = cellstr(DateTime_2007);
 
 DateTime_2008 = datestr(datenum('2008-01-01 00:00','yyyy-mm-dd HH:MM'):1/24:...
     datenum('2008-12-31 23:57','yyyy-mm-dd HH:MM'),...
     'yyyy-mm-dd HH:MM');
 DateTime_2008 = cellstr(DateTime_2008);
 
 data_2007 =  1 + (20-1).*rand(8760,1);
 data_2008 = 1 + (20-1).*rand(8784,1);
 


I would like to plot the data on one graph, showing how the data has varied over the 2 years, so basically a plot extending over 2 years. How can this be achieved, considering that I need the dates to be shown along the xaxis, and possible only the month name (mmm) to be given (not yyyy-mm-dd HH:MM).


Answer:


Have you tried the datetick command to label the axes?
plot(datenum(DateTime_2007),data_2007)
hold on
plot(datenum(DateTime_2008),data_2008,'g')
datetick('x','mmm')
It might be easier if you didn't convert your dates to date strings, and then have to convert them back for plotting.

How to drag & drop an image over a PDF page in android?

Here is my idea/requirement .



I want to open a pdf document on android device and edit the last page of pdf document by adding an image (pdf & image both are stored @ sdcard) to it. And the image should be draggable. i.e, i should be able to drag & drop the image wherever i want on last page of pdf doc. And when i click on one button (i.e save) the image should be merged with pdf at where i dropped it. Is it possible to edit a pdf by adding an image in such a way that the image should be draggable? How can i achieve it ? Please share some links/views.



Here is my code to add the image on a pdf file (using itext library). How do i make the image draggable ?



  PdfReader pdfReader = new PdfReader(PDF_PATH);                     
//copy of input pdf file
PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileOutputStream(NEW_PDF_PATH));

Image im = Image.getInstance(MY_IMAGE_PATH);
int numOfPages = pdfReader.getNumberOfPages();

for(int index = 1; index <= numOfPages; index++)
{
if( index == numOfPages)
{
PdfContentByte content = pdfStamper.getUnderContent(index);
im.setAbsolutePosition(50f,50f);
content.addImage(im);
}
}
pdfStamper.close();


or Please provide me any link from which i can get help. Thanks in Advance
Need very Urgently..





Cocoa - Where does NSCoding save?

what is the default saving location of NSCoding protocol?


Also, is there any way to change such a default location to say, the folder where the .app file is located?



Answer:

You can directly write your encoded object data encoded according NSCoding to a file using NSKeyedArchiver
Like this:
BOOL result = [NSKeyedArchiver archiveRootObject:yourObject toFile:filename];
With filename you can choose your file location (you may set it to the documents directory if you are on iOS).
EDIT 1: If you'd like to store in into NSUserDefault... do:
NSData *yourObjectAsNSData = [NSKeyedArchiver archivedDataWithRootObject:yourObject];
[[NSUserDefaults standardUserDefaults] setObject:yourObjectAsNSData forKey:@"aKey"]

Some of the Greek Characters in Java.AWT.Label are displayed as a box

When I read a greek string from a txt file encoded in UTF-8 format and try to display it as a Frame(Java.awt.frame) header it works fine, but when I set the same string as the text of a Label(Java.awt.Label) or Button(java.awt.Button), some of the characters (eg: '\u1F09' , especially the characters with with a quote on their head) are displayed as a box.



I have tried various fonts for the Label which support Greek characters like "DejaVu Sans", "Arial Unicode MS", "Cardo", etc but I wasnt able to get rid of the box character.



When I change the awt code to swing code (i.e., change Label to JLabel) the same code displays the correct Greek string. But it will be very difficult for me to replace every awt component with a swing component as it is a very large codebase.



Any help to solve this problem would be really appreciated. Thanks in advance !



Here is the code.. and I am running it on windows for now, but I need it to work on windows and MAC.



BufferedReader rd = null;
try {
rd = new BufferedReader(new InputStreamReader(new FileInputStream("D:/file.txt"), "UTF8"));
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
String s = null;
while ((s = rd.readLine()) != null) {

Label label = new Label();
Font f = new Font("DejaVu Sans Mono", Font.PLAIN, 15);
label.setFont(f);
label.setText(s);
mainPanel.add(label);

}
}


the one thing that makes it even more confusing is that.. when I run the same applet (which has AWT objects) on Eclipse with (widows->preferences->General->Workspace->Text file encoding as UTF-8) .. i am able to see the proper text. So, I was wondering if there is any way by which we can do this programatically.





What is the easiest way to practice PHP?

I am learning PHP and I'm looking for the simplest way to run practice scripts. I already have netbeans installed.