Here is the content of my JSON file named "jobInfo.json":
{
"job": {
"id": 1,
"name": "Job 1",
"description": "bla bla bla",
"locations": {
"type": "FeatureCollection",
"features": [{
"id": 1,
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [9.523853, 47.671412]
},
"properties": {
"name": "poi 1"
}
}, {
"id": 2,
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [9.484092, 47.650899]
},
"properties": {
"name": "poi 2"
}
}]
}
}
}
I am trying to read this file from ExtJS 4 in a unique way. In the initial step, I aim to extract the job properties 'name' and 'description'. A model has been attempted for this purpose:
Ext.define('VZ.model.Job', {
extend: 'Ext.data.Model',
alias: 'widget.jobmodel',
idProperty: 'id',
fields: [
{
name: 'id',
type: 'integer'
}, {
name: 'name',
type: 'string'
}, {
name: 'description',
type: 'string'
},
'locations'
]
});
Below is how the controller should handle it:
var jobfile = "data/jobs/jobInfo.json"
var jobInfo = Ext.create('Ext.data.Store', {
model: 'VZ.model.Job',
proxy: {
type: 'ajax',
url: jobfile,
reader: {
type: 'json'
root: 'job'
}
}
});
Unfortunately, this approach encountered an issue.
The next task involves accessing the property 'features' at the root level.
This was achieved with success using another JSON file ("data/jobs/job.json") that only contained features:
{
"type": "FeatureCollection",
"features": [{
"id": 472
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [9.523853, 47.671412]
},
"properties": {
"name": "Flughafen"
},
}, {
"id": 458
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [9.484092, 47.650899]
},
"properties": {
"name": "Hafen"
},
}]
}
By altering the code as shown below, the desired outcome can be achieved:
var jobfile = "data/jobs/job.json"
var jobStore = Ext.create('GeoExt.data.FeatureStore', {
fields: [
{name: 'name', type: 'string'}
],
autoLoad: true,
proxy: Ext.create('GeoExt.data.proxy.Protocol', {
reader: Ext.create('GeoExt.data.reader.Feature', {**root: 'features'**}),
protocol: new OpenLayers.Protocol.HTTP({
url: jobfile
format: new OpenLayers.Format.GeoJSON({
internalProjection: new OpenLayers.Projection('EPSG:900913'),
externalProjection: new OpenLayers.Projection('EPSG:4326')
})
})
})
});
With this setup, the information can be utilized as a layer on openlayers.
However, when using "jobInfo.json", attempting to use 'job.locations.features' as the root led to the following error:
Uncaught TypeError: Cannot read property 'locations' of undefined
If anyone could assist me in resolving this issue, it would be greatly appreciated.
Thank you for your help in advance.