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

How to change selected feature #345

Closed
mrAbra opened this issue May 8, 2024 · 4 comments
Closed

How to change selected feature #345

mrAbra opened this issue May 8, 2024 · 4 comments
Labels
question Further information is requested

Comments

@mrAbra
Copy link

mrAbra commented May 8, 2024

thats my map

<ol-map style="height: 400px">
      <ol-view ref="view" :center="center" :rotation="rotation" :zoom="zoom" :projection="projection"
        @change:center="centerChanged" @change:resolution="resolutionChanged" @change:rotation="rotationChanged" />
      <ol-tile-layer>
        <ol-source-osm />
      </ol-tile-layer>
      <ol-interaction-select @select="featureSelected" :pointRadius="20">
      </ol-interaction-select>
      <ol-animated-clusterlayer :animationDuration="500" :distance="40" ref="customInteraction">
        <ol-source-vector :features="geoJsonFeatures" :format="geoJson">
        </ol-source-vector>
      </ol-animated-clusterlayer >
    </ol-map>

thats my table for showing features.

<el-table :data="geoJsonFeatures" highlight-current-row 
@current-change="handleCurrentChange" style="width: 100%" :row-class-name="setDeviceStatusInTable">
<el-table-column type="expand">
....
async function handleCurrentChange(val) {
  if (val == null) {
    return;
  }
  selectedFeature.value = val;
}

I dont understand how to change selected feature from handleCurrentChange.
I will be glad to any advice

@mrAbra
Copy link
Author

mrAbra commented May 8, 2024

selectedFeature.value im using this for another element but wiil be realy cool if i can do smth like this mapreference.interactionSelect.removeSelectedFeature():
mapreference.interactionSelect.addSelectedFeature(selectedFeature.value );

@d-koppenhagen
Copy link
Collaborator

d-koppenhagen commented May 8, 2024

Please take the time and provide a formatted code example which makes it easy to follow and investigate.

@mrAbra
Copy link
Author

mrAbra commented May 13, 2024

  <ol-interaction-select @select="featureSelected" :pointRadius="20" ref="customInteraction">
    <!-- style of the marked selected from the cluster items after first click on the cluster itself -->
    <ol-style>
      <ol-style-circle :radius="20">
        <ol-style-fill color="#ff0000"></ol-style-fill>
      </ol-style-circle>
    </ol-style>
  </ol-interaction-select>
  <ol-animated-clusterlayer :animationDuration="500" :distance="40" ref="clusterLayer">
    <ol-source-vector :features="geoJsonFeatures" :format="geoJson" ref="vectorLayer">
    </ol-source-vector>
  </ol-animated-clusterlayer>
....
      <el-table  ref="tableRef" :data="geoJsonFeatures" highlight-current-row @current-change="handleCurrentChange" style="width: 100%"
        :row-class-name="setDeviceStatusInTable">
....
    const providerFeatureCollection = {
      type: "FeatureCollection",
      features: newFeatures,
    };

    geoJsonFeatures.value = geoJson.readFeatures(providerFeatureCollection);

...
async function handleCurrentChange(val) {
  if (val == null) {
    return;
  }
  selectedFeature.value = val;
  const selectedStyle = new Style({
    image: new Icon({
      src: workerIcon,
      anchor: [0.5, 1],
      width: 30,
      height: 30
    })
  });

  customInteraction.value.select.getFeatures().clear()
  customInteraction.value.select.getFeatures().push(vectorLayer.value.layer.features.find((f) => {
    return f.getProperties().features[0].values_.devaddr === val.values_.devaddr;
  }));
  customInteraction.value.select.getFeatures().forEach(function (feature) {
    feature.setStyle(selectedStyle);
  })
}

working for me, May be someone can find better solution with easier properties access. For me was not obvious that geoJsonFeatures not equal select event collection elements

@d-koppenhagen
Copy link
Collaborator

okay, I will close this issues since you could solve your problem I think

@d-koppenhagen d-koppenhagen added the question Further information is requested label Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants