简体   繁体   English

如何在OpenLayers中使用较大图像的一部分作为标记?

[英]How can I use part of a larger image as a marker in OpenLayers?

Is it possible to use part of a larger image as a marker with OpenLayers? OpenLayers是否可以将较大图像的一部分用作标记?

Like this (in google maps): 像这样(在Google地图中):

var icon = new google.maps.MarkerImage(
"img/marker_sprite.png", 
new google.maps.Size(26, 44), 
new google.maps.Point(0, 44)
);

The basic recipe for adding a marker to a map in OpenLayers starts with adding a Marker layer to your map, which you can do like this: 在OpenLayers中向地图添加标记的基本方法是从向地图添加Marker图层开始,您可以这样操作:

var markers = new OpenLayers.Layer.Markers("Markers");
map.addLayer(markers);

Then you will need to add markers to that layer, which goes something like this: 然后,您需要在该图层上添加标记,如下所示:

var position = new OpenLayers.LonLat(longitude, latitude);
position.transform(new OpenLayers.Projection("EPSG:4326",
                   map.getProjectionObject());

var icon = new OpenLayers.Icon("img/marker_sprite.png",
                               new OpenLayers.Size(26, 44));

var marker = new OpenLayers.Marker(position, icon);
markers.addMarker(marker);

Unfortunately it's not possible, as far as I know, so set the origin for the marker within the image file so you can just use part of the image. 不幸的是,据我所知,这是不可能的,因此请在图像文件中设置标记的原点,以便仅使用图像的一部分。 Well you can, but only if the part you want is in the corner, which isn't very helpful. 可以,但是只有当您想要的部分在角落时,这不是很有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM