Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Can anybody explain how to get geojson features .Can somebody show way to get attributes from geojson text.

OpenLayers.ProxyHost = "/gt/proxy.cgi?url=";
     var lon = 5;
    var lat = 44;
    var zoom = 5;
    var map, layer;

    //function init(){
       var bounds = new OpenLayers.Bounds(
                -125051.196, 3967670.8507,
                1549596.1896, 4677667.0145
            );
            var options = {
                controls: [],
                maxExtent: bounds,
                maxResolution: 6541.59135,
                projection: "EPSG:23036",
                units: 'm'
            };
    map = new OpenLayers.Map('map', options);
    map.addControl(new OpenLayers.Control.PanZoomBar({
                position: new OpenLayers.Pixel(2,10)
            }));

            map.addControl(new OpenLayers.Control.Navigation());
            //map.addControl(new OpenLayers.Control.Scale($('scale')));
            map.addControl(new OpenLayers.Control.MousePosition({element: $('location')}));
             var geojson_format = new OpenLayers.Format.GeoJSON();
        var vl2 = new OpenLayers.Layer.Vector("",
        {isBaseLayer: true,
         styleMap: new OpenLayers.StyleMap({'default':{
                strokeColor: "#00FF00",
                strokeOpacity: 1,
                strokeWidth: 1,
                fillColor: "#FF5500",
                fillOpacity: 0.5,
                label : "${ad}",
                fontSize: "8px",
                fontFamily: "Courier New, monospace", 
                labelXOffset: "0.5",
                labelYOffset: "0.5"
            }})
        });
        map.addLayer(vl2);

       function handler(request) {

        vl2.addFeatures(geojson_format.read(request.responseText))
        map.zoomToExtent(bounds);
        }
        var request = OpenLayers.Request.GET({
        url: "myurljson&srsName=EPSG:23036",
        params: {},
        callback: handler
    });

please show me some way

share|improve this question
    
Which software? OpenLayers? be more specific. –  Pablo Aug 15 '12 at 19:05
    
For the attributes are you talking about the geojson properties value? Remember, geojson is just JSON that can be read into a javascript object using JSON.parse(json_str); –  om_henners Aug 16 '12 at 1:16
    
i create in openlayers pablo i use two layers base layers geojson the other one is gml i want to show when somebody click my city from map i want to show city name and the other attributes. There all features in geojson text i can see but i didnt use it . –  Rusty Aug 16 '12 at 6:33
add comment

2 Answers

To create a vector layer for your map from a geojson string, the following should work (with changes depending on your environment). The documentation from the OpenLayers API on the GeoJSON read function would be worth taking a look at as well.

var in_options = {
                'internalProjection': map.projection,
                'externalProjection': map.projection
                 };
var geojson_format = new OpenLayers.Format.GeoJSON(in_options);
var vectors = new OpenLayers.Layer.Vector("Some name", {style_options_etc});

var features = geojson_format.read(geosjon_str, "FeatureCollection");

//vectors.addFeatures requires an array, thus
if(features.constructor != Array) {
    features = [features];
}

vectors.reportError = true;
vectors.addFeatures(features);
map.addLayers([features]);
share|improve this answer
    
Is there anybody answer my question plz ?? –  Rusty Aug 17 '12 at 13:29
add comment

I hope this is what you're looking for. I was trying to extract attributes from geojson file using jquery. Posted this question and got my answer.

If you're not using jquery, just iterate with JavaScript

share|improve this answer
    
no geomajor im not using jquery .But maybe you have another way to this solution because i need it but thx again –  Rusty Aug 17 '12 at 16:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.