Пример #1
0
    def update_from_viewer(self, conf, context=None):
        """
        Update this Map's details by parsing a JSON object as produced by
        a GXP Viewer.

        This method automatically persists to the database!
        """

        template_name = hookset.update_from_viewer(conf, context=context)
        conf = context['config']

        self.title = conf['title'] if 'title' in conf else conf['about']['title']
        self.abstract = conf['abstract'] if 'abstract' in conf else conf['about']['abstract']

        center = conf['map']['center'] if 'center' in conf['map'] else settings.DEFAULT_MAP_CENTER
        self.zoom = conf['map']['zoom'] if 'zoom' in conf['map'] else settings.DEFAULT_MAP_ZOOM
        self.center_x = center['x'] if isinstance(center, dict) else center[0]
        self.center_y = center['y'] if isinstance(center, dict) else center[1]
        if 'bbox' not in conf['map']:
            self.set_bounds_from_center_and_zoom(
                self.center_x,
                self.center_y,
                self.zoom)
        else:
            # Must be in the form : [x0, x1, y0, y1]
            self.set_bounds_from_bbox(conf['map']['bbox'], conf['map']['projection'])

        if self.projection is None or self.projection == '':
            self.projection = conf['map']['projection']

        if self.uuid is None or self.uuid == '':
            self.uuid = str(uuid.uuid1())

        def source_for(layer):
            try:
                return conf["sources"][layer["source"]]
            except BaseException:
                if 'url' in layer:
                    return {'url': layer['url']}
                else:
                    return {}

        layers = [l for l in conf["map"]["layers"]]
        layer_names = set([l.alternate for l in self.local_layers])

        self.layer_set.all().delete()
        self.keywords.add(*conf['map'].get('keywords', []))

        for ordering, layer in enumerate(layers):
            self.layer_set.add(
                layer_from_viewer_config(
                    self.id, MapLayer, layer, source_for(layer), ordering
                ))

        self.save()

        if layer_names != set([l.alternate for l in self.local_layers]):
            map_changed_signal.send_robust(sender=self, what_changed='layers')

        return template_name
Пример #2
0
    def update_from_viewer(self, conf):
        """
        Update this Map's details by parsing a JSON object as produced by
        a GXP Viewer.

        This method automatically persists to the database!
        """
        if isinstance(conf, basestring):
            conf = json.loads(conf)

        self.title = conf['about']['title']
        self.abstract = conf['about']['abstract']
        self.viewer_playbackmode = conf['viewer_playbackmode'] or 'Instant'

        self.set_bounds_from_center_and_zoom(
            conf['map']['center'][0],
            conf['map']['center'][1],
            conf['map']['zoom'])

        self.projection = conf['map']['projection']

        if self.uuid is None or self.uuid == '':
            self.uuid = str(uuid.uuid1())

        def source_for(layer):

            if 'sources' in conf:
                return conf["sources"][layer["source"]]
            else:
                # TODO: This is a work in progress will refactor
                # Handle special case for OL3 config model in storytools as source and sources may not available

                if layer['type'] == 'WMS':
                    return {"restUrl": "/gs/rest", "title": "", "baseParams": {"VERSION": "1.1.1", "REQUEST": "GetCapabilities", "TILED": 'true', "SERVICE": "WMS"}, "ptype": "gxp_wmscsource", "id": "local"}
                else:
                    return layer["source"]

        layers = [l for l in conf["map"]["layers"]]
        layer_names = set([l.alternate for l in self.local_layers])

        for layer in self.layer_set.all():
            layer.delete()

        self.keywords.add(*conf['map'].get('keywords', []))

        for ordering, layer in enumerate(layers):
            self.layer_set.add(
                layer_from_viewer_config(
                    MapLayer, layer, source_for(layer), ordering
                ))

        self.chapter_index = conf['chapter_index']
        story_id = conf.get('story_id',0)
        story_obj = MapStory.objects.get(id=story_id)
        self.story = story_obj
        self.save()

        if layer_names != set([l.alternate for l in self.local_layers]):
            map_changed_signal.send_robust(sender=self, what_changed='layers')
