Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/453.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript OpenLayers在地图上显示图标时出现问题_Javascript_Gps_Openlayers 6 - Fatal编程技术网

Javascript OpenLayers在地图上显示图标时出现问题

Javascript OpenLayers在地图上显示图标时出现问题,javascript,gps,openlayers-6,Javascript,Gps,Openlayers 6,我对OpenLayers 6.5.0有一个问题。我想在地图上显示一个图标,但尽管多次尝试,我还是失败了。我想这不是坐标的问题。我尝试了EPSG转换。我查看了文档和其他可用示例,不知道是什么导致了这个问题 var位置=[ [15.94606, 51.57557], [15.94602, 51.57572], [15.94604, 51.57576], [15.946, 51.57581], [15.94588, 51.57586], [15.94567, 51.57591], [15.94543

我对OpenLayers 6.5.0有一个问题。我想在地图上显示一个图标,但尽管多次尝试,我还是失败了。我想这不是坐标的问题。我尝试了EPSG转换。我查看了文档和其他可用示例,不知道是什么导致了这个问题

var位置=[
[15.94606, 51.57557],
[15.94602, 51.57572],
[15.94604, 51.57576],
[15.946, 51.57581],
[15.94588, 51.57586],
[15.94567, 51.57591],
[15.94543, 51.57597],
[15.94527, 51.57602],
[15.94513, 51.57605],
[15.94502, 51.57607],
[15.94497, 51.57609],
[15.94499, 51.57609],
[15.94497, 51.57611],
[15.94501, 51.57616],
[15.94525, 51.57636]
];
var lineString=new ol.geom.lineString(locations.transform('EPSG:4326','EPSG:3857'))
var startMarker=新的ol.功能({
键入:“图标”,
几何学:新的ol.geom.Point(ol.proj.transform([15.94606,51.57557],“EPSG:4326',“EPSG:3857'))
});
var endMarker=新的ol.特征({
键入:“图标”,
几何体:新的ol.geom.Point(lineString.GetCoordinate(1))
});
var lineLayer=新ol.layer.Vector({
来源:新ol.source.Vector({
功能:[新ol.功能({
几何图形:线串,
名称:“行”
}),
startMarker,
终点标记
]
}),
风格:新的ol风格({
笔划:新的ol风格笔划({
颜色:“红色”,
不透明度:0.5,
宽度:5
}),
“图标”:新的ol.style.style({
图片:新ol.style.Icon({
锚定:[0.5,1],
src:'https://openlayers.org/en/v3.20.1/examples/data/icon.png'
})
})
})
});
变量视图=新的ol.view({
中心:Lonlat的其他项目([15.94616,51.57555]),
缩放:13
});
var map=新ol.map({
目标:“地图”,
图层:[
新ol.layer.Tile({
来源:new ol.source.OSM()
}),
线人
],
目标:“地图”,
控件:ol.control.defaults({
AttributeOptions:/**@type{olx.control.AttributeOptions}*/({
可折叠:错误
})
}),
视图:视图
});
body,
html,
.地图{
宽度:100%;
身高:100%;
保证金:0;
填充:0;
}

样式不需要图标属性,只需包含带有笔划样式的图像即可

    style: new ol.style.Style({
        stroke: new ol.style.Stroke({
            color: 'red',
            opacity: 0.5,
            width: 5
        }),
        image: new ol.style.Icon({
            anchor: [0.5, 1],
            src: 'https://openlayers.org/en/v3.20.1/examples/data/icon.png'
        })
    })