使用 Vue JS 3,我试图在 OpenLayers 地图上选择从两个 json 文件显示的一个点或一条线(分别包含所有点和所有线)。 基本上,我正在尝试复制 Vue3 OpenLayers 示例代码.
而在 OpenLayers 示例中,用户可以通过移动鼠标选择显示的一部分要素(一个多边形或一个点),而我的指针在移动时选择所有要素(所有线或所有点)。
我的模板定义如下:
<template>
<ol-map :loadTilesWhileAnimating="true" :loadTilesWhileInteracting="true" style="height:400px" :key="map">
<ol-view ref="view" :center="center" :rotation="rotation" :zoom="zoom" :projection="projection"
@zoomChanged="zoomChanged" @centerChanged="centerChanged" @resolutionChanged="resolutionChanged"
@rotationChanged="rotationChanged" />
<ol-zoom-control />
<ol-scaleline-control />
<ol-tile-layer>
<ol-source-osm />
</ol-tile-layer>
<ol-interaction-select @select="featureSelected" :condition="selectCondition">
<ol-style>
(…)
</ol-style>
</ol-interaction-select>
<ol-vector-layer>
<ol-source-vector :format="geoJson" :projection="projection">
<!-- Affichage des arrêts et mouvements -->
<div v-else>
<!-- afficher l'ensemble des mouvements -->
<ol-feature>
<ol-geom-multi-line-string :coordinates="mouvementCoordinates"></ol-geom-multi-line-string>
<ol-style>
(…) </ol-style>
</ol-feature>
<!-- afficher l'ensemble des arrêts -->
<ol-feature>
<ol-geom-multi-point :coordinates="arretCoordinates"></ol-geom-multi-point>
<ol-style>
(…)
</ol-style>
</ol-feature>
</div>
</ol-source-vector>
</ol-vector-layer>
</ol-map>
</template>
收到的道具(geoJsonArretList,geoJsonMouvementList)是类型:
{
type : "FeatureCollection",
features: Array(60)
0: {type: "Feature", geometry:{...}, properties: {...}}
1: ...
}
发送到模板的信息(arretCoordinates,mouvementCoordinates)构建如下:
arretCoordinates() {
return this.geoJsonArretList.features.map(feature => feature.geometry.coordinates);
},
mouvementCoordinates() {
return this.geoJsonMouvementList.features.map(feature => feature.geometry.coordinates);
},
除了用指针移动一行或一点进行选择外,我想用 console.log 只显示其中的一些属性。
我尝试使用和不使用 OpenLayers 示例中的 selectInteractionFilter,以适应我的道具。我还尝试删除两个 ol 特征之一,例如,没有所有多线只保留多点。