Пример #3
0
    def update_from_viewer(self, conf, context=None):
        """
        Update this Map's details by parsing a JSON object as produced by
        a GXP Viewer.

        This method automatically persists to the database!
        """

        template_name = hookset.update_from_viewer(conf, context=context)
        conf = context['config']

        self.title = conf['about']['title']
        self.abstract = conf['about']['abstract']

        center = conf['map']['center'] if 'center' in conf['map'] else settings.DEFAULT_MAP_CENTER
        zoom = conf['map']['zoom'] if 'zoom' in conf['map'] else settings.DEFAULT_MAP_ZOOM
        center_x = center['x'] if isinstance(center, dict) else center[0]
        center_y = center['y'] if isinstance(center, dict) else center[1]
        self.set_bounds_from_center_and_zoom(
            center_x,
            center_y,
            zoom)

        self.projection = conf['map']['projection']

        if self.uuid is None or self.uuid == '':
            self.uuid = str(uuid.uuid1())

        def source_for(layer):
            try:
                return conf["sources"][layer["source"]]
            except BaseException:
                if 'url' in layer:
                    return {'url': layer['url']}
                else:
                    return {}

        layers = [l for l in conf["map"]["layers"]]
        layer_names = set([l.alternate for l in self.local_layers])

        for layer in self.layer_set.all():
            layer.delete()

        self.keywords.add(*conf['map'].get('keywords', []))

        for ordering, layer in enumerate(layers):
            self.layer_set.add(
                layer_from_viewer_config(
                    self.id, MapLayer, layer, source_for(layer), ordering
                ))

        self.save()

        if layer_names != set([l.alternate for l in self.local_layers]):
            map_changed_signal.send_robust(sender=self, what_changed='layers')

        return template_name
Пример #4
0
    def update_from_viewer(self, conf, context=None):
        """
        Update this Map's details by parsing a JSON object as produced by
        a GXP Viewer.

        This method automatically persists to the database!
        """

        template_name = hookset.update_from_viewer(conf, context=context)

        conf = context['config']
        self.title = conf['about']['title']
        self.abstract = conf['about']['abstract']

        self.set_bounds_from_center_and_zoom(
            conf['map']['center'][0],
            conf['map']['center'][1],
            conf['map']['zoom'])

        self.projection = conf['map']['projection']

        if self.uuid is None or self.uuid == '':
            self.uuid = str(uuid.uuid1())

        def source_for(layer):
            return conf["sources"][layer["source"]]

        layers = [l for l in conf["map"]["layers"]]
        layer_names = set([l.alternate for l in self.local_layers])

        for layer in self.layer_set.all():
            layer.delete()

        self.keywords.add(*conf['map'].get('keywords', []))

        for ordering, layer in enumerate(layers):
            self.layer_set.add(
                layer_from_viewer_config(
                    self.id, MapLayer, layer, source_for(layer), ordering
                ))

        self.save()

        if layer_names != set([l.alternate for l in self.local_layers]):
            map_changed_signal.send_robust(sender=self, what_changed='layers')

        return template_name
Пример #5
0
    def update_from_viewer(self, conf):
        """
        Update this Map's details by parsing a JSON object as produced by
        a GXP Viewer.

        This method automatically persists to the database!
        """
        if isinstance(conf, basestring):
            conf = json.loads(conf)

        self.title = conf['about']['title']
        self.abstract = conf['about']['abstract']

        self.zoom = conf['map']['zoom']

        self.center_x = conf['map']['center'][0]
        self.center_y = conf['map']['center'][1]

        self.projection = conf['map']['projection']

        if self.uuid is None or self.uuid == '':
            self.uuid = str(uuid.uuid1())

        def source_for(layer):
            return conf["sources"][layer["source"]]

        layers = [l for l in conf["map"]["layers"]]
        layer_names = set([l.typename for l in self.local_layers])

        for layer in self.layer_set.all():
            layer.delete()

        self.keywords.add(*conf['map'].get('keywords', []))

        for ordering, layer in enumerate(layers):
            self.layer_set.add(
                layer_from_viewer_config(
                    MapLayer, layer, source_for(layer), ordering
            ))

        self.set_bounds_from_layers(self.local_layers)

        self.save()

        if layer_names != set([l.typename for l in self.local_layers]):
            map_changed_signal.send_robust(sender=self,what_changed='layers')
Пример #6
0
    def update_from_viewer(self, conf):
        """
        Update this Map's details by parsing a JSON object as produced by
        a GXP Viewer.

        This method automatically persists to the database!
        """
        if isinstance(conf, basestring):
            conf = json.loads(conf)

        self.title = conf['about']['title']
        self.abstract = conf['about']['abstract']

        self.zoom = conf['map']['zoom']

        self.center_x = conf['map']['center'][0]
        self.center_y = conf['map']['center'][1]

        self.projection = conf['map']['projection']

        if self.uuid is None or self.uuid == '':
            self.uuid = str(uuid.uuid1())

        def source_for(layer):
            return conf["sources"][layer["source"]]

        layers = [l for l in conf["map"]["layers"]]
        layer_names = set([l.typename for l in self.local_layers])

        for layer in self.layer_set.all():
            layer.delete()

        self.keywords.add(*conf['map'].get('keywords', []))

        for ordering, layer in enumerate(layers):
            self.layer_set.add(
                layer_from_viewer_config(
                    MapLayer, layer, source_for(layer), ordering
            ))

        self.set_bounds_from_layers(self.local_layers)

        self.save()

        if layer_names != set([l.typename for l in self.local_layers]):
            map_changed_signal.send_robust(sender=self,what_changed='layers')
