Coder Social home page Coder Social logo

openlayer简易教程 about blog HOT 1 CLOSED

rottenpen avatar rottenpen commented on June 12, 2024
openlayer简易教程

from blog.

Comments (1)

rottenpen avatar rottenpen commented on June 12, 2024

生成线段

先来介绍最简单的生成线段,首先需要数据。
openlayers 的图层由 vector 组成,而 vector 里由 features 组成的。

// 生成 vector
let source = new ol.source.Vector()
// 生成 features
function createFeature ({type = 'Point', coordinates = [0, 0]}) {
  return new ol.Feature({
    geometry: new ol.geom[type](coordinates)
  })
}
// 为 vector 添加 features
source.addFeature(feature)
// 或者在生成 vector 的时候就添加 features
let Features = new ol.layer.Vector({
        source: new ol.source.Vector({
          features: Features // 注意:Features 是数组
        }),
        zIndex: 100
      })
  createDashFeatures ({features: featuresList} = {}, options = {}) { // 生成虚线
    let features = []
    for (let feature of featuresList) {
      let olFeature
      olFeature = createFeature({ 
        type: feature.geometry.type,
        coordinates: feature.geometry.coordinates
      })
      olFeature.setStyle(new ol.style.Style({
        fill: new ol.style.Fill({
          color: '#0044CC'
        }),
        stroke: new ol.style.Stroke({
          lineDash: [10, 10, 10, 10, 10, 10],
          color: options.color || '#ffd700',
          width: 4
        })
      })
      )
      olFeature.data = feature
      features.push(olFeature)
    }
    return features
  }

from blog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.