Diferencia entre revisiones de «Widget:OP»
De Wikiexplora
(Página creada con « <html> <head><title>OpenLayers KML Example</title></head> <body> <div id="mapdiv"></div> <script src="https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.11/lib/Op...») |
|||
Línea 13: | Línea 13: | ||
strategies: [new OpenLayers.Strategy.Fixed()], | strategies: [new OpenLayers.Strategy.Fixed()], | ||
protocol: new OpenLayers.Protocol.HTTP({ | protocol: new OpenLayers.Protocol.HTTP({ | ||
− | url: "./ | + | url: "http://www.wikiexplora.com/images/2/23/Monolito.kmz", |
format: new OpenLayers.Format.KML({ | format: new OpenLayers.Format.KML({ | ||
extractStyles: true, | extractStyles: true, | ||
Línea 61: | Línea 61: | ||
controls['selector'].activate(); | controls['selector'].activate(); | ||
</script> | </script> | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
</body></html> | </body></html> |
Revisión del 17:06 4 dic 2018
<html>
<head><title>OpenLayers KML Example</title></head> <body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.11/lib/OpenLayers.js"></script> <script> map = new OpenLayers.Map("mapdiv"); map.addLayer(new OpenLayers.Layer.OSM()); var kmllayer = new OpenLayers.Layer.Vector("KML", { strategies: [new OpenLayers.Strategy.Fixed()], protocol: new OpenLayers.Protocol.HTTP({ url: "http://www.wikiexplora.com/images/2/23/Monolito.kmz", format: new OpenLayers.Format.KML({ extractStyles: true, extractAttributes: true, maxDepth: 2 }) }) }); map.addLayer(kmllayer); //Set start centrepoint and zoom //TODO: Is it possible to just zoom to extents of KML objects instead? var lonLat = new OpenLayers.LonLat( -0.1279688 ,51.5077286 ) .transform( new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984 map.getProjectionObject() // to Spherical Mercator Projection ); var zoom=14; map.setCenter (lonLat, zoom); //Add a selector control to the kmllayer with popup functions var controls = { selector: new OpenLayers.Control.SelectFeature(kmllayer, { onSelect: createPopup, onUnselect: destroyPopup }) };
function createPopup(feature) { feature.popup = new OpenLayers.Popup.FramedCloud("pop", feature.geometry.getBounds().getCenterLonLat(), null,'
'+feature.attributes.description+'
',
null, true, function() { controls['selector'].unselectAll(); } ); //feature.popup.closeOnMove = true; map.addPopup(feature.popup); }
function destroyPopup(feature) { feature.popup.destroy(); feature.popup = null; } map.addControl(controls['selector']); controls['selector'].activate(); </script>
</body></html>