Пример #7
0
    def update_from_viewer(self, conf, context=None):
        """
        Update this Map's details by parsing a JSON object as produced by
        a GXP Viewer.

        This method automatically persists to the database!
        """

        template_name = hookset.update_from_viewer(conf, context=context)

        conf = context['config']
        self.title = conf['about']['title']
        self.abstract = conf['about']['abstract']

        self.set_bounds_from_center_and_zoom(conf['map']['center'][0],
                                             conf['map']['center'][1],
                                             conf['map']['zoom'])

        self.projection = conf['map']['projection']

        if self.uuid is None or self.uuid == '':
            self.uuid = str(uuid.uuid1())

        def source_for(layer):
            return conf["sources"][layer["source"]]

        layers = [l for l in conf["map"]["layers"]]
        layer_names = set([l.alternate for l in self.local_layers])

        for layer in self.layer_set.all():
            layer.delete()

        self.keywords.add(*conf['map'].get('keywords', []))

        for ordering, layer in enumerate(layers):
            self.layer_set.add(
                layer_from_viewer_config(self.id, MapLayer, layer,
                                         source_for(layer), ordering))

        self.save()

        if layer_names != set([l.alternate for l in self.local_layers]):
            map_changed_signal.send_robust(sender=self, what_changed='layers')

        return template_name
Пример #8
0
 def _post_change_routines(self, instance: Map,
                           create_action_perfomed: bool,
                           additional_data: dict):
     # Step 1: Handle Maplayers signals if this is and update action
     if not create_action_perfomed:
         dataset_names_before_changes = additional_data.pop(
             "dataset_names_before_changes", [])
         dataset_names_after_changes = [
             lyr.alternate for lyr in instance.datasets
         ]
         if dataset_names_before_changes != dataset_names_after_changes:
             map_changed_signal.send_robust(sender=instance,
                                            what_changed="datasets")
     # Step 2: Register Event
     event_type = EventType.EVENT_CREATE if create_action_perfomed else EventType.EVENT_CHANGE
     register_event(self.request, event_type, instance)
     # Step 3: Resource Manager
     resource_manager.update(instance.uuid, instance=instance, notify=True)
Пример #9
0
    def update_from_viewer(self, conf, context=None):
        """
        Update this Map's details by parsing a JSON object as produced by
        a GXP Viewer.

        This method automatically persists to the database!
        """

        template_name = hookset.update_from_viewer(conf, context=context)
        if not isinstance(context, dict):
            try:
                context = json.loads(ensure_string(context))
            except Exception:
                pass

        conf = context.get("config", {})
        if not isinstance(conf, dict) or isinstance(conf, bytes):
            try:
                conf = json.loads(ensure_string(conf))
            except Exception:
                conf = {}

        about = conf.get("about", {})
        self.title = conf.get("title", about.get("title", ""))
        self.abstract = conf.get("abstract", about.get("abstract", ""))

        _map = conf.get("map", {})
        center = _map.get("center", settings.DEFAULT_MAP_CENTER)
        self.zoom = _map.get("zoom", settings.DEFAULT_MAP_ZOOM)

        if isinstance(center, dict):
            self.center_x = center.get('x')
            self.center_y = center.get('y')
        else:
            self.center_x, self.center_y = center

        projection = _map.get("projection", settings.DEFAULT_MAP_CRS)
        bbox = _map.get("bbox", None)

        if bbox:
            self.set_bounds_from_bbox(bbox, projection)
        else:
            self.set_bounds_from_center_and_zoom(
                self.center_x,
                self.center_y,
                self.zoom)

        if self.projection is None or self.projection == '':
            self.projection = projection

        if self.uuid is None or self.uuid == '':
            self.uuid = str(uuid.uuid1())

        def source_for(layer):
            try:
                return conf["sources"][layer["source"]]
            except Exception:
                if 'url' in layer:
                    return {'url': layer['url']}
                else:
                    return {}

        layers = [lyr for lyr in _map.get("layers", [])]
        layer_names = set(lyr.alternate for lyr in self.local_layers)

        self.layer_set.all().delete()
        self.keywords.add(*_map.get('keywords', []))

        for ordering, layer in enumerate(layers):
            self.layer_set.add(
                layer_from_viewer_config(
                    self.id, MapLayer, layer, source_for(layer), ordering
                ))

        self.save(notify=True)

        if layer_names != set(lyr.alternate for lyr in self.local_layers):
            map_changed_signal.send_robust(sender=self, what_changed='layers')

        return template_name
