繁体   English   中英

适用于本地生成的geoJSON格式对象的OpenLayers协议

[英]OpenLayers Protocol for locally generated geoJSON formatted object

我正在使用本地服务器生成地图,但是我获取的形状数据只是数组。 我正在使用JavaScript将其转换为geoJSON,但是如何告诉OpenLayers使用此obj而不是URL? 该文档不可靠,Google并未向我提供答案。

我目前正在通话的内容:

var marketProtocal = new OpenLayers.Protocol.HTTP({
   url: 'json/lte_shapes.json',
   format: new OpenLayers.Format.GeoJSON()
});

容器看起来类似于:

var geoObj = {};

$.getJSON("/shape_server.json", function(result) {
     // convert arrays into new geoJSON obj
     geoObj.push(newGeoJSON);
   }).done(function() {
    // generate map using geoObj
});

下面的代码为我工作:

<script type="text/javascript">
var vectorSource = new ol.source.ServerVector({
   format: new ol.format.GeoJSON(),
   loader: function(extent, resolution, projection) {
      loadFeatures();
   },
   strategy:  function(extent, resolution) {
   // some code
    return [extent];
   },
   projection: "EPSG:25832"
});

var localdata ={
  "type": "FeatureCollection",
  "crs": {"type": "name","properties": {"name": "EPSG:25832" }},
  "features": [
      { 
        "type": "Feature",
        "properties": {"name": "Hub 1"},
        "geometry": {"type": "Point","coordinates":  [714844,6178000]}
      }
    ]
  }

var loadFeatures = function() { 
   vectorSource.addFeatures(vectorSource.readFeatures(localdata));
};

var SmallworldLayer = new ol.layer.Vector({
   source: vectorSource,
   style: avlFeatureStyle
});
</script>

本地数据是我的GeoJson数据。 用你自己的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM