[OpenLayers-Users] Layer rendering
Carlos Pinto
cmspinto at gmail.com
Wed Mar 5 05:51:34 EST 2008
Hi all,
Maybe it is a problem with my install of OpenLayers, I have version 2.5
But this exemple don't show the Markers in my computer,
It shows the map but not the markers, shoud I download the version 2.6?
what am I doing wrong?
Thanks, Carlos
<link rel="stylesheet" href="../OpenLayer/theme/default/style.css"
type="text/css" />
<style type="text/css">
#map {
width: 800px;
height: 400px;
border: 1px solid black;
}
</style>
<script src="../OpenLayer/lib/OpenLayers.js"></script>
<script type="text/javascript">
var map, layer;
function init(){
map = new OpenLayers.Map('map', {maxResolution:'auto'});
var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
map.addLayer(wms);
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
// create 20 random features with a random type attribute. The
// type attribute is a value between 0 and 2.
var features = new Array(20);
for (var i=0; i<20; i++) {
features[i] = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(Math.random()*360-180,
Math.random()*180-90),
{type: parseInt(Math.random()*3)}
);
}
// create a styleMap with a custom default symbolizer
var styleMap = new OpenLayers.StyleMap({
fillOpacity: 1,
pointRadius: 10
});
// create a lookup table with different symbolizers for 0, 1 and
2
var lookup = {
0: {externalGraphic: "../OpenLayer/img/marker-blue.png"},
1: {externalGraphic: "../OpenLayer/img/marker-green.png"},
2: {externalGraphic: "../OpenLayer/img/marker-gold.png"}
}
// add rules from the above lookup table, with the keyes mapped
to
// the "type" property of the features, for the "default" intent
styleMap.addUniqueValueRules("default", "type", lookup);
layer = new OpenLayers.Layer.Vector('Points', {
styleMap: styleMap
});
layer.addFeatures(features);
map.addLayer(layer);
}
</script>
On Fri, Feb 29, 2008 at 12:10 PM, Andreas Hocevar <andreas.hocevar at gmail.com>
wrote:
> Carlos,
>
> Carlos Pinto wrote:
> > I have try to use SLD but I was missing something.
> >
> > Then I try to apply the style and wen I put this line:
> >
> >
> > var styleMap = new OpenLayers.StyleMap(OpenLayers.Util.extend(
> > {fillColor: "green", fillOpacity: 1, strokeColor: "black"},
> > OpenLayers.Feature.Vector.style["default"]);
> >
> > the map just stop working :(
>
> There is nothing wrong with this style map definition. Also, if you just
> add this line, nothing should stop working, because you do not apply
> this style map to a layer.
>
> But are you using SLD or are you defining your StyleMap in JavaScript?
>
>
> > The problem is so simple and I can't get a solution, I have a gml file
> > with 300 polygons but with only 20 classes and I just want to make
> > each class with diferent collor, in this example I have two squares
> > with class 2 should be red and class 3 green but when I make load the
> > sld file for this simple example nothing happens and when I try the
> > style the map doesn't show, the gml file:
>
> Which attribute holds your class? I don't see it in your GML. The only
> "2" and "3" I see is in your fid (feature id), and if you have multiple
> features with the same fid, map rendering will probably fail because of
> that. The fid is supposed to be a unique id.
>
> Also, where are you loading your SLD? What does it look like? Maybe you
> can share an URL, that would make it easier to see your problem.
>
> But your requirement is now 100% covered by
> http://www.openlayers.org/dev/examples/styles-unique.html
>
> Maybe you want to have a look at that and see if that works for you. No
> need to use SLD in that case.
>
> Regards,
> Andreas.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20080305/77a1ea95/attachment.html
More information about the Users
mailing list