Geometry disappear and no show in openlayer map
See original GitHub issueDescribe the bug I have a really weird behavior when I add polygon on the map. I cope the code from https://openlayers.org/en/latest/examples/geojson.html
What I did is basically add three different sizes polygons to the map. However three polygons have three behavior .
- one appears normally (I put a //beijing comment right before the data for this polygon)
- one disappear after zoom in (I put a //ocean comment right before the data for this polygon)
- one never shows up (I put a //seattlecomment right before the data for this polygon)
To Reproduce copy the code below and put that in any openlayer app
import "ol/ol.css";
import Circle from "ol/geom/Circle";
import Feature from "ol/Feature";
import GeoJSON from "ol/format/GeoJSON";
import Map from "ol/Map";
import View from "ol/View";
import { Circle as CircleStyle, Fill, Stroke, Style } from "ol/style";
import { OSM, Vector as VectorSource } from "ol/source";
import { Tile as TileLayer, Vector as VectorLayer } from "ol/layer";
import { Polygon } from "ol/geom";
var geojsonObject = {
type: "FeatureCollection",
crs: {
type: "name",
properties: {
name: "EPSG:3857",
},
},
features: [
{
type: "Feature",
geometry: {
type: "Point",
coordinates: [0, 0],
},
},
{
type: "Feature",
geometry: {
type: "LineString",
coordinates: [
[4e6, -2e6],
[8e6, 2e6],
],
},
},
{
type: "Feature",
geometry: {
type: "LineString",
coordinates: [
[4e6, 2e6],
[8e6, -2e6],
],
},
},
{
type: "Feature",
geometry: {
type: "Polygon",
coordinates: [
[
[-5e6, -1e6],
[-4e6, 1e6],
[-3e6, -1e6],
],
],
},
},
{
type: "Feature",
geometry: {
type: "MultiLineString",
coordinates: [
[
[-1e6, -7.5e5],
[-1e6, 7.5e5],
],
[
[1e6, -7.5e5],
[1e6, 7.5e5],
],
[
[-7.5e5, -1e6],
[7.5e5, -1e6],
],
[
[-7.5e5, 1e6],
[7.5e5, 1e6],
],
],
},
},
{
type: "Feature",
geometry: {
type: "MultiPolygon",
coordinates: [
[
[
[-5e6, 6e6],
[-5e6, 8e6],
[-3e6, 8e6],
[-3e6, 6e6],
],
],
[
// ocean
[
[24450065.111636, 5579291.568592],
[25448026.952927, 5364044.896941],
[24816962.847405, 4507950.180147],
],
],
[
//beijing
[
[12956472.811422, 4853889.241058],
[12956636.434435, 4853874.909115],
[12956580.300993, 4853831.913287],
],
],
[
//seattle
[
[26455839.616239, 6042958.582169],
[26457148.600348, 6042949.027541],
[26456919.289263, 6041439.396232],
],
],
[
[
[1e6, 6e6],
[1e6, 8e6],
[3e6, 8e6],
[3e6, 6e6],
],
],
],
},
},
{
type: "Feature",
geometry: {
type: "GeometryCollection",
geometries: [
{
type: "LineString",
coordinates: [
[-5e6, -5e6],
[0, -5e6],
],
},
{
type: "Point",
coordinates: [4e6, -5e6],
},
{
type: "Polygon",
coordinates: [
[
[1e6, -6e6],
[2e6, -4e6],
[3e6, -6e6],
],
],
},
],
},
},
],
};
const vectorSource = new VectorSource({
features: new GeoJSON().readFeatures(geojsonObject),
});
var GEOLayer = new VectorLayer({
source: vectorSource,
//style: styleFunction,
});
const map = new Map({
target: "map",
layers: [
new TileLayer({
source: new OSM(),
}),
],
view: new View({
center: [0, 0],
zoom: 2,
}),
});
map.addLayer(GEOLayer);
Expected behavior Three polygon should all appear and will not disappear when I zoom in/out
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Openlayers 3 - how to keep features from disappear when ...
ol.layer.Vector has a property called renderBuffer . This property will prevent the icons from disappearing if you set this to the pixel value...
Read more >Disappearing shapes after selection · Issue #10008 - GitHub
Sometimes shapes disappear after selection. Let's say that we have piece of map with ~1000 objects. We select one of them then move...
Read more >Polygons disappear after drawing in TMS Layered openlayers ...
As soon as I draw the polygon or place the point on the map, the polygon/point disappears. Am I missing anything? How do...
Read more >OpenLayers v7.2.2 API - Class: Layer
A visual representation of raster or vector map data. Layers group together those properties that pertain to how the data is to be...
Read more >Integrating an OpenLayers map in Vue.js, a step-by-step guide
On the other hand, you may or may not have heard about OpenLayers, ... see it appear on the map; edit an object...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This should do:
So helpful!!! Really appreciate your help!