1624
1633
Custom View for GeoExplorer: http://projects.opengeo.org/geoext/wiki/GeoExplorer
1625
This version doesn't yet work properly
1628
1636
google_key = db(db.gis_apikey.name == "google").select(db.gis_apikey.apikey, limitby=(0, 1)).first().apikey
1630
return dict(google_key=google_key)
1638
# http://eden.sahanafoundation.org/wiki/BluePrintGISPrinting
1639
print_service = deployment_settings.get_gis_print_service()
1641
geoserver_url = deployment_settings.get_gis_geoserver_url()
1643
return dict(google_key=google_key, print_service=print_service, geoserver_url=geoserver_url)
1646
""" Custom View for GeoExplorer """
1652
Map Save/Publish Handler for GeoExplorer
1655
if request.env.request_method == "GET":
1656
# This is a request to read the config of a saved map
1658
# Which map are we updating?
1659
id = request.args(0)
1663
# Read the WMC record
1664
record = db(db.gis_wmc.id == id).select(limitby=(0, 1)).first()
1666
#projection = db(db.gis_projection.id == record.projection).select(limitby=(0, 1)).first()
1668
# Put details into the correct structure
1670
output["map"] = dict()
1672
map["center"] = [record.lat, record.lon]
1673
map["zoom"] = record.zoom
1674
# @ToDo: Read Projection (we generally use 900913 & no way to edit this yet)
1675
map["projection"] = "EPSG:900913"
1677
map["maxResolution"] = 156543.0339
1678
map["maxExtent"] = [ -20037508.34, -20037508.34, 20037508.34, 20037508.34 ]
1679
# @ToDo: Read Layers
1681
#map["layers"].append(dict(source="google", title="Google Terrain", name="TERRAIN", group="background"))
1682
#map["layers"].append(dict(source="ol", group="background", fixed=True, type="OpenLayers.Layer", args=[ "None", {"visibility":False} ]))
1683
for _layer in record.layer_id:
1684
layer = db(db.gis_wmc_layer.id == _layer).select(limitby=(0, 1)).first()
1685
if layer.type_ == "OpenLayers.Layer":
1687
map["layers"].append(dict(source=layer.source, title=layer.title, name=layer.name, group=layer.group_, type=layer.type_, format=layer.format, visibility=layer.visibility, transparent=layer.transparent, opacity=layer.opacity, fixed=layer.fixed, args=[ "None", {"visibility":False} ]))
1689
map["layers"].append(dict(source=layer.source, title=layer.title, name=layer.name, group=layer.group_, type=layer.type_, format=layer.format, visibility=layer.visibility, transparent=layer.transparent, opacity=layer.opacity, fixed=layer.fixed))
1691
# @ToDo: Read Metadata (no way of editing this yet)
1694
output = json.dumps(output)
1697
response.headers["Content-Type"] = "text/json"
1700
elif request.env.request_method == "POST":
1701
# This is a request to save/publish a new map
1703
# Get the data from the POST
1704
source = request.body.read()
1705
if isinstance(source, basestring):
1706
from StringIO import StringIO
1707
source = StringIO(source)
1710
source = json.load(source)
1711
# @ToDo: Projection (we generally use 900913 & no way to edit this yet)
1712
lat = source["map"]["center"][0]
1713
lon = source["map"]["center"][1]
1714
zoom = source["map"]["zoom"]
1717
for layer in source["map"]["layers"]:
1719
opacity = layer["opacity"]
1723
name = layer["name"]
1726
_layer = db((db.gis_wmc_layer.source == layer["source"]) &
1727
(db.gis_wmc_layer.name == name) &
1728
(db.gis_wmc_layer.visibility == layer["visibility"]) &
1729
(db.gis_wmc_layer.opacity == opacity)
1730
).select(db.gis_wmc_layer.id,
1731
limitby=(0, 1)).first()
1733
# This is an existing layer
1734
layers.append(_layer.id)
1736
# This is a new layer
1738
type_ = layer["type"]
1742
group_ = layer["group"]
1746
fixed = layer["fixed"]
1750
format = layer["format"]
1754
transparent = layer["transparent"]
1757
# Add a new record to the gis_wmc_layer table
1758
_layer = db.gis_wmc_layer.insert(source=layer["source"], name=name, visibility=layer["visibility"], opacity=opacity, type_=type_, title=layer["title"], group_=group_, fixed=fixed, transparent=transparent, format=format)
1759
layers.append(_layer)
1761
# @ToDo: Metadata (no way of editing this yet)
1763
# Save a record in the WMC table
1764
id = db.gis_wmc.insert(lat=lat, lon=lon, zoom=zoom, layer_id=layers)
1766
# Return the ID of the saved record for the Bookmark
1767
output = json.dumps(dict(id=id))
1770
elif request.env.request_method == "PUT":
1771
# This is a request to save/publish an existing map
1773
# Which map are we updating?
1774
id = request.args(0)
1778
# Get the data from the PUT
1779
source = request.body.read()
1780
if isinstance(source, basestring):
1781
from StringIO import StringIO
1782
source = StringIO(source)
1784
source = json.load(source)
1785
# @ToDo: Projection (unlikely to change)
1786
lat = source["map"]["center"][0]
1787
lon = source["map"]["center"][1]
1788
zoom = source["map"]["zoom"]
1791
for layer in source["map"]["layers"]:
1793
opacity = layer["opacity"]
1797
name = layer["name"]
1800
_layer = db((db.gis_wmc_layer.source == layer["source"]) &
1801
(db.gis_wmc_layer.name == name) &
1802
(db.gis_wmc_layer.visibility == layer["visibility"]) &
1803
(db.gis_wmc_layer.opacity == opacity)
1804
).select(db.gis_wmc_layer.id,
1805
limitby=(0, 1)).first()
1807
# This is an existing layer
1808
layers.append(_layer.id)
1810
# This is a new layer
1812
type_ = layer["type"]
1816
group_ = layer["group"]
1820
fixed = layer["fixed"]
1824
format = layer["format"]
1828
transparent = layer["transparent"]
1831
# Add a new record to the gis_wmc_layer table
1832
_layer = db.gis_wmc_layer.insert(source=layer["source"], name=name, visibility=layer["visibility"], opacity=opacity, type_=type_, title=layer["title"], group_=group_, fixed=fixed, transparent=transparent, format=format)
1833
layers.append(_layer)
1835
# @ToDo: Metadata (no way of editing this yet)
1837
# Update the record in the WMC table
1838
db(db.gis_wmc.id == id).update(lat=lat, lon=lon, zoom=zoom, layer_id=layers)
1840
# Return the ID of the saved record for the Bookmark
1841
output = json.dumps(dict(id=id))
1844
# Abort - we shouldn't get here
1632
1847
# -----------------------------------------------------------------------------
1633
1848
def potlatch2():