我只需要 OpenLayers 中的标记来动态更改。我不知道该怎么做。。
for循环console.debug(response.i)
输出是
[Object { lat="36.15900011", lon="-115.17205183"},
Object { lat="36.15899561", lon="-115.17276155"}]
抱歉在这里粘贴完整的代码..
<script type="text/javascript">
$.ajax({
url:'parser', success:function(response){
$(document).ready(function(){
console.debug('hello')
var jsonlen = response.length;
for (var i=0; i<=jsonlen; i++){
console.debug(response.i)
}
console.debug(response)
// icon feature started
var vectorSource = new ol.source.Vector({
// empty vector
})
var iconFeature = new ol.Feature({
geometry: new ol.geom.Point(ol.proj.transform([80.2700, 13.0839], 'EPSG:4326', 'EPSG:3857')),
name:'Null Island',
population: 4000,
rainfall:500
})
vectorSource.addFeature(iconFeature);
//create the style
var iconStyle = new ol.style.Style({
image: new ol.style.Icon(/**@type {olx.style.IconOptions}*/({
anchor: [0.5, 46],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
opacity: 0.75,
src: 'http://ol3js.org/en/master/examples/data/icon.png'
}))
});
// add the feature vector to the layer vector,
// and apply a style to whole layer
var vectorLayer = new ol.layer.Vector({
source: vectorSource,
style: iconStyle
});
var map = new ol.Map({
layers: [new ol.layer.Tile({ source: new ol.source.OSM() }),
vectorLayer],
target: document.getElementById('map'),
view: new ol.View({
center: [0, 0],
zoom: 3
})
});
})
}
})
</script>
上面的代码一个标记工作正常