我正在以这种方式在地图上显示一些多边形。
var featurecollection = {
"type": "FeatureCollection",
"totalFeatures": "unknown",
"features": [
{
"type": "Feature",
"id": "exm",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-18.216667,
28.933332
],
[
-18.416668,
27.6
],
[
-17.966667,
27.383333
],
[
-17.183332,
27.8
],
[
-16.75,
27.8
],
.......................
.......
var geojs_format = new OpenLayers.Format.GeoJSON({
'internalProjection': new OpenLayers.Projection("EPSG:900913"),
'externalProjection': new OpenLayers.Projection("EPSG:4326")
});
var vector_layer = new OpenLayers.Layer.Vector();
new OpenLayers.Projection("EPSG:4326"),
map.addLayer(vector_layer);
vector_layer.addFeatures(geojs_format.read(featurecollection));
它可以工作,但是我的“ var featurecollection = {”的值很大,在我的代码中需要51000行。可以像从file.json这样的项目中删除我的代码中的geojson,然后从那里访问和读取它。