[OpenLayers-Users] Re: Why does OpenLayers.Layer.WMS shows vectors well and OpenLayers.Layer.OSM does not? (Same code)

alexe100 imoveisnacionais at gmail.com
Wed Apr 25 06:03:35 EDT 2012


using:

projection: "EPSG:4326",

does not work either :-(


Here the main code: (now without raw text format)


function init() 
		{
			map = new OpenLayers.Map('mapdiv');
            
            //var layer = new OpenLayers.Layer.WMS( "OpenLayers
WMS","http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'} );
            //map.addLayer(layer);
			
			var layer = new OpenLayers.Layer.OSM();
			map.addLayer(layer);
		
            //Renderer
            var renderer =
OpenLayers.Util.getParameters(window.location.href).renderer;
            renderer = (renderer) ? [renderer] :
OpenLayers.Layer.Vector.prototype.renderers;
            
			//Vector layer: used to render map data in the browser
(http://workshops.opengeo.org/openlayers-intro/vector/concepts.html)
            var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry", 
			    {
                styleMap: new OpenLayers.StyleMap({'default':{
                    strokeColor: "black", //cor bordo
                    strokeOpacity: 1,
                    strokeWidth: 2, //bordo
                    fillColor: "red", //cor circulo dentro
                    fillOpacity: 0.5,
                    pointRadius: 6, //circulo de dentro
                    pointerEvents: "visiblePainted",
                    //label : "name: ${name}\n\nage: ${age}",
					//label : "\n${name} - ${age}",
					label : "\n	${name}",
                    fontColor: "${favColor}",
                    fontSize: "12px",
                    fontFamily: "Courier New, monospace",
                    fontWeight: "bold",
                    labelAlign: "${align}",
                    labelXOffset: "${xOffset}",
                    labelYOffset: "${yOffset}",
                    labelOutlineColor: "white",
                    labelOutlineWidth: 3
                }}),
                renderers: renderer,
				
				strategies: [new OpenLayers.Strategy.BBOX()], 
				srsName: "EPSG:4326",
                                projection: "EPSG:4326",
				
            });
            
            //A point feature
            var point = new OpenLayers.Geometry.Point(-111.04, 45.68);
            var pointFeature = new OpenLayers.Feature.Vector(point);
            pointFeature.attributes = 
			{
                name: "HB-22-65",
                age: 20,		
                favColor: 'blue', //cor da label no ponto
                align: "cm"
				};
			
			//Another point feature
            var point2 = new OpenLayers.Geometry.Point(-90.04, 35.68);
            var pointFeature2 = new OpenLayers.Feature.Vector(point2);
            pointFeature2.attributes = 
			{
                name: "CC-01-50",
                age: 20,
                favColor: 'blue	', //cor da label no ponto
                align: "cm"
            };

           //Paths
	var start_point = new OpenLayers.Geometry.Point(0,10);
	var end_point = new OpenLayers.Geometry.Point(30,0);
	var lines = new OpenLayers.Feature.Vector(new
OpenLayers.Geometry.LineString([start_point, end_point]));	

        vectorLayer.addFeatures([pointFeature,pointFeature2,lines]); 

        map.addLayer(vectorLayer);


        //Handling mouse over
        var selectControl = new OpenLayers.Control.SelectFeature(
  vectorLayer, {
					hover: true,
					onBeforeSelect: function(feature) 
					{
						//If it is a line then return imediatly
						var strName=feature.attributes.name;
						if(typeof(strName) == 'undefined') return; //line, do not show it
						
					   // add code to create tooltip/popup
					   popup = new OpenLayers.Popup.FramedCloud(
						  "",
						  feature.geometry.getBounds().getCenterLonLat(),
						  new OpenLayers.Size(100,100),
						  "<div>some text here</div>"+feature.attributes.name,
						  null,
						  true,
						  null);

					   feature.popup = popup;

					   map.addPopup(popup);
					   // return false to disable selection and redraw
					   // or return true for default behaviour
					   return true;
					},
					onUnselect: function(feature) 
					{
					   // remove tooltip
					   map.removePopup(feature.popup);
					   feature.popup.destroy();
					   feature.popup=null;
					}
				}	);

				map.addControl(selectControl);
				selectControl.activate();
			
               map.setCenter(new OpenLayers.LonLat(-109.370078125,
43.39484375), 4);
  

Thank you very much 

Alex

--
View this message in context: http://osgeo-org.1560.n6.nabble.com/Why-does-OpenLayers-Layer-WMS-shows-vectors-well-and-OpenLayers-Layer-OSM-does-not-Same-code-tp4915184p4916215.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list