Dear all,
With your help, I think it is fixed. The trick was to use OpenLayers.Util.applyDefaults in the named hash, for both "default" and "select". The code now reads: for(i=0; i<9; i++) { var styleMap = new OpenLayers.StyleMap({"default":OpenLayers.Util.applyDefaults({fillColor: stateColors[i], fillOpacity: 0.4, strokeColor: stateColors[i], strokeWidth:2},OpenLayers.Feature.Vector.style["default"]),"select": OpenLayers.Util.applyDefaults({}, OpenLayers.Feature.Vector.style["select"])}); var laag = new OpenLayers.Layer.GML(stateNames[i], url + stateNames[i] + ".geojson", {format:OpenLayers.Format.GeoJSON, projection: new OpenLayers.Projection("EPSG:28993"), resolutions:ress, visibility:false, styleMap:styleMap}); laag.events.on({"featuremodified": onFeatureModified}); map.addLayer(laag); selectControls[i]=new OpenLayers.Control.SelectFeature(laag,{onSelect: onFeatureSelect, onUnselect:onFeatureUnselect, toggleKey:"ctrlKey", multipleKey:"shiftKey", hover:false, toggle:false, clickout:false, multiple:true, box:false}); map.addControl(selectControls[i]); } This gives me 9 layers all, coloured differently. When a feature is selected, the feature turns blue (OpenLayers default). When browsing with Chrome, you can even select features that are not in the top layer. If the user switches to edit mode, a ModifyFeature control is created and activated: modifyControl = new OpenLayers.Control.ModifyFeature( map.getLayersByName(stateNames[top])[0], {mode: OpenLayers.Control.ModifyFeature.RESHAPE}); map.addControl(modifyControl); modifyControl.activate(); And this works for the top layer (as it was programmed to do), while in Chrome you can still select from the layers below the editable layer. Thanks for all the help. Kind regards, Jan -----Original Message----- From: arnd.wipperm...@web.de [mailto:arnd.wipperm...@web.de] Sent: Monday, December 15, 2008 18:23 To: j.vander...@magion.nl Cc: users@openlayers.org Subject: AW: [OpenLayers-Users] Edit circles not showing when styleMap isspecified There is a property virtualStyle for the ModifyFeature Control. Perhaps this has to set. I do this before I add the controls: OpenLayers.Feature.Vector.style['select']['fillColor'] = 'yellow'; OpenLayers.Feature.Vector.style['select']['strokeColor'] = 'yellow'; var selectStyle = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['select']); ctrlSelectFeature.selectStyle = selectStyle; ctrlModifyFeature.virtualStyle = selectStyle; Arnd Wippermann -----Ursprüngliche Nachricht----- Von: users-boun...@openlayers.org [mailto:users-boun...@openlayers.org] Im Auftrag von Jan van der Ven Gesendet: Montag, 15. Dezember 2008 15:23 An: users@openlayers.org Betreff: Re: [OpenLayers-Users] Edit circles not showing when styleMap isspecified Dear Alexandre, Thanks for the quick reply. I tried it out right away, and modified the code as shown below: function addGeoJSONLayers() { for(i=0; i<nLayers; i++) { mystyles = new OpenLayers.StyleMap( { "default": new OpenLayers.Style({ }) }); myrules = new OpenLayers.Rule({symbolizer:{fillColor:stateColors[i], strokeColor:stateColors[i], strokeWidth:2, fillOpacity:0.4}, elseFilter:true}); mystyles.styles["default"].addRules(myrules); var laag = new OpenLayers.Layer.GML(stateNames[i], biskurl + "html/kml/" + stateNames[i] + ".geojson", {format:OpenLayers.Format.GeoJSON, projection: new OpenLayers.Projection("EPSG:28993"), resolutions:ress, visibility:false, styleMap:mystyles }); [...] Unfortunately, the behavior still is that the handles do not appear. Kind regards, Jan -----Original Message----- From: Alexandre Dube [mailto:ad...@mapgears.com] Sent: Monday, December 15, 2008 14:56 To: j.vander...@magion.nl Cc: users@openlayers.org Subject: Re: [OpenLayers-Users] Edit circles not showing when styleMap is specified Hi Jan, I also had this problem and resolved it by adding theses lines : rules = [new OpenLayers.Rule({ symbolizer: {strokeColor:"red",strokeWidth: 2}, elseFilter: true })]; styles.styles["default"].addRules(rules); Hope this helps, Alexandre Jan van der Ven wrote: > Dear list, > > > > I have a map to which I add nine vector layers (all polygons). The > layers all should have their own color for rendering the features. I > have too many features to put them all in one layer, and use an > attribute to style them. > > The code I have for this is as follows: > /** > * Add the GeoJSON Layers > **/ > function addGeoJSONLayers() > { > for(i=0; i<nLayers; i++) > { > var styles = new OpenLayers.StyleMap({ > "default": new OpenLayers.Style({ > fillColor:stateColors[i], > strokeColor:stateColors[i], > strokeWidth:2, > fillOpacity:0.4 > }) > }); > var laag = new OpenLayers.Layer.GML(stateNames[i], url + > "html/kml/" + stateNames[i] + ".geojson", {format:OpenLayers.Format.GeoJSON, projection: > new OpenLayers.Projection("EPSG:28993"), resolutions:ress, > visibility:false, styleMap:styles}); > laag.events.on({"featuremodified": onFeatureModified}); > map.addLayer(laag); > > // These are the ones the user may work with > selectControls[i]=new OpenLayers.Control.SelectFeature(laag,{onSelect: > onFeatureSelect, onUnselect:onFeatureUnselect, toggleKey:"ctrlKey", > multipleKey:"shiftKey", hover:false, toggle:false, clickout:false, > multiple:true, box:false}); > map.addControl(selectControls[i]); > } > } > > I know only the topmost layer has an 'active' selectControl. > > There is a button that the user can click to go from "select" mode to "edit" > mode. This essentially turns off all selectControls and creates and > activates a ModifyFeature control for the top layer: > modifyControl = new > OpenLayers.Control.ModifyFeature(map.getLayersByName(stateNames[top])[ > 0], {mode:OpenLayers.Control.ModifyFeature.RESHAPE}); > map.addControl(modifyControl); > modifyControl.activate(); > > The problem is that if the styleMap entry is present when creating the > layer, the edit handles (the circles) do not become visible and the > mouse cursor does not changes when moving to the corners of the > polygon. But, if I comment out the styleMap, like so: > > var laag = new OpenLayers.Layer.GML(stateNames[i], url + > "html/kml/" + stateNames[i] + ".geojson", {format:OpenLayers.Format.GeoJSON, projection: > new OpenLayers.Projection("EPSG:28993"), resolutions:ress, > visibility:false /*, styleMap:styles*/}); > > It works as expected. > > My questions are: > 1) Is this the right way to set the color for a layer? > 2) If so, why would that influence the ModifyFeature control? > 3) What can I do to fix this? > > Thanks in advance. > > Kind regards, > > > > Jan van der Ven > > > _______________________________________________ > Users mailing list > Users@openlayers.org > http://openlayers.org/mailman/listinfo/users > -- Alexandre Dubé Mapgears www.mapgears.com No virus found in this incoming message. Checked by AVG - http://www.avg.com Version: 8.0.176 / Virus Database: 270.9.16/1842 - Release Date: 14-12-2008 12:28 _______________________________________________ Users mailing list Users@openlayers.org http://openlayers.org/mailman/listinfo/users No virus found in this incoming message. Checked by AVG - http://www.avg.com Version: 8.0.176 / Virus Database: 270.9.18/1848 - Release Date: 14-12-2008 12:28 _______________________________________________ Users mailing list Users@openlayers.org http://openlayers.org/mailman/listinfo/users