I added a fiddle here: https://jsfiddle.net/gnsmq2t9/

I am new here, and new to GIS I am building an app, and I want to put a polygon around different sections that will allow the user to click and zoom into that section.

How do I get my polygon to appear?

I am not getting any console errors.

Here is my source/feature

    var myOtherVectorSource = new ol.source.Vector({});
    var polyCoords = [
        ol.proj.transform([-121.901559, 37.417891], 'EPSG:4326', 'EPSG:3857'),
        ol.proj.transform([-121.901139, 37.416427], 'EPSG:4326', 'EPSG:3857'),
        ol.proj.transform([-121.899634, 37.416678], 'EPSG:4326', 'EPSG:3857'),
        ol.proj.transform([-121.900312, 37.418398], 'EPSG:4326', 'EPSG:3857'),
        ol.proj.transform([-121.901559, 37.417891], 'EPSG:4326', 'EPSG:3857')
    var pLotSection1 = new ol.geom.Polygon([
    var pLotSection1Feature = new ol.Feature({
        name: 'Parking Lot One',
        geometry: pLotSection1

Here is my layer

var myOtherVectorLayer = new ol.layer.Vector({
        source: myOtherVectorSource

And my map

myLayers = [myStaticImageLayer, myVectorLayer, myOtherVectorLayer];

    //set the view, center, and zoom level
    var myView = new ol.View({
        center: ol.proj.transform([-121.896436, 37.413208], 'EPSG:4326', 'EPSG:3857'),
        zoom: 19,
        enableRotation: false,
        constrainRotation: 0
    var map = new ol.Map({
        target: 'mymap',
        layers: myLayers,
        view: myView

I have another vector/feature layer that I am plotting similarly, and that is showing up perfect.


1 Answer 1


You put your polyCoords into 2 arrays when one is enough.

var pLotSection1 = new ol.geom.Polygon([polyCoords]);

then chane the default zoom view to 14 instead of 19

var myView = new ol.View({
  center: ol.proj.transform([-121.896436, 37.413208], 'EPSG:4326', 'EPSG:3857'),
  zoom: 14,
  enableRotation: false,
  constrainRotation: 0

See jsfiddle

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.