I am trying to understand how to get data from my GeoJSON while rendering the map, so I can style every polygon/point differently.It just doesn't seem to work...
My GeoJSON:
var puntobject = { "type": "Feature", "properties": { "OBJECTID_1": 4, "OBJECTID": 7403707, "Identifica": "0860200000002559", "Woonplaats": "Veghel", "OpenbareRu": "Rembrandtlaan", "Huisletter": null, "Huisnummer": 17, "Huisnumm_1": null, "Postcode": "5462CJ", "Controle": 1, "Naam": "Ketelaars auto's", "Functie": "Autobedrijf met showroom", "Goothoogte": 3, "Bouwhoogte": 6, "Opmerkinge": "Hekwerk van 1,80 hoog rondom terrein", "Bijzonderh": null, "Woningtype": null, "Label_opme": null }, "geometry": { "type": "Point", "coordinates": [5.533485496901196, 51.609474175170639, 0.0] }}My code so far, based on an example
var styleFunction = function(feature,geom) {console.log(feature.getType());return styles[feature.getGeometry().getType()];};var styles = { 'Feature': [new ol.style.Style({ image: circle })], 'LineString': [new ol.style.Style({ stroke: new ol.style.Stroke({ color: 'green', width: 1 }) })]};var puntObjectenSource = new ol.source.Vector ({ features: (new ol.format.GeoJSON()).readFeatures(puntobject)});//Puntobjecten stylevar puntObjectenStyle = new ol.style.Style ({ image:circle});//Puntobjecten layervar puntObjecten = new ol.layer.Vector ({ source: puntObjectenSource, style: styleFunction});And the final mapping in my html:
var map = new ol.Map({ target: 'map', layers: [ new ol.layer.Tile({ //source: new ol.source.MapQuest({layer: 'sat'}) source: new ol.source.OSM({layer:'hot'}) }), puntObjecten ], view: new ol.View({ center: ol.proj.transform(lonlat, 'EPSG:4326', 'EPSG:3857'), zoom: 15 }) });I am trying to get the properties out of my JSON -> ON LOAD.How can I get this done?
P.S.I am new to Openlayers and having HUGE difficulties trying to understand the documentation on the website. Any tips on how to understand the documentation are welcome.
أكثر...
My GeoJSON:
var puntobject = { "type": "Feature", "properties": { "OBJECTID_1": 4, "OBJECTID": 7403707, "Identifica": "0860200000002559", "Woonplaats": "Veghel", "OpenbareRu": "Rembrandtlaan", "Huisletter": null, "Huisnummer": 17, "Huisnumm_1": null, "Postcode": "5462CJ", "Controle": 1, "Naam": "Ketelaars auto's", "Functie": "Autobedrijf met showroom", "Goothoogte": 3, "Bouwhoogte": 6, "Opmerkinge": "Hekwerk van 1,80 hoog rondom terrein", "Bijzonderh": null, "Woningtype": null, "Label_opme": null }, "geometry": { "type": "Point", "coordinates": [5.533485496901196, 51.609474175170639, 0.0] }}My code so far, based on an example
var styleFunction = function(feature,geom) {console.log(feature.getType());return styles[feature.getGeometry().getType()];};var styles = { 'Feature': [new ol.style.Style({ image: circle })], 'LineString': [new ol.style.Style({ stroke: new ol.style.Stroke({ color: 'green', width: 1 }) })]};var puntObjectenSource = new ol.source.Vector ({ features: (new ol.format.GeoJSON()).readFeatures(puntobject)});//Puntobjecten stylevar puntObjectenStyle = new ol.style.Style ({ image:circle});//Puntobjecten layervar puntObjecten = new ol.layer.Vector ({ source: puntObjectenSource, style: styleFunction});And the final mapping in my html:
var map = new ol.Map({ target: 'map', layers: [ new ol.layer.Tile({ //source: new ol.source.MapQuest({layer: 'sat'}) source: new ol.source.OSM({layer:'hot'}) }), puntObjecten ], view: new ol.View({ center: ol.proj.transform(lonlat, 'EPSG:4326', 'EPSG:3857'), zoom: 15 }) });I am trying to get the properties out of my JSON -> ON LOAD.How can I get this done?
P.S.I am new to Openlayers and having HUGE difficulties trying to understand the documentation on the website. Any tips on how to understand the documentation are welcome.
أكثر...