Geographical Data Management for Web Applications


Published on

Lecture given at the Informatics Department of the Aristotle University of Thessaloniki on introductory topics of geographical data management for web applications.

Published in: Technology, Education
  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Geographical Data Management for Web Applications

  1. 1. Web Information Systems prof. Athena VakaliGeographical Data Management for Web Applications Symeon Papadopoulos Informatics Department, AUTh 13 Dec 2011
  2. 2. Overview• Introduction• Representation & storage of geographical data• Geographical data management with Java (JDBC)• Text Indexing for Geographical Data• Google Maps API• Use Cases: Geographical Data Clustering + Heat maps Web Information Systems
  3. 3. The Era of Geo• 350K websites make use of Google Maps API (2010)• GPS-enabled mobile phones > 200M (2010)• Foursquare users: 5M (2010)  15M (2011)• The HotPotato check-in service was acquired by Facebook for $10Μ (2010) Web Information Systems
  4. 4. Categories of Geo-Services• Primary services (providers) – Google Maps, Bing Maps, Yahoo Maps, MapQuest, OpenStreetMap• Derivative services (mash-ups)• Location-based social networks – Foursquare, Gowalla (acquired by Facebook), Brightkite• Intelligent geo-based services – Analytics, Route planning, Real estate Web Information Systems
  5. 5. GIS• GIS offer sophisticated software for geographical data management and processing.• They offer many means of representation, search and rendering.• They mostly target geo-centered applications: – Urban planning, environmental studies, etc.• Popular tools: ArcGIS, MapInfo, GeoMedia, κλπ.• GIS will not be discussed in this lecture. Web Information Systems
  6. 6. Representation and Storage of Geographical Data
  7. 7. Lat, Lon• Geo coordinates constitute the basic element of any geo-enabled service.• A coordinate element is defined by the following: Latitude Longitude Web Information Systems
  8. 8. Lat, Lon (ΙΙ)• Traditional writing: 40° 38′ 0″ N, 22° 57′ 0″ E• Decimal representation: 40.633333, 22.95• Important note for storage: Precision of 0.00001 in the decimal representation corresponds to approximately 1m distance (near the equator) Web Information Systems
  9. 9. Altitude, Bearing• Two additional variables related to geographical points (still not very common): – Altitude: vertical distance of point from the level of sea – Bearing: direction to which the user/device is pointed• The increasing use of GPS-enabled devices is expected to increase the importance of these variables, especially in Augmented Reality (AR) applications. Web Information Systems
  10. 10. Distance calculation (lat1, lon1) d• Haversine formula: – Δlat = lat2 – lat1, Δlon = lon2 – lon1 – a = sin2(Δlat/2) + cos(lat1)  cos(lat2)  sin2(Δlon/2) (lat2, lon2) – c = 2  atan2(sqrt(a), sqrt(1-a)) – d=Rc [R: earth radius (6 371 km)]• In JavaScript: More accurate and computational expensive – var R = 6371; // km alternative: Vincenty formula – var dLat = (lat2-lat1).toRad(); – var dLon = (lon2-lon1).toRad(); – var a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) * Math.sin(dLon/2) * Math.sin(dLon/2); – var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); – var d = R * c; Web Information Systems
  11. 11. Geo in DB• Representation in table form• e.g. List of Points of interest  Table of Pois• double  slightly faster• DECIMAL  higher accuracy Field type: double ή DECIMAL(13,9) Web Information Systems
  12. 12. Use cases• Query 1: What points of interest can I see near point of interest X? – Online city exploration in cities (e.g. recommend new Pois based on proximity)• Query 2: What points of interest are there near me? – Valuable within location-based applications (e.g. I need recommendations for sightseeing, eating, etc. based on my current location) Web Information Systems
  13. 13. Geo in DB – Proximity Queries (I)• Implementation 1 – Compute distance by use of SQL and return ordered results:• set @lat0 = 40.645466; set @lon0 = 22.858342; set @dist = 10;• SELECT *, 6371  2  ASIN ( SQRT( POWER( SIN(@lat0 – abs(  pi()/180 / 2), 2) + COS (@lat0  pi()/180 )  COS(abs(  pi()/180)  POWER( SIN(@lon0 – dest.lon)  pi()/180 / 2), 2) )) as distance FROM pois dest HAVING distance < @dist Haversine formula ORDER BY distance LIMIT 10; Web Information Systems
  14. 14. Geo in DB – Proximity Queries (II)• Problems: – Painfully slow! For tables of even modest sizes (~1000), response might take as long as 8-10 seconds. – Distance computations are not reused in successive invocations of the same query, since caching computations is not supported – Not an option for web applications. Web Information Systems
  15. 15. Geo in DB – Proximity Queries (IIΙ)• Alternative implementation: – If, instead of nearby Pois, we ask for Pois that lie within a certain radius from a fixed point (e.g. current location)? 300m Aghia 300m Sophia Web Information Systems
  16. 16. Geo in DB – Proximity Queries (IV)• Bounding box query: – SELECT * FROM pois WHERE pois.latitude > @min_lat AND pois.latitude < @max_lat AND pois.longitude > @min_lon AND pois.longitude < @max_lon; (@max_lat, @max_lon) – The question now is how to determine min_lat, min_lon, max_lat, max_lon. (@min_lat, @min_lon) Web Information Systems
  17. 17. Geo in DB – Proximity Queries (Vα)• Bounding box computation (top and bottom):• 1°difference in latitude ~ 111km (110.567 near the equator, 111.699 near the poles)  – 300m  ~0.0027° latitude (since our fixed point is located at approximately 45°) @max_lat – @min_lat = @lat0 – 0.0027 – @max_lat = @lat0 + 0.0027 e.g. for lat0 = 40.632844 (Aghia Sophia) @lat0 @min_lat ~ 40.630144 @max_lat ~ 40.635544 @min_lat Web Information Systems
  18. 18. Geo in DB – Proximity Queries (Vβ)• Bounding box computation (left and right):• 1°difference in longitude  depends a lot on the latitude of the fixed point, e.g ~111.320 km near the equator and 0 near the poles. Distance (km) for 1° – Table with distance correspondences difference in longitude (the more lines, the better the achieved approximation – for intermediate values one needs to use interpolation) – 300m  ~0.003805° latitude since the fixed point lies at latitude~45° – @min_lon = @lon0 – 0.003805 – @max_lon = @lon0 + 0.003805 – e.g. for lon0 = 22.947094 (Aghia Sophia) @max_lon @min_lon ~ 22.943289 @max_lon ~ 22.950899 @min_lon @lon0 Web Information Systems
  19. 19. Geo in DB – Proximity Queries (VI)• In summary: – During the table creation, we make sure to index the latitude and longitude columns (conventional B-tree). – We convert the proximity query to a bounding box query by use of geographical approximations (that can be made sufficiently precise if needed). – In this form, the SQL query can be executed really fast thanks to the indexes. Web Information Systems
  20. 20. Geo-enabled DBs• PostGIS (Extension for PostgreSQL) – Support for “geographical objects”: • POINT (X Y) • LINESTRING (0 0, 1 1, 1 2) • POLYGON (0 0, 4 0, 4 4, 0 4, 0 0) • MULTIPOINT, MULTIPOLYGON, GEOMETRYCOLLECTION – Support for tables and calculations (e.g. proximity queries) directly through the query engine.• GeoServer (GIS) – Complete Java framework for search of geographical objects and map rendering based on a server-client architecture. Web Information Systems
  21. 21. Geographical data management in Java (JDBC)
  22. 22. Typical lifecycle of geographical data Relational model specification JDBC Geo data source Transformation to RDBMS storage (e.g. Wikimapia) records JDBC UPDATE READ Processing JAVA Web Information Systems
  23. 23. Data model specification• Very simple example: table with id + 3 columns – Name: VARCHAR (100) – Latitude: DOUBLE – Longitude: DOUBLE Pois Web Information Systems
  24. 24. Input data + transformation parsing <name>Benaki museum</name>  “Benaki Museum” <lon>23.70825</lon>  23.70825 <lat>37.974515</lat>  37.974515 Record name latitude longitude Benaki museum 23.70825 37.974515 Web Information Systems
  25. 25. Record insertion with JDBC (1)• Step 1 Connection Creation (A) Load the appropriate JDBC driver E.g. in the following example: JDBC_DRIVER = “com.mysql.jdbc.Driver” Class.forName(JDBC_DRIVER); (B) Connection initialization Τhe variable dbURL has the form: protocol + vendor + server + port nr + dbName + params e.g. jdbc:mysql// useUnicode=true&characterEncoding=UTF-8 Connection con = DriverManager.getConnection(dbURL, username, password); throws exceptions (InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException) ATTENTION: Connection objects should be reused! Web Information Systems
  26. 26. Record insertion with JDBC (2)• Step 2 Creation and execution of statement (A) Statement creation String sqlInsert = “INSERT INTO Pois VALUES (‘Benaki museum’, 23.70825, 37.974515)”; Statement insertStmt = con.createStatement(); (B) Statement execution (throws SQLException) insertStmt.executeUpdate(sqlInsert); Alternatively PreparedStatement prepInsert = con.prepareStatement(sqlInsert, Statement.RETURN_GENERATED_KEYS); prepInsertStmt.executeUpdate(); ResultSet rs = prepInsertStmt.getGeneratedKeys(); long recordId = -1; Record database key  could if ( recordId = rs.getLong(1); be useful later (better keep it than query for it) Web Information Systems
  27. 27. Wrapper method creation• Encapsulation of process for easy reuse public long insertPoi(Connection con, String poiName, double lat, double lon) { String sqlInsert = “INSERT INTO Pois VALUES (‘” + poiName + “’,” String.valueof(lat) + “,” + String.valueof(lon) + “)”; PreparedStatement prepInsert = con.prepareStatement(sqlInsert, Statement.RETURN_GENERATED_KEYS); prepInsertStmt.executeUpdate(); ResultSet rs = prepInsertStmt.getGeneratedKeys(); long recordId = -1; if ( recordId = rs.getLong(1); return recordId; } Web Information Systems
  28. 28. Batch insertion• In case of massive insertions, it is better to make use of the batch mode of insertion in order to significantly speed up the process. con.setAutoCommit(false); Very important!! Statement batchInsert = con.createStatement(); for (int i = 0; i < 10,000; i++){ batchInsert.addBatch(“INSERT INTO Pois VALUES (‘“ + names*i+ + “’,” + String.valueof(lats*i+) + “,” + String.valueof(lons*i+) + “)”; } int[] updateCount = batchInsert.executeBatch(); con.commit(); con.setAutoCommit(true); Web Information Systems
  29. 29. ResultSet structure Initial cursor position C1 C2 C3 C4 C5 C6 C7 …. R1 22 ab 0.1 R2 27 cd R3 28 gc 1.2 R4 40 ob 3.5 R5 51 gz 3.2 rs.absolute(3) rs.getInt(1) rs.getDouble(3) rs.getInt(“C1”) rs.getDouble(“C3”) rs.getString(2) (faster) rs.getString(“C2”) Web Information Systems
  30. 30. Record reading• Use SELECT statement and iterate through ResultSet (A) SELECT statement creation Statement selectStmt = con.createStatement(); (B) Form and execute SELECT statement List<Poi> pois = new ArrayList<Poi>(); String sqlSelect = “SELECT * FROM Pois”; ResultSet rs = stmt.executeQuery(sqlSelect); while ( ) { long poiId = rs.getLong(“id”); String poiName = rs.getString(“name”); double lat = rs.getDouble(“latitude”); Candidate wrapper method Poi extractPoiFromResultSet(ResultSet rs) double lon = rs.getDouble(“longitude”); Poi poi = new Poi(poiId, poiName, lat, lon); pois.add(poi); } Web Information Systems
  31. 31. Record updates• Suppose I have collected data about the popularity of a Poi (e.g. count the number of results from a search engine) and I have its id at my disposal: public void updatePoiPopularity(Connection con, long poiId, int popularity) { PreparedStatement updateStatement = con.prepareStatement( “UPDATE Pois SET poi_popularity = ? WHERE id = ?”); updateStatement.setInt(1, popularity); updateStatement.setLong(2, poiId); int n = updateStatement.executeUpdate(); } NEW COLUMN name latitude longitude poi_popularity …. … … … Web Information Systems
  32. 32. Example Design WikimapiaWrapper PopWrapper PoiDbWrapper• Task separation List<Poi> pois = WikimapiaWrapper.collectPois(“Thessaloniki”); for (int i = 0; i < pois.size(); i++){ long poiId = PoiDbWrapper.insertPoi(con, pois.get(i).getName(), pois.get(i).getLatitude(), pois.get(i).getLongitude()); pois.get(i).setId(poiId); } …. Map<Poi,Integer> poiPopMap = PopWrapper.collectPoiPopularities(pois); for (Entry<Poi,Integer> poiPopEntry : poiPopMap.entrySet()){ PoiDbWrapper.updatePoiPopularity(con, poiPopEntry.getKey().getId(), poiPopEntry.getValue()); } Web Information Systems
  33. 33. Text Indexing for Geographical Data
  34. 34. Full-text Indexing• Extremely valuable technology for applications requiring full- text search features.• Classical DB systems do not offer a standard means of indexing and searching large amounts of text.• Established technology: Inverted indices• Popular implementations: – Lucene, Solr (Java) – Sphinx (C++) – OpenFTS (PostgreSQL) – Lemur (C++) Web Information Systems
  35. 35. Text queries in RDBMS• Operators LIKE and RLIKE – SELECT * FROM pois WHERE name LIKE ‘%museum%’ – SELECT * FROM pois WHERE name RLIKE ‘museum’• Conventional indexing structures in RDBMS are not particularly helpful in quickly responding to such queries (might require visiting every record  too slow for large tables)• Each vendor offers own solution, e.g. FULLTEXT INDEX από MySQL. Web Information Systems
  36. 36. Inverted index (I)• Starting point: Document collection (corpus)• Text processing  Dictionary: set of unique terms appearing in the documents of the collection + additional information (stats, stems, stop words)• Index: Document retrieval mechanism based on the terms contained in the documents Web Information Systems
  37. 37. Inverted index (II)• Inverted index: Set of inverted lists.• Inverted list: A list containing information about the occurrence of a term within the documents of the collection – represented as a list of postings.• Posting: Occurrence of a term in a certain position of a document. Apart from the document, where the term occurs, the posting also contains its position in the text  support for phrase search (increases the size of the index and complexity of the query mechanism). Web Information Systems
  38. 38. Inverted index (IIΙ)Example• Document collection: – Document 1: “White Tower” – Document 2: “Byzantine Museum” – Document 3: “Archeological Museum”• Inverted lists of postings: – “Archeological”: {(3,1)} – “Byzantine”: {(2,1)} – “Museum”: {(2,2), (3,2)} – “White”: {(1,1)} – “Tower”: {(1,2)} Document id Term position within the document Web Information Systems
  39. 39. Inverted index (IV)Query example• Query: “Museum”  documents 2 and 3• Query: “Byzantine Museum”  – Result 1: document 2 (contains both terms) – Result 2: document 3 (contains only the term “museum”) • “Archeological”: {(3,1)} • Document 1: “White Tower” • “Byzantine”: {(2,1)} • Document 2: “Byzantine Museum” • “Museum”: {(2,2), (3,2)} • Document 3: “Archeological Museum” • “White”: {(1,1)} • “Tower”: {(1,2)} Web Information Systems
  40. 40. Solr (text search engine)• Complete framework for indexing and searching massive document collections.• Based on the Lucene library.• Flexible document representation structure.• Flexible query structure.• Can be installed as a servlet in an appropriate container (e.g. Tomcat, Jetty)  Possibility for use over HTTP Web Information Systems
  41. 41. Solr basics (Ι)• Every document consists of a set of fields (similar to Lucene)• Every field can be of different type (e.g. text, number, etc.)• Every field can processed (e.g. tokenized, normalized) and indexed in a different way.• Every field or combination of fields can be queried in a different way  flexible query system Web Information Systems
  42. 42. Solr basics (ΙΙ)Example: – id: 13424 – name: White Tower of Thessaloniki – latitude: 40.626369 – longitude: 22.948428 – history: The tower, which once guarded the eastern end of the citys sea walls, was for many years attributed to Venice, to which the Byzantines ceded Thessaloniki in 1423. – wikipedia_link: representation suitable fοr use by Solr: <add><doc> <field name=“id”>13424</field> <field name=“name”>White Tower of Thessaloniki</field> ... </doc></add> Web Information Systems
  43. 43. Solr: index management• Addition of documents: java -jar post.jar lefkos_pirgos.xml – The xml file should follow the structure of the example in the previous example. – A list of files can be provided as input (whitespace separated). – If a document with the same id (unique key) is provided as input, then the new document will replace the existing.• Deletion of documents: java -Ddata=args -Dcommit=no -jar post.jar "<delete><id>13424</id></delete>"• Committing changes: java –jar post.jar• The above operations (and more) are available through a Java (not only) API as well. Web Information Systems
  44. 44. Solr: QueriesHTTP API: Base URL: http://server:8983/solr/select/?Return fields “name”, “id” of all entries containing ‘museum’.• q=museum&fl=name,idAs above but also return relevance score for each entry.• q=museum&fl=name,id,scoreAs above but return all stored field.• q=museum&fl=*,scoreReturn entries in JSON format.• q=museum&wt=jsonReturn all entries containing the keyword ‘pirgos’ in their field “name”.• q=name:pirgos Web Information Systems
  45. 45. Challenges• Text indexing and search frequently encounters the following two challenges: – Synonyms, writing variations: users search for something using a form different than the “reference” form. e.g. White Tower, Λευκός Πύργος, λευκός πύργος, lefkos pyrgos, ...  Solution: Attempt to collect and index many different lexical forms of the same term. – Polysemy/Ambiguity: A single term refers to more than one concepts. e.g. the term museum may refer to a number of real-world museums Solution: Appropriate interfaces are necessary to make the user aware of the different senses/contexts of a term and ask for query reformulation/specification (could also come up with suggestions). Web Information Systems
  46. 46. Synonyms• Strategy 1 (simple but not always available): – Use dictionary/thesaurus/gazetteer (e.g. Geonames) Contains alternative names and variations for a large number of Pois and locations. – Addition of a “synonyms” field in the index – Include the additional field in the search …but give a higher weight to the “name” field. Web Information Systems
  47. 47. Related terms• Strategy 2 (more complex but generally applicable): – Issue query to search engine or other content application (e.g. Flickr) • Use Poi name as query. – Process search results in two ways: • Find terms or term sequences that frequently occur in the same context (e.g. web page, title of photo, etc.). • Find terms that are lexically similar to the query term (e.g. based on the Levenshtein distance) . – Addition of a “similars” field in the index. – Include the additional field in the search • but give higher weight to the “name” field Web Information Systems
  48. 48. Google Maps API
  49. 49. Licensing• The Google Maps service is free for web pages that are freely available. Charges apply for commercial usage of the API.• Since V3, the API does not require a key. Web Information Systems
  50. 50. Google Maps API (I)• The map service is based on the notion of map tiles, which, when stitched together, provide an impression of a continuous map. Web Information Systems
  51. 51. Google Maps API (II)• There are different types of map types, e.g. ROADMAP, SATELLITE, HYBRID, TERRAIN. Those are called base map tiles. ROADMAP HYBRID HYBRID TERRAIN Web Information Systems
  52. 52. Google Maps API – Coordinates (I)Coordinates:• World: Point 0,0  lat ~ 85° lon 180°• Pixel: pixelCoord = worldCoord  2zoomLevelThe API first determines the visible area of the map on the client (viewport) based on the zoom level, the map center and the size (in pixels) of the DOM element in the client web page. Web Information Systems
  53. 53. Google Maps API – Coordinates (II)Coordinates:• Tile coordinates: – With every scroll or zoom to a new viewport, the API needs to render a new area on the map. For this to happen, it needs to translate the pixel coordinates into appropriate tile coordinates in order to load the appropriate tiles. At each zoom level the tile coordinates are different. – e.g. at zoom level 2 (beside) 16 tiles need to be indexed. The tile containing Greece has coordinates (2,1). At zoom level 3, 16 x 4 = 64 tiles need to to be indexed, and so on. Web Information Systems
  54. 54. The “hello world” of Google Maps• The map object is integrated to any web page as a DOM element. <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> html { height: 100% } body { height: 100%; margin: 0px; padding: 0px } #map_canvas { height: 100% }</style> Library import <script type="text/javascript" src=""></script> <script type="text/javascript"> function initialize() { Map initialization and centering var latlng = new google.maps.LatLng(40.66, 22.95); var myOptions = { zoom: 12, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); } </script> </head> <body onload="initialize()"> Map canvas DOM element <div id="map_canvas" style="width:100%; height:100%"></div> </body> </html> Spans the whole page body Web Information Systems
  55. 55. Basic objects• google.maps.LatLng – Initialization: var latlng = new google.maps.LatLng(lat_p, lon_p); – Very useful object, e.g. for marker placement. – In case we don’t know the geo coordinates, but know the street name, we could make use of a Geocoding service.• google.maps.Map – Initialization: var mapx = new google.maps.Map(domElement, options); – Basic parameters: zoom level, center, mapType (ROADMAP, HYBRID, etc.) – It is possible to have more than one map objects on the same page. Web Information Systems
  56. 56. Zoom level• Very important to select the proper zoom level depending on the application needs. zoom = 4 zoom = 8 zoom = 12 zoom = 16 zoom = 18 zoom = 20 Web Information Systems
  57. 57. More basic objects• google.maps.Marker – Initialization: var latlng = new google.maps.Marker({ position: latlng, map: mapx, title: “POI Title” });• Very useful object!• Use it for marking Pois. Web Information Systems
  58. 58. Events on the map UI• Interacting with the map, as in every UI, triggers a variety of events.• There are two basic event categories: – User/UI events: Objects on the map respond to certain user actions. – MVC events: Triggered by changes in the state of the map, e.g. change of value for some parameter (zoom level). Web Information Systems
  59. 59. Map events• UI events Look like common DOM events but are separately triggered in order to prevent incompatibility with different browsers. e.g. the Marker object responds to the following events: – “click”, – “dblclick”, – “mouseup”, – “mousedown”, – “mouseover”, – “mouseout”. Web Information Systems
  60. 60. Event listening (I)• addListener() – Object that “listens” – event that is “listened” MVC event – Method that is invoked as soon as the event occurs• Example: google.maps.event.addListener(map, zoom_changed, function() { setTimeout(moveToDarwin, 3000); // fire moveToDarwin() after 3 secs }); google.maps.event.addListener(marker, click, function() { map.setZoom(8); }); UI event function moveToDarwin() { var darwin = new google.maps.LatLng(-12.461334, 130.841904); map.setCenter(darwin); } Web Information Systems
  61. 61. Event listening (II)• Argument passing – Only for UI events – Access properties and their values as in any JavaScript object• Example: google.maps.event.addListener(map, click, function(event) { placeMarker(event.latLng); }); function placeMarker(location) { var marker = new google.maps.Marker({ position: location, Marker creation at the point clicked by map: map the user. }); map.setCenter(location); Map centering on the same point. } Web Information Systems
  62. 62. Event listening (IΙI)• Read and write properties within MVC events – The value that we read may be different than the value at the time of event triggering (usually we care only for the current value).• Example: google.maps.event.addListener(map, zoom_changed, function() { zoomLevel = map.getZoom(); alert("Zoom: " + zoomLevel); if (zoomLevel == 0) { map.setZoom(10); } }); Web Information Systems
  63. 63. Event listening (IV)• Listen to common DOM events – addDomListener() window, document.body, etc. DOM element• Example: named elements <script> event name function initialize() { // map initialization method to be invoked } google.maps.event.addDomListener(window, load, initialize); </script> <body> <div id="map_canvas"></div> </body> Web Information Systems
  64. 64. Control elements (I)• UI elements that enable users to interact with the viewport on the map.• Navigation control: pan & zoom• Scale control• MapType control Web Information Systems
  65. 65. Control elements (II)• Determine active controls by use of approprate arguments in the map object options (only at create time): { navigationControl: boolean, mapTypeControl: boolean, scaleControl: boolean }• Example: function initialize() { var myOptions = { zoom: 4, center: new google.maps.LatLng(-33, 151), navigationControl: false, scaleControl: true, mapTypeId: google.maps.MapTypeId.ROADMAP } var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); } Web Information Systems
  66. 66. Control elements (IΙI)• Control elements offer additional options: – google.maps.NavigationControlStyle.SMALL  mini-zoom form – google.maps.NavigationControlStyle.ZOOM_PAN  standard form of zoom & pan – google.maps.MapTypeControlStyle.DROPDOWN_MENU  select map types from dropdown menu• Example: var myOptions = { ... mapTypeControl: true, mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU }, navigationControl: true, navigationControlOptions: { style: google.maps.NavigationControlStyle.SMALL }, .... } var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); Web Information Systems
  67. 67. Control elements (IV)• Control elements can be placed in different positions on the map: navigationControl: true, navigationControlOptions: { style: google.maps.NavigationControlStyle.ZOOM_PAN, position: google.maps.ControlPosition.TOP_RIGHT } Web Information Systems
  68. 68. Control elements (V) custom control• It is possible to create custom control elements.• Control elements are essentially div elements.• In order to create them, you need: – Define their appearance by use of CSS. – Determine their interactions by use of event handlers. – Create div element and add it to controls property of the Map object. Web Information Systems
  69. 69. Overlays• Objects with specific coordinates. Markers Icons Polylines Polygons InfoWindow Web Information Systems
  70. 70. Overlays - Markers• Markers are initialized with their position, the map, and a title as arguments (the title appears in a tooltip upon mouse hover).• It is also possible to animate markers with two predefined animation schemes by use of the method marker.setAnimation(method): – google.maps.Animation.DROP: Drops and stops. – google.maps.Animation.BOUNCE: Bounces. – null: Static. Web Information Systems
  71. 71. Overlays - Icons• Markers with a different look.• Set the icon property.• Example: var image = `beachflag.png’; var myLatLng = new google.maps.LatLng(44.890, 22.27); var beachMarker = new google.maps.Marker({ position: myLatLng, map: map, icon: image });• Options for more complex appearance (e.g. by use of shadow and stacking). Web Information Systems
  72. 72. Polylines• Useful for presenting routes, directions, etc.• Example: var flightPlanCoordinates = [ new google.maps.LatLng(37.772323, -122.214897), new google.maps.LatLng(21.291982, -157.821856), new google.maps.LatLng(-18.142599, 178.431), new google.maps.LatLng(-27.46758, 153.027892) ]; var flightPath = new google.maps.Polyline({ path: flightPlanCoordinates, strokeColor: "#FF0000", strokeOpacity: 1.0, strokeWeight: 2 }); flightPath.setMap(map); Web Information Systems
  73. 73. Polylines - Processing• It is possible to dynamically modify a polyline.• Read and modify the points in a line: – var path = poly.getPath(); – var latlng_idx = path.getAt(idx)  read element on position idx – path.insertAt(idx)  insert element in position idx – path.removeAt(idx)  delete element on position idx – path.push(latlng)  add element at the end of the line Web Information Systems
  74. 74. Polygons• Polygons cover an area.• Example: var triangleCoords = [ new google.maps.LatLng(25.774252, -80.190262), Same start and new google.maps.LatLng(18.466465, -66.118292), new google.maps.LatLng(32.321384, -64.75737), end coordinate new google.maps.LatLng(25.774252, -80.190262) (optional) ]; bermudaTriangle = new google.maps.Polygon({ paths: triangleCoords, strokeColor: "#FF0000", strokeOpacity: 0.8, strokeWeight: 2, fillColor: "#FF0000", fillOpacity: 0.3 }); bermudaTriangle.setMap(map);• Same behaviour as Polylines with respect to processing their elements (e.g. getPath(), etc.). Web Information Systems
  75. 75. Info Window (Ι)• Very important for providing information for a Poi upon click.• May contain: (a) simple text, (b) HTML code, or (c) DOM element.• Initialized by use of the following elements: – content: String (simple text/HTML), DOM node – position: If the Info Window is to be opened on top of a marker, then the marker position is provided. – maxWidth: Maximum width in pixels (autowraps text). Web Information Systems
  76. 76. Info Window (ΙΙ)• Example: var contentString = <div id="content">+ <div id="siteNotice">+ </div>+ <h1 id="firstHeading" class="firstHeading">Uluru</h1>+ <div id="bodyContent">+ <p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large + sandstone rock formation in the southern part of the + Northern Territory, central Australia. It lies 335 km (208 mi) + .... + </p>+ <p>Attribution: Uluru, <a href="">‘ +</a> (last visited June 22, 2009).</p>‘ + </div>‘ + </div>; var infowindow = new google.maps.InfoWindow({ content: contentString }); var marker = new google.maps.Marker({ position: myLatlng, map: map, title:"Uluru (Ayers Rock)« }); google.maps.event.addListener(marker, click, function() {,marker); }); Web Information Systems
  77. 77. Layers• Collections of information that are overlaid on top of base map tiles and modify its appearance. They are treated as a single object.• Existing layers: – KmlLayer, GeoRSS • Presentation of feed of geotagged posts on a map. – TrafficLayer – BicyclingLayer Web Information Systems
  78. 78. Geocoding• Service for converting between street names and geographical coordinates.• Rate limit: 2500 calls / day• Base URL output: json / xml par  required: address OR latlng, sensor optional: bounds, region, language Web Information Systems
  79. 79. Use Cases:Geographical Data Clustering + Heat Maps
  80. 80. Geo-Clustering (1)• Represent each location p = (lat, lon) as a feature vector: x = [x1 x2]• Apply some density-based clustering method. – Prefer methods that do not require setting the number of clusters as parameter (e.g. k-means is not really appropriate). Recommend methods: BIRCH and DBSCAN (they require setting other parameters). Web Information Systems
  81. 81. Geo-Clustering (2)• Example of using the BIRCH algorithm on a set of geotagged Flickr photos in the vicinity of Thessaloniki. CENTER + 40 ΕKKLISIES + ANO POLI NEA PARALIA KARABOURNAKI ARETSOU d = 0.0015 d = 0.0030 Web Information Systems
  82. 82. Geo-Clustering (3) • Example of using clustering in a web application.http://www.clusttour.grmarkers + polygons + infowindow Web Information Systems
  83. 83. Heat maps• A visual analytics tool.• Useful for visualizing location-dependent quantities, e.g. population density, housing prices, crime rates, pollution, etc.• Requires knowledge or inference of quantity distribution over space.• Overlay on top of the map. Web Information Systems
  84. 84. Heat maps• Example: geotagged photos collected from Flickr based on the query “sziget festival”) GRID Web Information Systems
  85. 85. Heat maps• Counting frequency in each cell + smoothing based on adjacent cells + color coding Web Information Systems
  86. 86. Heat maps (1)Languages in Twitter Web Information Systems
  87. 87. Heat maps (2) road-in-great-britain/Deadly car accidents in the UK Web Information Systems
  88. 88. Heat maps (3) La Grande Arche de la Defense Versailles Orly AirportTwitter (blue) + Flickr (orange) Web Information Systems
  89. 89. maps Rome London Web Information Systems
  90. 90. Thank you!Symeon
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.