Hello,
I just started working with OpenLayers because I want to include a map on my JSF page (.xhtml files). I want to use the same feature that is demonstrated in this example:
http://openlayers.org/dev/examples/styles-context.html
I played with the code a little bit in the html example files that come with the .zip download.
When I copied the code into my JSF .xhtml page, the map appears but the markers are not displayed. Here is the example code:
<script type="text/javascript">
//<![CDATA[
var map;
function init(){
map = new OpenLayers.Map('map', {maxResolution:'auto'});
var wms = new OpenLayers.Layer.WMS.InlineXhtml( "OpenLayers WMS",
"http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic', format: 'image/svg+xml'} );
map.addLayer(wms);
// create 50 random features in the northern hemisphere
// give them a "type" attribute that will be used to style
// them by size
var features = new Array(50);
for (var i=0; i<features.length; i++) {
features[i] = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(
(360 * Math.random()) - 180, 90 * Math.random()
), {
type: 5 + parseInt(5 * Math.random())
}
);
}
// allow testing of specific renderers via "?renderer=Canvas", etc
var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;
// create the layer styleMap with a simple symbolizer template
yer1 = new OpenLayers.Layer.Vector('Points', {
styleMap: new OpenLayers.StyleMap({
pointRadius: "${type}", // based on feature.attributes.type
fillColor: "#000000"
}),
renderers: renderer
});
layer1.addFeatures(features);
map.addLayers([layer1]);
map.zoomToExtent(layer1.getDataExtent());
}
//]]>
</script>
I added:
map.zoomToExtent(layer1.getDataExtent());
and changed the markers from 50 random to 2 markers of the coordinates of London and Berlin. And the map was centered exactly to show them, but the markers are still not displayed. But that proves that the markers are read and loaded to the map correctly, just not displayed. If I do the same back in the example .html page the map is again centered properly and the markers are displayed.
Is it the problem of xhtml? How to fix this?
asked
10 May '12, 14:57
srd_pl
11●1●1●2
accept rate:
0%