Home > Software engineering >  (Uncaught ReferenceError: defaultInteractions is not defined) How Can I Add "Translate Features
(Uncaught ReferenceError: defaultInteractions is not defined) How Can I Add "Translate Features

Time:06-22

I'm new to Openlayers. While I was using Node.js, my codes were working fine. But I ran into some problems when I switched to Asp.Net Core.

I learned that when calling modules to use them in Asp.Net Core I need to add some prefixes to their heads.

For example to be able to use the "Map" module:

const map = new ol.Map({ });

But I don't know what prefix I should add before "defaultInteractions()" in this line

interactions: defaultInteractions().extend([select, translate]),

Here is my Map code snippet

const map = new ol.Map({
    interactions: defaultInteractions().extend([select, translate]),
    layers: [
        new ol.layer.Image({
            source: new ol.source.ImageStatic({
                url: 'https://imgs.xkcd.com/comics/online_communities.png',
                projection: projection,
                imageExtent: extent,
            }),
        }),
        rasterLayer, vectorLayer
    ],
    target: 'map',
    view: new ol.View({
        projection: projection,
        center: ol.extent.getCenter(extent),
        zoom: 2,
        maxZoom: 8,
    }),
});

When I ctrl left click on defaultInteraction(), the ol.interaction.js page opens,

When I ctrl left click on extend([select, translate]) the ol.Collection.js page opens.

But both are not working.

Here is the error i got

Thanks in advance and have a good day <(^.^)>

CodePudding user response:

[solved] I changed the line to:

interactions: ol.interaction.defaults().extend([select, translate]),
  • Related