getSource() not a function

22 views
Skip to first unread message

steve...@t1cg.com

unread,
Jan 18, 2018, 12:03:16 PM1/18/18
to OpenLayers Dev
I have defined my own featureOverlay for the purposes of highlighting any polygon layer I hover over.  When I try to make this work with featureOverlay.getSource(), I get the error featureOverlay.getSource() is not a function.  Below is the code where I define my feature Overlay, as well as the functionality for adding the featureOverlay(which is essentially a new Overlay with designated highlight details.  

const featureOverlay = new Overlay({
            source: new VectorSource(),
            zIndex: 0,
            map: map,
            style: new ol.style.Style({
                stroke: new ol.style.Stroke({
                    color: [155, 155, 0],
                    width: 3.5
                }),
                fill: new ol.style.Fill({
                    color: 'rgba(0, 0, 0, 0.8)'
                })
            })
        });

    map.on('pointermove', function(e){



      if (cursorSet) return;
         if (e.dragging) return;
         var pixel = map.getEventPixel(e.originalEvent);
         var hit = map.hasFeatureAtPixel(pixel);
         // console.log("Place break point here")
         if(hit) {
           var feature = map.forEachFeatureAtPixel(e.pixel,function(feature) {
                    if (clicked && feature) {
                        e.map.getTargetElement().style.cursor = hit ? 'pointer' : '';
                        cursorSet = true;
                        return;
                        console.log("clicked and Feature");
                    }
                    featureToRemove = feature;
                    if (!clicked && feature !== highlight) {
                        if (highlight) {
                            featureOverlay.getSource().removeFeature(highlight);
                        }
                        if (!clicked && feature) {
                            featureOverlay.getSource().addFeature(feature);
                        }
                        console.log("Hit me man")
                        highlight = feature;
                    }

                });
            } else {
                console.log("do something ELSE")
            }
  });

Richard Greenwood

unread,
Jan 18, 2018, 5:06:22 PM1/18/18
to OpenLayers Dev
"source" is not listed as a property of ol.Overlay http://openlayers.org/en/latest/apidoc/ol.Overlay.html

The developers prefer that questions are posted on stackoverflow https://stackoverflow.com/questions/tagged/openlayers rather than this list.

Rich


--
You received this message because you are subscribed to the Google Groups "OpenLayers Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openlayers-dev+unsubscribe@googlegroups.com.
To post to this group, send email to openlayers-dev@googlegroups.com.
Visit this group at https://groups.google.com/group/openlayers-dev.
To view this discussion on the web visit https://groups.google.com/d/msgid/openlayers-dev/463fbd76-9b5c-490d-a221-cf1796de6783%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Richard W. Greenwood, PLS
www.greenwoodmap.com
Reply all
Reply to author
Forward
0 new messages