diff --git a/src/plugins/webreport/NarrativeWeb.py b/src/plugins/webreport/NarrativeWeb.py index da7e1a7a1..1d3e8df42 100644 --- a/src/plugins/webreport/NarrativeWeb.py +++ b/src/plugins/webreport/NarrativeWeb.py @@ -96,7 +96,8 @@ import gen.mime from gen.display.name import displayer as _nd from DateHandler import displayer as _dd from gen.proxy import PrivateProxyDb, LivingProxyDb -from libhtmlconst import _CHARACTER_SETS, _CC, _COPY_OPTIONS, openstreetmap_jsc, google_jsc +from libhtmlconst import (_CHARACTER_SETS, _CC, _COPY_OPTIONS, + openstreetmap_jsc, google_jsc) # import HTML Class from src/plugins/lib/libhtml.py from libhtml import Html @@ -111,6 +112,8 @@ from gui.pluginmanager import GuiPluginManager #------------------------------------------------ # constants #------------------------------------------------ + +# javascript code for Google's FamilyLinks... familylinks = """ var tracelife = %s @@ -138,6 +141,7 @@ familylinks = """ flightPath.setMap(map); }""" +# javascript for Google's Drop Markers... dropmarkers = """ var markers = []; var iterator = 0; @@ -179,6 +183,7 @@ dropmarkers = """ iterator++; }""" +# javascript for Google's Markers... markers = """ var tracelife = %s var map; @@ -215,6 +220,49 @@ markers = """ map.fitBounds(bounds); } }""" + +# javascript for OpenStreetMap's markers... +osm_markers = """ + OpenLayers.Lang.setCode("%s"); + var map; + + var tracelife = %s + + function initialize(){ + map = new OpenLayers.Map('map_canvas'); + + var wms = new OpenLayers.Layer.WMS( + "OpenLayers WMS", + "http://vmap0.tiles.osgeo.org/wms/vmap0", + {'layers':'basic'}); + var dm_wms = new OpenLayers.Layer.WMS( + "Canadian Data", + "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap", + {layers: "bathymetry,land_fn,park,drain_fn,drainage," + + "prov_bound,fedlimit,rail,road,popplace", + transparent: "true", + format: "image/png"}, + {isBaseLayer: false}); + map.addLayers([wms, dm_wms]); + + map.setCenter(new OpenLayers.LonLat(%s, %s), %d); + + var markers = new OpenLayers.Layer.Markers("Markers"); + map.addLayer(markers); + + addMarkers(markers, map); + } + + function addMarkers(markers, map) { + for (var i = 0; i < tracelife.length; i++) { + var location = tracelife[i]; + + marker = new OpenLayers.Marker(new OpenLayers.LonLat(location[0], location[1])); + markers.addMarker(marker); + map.addControl(new OpenLayers.Control.LayerSwitcher()); + map.zoomToMaxExtent(); + } + }""" # there is no need to add an ending "", # as it will be added automatically by libhtml() @@ -1267,11 +1315,13 @@ class BasePage(object): # Header constants xmllang = Utils.xml_lang() - _META1 = 'name ="viewport" content ="width=device-width, initial-scale=1.0, user-scalable=yes" ' - _META2 = 'name="generator" content="%s %s %s"' % ( + _META1 = 'name ="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=1"' + _META2 = 'name ="apple-mobile-web-app-capable" content="yes"' + _META3 = 'name="generator" content="%s %s %s"' % ( const.PROGRAM_NAME, const.VERSION, const.URL_HOMEPAGE) - _META3 = 'name="author" content="%s"' % self.author + _META4 = 'name="author" content="%s"' % self.author + # begin each html page... page, head, body = Html.page('%s - %s' % (html_escape(self.title_str.strip()), html_escape(title)), @@ -1285,7 +1335,8 @@ class BasePage(object): meta = Html("meta", attr = _META1) + ( Html("meta", attr = _META2, indent = False), Html("meta", attr = _META3, indent =False), - ) + Html("meta", attr = _META4, indent = False) + ) # Link to _NARRATIVESCREEN stylesheet fname = "/".join(["styles", _NARRATIVESCREEN]) @@ -1352,6 +1403,7 @@ class BasePage(object): inc_repos = False # create media pages... + _create_media_link = False if self.create_media: _create_media_link = True if self.create_thumbs_only: @@ -4911,11 +4963,13 @@ class IndividualPage(BasePage): @param: person -- person from database @param: place_lat_long -- for use in Family Map Pages """ - - # if there is no latitude/ longitude data, then return? if not place_lat_long: return + of = self.report.create_file(person.get_handle(), "maps") + self.up = True + familymappage, head, body = self.write_header(_("Family Map")) + minx, maxx = Decimal("0.00000001"), Decimal("0.00000001") miny, maxy = Decimal("0.00000001"), Decimal("0.00000001") xwidth, yheight = [], [] @@ -4923,9 +4977,9 @@ class IndividualPage(BasePage): number_markers = len(place_lat_long) if number_markers > 1: - for (lat, long, p, h, d, etype) in place_lat_long: - xwidth.append(lat) - yheight.append(long) + for (latitude, longitude, placetitle, handle, date, etype) in place_lat_long: + xwidth.append(latitude) + yheight.append(longitude) xwidth.sort() yheight.sort() @@ -4960,12 +5014,9 @@ class IndividualPage(BasePage): else: zoomlevel = 3 - # sort place_lat_long based on latitude and longitude order... - place_lat_long.sort() - - of = self.report.create_file(person.get_handle(), "maps") - self.up = True - familymappage, head, body = self.write_header(_("Family Map")) + # 0 = latitude, 1 = longitude, 2 = place title, 3 = handle, and 4 = date, 5 = event type... + # being sorted by date, latitude, and longitude... + place_lat_long = sorted(place_lat_long, key =operator.itemgetter(4, 0, 1)) # for all plugins # if family_detail_page @@ -4985,111 +5036,55 @@ class IndividualPage(BasePage): head += Html("script", type ="text/javascript", src ="http://www.openlayers.org/api/OpenLayers.js", inline =True) - # begin inline javascript code - # because jsc is a docstring, it does NOT have to properly indented - with Html("script", type ="text/javascript", indent =False) as jsc: - head += jsc + if number_markers > 1: + tracelife = "[" + seq_ = 1 - # if the number of places is only 1, then use code from imported javascript? - if number_markers == 1: - latitude, longitude, pname, handle, date, etype_ = place_lat_long[0] + for index in xrange(0, (number_markers - 1)): + latitude, longitude, placetitle, handle, date, etype = place_lat_long[index] + + # are we using Google? if self.mapservice == "Google": - jsc += google_jsc % (latitude, longitude) - else: - jsc += openstreetmap_jsc % (Utils.xml_lang()[3:5].lower(), longitude, latitude) - # number of markers > 1 - else: - if self.mapservice == "Google": - tracelife = """[""" - - seq_ = 1 - for index in xrange(0, (number_markers - 1)): - latitude, longitude, placetitle, handle, date, etype = place_lat_long[index] - - if self.googleopts == "FamilyLinks": - tracelife += """ - new google.maps.LatLng(%s, %s),""" % (latitude, longitude) - - elif self.googleopts in ["Drop", "Markers"]: - tracelife += """ - ['%s', %s, %s, %d],""" % (placetitle, latitude, longitude, seq_) - seq_ += 1 - - latitude, longitude, placetitle, handle ,date, etype = place_lat_long[-1] + # are we creating Family Links? if self.googleopts == "FamilyLinks": tracelife += """ + new google.maps.LatLng(%s, %s),""" % (latitude, longitude) + + # are we creating Drop Markers or Markers? + elif self.googleopts in ["Drop", "Markers"]: + tracelife += """ + ['%s', %s, %s, %d],""" % (placetitle, latitude, longitude, seq_) + + # are we using OpenStreetMap? + else: + tracelife += """ + [%s, %s],""" % (longitude, latitude) + seq_ += 1 + latitude, longitude, placetitle, handle ,date, etype = place_lat_long[-1] + + # are we using Google? + if self.mapservice == "Google": + + # are we creating Family Links? + if self.googleopts == "FamilyLinks": + tracelife += """ new google.maps.LatLng(%s, %s) ];""" % (latitude, longitude) - elif self.googleopts in ["Drop", "Markers"]: - tracelife += """ + # are we creating Drop Markers or Markers? + elif self.googleopts in ["Drop", "Markers"]: + tracelife += """ ['%s', %s, %s, %d] - ];""" % (placetitle, latitude, longitude, seq_+1) + ];""" % (placetitle, latitude, longitude, seq_) - if self.googleopts == "FamilyLinks": - jsc += familylinks % (tracelife, midX_, midY_, zoomlevel) - - # Google Drop Markers... - if self.googleopts == "Drop": - jsc += dropmarkers % (tracelife, zoomlevel) - - # Google Maps Markers only... - elif self.googleopts == "Markers": - jsc += markers % (tracelife, zoomlevel) - - elif self.mapservice == "OpenStreetMap": - jsc += """ - OpenLayers.Lang.setCode("%s"); - - map = new OpenLayers.Map("map_canvas"); - map.addLayer(new OpenLayers.Layer.OSM()); - - epsg4326 = new OpenLayers.Projection("EPSG:4326"); //WGS 1984 projection - projectTo = map.getProjectionObject(); //The map projection (Spherical Mercator) - - var centre = new OpenLayers.LonLat( %s, %s ).transform(epsg4326, projectTo); - var zoom = %d; - map.setCenter(centre, zoom); - - var vectorLayer = new OpenLayers.Layer.Vector("Overlay");""" % (Utils.xml_lang()[3:5].lower(), - midY_, midX_, zoomlevel) - for (latitude, longitude, pname, h, d, etype) in place_lat_long: - jsc += """ - var feature = new OpenLayers.Feature.Vector( - new OpenLayers.Geometry.Point( %s, %s ).transform(epsg4326, projectTo), - {description:'%s'} - ); - vectorLayer.addFeatures(feature);""" % (longitude, latitude, pname) - jsc += """ - map.addLayer(vectorLayer); - - //Add a selector control to the vectorLayer with popup functions - var controls = { - selector: new OpenLayers.Control.SelectFeature(vectorLayer, { onSelect: - createPopup, onUnselect: destroyPopup }) - }; - function createPopup(feature) { - feature.popup = new OpenLayers.Popup.FramedCloud("pop", - feature.geometry.getBounds().getCenterLonLat(), - null, - '