Photo Map Challenge

By now you've gotten familiar with clickable icons and shapes.
Look at this as a challenge or a direct assignment for you to dig deeper into OpenLayers.

Here are a few online map sites with plenty of user-contributed content:
- http://panoramio.com
- http://wikilocation.org/
- http://wikimapia.org
- http://www.readwriteweb.com/archives/twitter_location_api_possible_uses.php
- http://foursquare.com
- http://www.u-shahid.org/cr/
- http://oilreporter.org/

Wouldn't you like that information on your maps?
Fortunately, each of these websites lets you link up to their map through a system known as an API (Application Programming Interface) or an RSS feed.  OpenLayers is one example of an API.

How do you find APIs?
- On a website, look for links such as "Developers" "Technical" "Community" "API"; possibly at bottom of the page
- Search on http://www.programmableweb.com/
http://www.programmableweb.com/apis/directory/1?apicat=Mapping
http://www.programmableweb.com/api/openlayers/mashups

The Challenge
I'll walk you through adding articles from WikiLocation.org.
- You can use similar code to load photos from Panoramio.
- If you're new to web programming and up for a challenge, try loading polygons/shapes from WikiMapia instead ( polygon walkthrough article coming soon )
- If you're already a web programmer, try connecting to a social site such as Twitter or an activist site such as Ushahidi.

Mapping Wikipedia


From that page, I determined that I want to make this request up to 10 nearby articles within 3000 metres of the center, and send it to a new function which I'll be writing, called mapWiki.

apiAddress = "http://api.wikilocation.org/articles?lat=27.173768&lng=78.042068&limit=10&radius=3000&jsonp=mapWiki";



apiScript = document.createElement("script");
apiScript.src = apiAddress;
document.body.appendChild(apiScript);


{
    "articles": [
        {
            "id": "7290308",
            "lat": "51.5006",
            "lng": "-0.124611",
            "title": "Big Ben",
            "url": "http:\/\/en.wikipedia.org\/w\/index.php?curid=7290308",
            "distance": "17m"
        }
    ]
}


What is a FOR loop?

function mapWiki(response){
    articles = response.articles;
    // create style for all article points
    articleStyle= OpenLayers.Util.extend({}, layerStyle);
        articleStyle.fillColor = "blue";
        articleStyle.graphicName = "circle";
        articleStyle.pointRadius = 10;
        articleStyle.strokeColor = "blue";
        articleStyle.strokeWidth = 3;
        articleStyle.fillOpacity = 1;
        
    for( i = 0; i <= articles.length - 1; i = i + 1 ){
        // get the article's location
        lat = articles[ i ].lat;
        lon = articles[ i ].lng;
        
        // create a point at that location
        myPoint = new OpenLayers.Geometry.Point( lon, lat ).transform(                  
              map.displayProjection, map.projection );
        // transfer information from articles[ i ] to myPoint
        myPointFeature.attributes = {
             name: articles[ i ].title
        };
        
        // make it into a Feature ( adding a style )
        myPointFeature = new OpenLayers.Feature.Vector( myPoint,null,articleStyle);
        
        // add feature to the pointLayer
        pointLayer.addFeatures( [ myPointFeature ] );
    }
}

Make some revisions

Now go back to your onFeatureSelect function and change what appears when you click one of these points.  We want it to be an <iframe>, which embeds another webpage inside our own. Let's load the mobile Wikipedia article ( http://en.m.wikipedia.org ) so that it fits inside the bubble.

Taking care with the quotes, set the HTML content of the bubble to be:

"<iframe src='http://en.m.wikipedia.org/wiki/" + clickedFeature.attributes.name +" ' height='300' width='300' style='border:none;'></iframe>"