是否可以通过正确的方式将GeoJson格式的数据加载到此处的maps js api?我正在使用AJAX发送来自以GeoJSON格式格式化的mysql的数据。我不想存储任何kml文件。
[legacy 2.x API中没有直接提供的GeoJSON解析器,您必须编写自己的。由于Google Maps API存在外部GeoJSON parser library,因此只需用等效的HERE Maps对象替换Google Specific Map对象即可。
我已基于原始端口创建了一个端口,但保留了此处的HERS Maps语法hereGeoJSONContainer
的基本用法是通过parseGeoJSON()方法,如下所示:function extend(B, A) {
function I() {}
I.prototype = A.prototype;
B.prototype = new I();
B.prototype.constructor = B;
}
function createGeoJsonParser(){
extend(GeoJSONContainer, nokia.maps.map.Container);
parser = new GeoJSONContainer();
}
function parseJson(jsonObject){
result = parser.parseGeoJSON(jsonObject);
if (parser.state == "finished") {
map.objects.addAll(result);
map.set("center", map.objects.get(0).getBoundingBox().getCenter());
map.addListener("click" , function(evt) {
var text = JSON.stringify(evt.target.properties);
bubble = infoBubbles.addBubble(text!== undefined ?
text : "properties undefined",
evt.target.getBoundingBox().getCenter());
}, false);
} else {
console.log(result);
}
}
查看链接:Simple geoJSON parsing是Container的扩展,因此您还可以使用addGeoJSON()将geoJSON数据直接添加到地图上由于
GeoJSONContainer
var err = resultSet.addGeoJSON(jsonManager.object);
if (resultSet.state == "finished") {
map.zoomTo(container.getBoundingBox());
container.addListener("click" , function(evt) {
infoBubbles.addBubble(evt.target.properties.Description,
evt.target.getBoundingBox().getCenter());
}, false);
} else {
alert(err);
}
基本示例用法:-Russia Provinces组件相同的方式添加和设置数据点样式您还可以使用与[[clustering
样式示例:
当前3.x
var reader = new H.data.geojson.Reader('/path/to/geojson/file.json');
reader.parse();
//assuming that map already exists
map.addLayer(reader.getLayer());
var reader = new H.data.geojson.Reader('/path/to/geojson/file.json');
reader.parse();
//assuming that map already exists
map.addLayer(reader.getLayer());