Created
March 19, 2012 04:11
-
-
Save ovnicraft/2094479 to your computer and use it in GitHub Desktop.
agregar markers con openlayers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var size = new OpenLayers.Size(21,25); | |
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h); | |
var icon = new OpenLayers.Icon("http://google-maps-icons.googlecode.com/files/arch.png", size, offset); | |
var zoom, center, currentPopup, map, lyrMarkers; | |
var popupClass = OpenLayers.Class(OpenLayers.Popup.FramedCloud, { | |
"autoSize": true, | |
"minSize": new OpenLayers.Size(300, 50), | |
"maxSize": new OpenLayers.Size(500, 300), | |
"keepInMap": true | |
}); | |
var bounds = new OpenLayers.Bounds(); | |
function addMarker(lng, lat, info) { | |
var pt = new OpenLayers.LonLat(lng, lat) | |
.transform(new OpenLayers.Projection("EPSG:4326"), | |
map.getProjectionObject()); | |
bounds.extend(pt); | |
var feature = new OpenLayers.Feature(lyrMarkers, pt); | |
feature.closeBox = true; | |
feature.popupClass = popupClass; | |
feature.data.popupContentHTML = info; | |
feature.data.overflow = "auto"; | |
var marker = new OpenLayers.Marker(pt, icon.clone()); | |
var markerClick = function(evt) { | |
if (currentPopup != null && currentPopup.visible()) { | |
currentPopup.hide(); | |
} | |
if (this.popup == null) { | |
this.popup = this.createPopup(this.closeBox); | |
map.addPopup(this.popup); | |
this.popup.show(); | |
} else { | |
this.popup.toggle(); | |
} | |
currentPopup = this.popup; | |
OpenLayers.Event.stop(evt); | |
}; | |
marker.events.register("mousedown", feature, markerClick); | |
lyrMarkers.addMarker(marker); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment