Javascript 如何从geojson openlayers3获取图像源

Javascript 如何从geojson openlayers3获取图像源,javascript,json,openlayers-3,Javascript,Json,Openlayers 3,需要为json点传递不同的图像。如何从json提供图像src url 矢量图层和样式 vector = new ol.layer.Vector({ source: new ol.source.Vector({ projection : 'EPSG:4326', format: new ol.format.GeoJSON(), url: 'resources/multipoint.geojson' }), style: styleFunction1 }); var s

需要为json点传递不同的图像。如何从json提供图像src url

矢量图层和样式

vector = new ol.layer.Vector({
  source: new ol.source.Vector({
   projection : 'EPSG:4326',
   format: new ol.format.GeoJSON(),
   url: 'resources/multipoint.geojson'
 }),
  style: styleFunction1
});

var styleFunction1 = function(feature) {
              return styles[feature.getGeometry().getType()];
            };

var styles = {
              'Point': [
              new ol.style.Style({
               image: new ol.style.Icon({
                 src: 'resources/icon.png',
                 anchor: [0.5, 1]
               })
             })],
              'LineString': [new ol.style.Style({
                stroke: new ol.style.Stroke({
                  color: 'gray',
                  width: 5
                })
              })]
            };
Json


如何从json传递
src:'resources/Blue\u pointer.png',
将样式函数更改为:

var styleFunction1 = function(feature) {
  var styles = {
    'Point': [
      new ol.style.Style({
        image: new ol.style.Icon({
          src: feature.get('src'),
          anchor: [0.5, 1]
        })
      })],
    'LineString': [
      new ol.style.Style({
        stroke: new ol.style.Stroke({
          color: 'gray',
          width: 5
        })
    })]
  };

  return styles[feature.getGeometry().getType()];
};
并将图像源添加到JSON:

{
  "type": "Feature",
  "properties": {
      "name": "Missing Person",
      "ref":" Ref 5684",
      "src": "resources/some-img.png"
  },
  "geometry": {
    "type": "Point",
    "coordinates": [-0.12755, 51.507222]
  }
},

将样式功能更改为:

var styleFunction1 = function(feature) {
  var styles = {
    'Point': [
      new ol.style.Style({
        image: new ol.style.Icon({
          src: feature.get('src'),
          anchor: [0.5, 1]
        })
      })],
    'LineString': [
      new ol.style.Style({
        stroke: new ol.style.Stroke({
          color: 'gray',
          width: 5
        })
    })]
  };

  return styles[feature.getGeometry().getType()];
};
并将图像源添加到JSON:

{
  "type": "Feature",
  "properties": {
      "name": "Missing Person",
      "ref":" Ref 5684",
      "src": "resources/some-img.png"
  },
  "geometry": {
    "type": "Point",
    "coordinates": [-0.12755, 51.507222]
  }
},

获取错误-如果获取名称,则无法读取styleFunction1中null ol.js//ol Version:v3.16.0的属性“0”。。console.log(feature.get('name'));但不获取src console.log(feature.get('src'));正在工作..它只占用2个属性。。“properties:{“name”:“Wanted”,“src”:“resources/icon.png”},获取错误-如果获取名称,则无法在styleFunction1中读取null ol.js//ol Version:v3.16.0的属性“0”。。console.log(feature.get('name'));但不获取src console.log(feature.get('src'));正在工作..它只占用2个属性。。“属性”:{“名称”:“通缉”,“src”:“resources/icon.png”},