2016-07-12 6 views
1

私はサーバーから得たものを持っており、それをループする必要があります。この文字列は、実際にはopenLayersを使用してマップで視覚化したい場所のジオジーンです。あなたがfeaturesの各featureは、いくつかのpropertiesgeometryを持って見ることができるように座標のセットごとに異なるスタイルのopenLayersレイヤーを描画します

{crs: 
    {"type":"name", 
    "properties":{ 
      "name":"ESPG:4326" 
     }, 
    }, 
    "features":[{"properties":{ 
       "image":"IMAGE1"}, 
       "type":"Feature", 
       "geometry":{ 
          "type":"Point", 
          "coordinates":[0,0] 
        }},{"properties":{ 
       "image":"IMAGE2"}, 
       "type":"Feature", 
       "geometry":{ 
          "type":"Point", 
          "coordinates":[10,10] 
        }},{"properties":{ 
       "image":"IMAGE3"}, 
       "type":"Feature", 
       "geometry":{ 
          "type":"Point", 
          "coordinates":[75,99] 
        }}] 
     ,type:"FeatureCollection" 
} 

:ここで返される文字列の例があります。新しいlayer(ol.layer.Vector)を作成したいと思います。フィーチャの各要素に対して、対応する座標とイメージを持つ点が描画されます。次のコードでは、マップ内のすべての点を描画するようにしていますが、定義済みの画像を使用しています。私はこの文字列をループして、座標とイメージを取得し、何らかの形でレイヤー(または多くのレイヤー)を作成する必要があると思います。任意のアイデア?ありがとう!

//map is the actual map where the images load 
//responseText is the String that I get from the server 
//predefinedImage is actually a predefined image that I use as icon for the points. 
//If I complitelly remove the "style" from geojson_layer it sets the image to a default value. 
var geoJSONsource = new ol.source.Vector({ 
    features: (new ol.format.GeoJSON()).readFeatures(responseText) 
}); 

geojson_layer = new ol.layer.Vector({ 
    source: geoJSONsource, 
    style: predefinedImage 
}); 

map.addLayer(geojson_layer); 
+0

使用する画像をどのように知っていますか? –

+0

名前 'IMAGE1'などは、サービス(javaサーブレット)のリンクに付加される値を表します。例えば、私が何とか 'IMAGE1'という値を得た後、私はjavascriptの文字列を' var imageSource = 'http:// localhost:8080/project/getImage?' + IMAGE1 '; – Panos

答えて

1

これはあなたを助けるかもしれない:

https://gis.stackexchange.com/a/95389/77349

あなたはしかし、この行を変更する必要があります

externalGraphic: 'marker.png', 

externalGraphic: this.image, 

希望のようなものにこれは役に立ちます!

関連する問題