简体   繁体   English

Vuelayers vl-style-icon 语法

[英]Vuelayers vl-style-icon syntax

I've been looking through the vuelayers documentation and have found little info on to use the vl-style-icon module, which is quite important if you want to create icons on your vuelayer map.我一直在查看 vuelayers 文档,但几乎没有发现使用 vl-style-icon 模块的信息,如果您想在 vuelayer 地图上创建图标,这非常重要。

I'm pretty sure I have proper syntax when it comes to using it but marker.png won't load in through it.我很确定在使用它时我有正确的语法,但marker.png不会通过它加载。 I've tried accessing it as just a normal image and it works fine so it is to my assumption that it's something with my syntax.我已经尝试将它作为普通图像访问并且它工作正常,所以我假设它与我的语法有关。

Here is my code:这是我的代码:

<template>
  <vl-map :load-tiles-while-animating="true" :load-tiles-while-interacting="true" style="height: 400px">
    <vl-view :zoom.sync="zoom" :center.sync="center" :rotation.sync="rotation" projection="EPSG:4326"></vl-view>
    <vl-feature v-for="crime in crimePoints" :key="crime.id">
      <vl-geom-point :coordinates="crime.coords"></vl-geom-point>
      <vl-style-box>
        <vl-style-icon src="./marker.png" :scale="0.4" :anchor="[0.5, 1]"></vl-style-icon>
      </vl-style-box>
    </vl-feature>
    <vl-layer-tile>
      <vl-source-osm></vl-source-osm>
    </vl-layer-tile>
  </vl-map>
</template>

vl-style-box and vl-style-icon are the main points here. vl-style-boxvl-style-icon是这里的重点。 I have also checked to see if the points come up without vl-style-box and they do.我还检查了点是否在没有vl-style-box ,并且确实如此。 What could be wrong with my code?我的代码可能有什么问题?

You can try like this:你可以这样试试:

<vl-style-icon :src="require('./marker.png')" :scale="0.4" :anchor="[0.5, 1]"></vl-style-icon>
  </vl-style-box>

If you used Vue CLI to create your vue project include this in your vue.config.js file.如果您使用 Vue CLI 创建您的 vue 项目,请将包含在您的vue.config.js文件中。 First section tells webpack to parse url attribute on custom tags other than what is already configured ( Source ).第一部分告诉 webpack 解析自定义标签上的 url 属性,而不是已经配置的( Source )。

module.exports = {
  chainWebpack: config => {
    config.module.rule('vue').use('vue-loader').tap(options => {
      options.transformAssetUrls = {
        'vl-style-icon': 'src',
        ...options.transformAssetUrls,
      };
      return options;
    });
  }
}

Run the following command to verify the correct vue-loader configuration is there Source运行以下命令来验证正确VUE装载机配置有

vue inspect > output.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM