首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在d3 API版本4中,GeoStream不能赋值给'GeoRawProjection‘类型的参数

在d3 API版本4中,GeoStream不能赋值给'GeoRawProjection‘类型的参数
EN

Stack Overflow用户
提问于 2017-08-25 16:22:47
回答 1查看 125关注 0票数 0

在d3.geo API 3中,它具有像leaflet一样将地理位置坐标投影到地图上的功能。

例如,版本3中的代码如下所示

代码语言:javascript
复制
var transform = d3.geo.transform({point: self.projectPoint});
          self._path = d3.geo.path().projection(transform);

projectPoint: function(x, y) {
      var point = MELBPARKING.Map.map.latLngToLayerPoint(new L.LatLng(y, x));
      this.stream.point(point.x, point.y);
    }

现在我使用angular2框架构建了小叶地图来投影D3.js中的坐标,D3.js的API是建立在the version 4之上的。

代码语言:javascript
复制
export {default as geoTransform} from "./src/transform";
export {default as geoProjection, projectionMutator as geoProjectionMutator} from "./src/projection/index";

在我的angular2项目中,我使用d3.js和leaflet.js构建了一个小叶地图组件,如下所示

代码语言:javascript
复制
import * as L from 'leaflet';
import * as d3 from 'd3';
import {geoTransform,geoProjection} from "d3-geo";

export class MapsComponent implements OnInit {
   map;
   _path ;

   ngOnInit(){
      console.log('init map');
      this.map = L.map('mapid', {
      center: L.latLng(38, 15),
      zoom: 5,
      });
      this.map.setView(L.latLng(-37.81108500, 144.96269970), 18);
      var self = this;
      var transform = geoTransform({point: self.projectPoint})
      console.log(transform);
      self._path = geoProjection(transform);
   }

   projectPoint(x, y) {
       var point = this.map.latLngToLayerPoint(new L.LatLng(y,x));
       this.map.stream.point(point.x, point.y);
   }
}

然而,该项目遇到了如下错误

代码语言:javascript
复制
    ERROR in /maps.component.ts (87,32): Argument of type '{ stream(s: 
GeoStream): { point: (x: any, y: any) => void; } & GeoStream; }' is not
 assignable to parameter of type 'GeoRawProjection'.

    Type '{ stream(s: GeoStream): { point: (x: any, y: any) => void; } &
 GeoStream; }' provides no match for the signature '(lambda: number, phi: 
number): [number, number]'.

出了什么问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-27 13:35:56

将您的转换作为第一个参数传递给d3.geoPath,而不是d3.geoProjection。根据path.projection,此参数可以是任何投影流(这对于缩放和平移等平面变换很有用),而不仅仅是球形d3.geoProjection实例。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45877217

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档