def add_layer_to_mapstory(self, mapstory, layer, stack_order, style): map = mapstory.chapters[0] maplayer = MapLayer() maplayer.map = map maplayer.name = layer.name maplayer.stack_order = stack_order maplayer.opacity = 1.0 maplayer.fixed = False maplayer.visibility = True maplayer.source_params = u'{"lazy": true, "name": "local geoserver", "title": "Local Geoserver", "ptype": "gxp_wmscsource", "restUrl": "/gs/rest", "isVirtualService": false, "mapLayerRequiresServer": true}' maplayer.layer_config = "" maplayer.styles = style maplayer.save()
def add_layer_to_mapstory(self, mapstory, layer, stack_order, style): map = mapstory.chapters[0] maplayer = MapLayer() maplayer.map = map maplayer.name = layer.name maplayer.stack_order = stack_order maplayer.opacity = 1.0 maplayer.fixed = False maplayer.visibility = True maplayer.source_params = u'{"lazy": true, "name": "local geoserver", "title": "Local Geoserver", "ptype": "gxp_wmscsource", "restUrl": "/gs/rest", "isVirtualService": false, "mapLayerRequiresServer": true}' maplayer.layer_config = "" maplayer.styles = style maplayer.save()
def add_to_map(req, id, typename): if req.method != 'POST': return HttpResponse('POST required', status=400) mapobj = get_object_or_404(Map, id=id) if mapobj.owner != req.user and not req.user.has_perm( 'maps.change_map', mapobj): return HttpResponse('Not sufficient permissions', status=401) layer = get_object_or_404(Layer, typename=typename) existing = MapLayer.objects.filter(map=mapobj) vs_url = settings.GEOSERVER_BASE_URL + '%s/%s/wms' % tuple( layer.typename.split(':')) stack_order = max([l.stack_order for l in existing]) + 1 # have to use local name, not full typename when using ows_url maplayer = MapLayer(name=layer.name, ows_url=vs_url, map=mapobj, stack_order=stack_order) maplayer.save() # if bounding box is equivalent to default, compute and save ints = lambda t: map(int, t) if ints(mapobj.center) == ints( forward_mercator(settings.DEFAULT_MAP_CENTER)): bbox = layer.resource.latlon_bbox[0:4] # @todo copy-paste from geonode.maps.views - extract this for reuse minx, maxx, miny, maxy = [float(c) for c in bbox] x = (minx + maxx) / 2 y = (miny + maxy) / 2 center = forward_mercator((x, y)) if center[1] == float('-inf'): center = (center[0], 0) if maxx == minx: width_zoom = 15 else: width_zoom = math.log(360 / (maxx - minx), 2) if maxy == miny: height_zoom = 15 else: height_zoom = math.log(360 / (maxy - miny), 2) mapobj.center_x = center[0] mapobj.center_y = center[1] mapobj.zoom = math.ceil(min(width_zoom, height_zoom)) mapobj.save() return HttpResponse('OK', status=200)
def add_mapstory(self): mapstory = MapStory() mapstory.name = "test_case1" mapstory.owner = self.admin_user mapstory.uuid = str(uuid.uuid1()) mapstory.save() map = Map() map.story = mapstory map.chapter_index = 0 map.title = "test_case" map.projection = 'EPSG:4326' map.owner = mapstory.owner map.uuid = str(uuid.uuid1()) map.zoom = 4 map.center_x = 0 map.center_y = 0 map.set_bounds_from_center_and_zoom( map.center_x, map.center_y, map.zoom) map.save() mapstory.chapter_list.add(map) mapstory.save() # background maplayer_background = MapLayer() maplayer_background.map = map maplayer_background.name = "control-room" maplayer_background.stack_order = 4 maplayer_background.opacity = 1.0 maplayer_background.fixed = False maplayer_background.visibility = True maplayer_background.source_params = u'{"hidden": true, "ptype": "gxp_mapboxsource"}' maplayer_background.layer_config = "" maplayer_background.group = "background" maplayer_background.save() # map.layers.add(maplayer) map.save() return mapstory
def add_mapstory(self): mapstory = MapStory() mapstory.name = "test_case1" mapstory.owner = self.admin_user mapstory.uuid = str(uuid.uuid1()) mapstory.save() map = Map() map.story = mapstory map.chapter_index = 0 map.title = "test_case" map.projection = 'EPSG:4326' map.owner = mapstory.owner map.uuid = str(uuid.uuid1()) map.zoom = 4 map.center_x = 0 map.center_y = 0 map.set_bounds_from_center_and_zoom(map.center_x, map.center_y, map.zoom) map.save() mapstory.chapter_list.add(map) mapstory.save() # background maplayer_background = MapLayer() maplayer_background.map = map maplayer_background.name = "control-room" maplayer_background.stack_order = 4 maplayer_background.opacity = 1.0 maplayer_background.fixed = False maplayer_background.visibility = True maplayer_background.source_params = u'{"hidden": true, "ptype": "gxp_mapboxsource"}' maplayer_background.layer_config = "" maplayer_background.group = "background" maplayer_background.save() # map.layers.add(maplayer) map.save() return mapstory
def add_to_map(req,id,typename): if req.method != 'POST': return HttpResponse('POST required',status=400) mapobj = get_object_or_404(Map, id=id) if mapobj.owner != req.user and not req.user.has_perm('maps.change_map', mapobj): return HttpResponse('Not sufficient permissions',status=401) layer = get_object_or_404(Layer, typename=typename) existing = MapLayer.objects.filter(map = mapobj) vs_url = settings.GEOSERVER_BASE_URL + '%s/%s/wms' % tuple(layer.typename.split(':')) stack_order = max([l.stack_order for l in existing]) + 1 # have to use local name, not full typename when using ows_url maplayer = MapLayer(name = layer.name, ows_url=vs_url, map=mapobj, stack_order=stack_order) maplayer.save() # if bounding box is equivalent to default, compute and save ints = lambda t: map(int,t) if ints(mapobj.center) == ints(forward_mercator(settings.DEFAULT_MAP_CENTER)): bbox = layer.resource.latlon_bbox[0:4] # @todo copy-paste from geonode.maps.views - extract this for reuse minx, maxx, miny, maxy = [float(c) for c in bbox] x = (minx + maxx) / 2 y = (miny + maxy) / 2 center = forward_mercator((x, y)) if center[1] == float('-inf'): center = (center[0], 0) if maxx == minx: width_zoom = 15 else: width_zoom = math.log(360 / (maxx - minx), 2) if maxy == miny: height_zoom = 15 else: height_zoom = math.log(360 / (maxy - miny), 2) mapobj.center_x = center[0] mapobj.center_y = center[1] mapobj.zoom = math.ceil(min(width_zoom, height_zoom)) mapobj.save() return HttpResponse('OK', status=200)