0
オープンレイヤー3でマーカーにマーカーを表示しようとしています。以下は私が使用したコードです。特定の位置にアイコンが表示されないため、誰かが問題を見つけるのを助けることができますか?オープンレイヤー3でマーカーを表示する方法
var app = angular.module('Openlayers', []);
//The list of points to be connected
var dataSource1 = [{
"title": 'Duero',
"lat": '40.480243',
"lng": '-3.866172',
"description": 'This is Duero'
}, {
"title": 'Reyes Catolicos',
"lat": '49.47806',
"lng": '-1.870937',
"description": 'This is Reyes Catolicos'
}, {
"title": 'Guadarrama',
"lat": '58.478998',
"lng": '-2.878755',
"description": 'This is Guadarrama'
}];
var defaultIconPath = 'images/location.jpg';
var centerPosition = dataSource1[1];
var vehicleIconpath = 'images/vehicle.ico';
私は、メソッドを呼び出すための呼び出しの下に使用しています。データが間違った形式であるとき
$scope.populateMarkers($scope.dataPoints, defaultIconPath);
$scope.populateMarkers = function (data, iconPath) {
var features = [];
angular.forEach(data, function (value, key) {
debugger;
var iconFeature = new ol.Feature({
geometry: new ol.geom.Point(ol.proj.transform([value.lng, value.lat], 'EPSG:4326',
'EPSG:3857'))
});
var iconStyle = new ol.style.Style({
image: new ol.style.Icon(({
anchor: [0.5, 46],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
opacity: 0.75,
src: iconPath
}))
});
iconFeature.setStyle(iconStyle);
features.push(iconFeature);
});
var vectorSource = new ol.source.Vector({
features: features
});
var vectorLayer = new ol.layer.Vector({
source: vectorSource
});
map.addLayer(vectorLayer);
}
コード自体は適切です。最初のアイデアは 'iconPath'が間違っています。あなたはそれを初期化していますか?それを削除して、デフォルトのマーカーが表示されているかどうか確認してください。また、全世界にズームアウトしてみてください。多分指針は間違っています。 –
はい私はiconpathを初期化しました。デバッグで私はそれを見ることができます。しかしそれでも私はそれを削除しようとしましたが、デフォルトのアイコンも表示されませんでした。私はより詳細な質問を変更しました – user1770461