-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a871e7
commit 797527a
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<div id='map'></div> | ||
|
||
<script> | ||
var map = new mapboxgl.Map({ | ||
container: 'map', | ||
style: 'mapbox://styles/mapbox/streets-v9', | ||
zoom: 1 | ||
}); | ||
|
||
map.on('load', function() { | ||
// Add GeoJSON data | ||
map.addSource('source', { | ||
"type": "geojson", | ||
"data": { | ||
"type": "Feature", | ||
"properties": {}, | ||
"geometry": { | ||
"type": "Polygon", | ||
"coordinates": [[ | ||
[-30, -25], | ||
[-30, 35], | ||
[30, 35], | ||
[30, -25], | ||
[-30, -25] | ||
]] | ||
} | ||
} | ||
}); | ||
|
||
// Load an image to use as the pattern | ||
map.loadImage('https://upload.wikimedia.org/wikipedia/commons/thumb/6/60/Cat_silhouette.svg/64px-Cat_silhouette.svg.png', function(err, image) { | ||
// Throw an error if something went wrong | ||
if (err) throw err; | ||
|
||
// Declare the image | ||
map.addImage('pattern', image); | ||
|
||
// Use it | ||
map.addLayer({ | ||
"id": "pattern-layer", | ||
"type": "fill", | ||
"source": "source", | ||
"paint": { | ||
"fill-pattern": "pattern" | ||
} | ||
}); | ||
}); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/*--- | ||
title: Add a pattern to a polygon | ||
description: Use [fill-pattern](https://docs.mapbox.com/mapbox-gl-js/style-spec/#paint-fill-fill-pattern) to draw a polygon from a repeating image pattern. | ||
tags: | ||
- layers | ||
pathname: /mapbox-gl-js/example/fill-pattern/ | ||
---*/ | ||
import Example from '../../components/example'; | ||
import html from './fill-pattern.html'; | ||
export default Example(html); |