【问题标题】:Simplest GeoJSON map script最简单的 GeoJSON 地图脚本
【发布时间】:2012-10-25 13:12:50
【问题描述】:

我过去使用过 Polymaps,但谁能指出一些非常简单的脚本,它可以从 geojson 生成地图而没有额外的膨胀和库依赖项?

我有一个包含 geojson 的 country.json 文件,并且想在没有 d3、openLayers 或其他库的情况下渲染地图。

【问题讨论】:

  • 为了澄清,您真的要渲染地图还是只显示覆盖在另一张地图(例如 Google 地图)上的 GeoJSON 数据?
  • 我想展示地图,抱歉没有澄清。

标签: javascript maps geojson


【解决方案1】:

它不是一个独立的脚本,而是一个库,但我过去使用过OpenLayers。使用起来非常简单,并且可以与 GeoJson 一起使用。

他们网站上的examples 也非常有用。来自他们的GeoJson example


map = new OpenLayers.Map( 'map' );
            layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", 
                    "http://vmap0.tiles.osgeo.org/wms/vmap0",
                    {layers: 'basic'} );
            map.addLayer(layer);
            map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
            var featurecollection = {
              "type": "FeatureCollection", 
              "features": [
                {"geometry": {
                    "type": "GeometryCollection", 
                    "geometries": [
                        {
                            "type": "LineString", 
                            "coordinates": 
                                [[11.0878902207, 45.1602390564], 
                                [15.01953125, 48.1298828125]]
                        }, 
                        {
                            "type": "Polygon", 
                            "coordinates": 
                                [[[11.0878902207, 45.1602390564], 
                                  [14.931640625, 40.9228515625], 
                                  [0.8251953125, 41.0986328125], 
                                  [7.63671875, 48.96484375], 
                                  [11.0878902207, 45.1602390564]]]
                        },
                        {
                            "type":"Point", 
                            "coordinates":[15.87646484375, 44.1748046875]
                        }
                    ]
                }, 
                "type": "Feature", 
                "properties": {}}
              ]
           };
           var geojson_format = new OpenLayers.Format.GeoJSON();
           var vector_layer = new OpenLayers.Layer.Vector(); 
           map.addLayer(vector_layer);
           vector_layer.addFeatures(geojson_format.read(featurecollection));

【讨论】:

  • 谢谢你,但我也使用过 OpenLayers,现在正在寻找不依赖库的简单东西。
猜你喜欢
  • 1970-01-01
  • 2012-07-13
  • 2010-09-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-02
  • 2013-09-24
相关资源
最近更新 更多