javascript - <OpenLayers3> Make choropleth map with GeoJson -


After the

I try to create a choropleth that OpenLayers3 and a map < Strong> GeoJSON generated in javascript .

I want to use the properties of my GeoJSON to make this map look-up.

For example, if I have a city with property, then ["name" = '1'] and a city with property ["name" = '2' ] I have to have blue for red color for '1' and '2'.

How do I create this map with Open Layers 2 (with Corpath map OL2] [1]) found on the Internet But I do not find equality in the OL3 code with the I OL2 looks like this:

  var subteStyleMap = new OpenLayer.Style Map ({'Strokewidth': 4}); see above = {"1": {strokeColor: "# 46C7FA"}, "2": {strokeColor: "# E81D1A"}} subteStyleMap.addUniqueValueRules ("default", "number ", See); on geojson_layer = new OpenLayers.Layer.Vector (" GeoJSON ", {projection: New OpenLayers.Projection ( "EPSG: 4326"), Strategies: [New OpenLayers.Strategy.Fixed ()], Protocol: New OpenLayers.Protocol.HTTP ({Url: "generation_geojson2.php", format: New OpenLayer.format.GJSON ()}) , Styledmap: subteStyleMap});  

I started optimization, but I can not find the equivalence for 'addUniqueValueRules'

  see above = {" 1 ": {strokeColor:" # 46C7FA "}," 2 ": {stroke color:" # E81D1A "}} subteStyleMap.addUniqueValueRules (" default "," number ", lookup); Var vector_arret_tad = new ol.layer.Vector ({source: new ol.source.GeoJSON ({url: 'generation_geojson2.php', default projection: 'EPSG: 4326', projection: 'EPSG: 3857'}), name: 'City', style: subteStyleMap});  

What is the OL3 equivalent of this code, or another solution for this problem?

You have to use a style function. A style function is a task that takes a feature as a logic and gives an array of style objects.

In your case, it will look like this:

 see  view = {"1" [new ol.style. Style ({stroke: new ol.style.Stroke ({color: "# 46C7FA"}}), "2": [new ol.style.Style ({stroke: new ol.style.Stroke ({color: "# E81D1A"})}))}; Var vectorLayer = New ol.layer.Vector ({// ... Style: Function (Feature, Resolution) {Return Lookup [feature.get ('number')];}});  

For an example, see which polygon uses a style function to add labels.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -