Javascript Openlayers v3.13.1,从PHP/Mysql构建层
我在用Openlayers制作的地图项目中。我对JS、AJAX和Openlayers都非常熟悉 我需要在地图中构建层,我有Mysql数据库中的数据,需要执行以下操作:Javascript Openlayers v3.13.1,从PHP/Mysql构建层,javascript,php,mysql,ajax,Javascript,Php,Mysql,Ajax,我在用Openlayers制作的地图项目中。我对JS、AJAX和Openlayers都非常熟悉 我需要在地图中构建层,我有Mysql数据库中的数据,需要执行以下操作: var *layername* = new ol.layer.Vector({ // *layername* need to have layername came from php file visible: false, title: 'puntos', // Here
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
}),
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"
})),
}),
}),
]
注意:我现在有五层要解析,可能是一个循环。。。我的意思是五个结果的动态构建,需要构建如下内容:
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
}),
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"
})),
}),
}),
]
烧掉我的眼睛在谷歌中搜索一些对我有帮助的东西,但是我发现所有的东西都使用AJAX,结果都写在HTML对象中,我不需要这个
对不起,如果这是一个很难回答的问题,非常抱歉我的英语这不是我的主要语言
PD:提前谢谢,希望有人能帮上忙。。。。好吧,也许这是不可能的。。。并且需要手动添加层。。。。其想法是:用户可以创建层,OpenLayer3可以从数据库中提供这些层。。。。但我仍然在到处搜索,什么也没找到,,,,,有可能做这样的事情吗?.我现在正在尝试做这样的事情:层['layer_'+layername]=new ol.layer.Vector({……source:new ol.source.GeoJSON({……php Json result…});。。。。。。对象形式确定。。。但是我不知道怎么把这个添加到地图上。。ajax给了我layername