Skip to content

Commit

Permalink
make contenttypes folderish, add projection to layer add form, get wm…
Browse files Browse the repository at this point in the history
…ts matrix from server
  • Loading branch information
cleder committed Jan 18, 2013
1 parent b2b21af commit d7baaec
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 53 deletions.
112 changes: 66 additions & 46 deletions collective/geo/wms/maplayers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#
import json
from five import grok
from collective.geo.mapwidget.browser.widget import MapLayers
from collective.geo.mapwidget.maplayers import MapLayer
Expand Down Expand Up @@ -29,17 +30,18 @@ def jsfactory(self):
ollayers.append(
u"""
function() {
return new OpenLayers.Layer.WMS("%s",
"%s",
{layers: '%s', transparent: %s},
{isBaseLayer: %s, opacity: %.1f});
}""" % (layername,
server_url,
layer,
transparent,
baselayer,
opacity,
)
return new OpenLayers.Layer.WMS('%(name)s',
'%(url)s',
{layers: '%(layer)s', transparent: %(transparent)s,
transitionEffect: 'resize',
isBaseLayer: %(baselayer)s, opacity: %(opacity).1f});
}""" % {'name': layername,
'url': server_url,
'layer': layer,
'transparent': transparent,
'baselayer': baselayer,
'opacity': opacity,
}
)
baselayer = 'false'
transparent = 'true'
Expand All @@ -48,17 +50,18 @@ def jsfactory(self):
layers = ', '.join(self.context.layers)
return u"""
function() {
return new OpenLayers.Layer.WMS("%s",
"%s",
{layers: '%s', transparent: %s},
{isBaseLayer: %s, opacity: %.1f});
}""" % (self.context.Title().replace("'", "'"),
server_url,
layers,
transparent,
baselayer,
opacity,
)
return new OpenLayers.Layer.WMS('%(name)s',
'%(url)s',
{layers: '%(layers)s', transparent: %(transparent)s,
transitionEffect:'resize',
isBaseLayer: %(baselayer)s, opacity: %(opacity).1f});
}""" % {'name': self.context.Title().replace("'", "'"),
'url': server_url,
'layers': layers,
'transparent': transparent,
'baselayer': baselayer,
'opacity': opacity,
}



Expand All @@ -83,36 +86,53 @@ def jsfactory(self):
ollayers = []
for layer in layers:
style = wmts.contents[layer].styles.keys()[0]
layername = wmts.contents[layer].title
if wmts.contents[layer].boundingBoxWGS84:
max_extent = MAX_EXTENT % wmts.contents[layer].boundingBoxWGS84
layername = wmts.contents[layer].title.replace("'", "'")
#if wmts.contents[layer].boundingBoxWGS84:
# max_extent = MAX_EXTENT % wmts.contents[layer].boundingBoxWGS84
#else:
# max_extent =''
tilematrixset = None
for tms in wmts.contents[layer].tilematrixsets:
if tms == self.context.srs:
tilematrixset = tms
if tilematrixset:
tilematrixids = []
for tm in wmts.tilematrixsets[tilematrixset].tilematrix.values():
tilematrixids.append({
'identifier': tm.identifier,
'scaleDenominator': tm.scaledenominator,
#'topLeftCorner': tm.topleftcorner,
'tileWidth': tm.tilewidth,
'tileHeight': tm.tileheight,
})
else:
max_extent =''
raise ValueError('No TileMatrix found')

ollayers.append(
u"""
function() {
var matrixIds = new Array(26);
for (var i=0; i<26; ++i) {
matrixIds[i] = "EPSG:900913:" + i;
}
return new OpenLayers.Layer.WMTS({
name: "%s",
url: "%s",
layer: '%s',
style: '%s',
matrixSet: 'EPSG:900913',
matrixIds: matrixIds,
zoomOffset: 0,
format:'image/%s',
opacity: %.1f,
isBaseLayer: %s });
}""" % (layername,
server_url, layer, style,
format, opacity, baselayer
))
name: "%(name)s",
url: "%(url)s",
layer: '%(layer)s',
style: '%(style)s',
matrixSet: '%(matrixset)s',
matrixIds: %(matrixids)s,
/*zoomOffset: 0,*/
format:'image/%(format)s',
opacity: %(opacity).1f,
transitionEffect:'resize',
isBaseLayer: %(baselayer)s });
}""" % {'name': layername,
'url': server_url,
'layer': layer,
'matrixset': tilematrixset,
'matrixids': json.dumps(tilematrixids),
'style': style,
'format': format,
'opacity': opacity,
'baselayer': baselayer
})
baselayer = 'false'
return ', '.join(ollayers)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<property name="icon_expr">string:${portal_url}/++resource++layers.png</property>
<property name="factory">collective.geo.wms.wmslayer</property>
<property name="global_allow">True</property>
<property name="filter_content_types">False</property>
<property name="filter_content_types">True</property>
<property name="allowed_content_types" />
<property name="allow_discussion">False</property>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<property name="icon_expr">string:${portal_url}/++resource++map_server.png</property>
<property name="factory">collective.geo.wms.wmsserver</property>
<property name="global_allow">True</property>
<property name="filter_content_types">False</property>
<property name="filter_content_types">True</property>
<property name="allowed_content_types" />
<property name="allow_discussion">False</property>

Expand Down
21 changes: 17 additions & 4 deletions collective/geo/wms/wmslayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class IWMSLayer(form.Schema):
# wms specific
singlelayers = schema.Bool(
title=_(u"Single Layers"),
description=_(u"Request the layers seperately from the server and overlay them on the client side"),
description=_(u"""Request the layers seperately from the
server and overlay them on the client side"""),
required=False,
default=False,
)
Expand All @@ -89,6 +90,17 @@ class IWMSLayer(form.Schema):
)


srs = schema.Choice(
title=_(u'Projection'),
description=_(u"""Projection (SRS) of the layer"""),
#XXX Should the vocabulary come out of the layers?
values=('EPSG:900913', 'EPSG:4326'),
default='EPSG:900913',
required=True,
)



opacity = schema.Float(
title=_(u"Opacity"),
min=0.0,
Expand All @@ -99,7 +111,8 @@ class IWMSLayer(form.Schema):

featureinfo = schema.Bool(
title=_(u"Feature Info"),
description=_(u"Get feature info for layers and display it in a popup window"),
description=_(u"""Get feature info for layers and display it
in a popup window"""),
required=False,
default = True,
)
Expand All @@ -116,7 +129,7 @@ class IWMSLayer(form.Schema):
# methods and properties. Put methods that are mainly useful for rendering
# in separate view classes.

class WMSLayer(dexterity.Item):
class WMSLayer(dexterity.Container):
grok.implements(IWMSLayer)

# Add your class methods and properties here
Expand Down Expand Up @@ -191,7 +204,7 @@ class EditForm(dexterity.EditForm):

def updateWidgets(self):
""" """
self.fields = self.fields.omit('server')
self.fields = self.fields.omit('server', 'srs')
if self.context.server.to_object.protocol == 'wmts':
self.fields = self.fields.omit('singlelayers')
else:
Expand Down
2 changes: 1 addition & 1 deletion collective/geo/wms/wmsserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _wms_server_cachekey(context, fun, url, protocol):
return ckey


class WMSServer(dexterity.Item):
class WMSServer(dexterity.Container):
grok.implements(IWMSServer)

# Add your class methods and properties here
Expand Down

0 comments on commit d7baaec

Please sign in to comment.