2017-02-12 5 views
0

{draggable:'true'}機能が受け入れられ、エラーになりません。Ionic2リーフレットマーカーは受け入れられませんドラッグ可能な機能?このコードで

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

import * as Leaflet from 'leaflet'; 

@Component({ 
    selector: 'page-street', 
    templateUrl: 'street.html' 
}) 
export class StreetPage { 
private latLng: any; 
    private marker: any; 
    private map: any; 
    constructor(public navCtrl: NavController) { 

    } 
    ngOnInit(): void { 
    this.drawMap(); 
    } 
    drawMap(): void { 
    let map = Leaflet.map('map'); 
    Leaflet.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { 
     maxZoom: 15 
    }).addTo(map); 

    map.locate({ setView: true}); 
    function onLocationFound(e) {  
     var radius = e.accuracy/3;  
     Leaflet.marker(e.latlng, {draggable:'true'}).addTo(map); 
     Leaflet.circle(e.latlng, radius).addTo(map); 
    } 
    map.on('locationfound', onLocationFound); 
    //alert on location error 
    function onLocationError(e) { 
     alert(e.message); 
    } 
    map.on('locationerror', onLocationError); 
    } 
} 

それを解決するための任意のアイデア?

更新:{draggable:'true'}ため

エラー:

Typescript Error Argument of type '{ draggable: string; }' is not assignable to parameter of type 'MarkerOptions'. Types of property 'draggable' are incompatible. Type 'string' is not assignable to type 'boolean

{draggable: true}

のエラー:

Typescript Error Argument of type '{ draggable: true; }' is not assignable to parameter of type 'MarkerOptions'. Property 'options' is missing in type '{ draggable: true

+0

エラーは何ですか? – n00b

+0

@ n00b私はエラーショーで投稿を更新しました。 – RSA

答えて

1

最初の使用

{draggable:true} 

ここで、真は文字列である '真'の代わりにブール値です。 TypeScriptは、文字列プロパティを持つオブジェクトとしてコードを認識します。このオブジェクトは、 'draggable'というブール値プロパティを持つオブジェクトである変数に割り当てられません。

'options'プロパティも必要です。 MarkerOptionsの定義を見ることで、オプションに何を入れるべきかを理解できるはずです。

MarkerOptionsの定義が余りにも限定されている「リーフレット」用の入力(.d.ts)をダウンロードした可能性があります。

のは、あなたがこのタイピング取得するためにこれを使用していたとしましょう

npm install @types/leaflet

オプション1:MarkerOptionsのために作られた宣言を見つけて、どちらかあなたの目的に合うか、その定義に合わせてパラメータを変更するように変更。

オプション2:あなたがダウンロードした宣言ファイルに「マーカー」関数の宣言を見つけ、「任意の」

に「MarkerOption」から2番目のパラメータの種類を変更し、最終的にあなたのindex.d.tsはのようになります。この

​​
+0

このガイドでは、ファイルの内容をチェックするアイデアがあり、 'Leaflet.marker(e.latlng、{'draggable':true)).addTo(map);' nowマーカードラッグ可能ですが、円はメーカーでドラッグされていません(マーカーとバインドされていません)。ドラッグされたマーカーの位置を読み取る方法があります。 qoogleには「draggend」イベントリスナーがありました。 – RSA

関連する問題