Skip to content

Category: Web

Handling Large KML Files Without Google Maps

In the four weeks or so, I’ve become quite familiar with the Google Maps API, pitfalls included. I’ve been contracted to work on an interactive map for the RAIN Group, a not-for-profit out of Pennsylvania that is focused on water quality. Especially in areas where hydraulic fracturing (fracking) for natural gas is taking place.

Google’s API, to say the least, is easy to customize with some javascript experience. The requirements of the project required overlays gathered from USGS, EPA and other entities. It was fairly straight forward to incorporate the KML layers that we procured, but some of these files ran rather large in size. After the heartbreak of having to admit that Google was telling the truth about the size limitations on KML files, it was back to the drawing board.

Luckily, after a lot of hunting, I found the GeoXML library. Rather than using Google’s servers to render these layers, GeoXML provided a client-side alternative. This means that the size limitations that we faced were no longer an obstacle in displaying our layers.

Everything came together and the world was at peace again. If you are considering building your own map elements from complex datasets, I would not overlook this library. It will save your life… or at least a little headache.

Leave a Comment

Utilizing CAP (Common Alert Protocol)

Rave Alert has been a major project that I have have been assigned to implement. This system provides an easy way of contacting students and staff in case of emergency via email, text message, voice call, Facebook and Twitter. We also use it for snow days and class cancellations. Not too long ago the helpful staff at Rave introduced me to the CAP XML standard. CAP is a standard not just specific to Rave, but many emergency alert systems. It is also used by various government agencies for sharing emergency information over multiple systems.

PHP CAP Alert Function

Once I heard of CAP, I knew we could use this XML standard in various ways to extend the reach of our own emergency alerts. One being the school web page. Here is a small function I put together using PHP that will display an emergency message on a web page:

Just include this code on your PHP page and then call it with the CAP URL location you want to pull from:

cap_parse("http://example.com/cap.xml");

CAP Desktop Alerting Software

Taking this a step further, I decided to get a little more familiar with .NET. It was brought to my attention that we were missing a desktop alert component. There are server-based systems out there that require some setup and a good deal of money. After a little thought, I concluded we could meet these same goals with a simple desktop client that used the CAP XML feed to trigger an emergency message. And in a couple days I had something built.

I thought this project warranted creating a Github repository. It’s still a little rough, but by bringing it to git, I’m hoping to get some more interest and input in this project. I’ve made the source code available, so maybe someone will find this code useful to bolster their own emergency alerting using CAP. Please visit my CAP Alerting Desktop repository if you are interested. Any contributions to the code are welcome.

Mentioned Resources:

PHP CAP Alert Function
CAP Desktop Alerting Software

4 Comments

Rewarding Those That Like You (on Facebook)

Facebook Like Button