Пример #10
0
    def update_from_viewer(self, conf):
        """
        Update this Map's details by parsing a JSON object as produced by
        a GXP Viewer.

        This method automatically persists to the database!
        """
        if isinstance(conf, basestring):
            conf = json.loads(conf)

        self.title = conf['about']['title']
        self.abstract = conf['about']['abstract']
        self.viewer_playbackmode = conf['viewer_playbackmode'] or 'Instant'

        self.set_bounds_from_center_and_zoom(conf['map']['center'][0],
                                             conf['map']['center'][1],
                                             conf['map']['zoom'])

        self.projection = conf['map']['projection']

        if self.uuid is None or self.uuid == '':
            self.uuid = str(uuid.uuid1())

        def source_for(layer):

            if 'sources' in conf:
                return conf["sources"][layer["source"]]
            else:
                # TODO: This is a work in progress will refactor
                # Handle special case for OL3 config model in storytools as source and sources may not available

                if layer['type'] == 'WMS':
                    return {
                        "restUrl": "/gs/rest",
                        "title": "",
                        "baseParams": {
                            "VERSION": "1.1.1",
                            "REQUEST": "GetCapabilities",
                            "TILED": 'true',
                            "SERVICE": "WMS"
                        },
                        "ptype": "gxp_wmscsource",
                        "id": "local"
                    }
                else:
                    return layer["source"]

        layers = [l for l in conf["map"]["layers"]]
        layer_names = set([l.alternate for l in self.local_layers])

        for layer in self.layer_set.all():
            layer.delete()

        self.keywords.add(*conf['map'].get('keywords', []))

        for ordering, layer in enumerate(layers):
            self.layer_set.add(
                layer_from_viewer_config(MapLayer, layer, source_for(layer),
                                         ordering))

        self.chapter_index = conf['chapter_index']
        story_id = conf.get('story_id', 0)
        story_obj = MapStory.objects.get(id=story_id)
        self.story = story_obj
        self.save()

        if layer_names != set([l.alternate for l in self.local_layers]):
            map_changed_signal.send_robust(sender=self, what_changed='layers')
Пример #11
0
    def update_from_viewer(self, conf, context=None):
        """
        Update this Map's details by parsing a JSON object as produced by
        a GXP Viewer.

        This method automatically persists to the database!
        """

        template_name = hookset.update_from_viewer(conf, context=context)
        if not isinstance(context, dict):
            try:
                context = json.loads(ensure_string(context))
            except Exception:
                pass

        conf = context.get("config", {})
        if not isinstance(conf, dict) or isinstance(conf, bytes):
            try:
                conf = json.loads(ensure_string(conf))
            except Exception:
                conf = {}

        about = conf.get("about", {})
        self.title = conf.get("title", about.get("title", ""))
        self.abstract = conf.get("abstract", about.get("abstract", ""))

        _map = conf.get("map", {})
        center = _map.get("center", settings.DEFAULT_MAP_CENTER)
        self.zoom = _map.get("zoom", settings.DEFAULT_MAP_ZOOM)

        if isinstance(center, dict):
            self.center_x = center.get("x")
            self.center_y = center.get("y")
        else:
            self.center_x, self.center_y = center

        projection = _map.get("projection", settings.DEFAULT_MAP_CRS)
        bbox = _map.get("bbox", None)

        if bbox:
            self.set_bounds_from_bbox(bbox, projection)
        else:
            self.set_bounds_from_center_and_zoom(self.center_x, self.center_y, self.zoom)

        if self.projection is None or self.projection == "":
            self.projection = projection

        if self.uuid is None or self.uuid == "":
            self.uuid = str(uuid.uuid1())

        def source_for(layer):
            try:
                return conf["sources"][layer["source"]]
            except Exception:
                if "url" in layer:
                    return {"url": layer["url"]}
                else:
                    return {}

        layers = [lyr for lyr in _map.get("layers", [])]
        dataset_names = {lyr.alternate for lyr in self.local_datasets}

        self.dataset_set.all().delete()
        self.keywords.add(*_map.get("keywords", []))

        for ordering, layer in enumerate(layers):
            self.dataset_set.add(dataset_from_viewer_config(self.id, MapLayer, layer, source_for(layer), ordering))

        from geonode.resource.manager import resource_manager

        resource_manager.update(self.uuid, instance=self, notify=True)
        resource_manager.set_thumbnail(self.uuid, instance=self, overwrite=False)

        if dataset_names != {lyr.alternate for lyr in self.local_datasets}:
            map_changed_signal.send_robust(sender=self, what_changed="datasets")

        return template_name