Attualmente sto cercando una soluzione per selezionare (o evidenziare) un vettore in un OpenLayers.Layer.Vector.Come selezionare una funzione a livello di codice su un livello vettoriale in OpenLayers?
Ho creato una griglia semplice in cui un utente può selezionare un vettore (dato come stringa formattata WKT) che dovrebbe evidenziare il vettore corrispondente sul livello. Tutti i vettori nella griglia sono disegnati sul livello vettoriale sulla mappa quando l'utente visita il sito.
ho scoperto che ho neanche bisogno di 's selectFeature(feature) funzione o l'OpenLayers.Control.SelectFeature il OpenLayers.Control.ModifyFeature (vedi dev.openlayers.org/apidocs/files/OpenLayers/Control/SelectFeature-js.html's selezionare la funzione (funzione) (che probabilmente non esiste o non esiste più?). Vedere un post da una Mailinglist: osgeo-org.1803224.n2.nabble.com/Programatically-Select-a-Feature-tt2192485.html#a2193928 per ulteriori informazioni.
ho provato la seguente senza successo, quindi spero che qualcuno potesse afferrare queste righe di codice e mi potrebbe mostrare un frammento di codice di lavoro ;-)
// ... some initializing code
this.vlayer = new OpenLayers.Layer.Vector("VectorLayer"); // VectorLayer
// some controls
this.openLayerControlPoint = new OpenLayers.Control.DrawFeature(this.vlayer, OpenLayers.Handler.Point);
this.openLayerControlPolygon = new OpenLayers.Control.DrawFeature(this.vlayer, OpenLayers.Handler.Polygon);
this.openLayerControlModify = new OpenLayers.Control.ModifyFeature(this.vlayer, {
mode: OpenLayers.Control.ModifyFeature.RESHAPE | OpenLayers.Control.ModifyFeature.DRAG,
standalone: false
});
// just deactivate to make sure everything is really deactivated
this.openLayerControlPoint.deactivate();
this.openLayerControlPolygon.deactivate();
this.openLayerControlModify.deactivate();
// add the just created layer to the map
this.map.addLayer(this.vlayer);
// add all (deactivated) controls to the map
this.map.addControl(this.openLayerControlPoint);
this.map.addControl(this.openLayerControlPolygon);
this.map.addControl(this.openLayerControlModify);
Più avanti nel codice:
// ... another function doing the action
selectVector: function(wktVector) {
this.openLayerControlModify.activate();
// this is no elegant solution, this should only show how I would
// test the functionallity.
for (var i = 0; i < this.vlayer.features.length; ++i) {
// returns a WKT formatted string:
// 'POLYGON((xxxx.xxx xxxx.xxx), (xxxx.xxx xxxx.xxx))'
var wktVectorCurrent = this.vlayer.features[i].geometry.toString();
if (wktVector == wktVectorCurrent) {
// \/ doesn't work :-(
this.openLayerControlModify.selectFeature(this.vlayer.features[i]);
break;
}
}
}
Grazie per la risposta questo ha funzionato per me! Ho scoperto che il documento API OpenLayers nella versione corrente è danneggiato (e non c'era un metodo 'select'). Funziona [collegamento all'API OpenLayers] (http://dev.openlayers.org/docs/files/OpenLayers/Control/SelectFeature-js.html#OpenLayers.Control.SelectFeature.select) –
anche il mio consiglio per il futuro guarda il codice sorgente degli openlayers invece dei documenti. è facile trovare quello che ti serve e avrai una migliore comprensione di come funzionano le cose. troverai spesso preziosi commenti nel codice sorgente che non vedrai nei documenti. – igorti
nota che dovrai aggiungere il controllo "selectFeature" alla mappa prima che tu possa chiamare attivare su di esso. map.addControl (selectFeature); – JSancho