diff --git a/src/plugins/lib/libhtmlconst.py b/src/plugins/lib/libhtmlconst.py index a89f16a90..6a1e624d5 100644 --- a/src/plugins/lib/libhtmlconst.py +++ b/src/plugins/lib/libhtmlconst.py @@ -121,9 +121,8 @@ _COPY_OPTIONS = [ # NarrativeWeb javascript code for PlacePage's "Open Street Map"... openstreet_jsc = """ -OpenLayers.Lang.setCode("%s"); + OpenLayers.Lang.setCode("%s"); -function initialize() { map = new OpenLayers.Map("map_canvas"); var osm = new OpenLayers.Layer.OSM() map.addLayer(osm); @@ -144,8 +143,7 @@ function initialize() { map.addControl(new OpenLayers.Control.OverviewMap()); // add a layer switcher - map.addControl(new OpenLayers.Control.LayerSwitcher()); -}""" + map.addControl(new OpenLayers.Control.LayerSwitcher());""" # NarrativeWeb javascript code for PlacePage's "Google Maps"... google_jsc = """ diff --git a/src/plugins/webreport/NarrativeWeb.py b/src/plugins/webreport/NarrativeWeb.py index 389a3af4e..3a74cf62f 100644 --- a/src/plugins/webreport/NarrativeWeb.py +++ b/src/plugins/webreport/NarrativeWeb.py @@ -3981,7 +3981,7 @@ class IndividualPage(BasePage): # create family map link if self.familymappages: if len(place_lat_long): - individualdetail += self.display_ind_family_map(person) + individualdetail += self.__display_family_map(person) # display pedigree sect13 = self.display_ind_pedigree() @@ -4003,7 +4003,7 @@ class IndividualPage(BasePage): # and close the file self.XHTMLWriter(indivdetpage, of) - def _create_family_map(self, person): + def __create_family_map(self, person): """ creates individual family map page @@ -4018,6 +4018,7 @@ class IndividualPage(BasePage): return self.familymappages = self.report.options['familymappages'] + self.mapservice = self.report.options['mapservice'] minX, maxX = "0.00000001", "0.00000001" minY, maxY = "0.00000001", "0.00000001" @@ -4039,11 +4040,13 @@ class IndividualPage(BasePage): maxY = YCoordinates[-1] if YCoordinates[-1] is not None else maxY minY, maxY = Decimal(minY), Decimal(maxY) centerY = str( Decimal( ( ( (maxY - minY) / 2) + minY) ) ) + centerX, centerY = conv_lat_lon(centerX, centerY, "D.D8") try: spanY = int(maxY - minY) except ValueError: spanY = 0 + try: spanX = int(maxX - minX) except ValueError: @@ -4070,31 +4073,45 @@ class IndividualPage(BasePage): # if active # call_(report, up, head) - # add narrative-maps stylesheet... + # add narrative-maps style sheet fname = "/".join(["styles", "narrative-maps.css"]) url = self.report.build_url_fname(fname, None, self.up) head += Html("link", href =url, type ="text/css", media ="screen", rel ="stylesheet") - if self.familymappages: - head += Html("script", type ="text/javascript", + # add MapService specific javascript code + if self.mapservice == "Google": + head += Html("script", type ="text/javascript", src ="http://maps.googleapis.com/maps/api/js?sensor=false", inline =True) + else: + head += Html("script", type ="text/javascript", + src ="http://www.openlayers.org/api/OpenLayers.js", inline =True) # set zoomlevel for size of map # the smaller the span is, the larger the zoomlevel must be... if spanY in smallset: - zoomlevel = 13 + zoomlevel = 15 elif spanY in middleset: - zoomlevel = 5 + zoomlevel = 11 elif spanY in largeset: - zoomlevel = 3 + zoomlevel = 8 else: - zoomlevel = 3 + zoomlevel = 4 # begin inline javascript code # because jsc is a string, it does NOT have to properly indented with Html("script", type ="text/javascript") as jsc: head += jsc - jsc += """ + + # if the number of places is only 1, then use code from imported javascript? + if number_markers == 1: + if self.mapservice == "Google": + jsc += google_jsc % (place_lat_long[0][0], place_lat_long[0][1]) + + # Google Maps add their javascript inside of the head element... + else: + # Family Map pages using Google Maps + if self.mapservice == "Google": + jsc += """ function initialize() { var myLatLng = new google.maps.LatLng(%s, %s); var myOptions = { @@ -4106,13 +4123,13 @@ class IndividualPage(BasePage): var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); var lifeHistory = [""" % (centerX, centerY, zoomlevel) - for index in xrange(0, (number_markers - 1)): - data = place_lat_long[index] - latitude, longitude = conv_lat_lon(data[0], data[1], "D.D8") - jsc += """ new google.maps.LatLng(%s, %s),""" % (latitude, longitude) - data = place_lat_long[-1] - latitude, longitude = conv_lat_lon(data[0], data[1], "D.D8") - jsc += """ new google.maps.LatLng(%s, %s) + for index in xrange(0, (number_markers - 1)): + data = place_lat_long[index] + latitude, longitude = conv_lat_lon(data[0], data[1], "D.D8") + jsc += """ new google.maps.LatLng(%s, %s),""" % (latitude, longitude) + data = place_lat_long[-1] + latitude, longitude = conv_lat_lon(data[0], data[1], "D.D8") + jsc += """ new google.maps.LatLng(%s, %s) ]; var flightPath = new google.maps.Polyline({ path: lifeHistory, @@ -4123,14 +4140,9 @@ class IndividualPage(BasePage): flightPath.setMap(map); }""" % (latitude, longitude) - - # there is no need to add an ending "", # as it will be added automatically! - # add body onload to initialize map - body.attr = 'onload ="initialize()" id ="FamilyMap" ' - with Html("div", class_ ="content", id ="FamilyMapDetail") as mapbackground: body += mapbackground @@ -4163,14 +4175,78 @@ class IndividualPage(BasePage): Xheight = 800 # here is where the map is held in the CSS/ Page - canvas = Html("div", id ="map_canvas") - mapbackground += canvas + with Html("div", id ="map_canvas") as canvas: + mapbackground += canvas - # add dynamic style to the place holder... - canvas.attr += ' style ="width:%dpx; height:%dpx; border: double 4px #000;" ' % (Ywidth, Xheight) + # add dynamic style to the place holder... + canvas.attr += ' style ="width: %dpx; height: %dpx;" ' % (Ywidth, Xheight) - # add fullclear for proper styling - canvas += fullclear + if self.mapservice == "OpenStreetMap": + with Html("script", type ="text/javascript") as jsc: + canvas += jsc + + if number_markers == 1: + data = place_lat_long[0] + latitude, longitude = conv_lat_lon(data[0], data[1], "D.D8") + jsc += openstreet_jsc % (Utils.xml_lang()[3:5].lower(), + longitude, latitude) + else: + 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(), + centerY, centerX, zoomlevel) + + for (lat, long, pname, h, d) in place_lat_long: + latitude, longitude = conv_lat_lon(lat, long, "D.D8") + 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, + '