A client that I have been working for had an interesting request for me a couple weeks ago. He wanted to create a campaign for his Facebook page where an individual would get rewarded with a free music download for liking the page. This was already accomplished from the Facebook page, but I was curious if such a thing could be done directly from a web site, since Facebook’s button is generated through Javascript code.  What I really wanted to do was create a page redirect to this free music download page once the Like button was clicked.  Here are the steps I’ve done to make this work:

    1. Create an new application and get an app id by going here. Get started and follow the steps after clicking “Create New App”.

 

    1. Generate the Facebook button code by going here. After you’ve entered in the page you are putting the like button on, click on the “Get Code” button.

 

    1. When the box pops up, I selected “XFBML”. Also make sure to select the application you created in step one next to “This script uses the app ID of your app:”. Follow the steps that Facebook provides. You will need to add “xmlns:fb=”http://ogp.me/ns/fb#” to your <html> tag.

 

  1. After the first body tag, place the code that Facebook suggests. This is what I placed:
    <body>
    <div id="fb-root"></div>
    <script>
       (function(d, s, id) {
          var js, fjs = d.getElementsByTagName(s)[0];
          if (d.getElementById(id)) return;
          js = d.createElement(s); js.id = id;
          js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=Application ID that was created in the first step";
          fjs.parentNode.insertBefore(js, fjs);
       }(document, 'script', 'facebook-jssdk'));
    </script>

  2. Don’t forget to add the Like button where you want it on the page. This code can be placed anywhere you want to appear on the page:
    <fb:like href="The address of the page the button sits on" send="true" width="450" show_faces="true"></fb:like>
  3. Now that all the Facebook code has been added to the page, you’ll need to add a little bit of code for the redirect. Looking at the script that was placed right before the body tag add these lines as shown in bold:
    <body>
    <div id="fb-root"></div>
    <script>
    window.fbAsyncInit = function() {
       FB.init({appId: 'Application ID that was created in the first step', status: true, cookie: true,xfbml: true});
       FB.Event.subscribe("edge.create", function(targetUrl) {
         window.location.href = "The address of the page you want to redirect to.";
       });
       FB.Event.subscribe("edge.remove", function(targetUrl) {
         console.log('edge.remove');
       });
    };

    (function(d, s, id) {
       var js, fjs = d.getElementsByTagName(s)[0];
       if (d.getElementById(id)) return;
          js = d.createElement(s); js.id = id;
          js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=Application ID that was created in the first step";
          fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
    </script>
     
Leave a Comment

Why the iPad Doesn’t Support Flash – Personal Speculation

Webkit Logo

Recently, I went to an Apple training session, which may have been more of a sales pitch, but it was good and informative and we picked up some tools from it.  One of the questions that one of my colleagues brought up was whether Apple was going to support Flash on its mobile device browsers.  The salespeople alluded somewhat to HTML5.

I’ve been watching the recent emergence of Webkit as a popular browser engine. It’s the backbone for Safari and many browsers for mobile devices, touting major support for HTML5 and CSS3.  I’ve also recently read an article where Wired magazine had formed a partnership with Adobe to develop their magazine app for the iPad.  Surprisingly it uses Flash, but within the Adobe AIR platform.  AIR is platform agnostic and provides a way in which your Flash/Flex/AJAX web application can be run as a desktop/mobile application.  This, to me, seems like an interesting move for Adobe.

CSS3, on the other hand is looking to be a contender with Flash animation (jQuery too).  The Art of Web posted a great article on how to use CSS3’s 2d transformations properties.  Make sure you are viewing it in Safari or other Webkit browsers for best results.

As a CSS fan, this looks very promising.  No Flash, no jQuery knowledge; None of that is required.  You just need an understanding of CSS.  As Apple, this probably looks like an opportunity to make their browser (Webkit) the standard, especially on mobile devices right now.  Also maybe another opportunity to rid itself of Flash as a browser application.  The only drawback to HTML5 CSS3 is the same drawback that affects all new adoptions of HTML, XHTML and CSS.  It takes some time for all browsers to adopt these standards and takes time for developers to use such standards; some don’t fully adopt them anyway (thank you, Microsoft).

Apple is leading the race nonetheless and I think HTML5 and CSS3 should be taken seriously.  I don’t think Adobe should be ruled out though when it comes to engaging, interactive media.

Leave a Comment

Phone Validation Using Really Simple Validation Plugin

From past posts you could probably ascertain that I’ve taken quite a liking to jQuery.  Lately I’ve been developing a form for my brother, Karl’s drafting service and have used this handy javascript framework.  There is a jQuery plugin that I’ve been working with called Really Simple Validation that presents a simple, easy-to-use way of validating your forms before submitting them.  It also allows an individual to implement their custom functions for validating your forms.

Karl’s order form required a specific phone number format (xxx-xxx-xxxx).  Unfortunately, Really Simple Validation does not have pre-made phone number validation.  I scoured the internet for such a function to no avail, so I decided to write my own custom function for RSV.  It’s fairly simple and straightforward.  Here is the javascript code:

function phoneValid()
{
var phoneRE = /^\d\d\d\-\d\d\d-\d\d\d\d$/;
var val = document.getElementById(“phone”).value;

if (!val.match(phoneRE)) {
var field = document.getElementById(“phone”);
return [[field, “Please enter a valid phone number format (xxx-xxx-xxxx).”]];
}
return true;
}

The first variable created (phoneRE) is a regular expression and is used to match the sequence of phone number (xxx-xxx-xxxx).  The second variable (val) is the value of the particular form input field that has the id of “phone”.  Below that is a conditional statement that returns an error message if the value of the input field doesn’t match the particular regular expression defined as phoneRE.  If you look within that statement you’ll see “return [[field, “Please enter a valid phone number format (xxx-xxx-xxxx ).”]];”.  This area is required for RSV and will display the message if an error is thrown.  The field variable points to the form input field with the id “phone”.

Now that the function is created you just need RSV to make a call.

$(“#order_form”).RSV({
onCompleteHandler: myOnComplete,
rules: [
“function,phoneValid”,
]
});

To make this coexist within your form you will have to change “#order_form” to the particular id that you have given to your form.  If you look at the line: “function, phoneValid”, you’ll see where the function we created above is being be called.

That’s it!  For those new to jQuery remember that you need to include the jQuery script and the RSV plugin script as described in the links above.


Leave a Comment