How to set a layer to be unselectable

36 views
Skip to first unread message

Jacob Fullerton

unread,
Jun 23, 2016, 2:17:07 PM6/23/16
to Tethys Platform
In my app I am generating a water table raster map from scratch. As the app is currently configured the layer that is generated by my javascript is being loaded correctly and displays perfectly in the map and in the legend. The struggle I'm having is with how to set the layer as unselectable to the user. I don't want the user to be able to modify the generated layer at all. They should be able to modify the objects that they draw using the drawing tools, but for instance they should not be allowed to move bits of the raster to new locations.

Is there an attribute that I can give my layer so that the tethys drawing tools such as 'Modify' or 'Move' do not have access to the water table raster I'm generating? Thanks!

Jacob Fullerton

unread,
Jun 23, 2016, 3:39:27 PM6/23/16
to Tethys Platform
So I was poking around in the Tethys_map_view.js function and found this code:

// Trigger a drag feature
  DragFeatureInteraction.prototype.handleDownEvent = function(event) {
    var map = event.map;

    var feature = map.forEachFeatureAtPixel(event.pixel,
        function(feature, layer) {
          return feature;
        });

    if (feature) {
      this.coordinate_ = event.coordinate;
      this.feature_ = feature;
    }

    return !!feature;
  };
  
  // Handle drag feature
  DragFeatureInteraction.prototype.handleDragEvent = function(event) {
    var map = event.map;

    var feature = map.forEachFeatureAtPixel(event.pixel, function(feature, layer) {
      return feature;
    });

    var deltaX = event.coordinate[0] - this.coordinate_[0];
    var deltaY = event.coordinate[1] - this.coordinate_[1];

    var geometry = /** @type {ol.geom.SimpleGeometry} */
        (this.feature_.getGeometry());
    geometry.translate(deltaX, deltaY);

    this.coordinate_[0] = event.coordinate[0];
    this.coordinate_[1] = event.coordinate[1];
  };

  // Handle map movement
  DragFeatureInteraction.prototype.handleMoveEvent = function(event) {
    if (this.cursor_) {
      var map = event.map;
      var feature = map.forEachFeatureAtPixel(event.pixel,
          function(feature, layer) {
            return feature;
          });
      var element = event.map.getTargetElement();
      if (feature) {
        if (element.style.cursor != this.cursor_) {
          this.previousCursor_ = element.style.cursor;
          element.style.cursor = this.cursor_;
        }
      } else if (this.previousCursor_ !== undefined) {
        element.style.cursor = this.previousCursor_;
        this.previousCursor_ = undefined;
      }
    }
  };

  // Un-trigger drag feature
  DragFeatureInteraction.prototype.handleUpEvent = function(event) {
    this.coordinate_ = null;
    this.feature_ = null;
    return false;
  };

This means that there is no current attribute I can give my features that will make them unselectable. Is there a nice way that we could add this to the platform? If not, I still would like a way to restrict the user from editing a layer
Reply all
Reply to author
Forward
0 new messages