0

I'm trying to add a vector layer from vector source , but getting error like this

AppComponent.html:1 ERROR TypeError: this.adaptAttributions_ is not a function
    at Object._ol_source_Source_ (source.js:41) 

here is my code ,

import {Component, OnInit} from '@angular/core';

import OlMap from 'ol/map';
import OlXYZ from 'ol/source/xyz';
import OlTileLayer from 'ol/layer/tile';
import OlView from 'ol/view';
import OlProj from 'ol/proj';
import OlProjection from 'ol/proj/projection'
import OlExtent from 'ol/extent';
import OlTileGrid from 'ol/tilegrid/tilegrid'
import OlLayer from 'ol/layer/layer';
import OlLayerImage from 'ol/layer/image';
import OlSource from 'ol/source/source';
import OlSourceOSM from 'ol/source/osm';
import OlTileWMS from 'ol/source/tilewms';
import OlVector from 'ol/source/vector';
import OlLayerVector from 'ol/layer/vector';
import OlFormatGeoJSON from 'ol/format/geojson';
import OlLoadingStrategy from 'ol/loadingstrategy';
import OlImageWMS from 'ol/source/imagewms';
import OlStyle from 'ol/style'
import Proj4 from 'proj4';
//import * as ol from 'ol';
@Component({
  selector: 'app-map',
  templateUrl: './map.component.html',
  styleUrls: ['./map.component.css']
})

export class MapComponent implements OnInit {

  map: OlMap;
  source: OlXYZ;
  layer: OlTileLayer;
  view: OlView;

  constructor() {
  }

  ngOnInit() {

      var vectorSource = OlVector({
        format: new OlFormatGeoJSON(),
        url: function(extent) {
    return 'http://localhost:8080/geoserver/workspace/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=workspace:roadcentreline&outputFormat=application/json&srsname=EPSG:32640&'+
    'bbox=' + extent.join(',') + ',EPSG:32640';

        },
        strategy: OlLoadingStrategy.bbox
      });

      Proj4.defs("EPSG:32640","+proj=utm +zone=40 +datum=WGS84 +units=m +no_defs");
      var proj27700 = OlProjection.get('EPSG:32640');


       var vector = new OlLayerVector({
        source: vectorSource,
        style: new OlStyle.Style({
          stroke: new OlStyle.Stroke({
            color: 'rgba(0, 0, 255, 1.0)',
            width: 2
          })
        })
      });

      this.view= new OlView({
                    center: [376581.6867, 2679756.7678],
                    projection: 'EPSG:32640',
                    maxZoom: 19,
                    zoom: 15
        });

        this.map= new OlMap({
        layers: [vector],
        target: document.getElementById('map'),
        view: this.view
      });


  }
}

i used same version of openlayers(4.6.5) used here

working here, but not for me.

2

Use "new" keyword for OlVector.

 var vectorSource = new OlVector({
        format: new OlFormatGeoJSON(),
        url: function(extent) {
    return 'http://localhost:8080/geoserver/workspace/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=workspace:roadcentreline&outputFormat=application/json&srsname=EPSG:32640&'+
    'bbox=' + extent.join(',') + ',EPSG:32640';

        },
        strategy: OlLoadingStrategy.bbox
      });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.