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?
Like this (in google maps):
开发者_JAVA百科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:
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.
精彩评论