Posts with tag overlays

Zoom Levels and Image Overlays

In this post I will continue my discussion of overlays in the MapQuest JavaScript API 5.2. My last two posts covered a couple of methods for adding rollover functionality to overlays. Over the next couple of posts I will discuss some of the options that are available when working with image overlays.

There are a few things that set image overlays apart from the other overlay types. The one that poses the biggest obstacle is image resolution. Since an image overlay is "pinned" to a map with Lat and Lng coordinates, there is a significant difference in resolution required to display an image properly at different zoom levels. If this becomes an issue for your application, one of the options that is available is the setImageOverlayLevels method provided by the API.

Continue reading Zoom Levels and Image Overlays

Using Map Overlays with Flex and the Mapquest 5.2 APIs

Ok, I was driving (very carefully, mind you) on a very sunny afternoon to the airport, and I got a call from my very bright and brilliant niece who recently enrolled into Michigan State University (MSU if you're a Michigan native). During the midpoint of the conversation, all I heard was "cell phone silence", for lack of a better term, and within a few more seconds the call was dropped -- argh!

Obviously, I'm not the only person in the world who gets aggravated when a mobile call gets dropped. Of course, my wireless carrier has to go unnamed here in order to protect the guilty... er, uh... innocent.

So, after I called my niece to finish our conversation, I started to think. "Shouldn't there a way to show folks where the various dead spots are for the wireless carriers?" As you will see shortly, the MapQuest 5.2 APIs actually come in quite handy for solving this sort of problem. If you read my previous blog post and tried out the example code that I provided, then you should be familiar with the concept of creating a POI (point of interest) on a map and displaying it. Today, we're going to use overlays to highlight a region of interest. Take a look at the image below to see my "dead spot" awareness system:

Continue reading Using Map Overlays with Flex and the Mapquest 5.2 APIs

Adding Rollover Functionality to Overlays: Part 2

This method, although similar to the method I covered in my last post, uses the InfoWindow of the map rather than a rollover associated with a Point Of Interest (POI). The InfoWindow is populated with the title and content when the overlay is moused-over, and follows the cursor, similar to a tooltip.

The biggest disadvantage with this method comes from the need to step outside of the API to attach a mousemove event. This means that the solution needs to take browser differences into consideration. In order to simplify the code, and because I generally use ASP.NET for most of my work, you will notice that I have utilized a few shortcuts provided by the Microsoft AJAX Library.

Continue reading Adding Rollover Functionality to Overlays: Part 2

Adding Rollover Functionality to Overlays: Part 1

Over the next couple of posts I'm going to look at the different rollover capabilities that are available for overlays in the MapQuest JavaScript API. To get started I'll post a simple module that can be imported into any application. To demonstrate, I have included links to an application that uses the module. The original Capture the Flag application can be seen here, and with the new functionality, here.

The module accomplishes two things. First, it uses the altState fields of the overlay to change the alpha value of the overlay, making it more transparent. Second, it accepts a string as an argument, using that as a title which is displayed in a rollover window. The following image is a screenshot of the Capture the Flag application, shown with the mouse hovering over the overlay on the left.

Capture The Flag Screenshot.

Continue reading Adding Rollover Functionality to Overlays: Part 1

More Overlay Events

Custom events are also a great way to 'clean up' the look of your maps. In most of my previous MapQuest posts, I've been only loading a single overlay or polyline at a time. Chances are, you'll encounter the need to load more than one at a time - but also don't want to clutter up the look of the map by having them all visible at the same time.

Here's an example where I've loaded two different polylines from different GeoRSS/GML files. Instead of having both automatically displayed on the map, I'm going to use a mousever event on a POI to display the polyline. Two do so, I create two POIs has a legend to each polyline. On a 'mouseover' event I load and display the appropriate file. On a 'mouseout' event the overlay is set to not be visible.

<html>
<head>
<title>Overlay Events</title>
<script src="http://btilelog.access.mapquest.com/tilelog/transaction?
  transaction=script&key=YOUR_API-KEY
  &ipr=true∓itk=true&v=5.2.0" type="text/javascript"></script>
<script language="javascript">
MQInitDojo(initMap);
var myOverlayColl = new MQOverlayCollection();
var myXMLDoc;
function openXMLFile1(){
    myXMLDoc = document.implementation.createDocument("","",null);
    myXMLDoc.load("./foo1.xml");
    myXMLDoc.onload = loadGeoRSS;
}
function openXMLFile2(){
    myXMLDoc = document.implementation.createDocument("","",null);
    myXMLDoc.load("./foo2.xml");
    myXMLDoc.onload = loadGeoRSS;
}
function loadGeoRSS() {
    myOL = new MQLineOverlay();
    for (i = 0; i < myXMLDoc.getElementsByTagName("entry").length; i++) {
        var c = myXMLDoc.getElementsByTagNameNS("http://www.opengis.net/gml",
         "posList")[i].textContent;
        var tmp = c.split(/ /);
        var myShapePts = new MQLatLngCollection();
        for (j = 0; j > tmp.length; j++) {
            myShapePts.add(new MQLatLng(tmp[j], tmp[j+1]));
            j++;
        }
        myOL.setShapePoints(myShapePts);
        myOverlayColl.add(myOL);
        myMap.replaceOverlays(myOverlayColl);
	myOL.setColor("#800000");
        myOL.setBorderWidth(1);
	myOL.setColorAlpha(1.0);
    }
}
function loadData() {
    myPoint1 = new MQPoi(new MQLatLng(33.305389, -116.879258));
    myPoint1.setInfoTitleHTML("Palomar Mountain South Grade");
    myMap.addPoi(myPoint1);
    MQEventManager.addListener(myPoint1,'mouseover', openXMLFile1);
    MQEventManager.addListener(myPoint1,'mouseout', clear);

    myPoint2 = new MQPoi(new MQLatLng(33.288569, -116.805051));
    myPoint2.setInfoTitleHTML("Palomar Mountain East Grade");
    myMap.addPoi(myPoint2);
    MQEventManager.addListener(myPoint2,'mouseover', openXMLFile2);
    MQEventManager.addListener(myPoint2,'mouseout', clear);
}
function clear() {
    myOL.setVisible(false);
}
function initMap() {
   myMap = new MQTileMap(document.getElementById('mapDiv'),
     8,new MQLatLng(33.272866, -116.831869));
   myMap.addControl(new MQLargeZoomControl(myMap));
   loadData();
}
</script>
</head>
<body>
<div id="mapDiv" style="width:384px; height:384px; border:2px solid"></div>
</body>
</html>

Here's a screenshot of the results:

More resources:

* Map data courtesy SundayMorningRides.com

Capture the Flag: Using a JavaScript API to Enable Interactive Drawing in MapQuest

Introduction

The MapQuest Platform provides a powerful means for developers to integrate MapQuest technology into their web applications. In this article, I will demonstrate how to add interactive drawing to a map using the JavaScript-based API. In the resulting application, a user can set up a real-life game of Capture the Flag by drawing components of the game on an online map. You can see the application live here, and you can download the source in a .zip file here.

Continue reading Capture the Flag: Using a JavaScript API to Enable Interactive Drawing in MapQuest

Beta Update: 5.3 Release Candidate 2 Released!

Turn Your World Upside Down

Let's talk briefly about globes. You know, those ones that sit in libraries in period piece movies where some old guy in a leather chair sits next to it, smoking a pipe and calling Shakespeare a hack? Those globes. The ones where when you see them, you can't help but spin it as hard as you can in the slim hope the momentum will send it rolling across the room.

Well you can now create and spin your own virtual globe. We fixed a bug in the new full-axis globe view so you should now see improved performance when trying to spin it off your web page.

KML and GeoRSS Support: We got it.

Create a RemoteCollection, tell it the location of the feed and its format, and watch it get automagically sucked onto the map! And if you have another format, feel free to extend the feed loading classes to create your own loadable formats. Sorry, LOLcode support is still a no-go.

But wait, there's more!

Here's the list of other major updates in the just released 5.3rc2 Beta update of the MapQuest Platform:

  • Beta Issues Forum now available - A forum for posting about Beta has been created in the Technical Resource Center.
  • Old POI & Overlay Getters/Setters restored (JavaScript) - We've added back in the 5.2 getters and Setters for POIs and Overlays.
  • POI & Overlay getValue & setValue methods added (JS and FUJAX) - The new getValue and setValue functions have been added to the POI and Overlay objects in FUJAX so that both the old, and the new methods of setting properties on these objects are now available in both JavaScript and FUJAX.
  • Multiple Collections (JS, AS3, FUJAX) - Building on our efforts last month to combine POICollections and OverlayCollections into a single ShapeCollection, you can now add multiple ShapeCollections to a map.

Check out more information and samples on the MapQuest Developer Network Beta page.

Custom Mouse Events to Data Overlays

In my previous MapQuest post I demonstrated to to add customized interactivity to maps via mouse control events. Here we'll add mouseover events to data overlays on the map.

I've loaded data to my map via a GeoRSS file using GML encoding. Unlike my previous GeoRSS/GML example, however, here I'm loading a data for a polyline overlay (For brevity, I've ommited the list of coordinates).

<feed xmlns="http://www.w3.org/2005/Atom"
      xmlns:georss="http://www.georss.org/georss"
      xmlns:gml="http://www.opengis.net/gml">
  <title>Sample GeoRSS ATOM feed</title>
  <entry>
    <title>Mesa Grande Road</title>
    <georss:where>
      <gml:LineString>
      <gml:posList> 
        [space delimited list of lat long coordinates]
      </gml:postList>
      </gml:LineString>
    </georss:where>
  </entry>
</feed>

With the feed, I simply read/parse the XML file and use the MapQuest API to create a polyline based on the coordinates - additionally we'll create default settings for the polyline (color, line width and opacity) which we will change depending if the mouse is over the polyline.

<html>
<head>
<title>Overlay Events</title>
<script src="http://btilelog.access.mapquest.com/tilelog/transaction?
	transaction=script&key=YOUR_API-KEY&ipr=true∓itk=true
	&v=5.2.0" type="text/javascript"></script>

>script language="javascript"<
MQInitDojo(initMap);
var myOverlayColl = new MQOverlayCollection();
var myXMLDoc;
function openXMLFile() {
    myXMLDoc = document.implementation.createDocument("","",null);
    myXMLDoc.load("./bah.xml");
    myXMLDoc.onload = loadGeoRSS;
}
function loadGeoRSS() {
    myOL = new MQLineOverlay();
    for (i = 0; i < myXMLDoc.getElementsByTagName("entry").length; i++) {
        var title = myXMLDoc.getElementsByTagName("title")[i].textContent;
        var c = myXMLDoc.getElementsByTagNameNS("http://www.opengis.net/gml", "p
osList")[i].textContent;
        var tmp = c.split(/ /);
        var myShapePts = new MQLatLngCollection();
        for (j = 0; j < tmp.length; j++) {
            myShapePts.add(new MQLatLng(tmp[j], tmp[j+1]));
            j++;
        }
        myOL.setShapePoints(myShapePts);
        myOverlayColl.add(myOL);
        myMap.replaceOverlays(myOverlayColl);
        // set defautView
        myOL.setColor("#800000");
        myOL.setBorderWidth(1);
        myOL.setColorAlpha(1.0);
        // set eventmanager objects
        MQEventManager.addListener(myOL,'mouseover', highlightView);
        MQEventManager.addListener(myOL,'mouseout', defaultView);
    }
}
function highlightView() {
    myOL.setColor("#000080");
    myOL.setBorderWidth(5);
    myOL.setColorAlpha(0.5);
}
function defaultView() {
    myOL.setColor("#800000");
    myOL.setBorderWidth(1);
    myOL.setColorAlpha(1.0);
}
function initMap() {
   myMap = new MQTileMap(document.getElementById('mapDiv'),8,
	new MQLatLng(33.173 676, -116.714889));
   myMap.addControl(new MQLargeZoomControl(myMap));
   openXMLFile();
}
</script>
</head>
<body>
<div id="mapDiv" style="width:384px; height:384px; border:2px solid"></div>
</body>
</html>

To create the highlighted view of the polyline for the mouseover event, I simply create a highlightView() function that alters the settings for the polyline when activated by the event manager. I also create a defaultView function to return the polyline to default settings.

Here's a screenshot of the results:


Default View (mouseout)


Highlight View (mouseover)

More resources:

* Map data courtesy SundayMorningRides.com