I'm In a Map proyect made with Openlayers. I'm realy, realy new in JS, AJAX and Openlayers
I need to build layers in the map, I have DATA in Mysql dbase, need to do something like this:
var *layername* = new ol.layer.Vector({ // *layername* need to have layername came from php file
visible: false,
title: 'puntos', // Here I need to parse a result from mysql data that has the layers names that I need
source: new ol.source.GeoJSON({
url: 'file.php?layer='+, // plus layername
projection: 'EPSG:3857',
}),
style: new ol.style.Style({
image: new ol.style.Icon(({
anchor: [10, 26],
anchorXUnits: 'pixels',
anchorYUnits: 'pixels',
src: "./img/marquita_naranja.png" // this has to came from php too
})),
})
new ol.layer.Group({
title: 'Capas',
layers: lcapas, // I need to build this from an Array with Mysql reasult
}),
Note: I have, for now, five Layers to parse in, maybe a loop... I mean a dynamically build of that five result, need to build something like this:
new ol.layer.Group({
title: 'Capas',
layers: [
new ol.layer.Vector({
visible: false,
title: 'Ciudades y Plazas',
source: new ol.source.GeoJSON({
url: 'consulta_puntos.php?capa=Ciudades y Plazas',
projection: 'EPSG:3857',
}),
style: new ol.style.Style({
image: new ol.style.Icon(({
anchor: [10, 26],
anchorXUnits: 'pixels',
anchorYUnits: 'pixels',
src: "./img/marquita_verde.png"
})),
}),
}),
new ol.layer.Vector({
visible: false,
title: 'Museos',
source: new ol.source.GeoJSON({
url: 'consulta_puntos.php?capa=Museos',
projection: 'EPSG:3857',
}),
style: new ol.style.Style({
image: new ol.style.Icon(({
anchor: [10, 26],
anchorXUnits: 'pixels',
anchorYUnits: 'pixels',
src: "./img/marquita_amarilla.png"
})),
}),
}),
new ol.layer.Vector({
visible: false,
title: 'Lagos',
source: new ol.source.GeoJSON({
url: 'consulta_puntos.php?capa=Lagos',
projection: 'EPSG:3857',
}),
style: new ol.style.Style({
image: new ol.style.Icon(({
anchor: [10, 26],
anchorXUnits: 'pixels',
anchorYUnits: 'pixels',
src: "./img/marquita_azul.png"
})),
}),
}),
]
burn my eyes search in google something that help me, but all that i found uses AJAX and with the result writes in a HTML objet, I don't need this....
Sorry if this is a very noob question, and very sorry about my english this isn't my principal language
PD.: Thanks in advance, hope someone can help with this