[OpenLayers-Users] Re: GeoJSON Fill Colors
pday
pday at mitre.org
Mon Jun 20 09:31:24 EDT 2011
Thanks Nizzok. Functional changes are below for anyone interested in the init
function changes:
function init(){
map = new OpenLayers.Map( 'map' );
layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://vmap0.tiles.osgeo.org/wms/vmap0",
{layers: 'basic'} );
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
var featurecollection = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry":
{
type: "Polygon",
coordinates:
[[
[-14.7656, 73.0309],
[-30.2344, 46.0929],
[-9.8438, -47.9709],
[-94.9219, -59.1614],
[-124.4531, -18.6194],
[-155.3906, 45.6031],
[-137.1094, 75.3272]
]]
},
"properties": {"fillColor": "#0000FF"}
},
{
"type": "Feature",
"geometry":
{
type: "Polygon",
coordinates:
[[
[-106.1719, -28.8968],
[-16.1719, 41.5298],
[39.3750, -37.1377]
]]
},
"properties": {"fillColor": "#CCCC99"}
}
]
};
// Create a styleMap to style your features for two different
// render intents. The style for the 'default' render intent will
// be applied when the feature is first drawn. The style for the
// 'select' render intent will be applied when the feature is
// selected.
var myStyles = new OpenLayers.StyleMap({
"default": new OpenLayers.Style({
fillColor: "${fillColor}",
//fillColor: "#00FF00",
strokeColor: "#00FF01",
fillOpacity: 0.5,
graphicZIndex: 1
}),
"select": new OpenLayers.Style({
fillColor: "#FF0000",
strokeColor: "#3399ff",
graphicZIndex: 2
})
});
var geojson_format = new OpenLayers.Format.GeoJSON();
var vector_layer = new OpenLayers.Layer.Vector("Zones",{
styleMap: myStyles,
rendererOptions: {zIndexing: true},
});
//var vector_layer = new OpenLayers.Layer.Vector();
vector_layer.addFeatures(geojson_format.read(featurecollection));
map.addLayer(vector_layer);
var select = new OpenLayers.Control.SelectFeature(vector_layer, {hover:
true});
map.addControl(select);
select.activate();
}
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/GeoJSON-Fill-Colors-tp6495593p6495765.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
More information about the Users
mailing list