[hello world 動かない ][検索]

プログラミング関連で自分が調べた事をメモる

openlayers geojson

OpenLayersでGeoJSONを読み込む


ちょっとソースだけ置いておく

    var createPointStyleFunction = function() {
      return function(feature, resolution) {
        var style = new ol.style.Style({
          image: new ol.style.Circle({
            radius: 5,
            fill: new ol.style.Fill({color: feature.get('color')}),
            stroke: new ol.style.Stroke({color: 'black', width: 1})
          }),
          text: new ol.style.Text({
            font: 'Normal 12px Arial',
            fill: new ol.style.Fill({color: '#000'}),
            offsetY: -10,
            text: feature.get('name')
          })
        });
        return [style];
      };
    };

    var vectorSource = new ol.source.Vector({
      url: 'example.geojson',
      format: new ol.format.GeoJSON({
        defaultDataProjection: 'EPSG:4326'
      })
    });

    var vectorLayer = new ol.layer.Vector({
      source: vectorSource,
      style: createPointStyleFunction()
    });