Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/1526 measurer select feature #1532

Merged
merged 9 commits into from
Jul 2, 2024

Conversation

OlofSvahnVbg
Copy link
Collaborator

closes #1526

@OlofSvahnVbg OlofSvahnVbg added the new feature Request for adding/changing functionality label Jun 25, 2024
@OlofSvahnVbg OlofSvahnVbg added this to the 3.x milestone Jun 25, 2024
@OlofSvahnVbg OlofSvahnVbg self-assigned this Jun 25, 2024
Copy link
Member

@jacobwod jacobwod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks fine and I was about to approve. However, a quick test (compared with Sketch) reveals that the SelectFeaturesDialog does not show the highlight, as Sketch does, making it difficult to see which feature actually gets selected.

Please see the attached video.

Skarminspelning.2024-06-26.kl.10.57.50.mov

@OlofSvahnVbg
Copy link
Collaborator Author

Thanks for the video, will check this

@OlofSvahnVbg
Copy link
Collaborator Author

OlofSvahnVbg commented Jun 26, 2024

So a few things: SketchModel has this function:

createHighlightFeature = (feature) => {
    // If no feature (or a feature with no get-geometry) is supplied, we abort.
    if (feature && feature.getGeometry()) {
      // Otherwise we create a new feature...
      const highlightFeature = new Feature({
        geometry: feature.getGeometry().clone(),
      });
      // ...set an id and a highlight-style...
      highlightFeature.setId(this.generateRandomString());
      highlightFeature.setStyle(this.#createHighlightStyle());
      // Finally we return the feature so that we can add it to the map etc.
      return highlightFeature;
    }
  };

This is being used via a model passed down to SelectFeaturesDialog in Sketch.

The problem is that Measurer doesnt have a model. Should we use Sketchmodel in measurer as model to acces this function or what is best practice here?

@Hallbergs
Copy link
Member

So a few things: SketchModel has this function:

createHighlightFeature = (feature) => {
    // If no feature (or a feature with no get-geometry) is supplied, we abort.
    if (feature && feature.getGeometry()) {
      // Otherwise we create a new feature...
      const highlightFeature = new Feature({
        geometry: feature.getGeometry().clone(),
      });
      // ...set an id and a highlight-style...
      highlightFeature.setId(this.generateRandomString());
      highlightFeature.setStyle(this.#createHighlightStyle());
      // Finally we return the feature so that we can add it to the map etc.
      return highlightFeature;
    }
  };

This is being used via a model passed down to SelectFeaturesDialog in Sketch.

The problem is that Measurer doesnt have a model. Should we use Sketchmodel in measurer as model to acces this function or what is best practice here?

Maybe the function can be moved to a core model such as the DrawModel? We shouldn't share (plugin-)models between plugins (since measurer can be activated while sketch is not).

@OlofSvahnVbg
Copy link
Collaborator Author

So a few things: SketchModel has this function:

createHighlightFeature = (feature) => {
    // If no feature (or a feature with no get-geometry) is supplied, we abort.
    if (feature && feature.getGeometry()) {
      // Otherwise we create a new feature...
      const highlightFeature = new Feature({
        geometry: feature.getGeometry().clone(),
      });
      // ...set an id and a highlight-style...
      highlightFeature.setId(this.generateRandomString());
      highlightFeature.setStyle(this.#createHighlightStyle());
      // Finally we return the feature so that we can add it to the map etc.
      return highlightFeature;
    }
  };

This is being used via a model passed down to SelectFeaturesDialog in Sketch.
The problem is that Measurer doesnt have a model. Should we use Sketchmodel in measurer as model to acces this function or what is best practice here?

Maybe the function can be moved to a core model such as the DrawModel? We shouldn't share (plugin-)models between plugins (since measurer can be activated while sketch is not).

Sure. That makes sense

@OlofSvahnVbg
Copy link
Collaborator Author

OlofSvahnVbg commented Jun 26, 2024

So in DrawModel, we have this prop:

  #publishInformation = ({ subject, payLoad }) => {
    // We utilize the fact that this method runs on important changes, such
    // as feature add/remove. We check if there are any features in the draw
    // layer and save that information in the Public API. This is later
    // read in a handler for "onbeforeunload". See #1403.
    if (this.getAllDrawnFeatures().length > 0) {
      window.hajkPublicApi.dirtyLayers[this.#layerName] = true;
    } else {
      delete window.hajkPublicApi.dirtyLayers[this.#layerName];
    }

    // If no observer has been set-up, or if the subject is missing, we abort
    if (!this.#observer || !subject) {
      return;
    }
    // Otherwise we create the prefixed-subject to send. (The drawModel might have
    // been initiated with a prefix that should be added on all subjects).
    const prefixedSubject = this.#observerPrefix
      ? `${this.#observerPrefix}.${subject}`
      : subject;
    // Then we publish the event!
    this.#observer.publish(prefixedSubject, payLoad);
  };

Why do we need the prefixedSubject?

@Hallbergs
Copy link
Member

So in DrawModel, we have this prop:

  #publishInformation = ({ subject, payLoad }) => {
    // We utilize the fact that this method runs on important changes, such
    // as feature add/remove. We check if there are any features in the draw
    // layer and save that information in the Public API. This is later
    // read in a handler for "onbeforeunload". See #1403.
    if (this.getAllDrawnFeatures().length > 0) {
      window.hajkPublicApi.dirtyLayers[this.#layerName] = true;
    } else {
      delete window.hajkPublicApi.dirtyLayers[this.#layerName];
    }

    // If no observer has been set-up, or if the subject is missing, we abort
    if (!this.#observer || !subject) {
      return;
    }
    // Otherwise we create the prefixed-subject to send. (The drawModel might have
    // been initiated with a prefix that should be added on all subjects).
    const prefixedSubject = this.#observerPrefix
      ? `${this.#observerPrefix}.${subject}`
      : subject;
    // Then we publish the event!
    this.#observer.publish(prefixedSubject, payLoad);
  };

Why do we need the prefixedSubject?

If i remember correctly, we use the prefix so that plugins etc. that uses the DrawModel can catch "their" events. For example: the measure plugin might initiate a DrawModel with "measure-draw-model".

jacobwod
jacobwod previously approved these changes Jul 1, 2024
Copy link
Member

@jacobwod jacobwod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work rather nice now. You have one tiny warning to fix, then it's ready to merge. Feel free to add a CHANGELOG row about it too!

[eslint] 
src/plugins/Sketch/models/SketchModel.js
  Line 3:32:  'Style' is defined but never used  no-unused-vars

@OlofSvahnVbg
Copy link
Collaborator Author

Fixed warning and added to changelog

@OlofSvahnVbg OlofSvahnVbg merged commit d9db61d into develop Jul 2, 2024
@OlofSvahnVbg OlofSvahnVbg deleted the feature/1526-measurer-select-feature branch July 2, 2024 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature Request for adding/changing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants