0

I am trying to get popups from the ArcGIS API JS to display using the framework Vue-CLI 3. But even with a simple sample code, I cannot make it work: Here is the code in vanilla JS:

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
    <title>Popup actions | Sample | ArcGIS API for JavaScript 4.17</title>

    <style>
        html,
        body,
        #viewDiv {
            padding: 0;
            margin: 0;
            height: 100%;
            width: 100%;
        }
    </style>

    <link rel="stylesheet" href="https://js.arcgis.com/4.17/esri/themes/light/main.css" />
    <script src="https://js.arcgis.com/4.17/"></script>

    <script>
        require([
            "esri/Map",
            "esri/layers/FeatureLayer",
            "esri/views/MapView",
            "esri/geometry/geometryEngine"
        ], function (Map, FeatureLayer, MapView, geometryEngine) {
            // Create the Map
            var map = new Map({
                basemap: "gray-vector"
            });

            // Create the MapView
            var view = new MapView({
                container: "viewDiv",
                map: map,
                center: [-117.08, 34.1],
                zoom: 11
            });

            var template = {
                // autocasts as new PopupTemplate()
                title: "Trail run",
                content: "{name}",
            };

            var featureLayer = new FeatureLayer({
                url:
                    "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/TrailRuns/FeatureServer/0",
                outFields: ["*"],
                popupTemplate: template,
            });
            map.add(featureLayer);
        });
    </script>
</head>

<body>
    <div id="viewDiv"></div>
</body>

</html>

As you can see, when clicking a feature, a popup appears.

If I try to implement this in my vue-CLI project I can not make it work. When clicking on the a feature, it will highlight, but nothing will open. Here is my code .vue:

<template>
    <div></div>
</template>

<script>
    import { loadModules } from "esri-loader";

    export default {
        name: "web-map",
        mounted() {
            // lazy load the required ArcGIS API for JavaScript modules and CSS
            loadModules([
                "esri/Map",
                "esri/views/MapView",
                "esri/layers/FeatureLayer",
            ]).then(([ArcGISMap, MapView, FeatureLayer]) => {
                const map = new ArcGISMap({
                    basemap: "topo-vector",
                });

                this.view = new MapView({
                    container: this.$el,
                    map: map,
                    center: [-117.08, 34.1],
                    zoom: 11,
                });

                var template = {
                    // autocasts as new PopupTemplate()
                    title: "Trail run",
                    content: "{name}",
                };

                var featureLayer = new FeatureLayer({
                    url:
                        "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/TrailRuns/FeatureServer/0",
                    outFields: ["*"],
                    popupTemplate: template,
                });
                map.add(featureLayer);
            });
        },
        beforeDestroy() {
            if (this.view) {
                // destroy the map view
                this.view.destroy();
            }
        },
    };
</script>

<style scoped>
    div {
        padding: 0;
        margin: 0;
        width: 100%;
        height: 100%;
    }
</style>

Am I missing something? (I followed arcgis api js tutorial to get it work in vue-cli -https://developers.arcgis.com/javascript/latest/guide/vue/ ) Thank you very much for your help!

Julien

0

1 Answer 1

0

Your code is fine, you are just not adding css. You are missing { css: true }, that's all.

loadModules(
  ["esri/Map", "esri/views/MapView", "esri/layers/FeatureLayer"],
  { css: true } // <-- HERE
).then(([ArcGISMap, MapView, FeatureLayer]) => {
  //...
}

HERE code with the fix.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the answer. When I had this bit of code in ,y script, the ma doesn't appear properly: i.postimg.cc/X7LQC4Xp/arcgis-vue.png I know it is probably a probelm with my css, but I am pretty new at this so if you could help me sort this out, that would be great! Thanks !
Thanks for your help. Indeed it works fine. and I just found out that the display issue came from the fact that I had the router plugin installed and imported in my project. I dont understand why it did that, but at least now I have a clean map. Thanks!
Glad you figure it out!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.