是“此处映射javascript api”,支持GeoJSON或KML的任何其他文件格式

问题描述 投票:-1回答:2

是否可以通过正确的方式将GeoJson格式的数据加载到此处的maps js api?我正在使用AJAX发送来自以GeoJSON格式格式化的mysql的数据。我不想存储任何kml文件。

kml geojson here-api
2个回答
1
投票

[legacy 2.x API中没有直接提供的GeoJSON解析器,您必须编写自己的。由于Google Maps API存在外部GeoJSON parser library,因此只需用等效的HERE Maps对象替换Google Specific Map对象即可。

我已基于原始端口创建了一个端口,但保留了此处的HERS Maps语法here

GeoJSONContainer

的基本用法是通过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

由于

GeoJSONContainer

Container的扩展,因此您还可以使用addGeoJSON()将geoJSON数据直接添加到地图上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

组件相同的方式添加和设置数据点样式

样式示例:

Football Teams

  • 当然不附带任何保证。
  • 对于

    当前3.x

  • API,包括了geojson阅读器作为标准配置,您可以在下面参考fxxxit的回答:

    var reader = new H.data.geojson.Reader('/path/to/geojson/file.json'); reader.parse(); //assuming that map already exists map.addLayer(reader.getLayer());


    2
    投票
    var reader = new H.data.geojson.Reader('/path/to/geojson/file.json'); reader.parse(); //assuming that map already exists map.addLayer(reader.getLayer());
    © www.soinside.com 2019 - 2024. All rights reserved.