2015-09-24 13 views
6

Io sto cercando di fare la regola styling con sede a OpenLayers 3, qui è il mio codice:Regola in OpenLayers 3

<!DOCTYPE html> 
<html> 
<head> 
<title>CONFIG</title> 


<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script> 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> 
<link rel="stylesheet" href="http://openlayers.org/en/v3.8.2/css/ol.css" type="text/css"> 
<script src="http://openlayers.org/en/v3.8.2/build/ol.js"></script> 

</head> 
<body> 
<div class="container-fluid"> 

<div class="row-fluid"> 
    <div class="span12"> 
    <div id="map" class="map"></div> 
    </div> 
</div> 
<script> 

    var layerStyle = { 
     default: { 
     style: new ol.style.Style({ 
     stroke: new ol.style.Stroke({ 
     color: 'rgba(0, 0, 0, 1.0)', 
     width: 0.5 
      }), 
     fill: new ol.style.Fill({ 
     color: 'rgba(0, 255, 0, 0.5)' 
      }) 
      }) 
     }, 

     filter: [{ 
     type: "AND", 
     rules: [{ 
      type: "==", 
      property: "CODE", 
      value: "16" 
     }, { 
      type: "==", 
      property: "NAME", 
      value: "CHIKMAGALUR" 
     }], 
     symbolizers: { 
     style: new ol.style.Style({ 
     stroke: new ol.style.Stroke({ 
       color: 'rgba(0, 255, 0, 0.5)', 
       width: 0.5 
      }), 
     fill: new ol.style.Fill({ 
       color: 'red' 
      }) 
      }) 
     } 
    } ] 
    }; 

    var geojson_layer = new ol.layer.Vector({ 
    source: new ol.source.Vector({ 
     url: 'file.geojson', 
     format: new ol.format.GeoJSON() 
    }), 
}); 
var vectorLayer = new ol.source.Vector({ 
     features: (new ol.format.GeoJSON()).readFeatures(geojsonObject) 
    }); 

     if ('CODE'=='16' && 'NAME'=='CHIKMAGALUR') { 
     style: symbolizers; 
     } 




     var map = new ol.Map({ 
    layers: [ 
    new ol.layer.Tile({ 
     source: new ol.source.OSM() 
    }), 
    vectorLayer, 
    ], 
    target: 'map', 
    controls: ol.control.defaults({ 
    attributionOptions: /** @type {olx.control.AttributionOptions} */ ({ 
     collapsible: false 
    }) 
    }), 
    view: new ol.View({ 
    center: [0, 0], 
    zoom: 5 
    }) 
}); 

</script> 
</body> 
</html> 

sto cercando cercando di ottenere lo stile dal symbolizer, ma io sono sempre l'errore . Come openlayer2 ho usato i filtri per l'operazione AND, ma mi sono bloccato. Qualcuno può aiutarmi su questo ??

+0

Add ** ** OpenLayers tag (per OL 2) alla tua domanda per vedere se Openlayers 2 ragazzi possono aiutare a trovare il equivalente su Openlayers 3. Inoltre, leggi la documentazione dell'API, riceverai sempre un errore se stai provando una proprietà che non è presente sull'API. –

risposta

2

In OL3 i livelli vettoriali hanno un attributo di stile che può essere un oggetto Style, una matrice di oggetti Style o una funzione che restituisce un oggetto Style o una matrice di oggetti Style. Probabilmente vuoi usare una funzione di stile per quello che stai cercando di fare.

Vedere il seguente esempio di come questo può essere fatto:

http://openlayers.org/en/v3.20.1/examples/earthquake-clusters.html

+0

Grazie Bob Holmes, non posso applicare un filtro in ol3 ?? – Rajan

+2

Non esattamente, almeno non c'è niente con quel nome. Tuttavia, puoi implementare il filtro nella tua funzione di styling, restituendo un oggetto stile per tutte le funzionalità che dovrebbero essere visualizzate e restituendo "null" per tutte le funzionalità che dovrebbero essere filtrate. – Dirk