• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

My Monkey Do

A Log of Coding Solutions

  • Home
  • Web Hosts
  • Tools
  • About

javascript

Firebug

May 14, 2011 by Webhead

I don’t know how I used to develop web pages before Firebug.  It is the single best tool you can have when debugging a webpage.  If something doesn’t look right I open Firebug and find out what styles are being inherited.  If some javascript functionality is not working I open Firebug and enter debug statements.   If some ajax call is messing up and the page isn’t showing the response correctly, I open Firebug.

Installation

The best thing about Firebug is how much time it saves you on debugging.  Even better than it being free.  That’s a lot considering how I watch my money.   I only use Firebug with Firefox.  It can be downloaded at https://addons.mozilla.org/en-us/firefox/addon/firebug/.  What’s good is that it’s available on both Mac and PC.   Just click on the Add to Firefox button and it’s mostly done for you.  That easy.  A firebug was also developed for IE but I haven’t tried it recently.  I tried it a couple years ago and it didn’t help me very much so I stuck with just using the Firefox one.

CSS

When you need to see why an item on a webpage is not showing as its supposed to you can right click on it and select “Inspect Element”.  Doing this opens up the firebug window and it will tell you exactly what styles are being applied to it and what styles have been overwritten.  You can even change the values of anything you want to see the outcome in real-time.

Javascript

Browsers can tell you the last error code that happened, but firebug can let you watch expressions, look at the stack, insert breakpoints, and print out statements in the console.

Request / Response

Any and all requests to the server can be inspected on the Net tab.  You can see each javascript include file, each image, each ajax request.  This means that if an ajax call goes wrong, you can inspect the parameters that were sent and the response the page got back from that request.  It makes debugging a breeze.

Firebug can be downloaded here: http://getfirebug.com/

Filed Under: Tools Tagged With: css, debug, firebug, html, javascript

Converting Google Maps v2 to v3

May 12, 2011 by Webhead

Problem:

I was given a project where the client switched from using http to https.  Everything worked fine except for their Google Maps page.  The page  had a warning in IE about unsecure mixed content.  This was because Google Maps was pulling from an http (unsecured) address.  It turns out that the Map was using version 2 of Google Maps API which does not support https.  Only version 3 does.

Solution:

Don’t be fooled into thinking this is a straight forward, simple upgrade.  It is not.  This solution is just a log of what I did to get the site from v2 up to v3.  It is in no way  a complete guide.  The site used EWindow instead of the infoWindow because of its customized look.  So I guess the following could be a rough step-by-step guide to converting the Ewindow script to v3.


In general you’ll need to replace all “G” prefixes like “GSize” with “google.maps” like “google.maps.Size”.

Replace GSize with google.maps.Size
Replace GLatLng with google.maps.LatLng
Replace GPoint with google.maps.Point
Replace GOverlay with google.maps.Overlay

Replace “new google.maps.Overlay” with “new google.maps.OverlayView()”

Take out or replace GBrowserIsCompatible. There is no equivalent function in v3.

Replace

map = new GMap2(document.getElementById("map_canvas"))

with something like:

    var myOptions = {
      zoom: 4,
      center: myLatlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

Replace a custom icon marker using the icon-complex example:
http://code.google.com/apis/maps/documentation/javascript/examples/icon-complex.html

Before the change:

var tinyIcon = new GIcon();
tinyIcon.image = "images/gmap/marker.gif";
tinyIcon.iconSize = new google.maps.Size(22, 22);
tinyIcon.iconAnchor = new google.maps.Point(11, 11);
tinyIcon.infoWindowAnchor = new google.maps.Point(0, 0);
var myLatLng = new google.maps.LatLng(loc['lat'], loc['lng']);
var marker = new GMarker(myLatLng, { icon:tinyIcon });
GEvent.addListener(marker, showWindow, mouseover);
map.addOverlay(marker);

After:

var image = new google.maps.MarkerImage('images/gmap/marker.gif',
  // This marker is 20 pixels wide by 32 pixels tall.
  new google.maps.Size(22, 22),
  // The origin for this image is 0,0.
  new google.maps.Point(0,0),
  // The anchor for this image is the base of the flagpole at 0,32.
  new google.maps.Point(11, 11));

var myLatLng = new google.maps.LatLng(loc['lat'], loc['lng']);
var marker = new google.maps.Marker({
    position: myLatLng,
    map: map,
    shadow: shadow,
    icon: image
});
google.maps.event.addDomListener(marker,'mouseover', showWindow);

Replace getPoint to getPosition

var vx = marker.getIcon().iconAnchor.x - marker.getIcon().infoWindowAnchor.x;
var vy = marker.getIcon().iconAnchor.y - marker.getIcon().infoWindowAnchor.y;
this.openOnMap(marker.getPoint(), html, new google.maps.Point(vx,vy));

For infoWindowAnchor I could not find an equivalent so I scratched the whole calculation and just put in a hard coded value.

var vx = 10;
var vy = 10;
this.openOnMap(marker.getPosition(), html, new google.maps.Point(vx,vy));

Replace initialize:

EWindow.prototype.initialize = function(map) {

With onAdd:

EWindow.prototype.onAdd = function() {

Replace map.addOverlay(object) by moving a similar call to within the object.

map.addOverlay(ewindow)

To this within the object:

this.setMap(map)

Replace map.getPane()

map.getPane(G_MAP_FLOAT_SHADOW_PANE)

With this:

this.getPanes().mapPane

Replace this.redraw

this.redraw

with this.draw

this.draw

Replace Overlay.getZindex

var z = google.maps.Overlay.getZIndex(this.point.lat());

I could not find an equivalent to getZIndex so, again, it’s somewhat hard coded.

// you may need to work on this "hack" to replace V2 getZindex
// GOverlay.getZIndex(this.point.lat());
var z = 1000*(90-this.point.lat());
this.div_.style.zIndex = parseInt(z);

Replace this.map.fromLatLngToDivPixel

var p = this.map.fromLatLngToDivPixel(this.point);

With this:

var proj = this.getProjection();
var p = proj.fromLatLngToDivPixel(this.point);

Replace map.panBy(Size) to map.panBy(x:number, y:number)

map.panBy(new google.maps.Size(pan_right, pan_up));

With this:

map.panBy(-pan_right, -pan_up);

A very helpful site was one that made google maps compatible for both versions:
http://notebook.kulchenko.com/maps/google-maps-using-multiple-api-versions

And of course the Google Maps v3 Examples and API docs helped a great deal.  It may also help to look at version 2 of the API so that you can try and find something equivalent.

I uploaded a converted EWindow.js for whoever needs a google maps v3 version of EWindow.

Filed Under: Coding Tagged With: google maps, javascript

  • « Go to Previous Page
  • Go to page 1
  • Interim pages omitted …
  • Go to page 3
  • Go to page 4
  • Go to page 5

Primary Sidebar

Topics

apache apple bootstrap buddypress chrome cloudways cms css debug drupal eCommerce firebug firefox git gmail goDaddy google hosting htaccess html html 5 IE crap image iPad iPhone javascript jquery kinsta linux localization mac os x ms sql mysql open source optimize php php 7.2 svg tinymce woocommerce wordpress wpengine xss yii youtube

Categories

  • Coding
  • Off the Shelf
  • Plugins
  • Random Thoughts
  • Server Stuff
  • Tools
  • Uncategorized