npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

maptalks.query

v0.1.2

Published

[maptalks](https://github.com/maptalks/maptalks.js) layers data query tool * Request [maptalks-gl](https://github.com/maptalks/maptalks-gl-layers) version>0.98.0, current version 0.98.0 has a bug [vt _convertGeometry](https://github.com/maptalks/issues

Downloads

14

Readme

maptalks.query

maptalks layers data query tool

Features

  • support simple data filter. such as keyword query

  • support spatial query

  • support layers:

    • VectorLayer
    • PointLayer
    • LineStringLayer
    • PolygonLayer
    • VectorTileLayer
    • GeoJSONVectorTileLayer
    • ...
  • Time slicing to solve the problem of large data volume lag

Examples

Install

NPM

npm i maptalks-gl
npm i maptalks.query

CDN

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/maptalks-gl/dist/maptalks-gl.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/maptalks.query/dist/maptalks.query.js"></script>
<!-- if need spatial query -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jsts.min.js"></script>

API

injectJSTS(jsts)

Inject jsts namespace. If you need spatial query, this is necessary

import * as jsts from 'jsts';
import {
    injectJSTS
} from 'maptalks.query';

injectJSTS(jsts);

Query class

layers query tool Class

constructor(map, options)

 new Query(map, options)
  • map: maptalks Map
  • options:config object
    • options.log: Whether to output logs when calculation errors occur
 const query = new Query(map, {
     log: true
 })
import {
    Map,
    TileLayer,
    Polygon
} from 'maptalks-gl';
import {
    Query,
    injectJSTS
} from 'maptalk.query';
import * as jsts from 'jsts';

injectJSTS(jsts);

const mapView = {
    'center': [120.54069005, 31.14989446],
    'zoom': 9.49995108663881,
    'pitch': 0,
    'bearing': 0
};
// create map
const map = new Map('map1', {
    ...mapView,
    baseLayer: new TileLayer('base', {
        urlTemplate: 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
        subdomains: ['a', 'b', 'c', 'd'],
        attribution: '&copy; <a href="http://osm.org">OpenStreetMap</a> contributors, &copy; <a href="https://carto.com/">CARTO</a>'
    })
});
//create query instance 
const query = new Query(map, {
    log: true
});

methods

  • query(options) simple data filter query. Keyword search, etc, return Promise
    • options.filter:data filter function
    • options.layers: The layer to be queried, if empty, will query all layers on the map
function getPropties(geo) {
    let properties = geo.getPropties ? geo.getPropties() : geo.properties;
    properties = properties || {};
    if (properties.__original_properties) {
        return properties.__original_properties;
    }
    return properties;
}

query.query({
    filter: (geo, layer) => {
        const properties = getPropties(geo);
        const name = properties.name;
        //mock simple keyword query
        return name && name.includes('hello world');
    },
    layers: [layer, layer1, ...otherlayers]
}).then(result => {
    console.log(result);
    //do some things
}).catch(error => {
    console.error(error);
});
  • spatialQuery(options) Geometric spatial query . return Promise

    • options.geometry: Input query geometry, maptalks. Polygon/maptalks. Circle/maptalks. Rectangle...

    • options.filter data filter function if need

    • options.layers: The layer to be queried, if empty, will query all layers on the map

    • options.op Geometric Shape Relationship Query Operation, default value is Query.intersects
      op support list:

      • Query.contains
      • Query.crosses
      • Query.disjoint
      • Query.equals
      • Query.intersects
      • Query.contains
      • Query.overlaps
      • Query.within
injectJSTS(jsts);

const polygon = new Polygon([...]);
query.spatialQuery({
    geometry: polygon,
    layers: [layer, layer1, ...otherlayers]
    op: Query.intersects
}).then((result) => {
    console.log(result);
    //do some things
}).catch(error => {
    console.error(error);
});
  • dispose()
query.dispose();