[mapguide-users] remove feature problem

Zac Spitzer zac.spitzer at gmail.com
Tue Sep 11 02:37:32 PDT 2012


looks like both your vectorLayer and feature are var scoped within
your init function,
i.e. not a global variable, so they aren't defined in remove()

anyway, it's a javascript problem, what did the problem the browser report?

(dev tools, javascript console, firebug etc)

On Tue, Sep 11, 2012 at 7:33 PM, jackyfox <htrforum at gmail.com> wrote:
> how to remove vector feature?
>
> body onload the map
> after that click drop down menu(onchange) remove it.
> but i cant remove feature
>
> any mistake with my code?
> thanks~~!!
>
> sample code as below:
>
> *javascript*
>
>
> var map, layer;
>         //var url =
> "http://data.mapguide.com/mapguide/mapagent/mapagent.fcgi?USERNAME=Anonymous&";
>         //you can use this URL when MapGuide OS is installed locally
>         var url = "http://localhost:8008/mapguide/mapagent/mapagent.fcgi";
>
>         //Adjust the scale assumptions for MapGuide layers
>         //Tiled layers MUST use a DPI value of 96, untiled layers can use a
>         //different DPI value which will be passed to the server as a parameter.
>         //Tiled and untiled layers must adjust the OL INCHES_PER_UNIT values
>         //for any degree-based projections.
>         var metersPerUnit = 1;  //value returned from mapguide
>         var inPerUnit = OpenLayers.INCHES_PER_UNIT.m * metersPerUnit;
>         OpenLayers.INCHES_PER_UNIT["dd"] = inPerUnit;
>         OpenLayers.INCHES_PER_UNIT["degrees"] = inPerUnit;
>         OpenLayers.DOTS_PER_INCH = 96;
>
>
>         function init() {
>
>           var extent = new OpenLayers.Bounds(-180,-80,180,80);
>           var mapOptions = {
>                         maxExtent: extent,
>                         controls: [
>                                 new OpenLayers.Control.Navigation(),
>                                 new OpenLayers.Control.PanZoomBar(),
>                                 new OpenLayers.Control.MousePosition()
>                         ]
>           };
>
>
>           map = new OpenLayers.Map( 'map', mapOptions );
>
>
>           var options = {
>                  singleTile: true,
>                  isBaseLayer: true,
>                  visibility: true,
>                  /* useAsyncOverlay: true, */ //<- remove
>                  //useOverlay:true
>           };
>
>
>           var params = {
>                   mapdefinition: 'Library://sample/Maps/sample.MapDefinition'
>           };
>
>
>
>           var layer = new OpenLayers.Layer.MapGuide( "sample", url, params, options
> );
>           map.addLayer(layer);
>
>
>           var vectorLayer = new OpenLayers.Layer.Vector("vector layer1");
>                 var feature = new OpenLayers.Feature.Vector(
>                  new OpenLayers.Geometry.Point(180,80),
>                  {some:'data'},
>                  {externalGraphic: 'images/car1.png', graphicHeight: 21, graphicWidth:
> 16});
>                 vectorLayer.addFeatures(feature);
>                 map.addLayer(vectorLayer);
>
>
>
>           map.addControl(new OpenLayers.Control.LayerSwitcher());
>           map.zoomToMaxExtent();
>           map.setCenter(new OpenLayers.LonLat(180,80), 4);
>
> }
>
>
> function remove(sel){
>         vectorLayer.removeFeatures(feature);
> }
>
>
>
>
>
>
> *html part*
> <body onload="init();">
>
> <div>
>
> <select id="sel" name="sel"
> onchange="remove(this.value)"><option></option><option
> value="Y">Remove</option></select>
>
>
> <div id="map" >
> </div>
>
> </div>
>
> </body>
>
>
>
>
>
> --
> View this message in context: http://osgeo-org.1560.n6.nabble.com/remove-feature-problem-tp5001007.html
> Sent from the MapGuide Users mailing list archive at Nabble.com.
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapguide-users



-- 
Zac Spitzer
Solution Architect / Director
Ennoble Consultancy Australia
+61 405 847 168


More information about the mapguide-users mailing list